« Module:Autorité » : différence entre les versions
Aller à la navigation
Aller à la recherche
Nouvelle page : function sudocLink( id ) if not string.match( id, '^%d%d%d%d%d%d%d%d%d$' ) then return false end return 'http://www.idref.fr/' .. id end function bnfLink( id ... |
Aucun résumé des modifications |
||
| Ligne 52 : | Ligne 52 : | ||
end | end | ||
function createRow( id, label, rawValue, link ) | function createRow( id, label, rawValue, link, isDepreciated ) | ||
if link then | if link then | ||
local text = '<span class="nowrap uid">[' .. link .. ' ' .. label .. ']</span>' | |||
if isDepreciated then | |||
text = text .. '[[Catégorie:Page utilisant le modèle Autorité avec un paramètre obsolète]]' | |||
end | |||
return text | |||
else | else | ||
return '* <span class="error">L\'indentifiant ' .. id .. ' ' .. rawValue .. ' n\'est pas valide.</span>[[Catégorie:Page utilisant le modèle Autorité avec un paramètre erroné]]' | return '* <span class="error">L\'indentifiant ' .. id .. ' ' .. rawValue .. ' n\'est pas valide.</span>[[Catégorie:Page utilisant le modèle Autorité avec un paramètre erroné]]' | ||
| Ligne 60 : | Ligne 64 : | ||
end | end | ||
--In this order: name of the parameter, label, propertyId in Wikidata, formatting function | --In this order: name of the parameter, label, propertyId in Wikidata, formatting function, boolean if the parameter is depreciated | ||
local conf = { | local conf = { | ||
{ 'SUDOC', 'Système universitaire de documentation', 0, sudocLink }, | { 'SUDOC', 'Système universitaire de documentation', 0, sudocLink }, | ||
| Ligne 68 : | Ligne 72 : | ||
{ 'DNB', 'Bibliothèque nationale allemande', 0, gndLink }, | { 'DNB', 'Bibliothèque nationale allemande', 0, gndLink }, | ||
{ 'GND', 'Gemeinsame Normdatei', 0, gndLink }, | { 'GND', 'Gemeinsame Normdatei', 0, gndLink }, | ||
{ 'PND', 'Personennamendatei', 0, gndLink }, | { 'PND', 'Personennamendatei', 0, gndLink, true }, | ||
{ 'GKD', 'Gemeinsame Körperschaftsdatei', 0, gndLink }, | { 'GKD', 'Gemeinsame Körperschaftsdatei', 0, gndLink, true }, | ||
{ 'GKD-V1', 'Gemeinsame Körperschaftsdatei', 0, gndLink }, | { 'GKD-V1', 'Gemeinsame Körperschaftsdatei', 0, gndLink, true }, | ||
{ 'SWD', 'Schlagwortnormdatei', 0, swdLink } | { 'SWD', 'Schlagwortnormdatei', 0, swdLink } | ||
} | } | ||
| Ligne 85 : | Ligne 89 : | ||
local val = parentArgs[params[1]] | local val = parentArgs[params[1]] | ||
if val and val ~= '' then | if val and val ~= '' then | ||
table.insert( elements, createRow( params[1], params[2] .. ':', val, params[4]( val ) ) ) | table.insert( elements, createRow( params[1], params[2] .. ':', val, params[4]( val ) ), params[5] ) | ||
end | end | ||
end | end | ||
| Ligne 91 : | Ligne 95 : | ||
--Worldcat | --Worldcat | ||
if parentArgs['WORLDCATID'] and parentArgs['WORLDCATID'] ~= '' then | if parentArgs['WORLDCATID'] and parentArgs['WORLDCATID'] ~= '' then | ||
table.insert( elements, createRow( 'WORLDCATID', '', parentArgs['WORLDCATID'], '[http://www.worldcat.org/identities/' .. parentArgs['WORLDCATID'] .. ' WorldCat]' ) ) --Validation? | table.insert( elements, createRow( 'WORLDCATID', '', parentArgs['WORLDCATID'], '[http://www.worldcat.org/identities/' .. parentArgs['WORLDCATID'] .. ' WorldCat]', false ) ) --Validation? | ||
elseif parentArgs['LCCN'] and parentArgs['LCCN'] ~= '' then | elseif parentArgs['LCCN'] and parentArgs['LCCN'] ~= '' then | ||
local lccnParts = splitLccn( parentArgs['LCCN'] ) | local lccnParts = splitLccn( parentArgs['LCCN'] ) | ||
if lccnParts then | if lccnParts then | ||
table.insert( elements, createRow( 'LCCN', '', parentArgs['LCCN'], '[http://www.worldcat.org/identities/lccn-' .. lccnParts[1] .. lccnParts[2] .. '-' .. lccnParts[3] .. ' WorldCat]' ) ) | table.insert( elements, createRow( 'LCCN', '', parentArgs['LCCN'], '[http://www.worldcat.org/identities/lccn-' .. lccnParts[1] .. lccnParts[2] .. '-' .. lccnParts[3] .. ' WorldCat]', false ) ) | ||
end | end | ||
end | end | ||
Version du 26 avril 2013 à 17:34
function sudocLink( id )
if not string.match( id, '^%d%d%d%d%d%d%d%d%d$' ) then
return false
end
return 'http://www.idref.fr/' .. id
end
function bnfLink( id )
--Add cb prefix if it has been removed
if not string.match( id, '^cb.+$' ) then
id = 'cb' .. id
end
return 'http://catalogue.bnf.fr/ark:/12148/' .. id
end
function viafLink( id )
if not string.match( id, '^%d+$' ) then
return false
end
return 'http://viaf.org/viaf/' .. id
end
function lccnLink( id )
local parts = splitLccn( id )
if not parts then
return false
end
id = parts[1] .. parts[2] .. append( parts[3], '0', 6 )
return 'http://id.loc.gov/authorities/names/' .. id
end
function splitLccn( id )
if id:match( '^%l%l?%l?%d%d%d%d%d%d%d%d%d?%d?$' ) then
id = id:gsub( '^(%l+)(%d+)(%d%d%d%d%d%d)$', '%1/%2/%3' )
end
if id:match( '^%l%l?%l?/%d%d%d?%d?/%d+$' ) then
return mw.text.split( id, '/' )
end
return false
end
function append(str, c, length)
while str:len() < length do
str = c .. str
end
return str
end
function gndLink( id )
return 'http://d-nb.info/gnd/' .. id
end
function createRow( id, label, rawValue, link, isDepreciated )
if link then
local text = '[' .. link .. ' ' .. label .. ']'
if isDepreciated then
text = text ..
end
return text
else
return '* L\'indentifiant ' .. id .. ' ' .. rawValue .. ' n\'est pas valide.'
end
end
--In this order: name of the parameter, label, propertyId in Wikidata, formatting function, boolean if the parameter is depreciated local conf = {
{ 'SUDOC', 'Système universitaire de documentation', 0, sudocLink },
{ 'BNF', 'Bibliothèque nationale de France', 0, bnfLink },
{ 'VIAF', 'Fichier d’autorité international virtuel', 0, viafLink },
{ 'LCCN', 'Bibliothèque du Congrès', 0, lccnLink },
{ 'DNB', 'Bibliothèque nationale allemande', 0, gndLink },
{ 'GND', 'Gemeinsame Normdatei', 0, gndLink },
{ 'PND', 'Personennamendatei', 0, gndLink, true },
{ 'GKD', 'Gemeinsame Körperschaftsdatei', 0, gndLink, true },
{ 'GKD-V1', 'Gemeinsame Körperschaftsdatei', 0, gndLink, true },
{ 'SWD', 'Schlagwortnormdatei', 0, swdLink }
}
local p = {}
function p.authorityControl( frame )
local parentArgs = frame:getParent().args
--Create rows
local elements = {}
--Configured rows
for k, params in pairs( conf ) do
local val = parentArgs[params[1]]
if val and val ~= then
table.insert( elements, createRow( params[1], params[2] .. ':', val, params[4]( val ) ), params[5] )
end
end
--Worldcat
if parentArgs['WORLDCATID'] and parentArgs['WORLDCATID'] ~= then
table.insert( elements, createRow( 'WORLDCATID', , parentArgs['WORLDCATID'], '.. parentArgs['WORLDCATID' .. ' WorldCat]', false ) ) --Validation?
elseif parentArgs['LCCN'] and parentArgs['LCCN'] ~= then
local lccnParts = splitLccn( parentArgs['LCCN'] )
if lccnParts then
table.insert( elements, createRow( 'LCCN', , parentArgs['LCCN'], '.. lccnParts[1 .. lccnParts[2] .. '-' .. lccnParts[3] .. ' WorldCat]', false ) )
end
end
return "* Notices d’autorité : " .. table.concat( elements, ' • ' )
end
return p