« Module:Autorité » : différence entre les versions
Contenu supprimé Contenu ajouté
mAucun résumé des modifications |
Suppression du support des paramètres locaux |
||
Ligne 80 : | Ligne 80 : | ||
function lccnLink( id ) |
function lccnLink( id ) |
||
⚫ | |||
local parts = splitLccn( id ) |
|||
if not parts then |
|||
return false |
return false |
||
end |
end |
||
id = parts[1] .. parts[2] .. append( parts[3], '0', 6 ) |
|||
return '[http://id.loc.gov/authorities/' .. id .. ' ' .. id .. ']' |
return '[http://id.loc.gov/authorities/' .. id .. ' ' .. id .. ']' |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return mw.text.split( id, '/' ) |
|||
end |
|||
⚫ | |||
end |
end |
||
Ligne 132 : | Ligne 121 : | ||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return '[//www.worldcat.org/identities/lccn-' .. id .. ' lccn-' .. id .. ']' |
|||
⚫ | |||
⚫ | |||
if link then |
if link then |
||
return '<li>' .. label .. ' : ' .. link .. '</li>' |
|||
return '<li>' .. label .. ' : ' .. link .. '</li>' |
|||
else |
|||
return '<li>' .. link .. '</li>' |
|||
end |
|||
else |
else |
||
return '<li><span class="error">L\'identifiant ' .. label .. ' ' .. rawValue .. ' n\'est pas valide.</span>[[Catégorie:Pages utilisant le modèle Autorité avec un paramètre erroné]]</li>' |
return '<li><span class="error">L\'identifiant ' .. label .. ' ' .. rawValue .. ' n\'est pas valide.</span>[[Catégorie:Pages utilisant le modèle Autorité avec un paramètre erroné]]</li>' |
||
Ligne 157 : | Ligne 152 : | ||
end |
end |
||
--In this order: |
--In this order: label, propertyId in Wikidata, formatting function |
||
local conf = { |
local conf = { |
||
{ |
{ '[[w:Fichier d\'autorité international virtuel|VIAF]]', 214, viafLink }, |
||
{ |
{ '[[w:International Standard Name Identifier|ISNI]]', 213, isniLink }, |
||
{ |
{ '[[w:Union List of Artist Names|ULAN]]', 245, ulanLink }, |
||
{ |
{ '[[w:Bibliothèque nationale de France|BNF]]', 268, bnfLink }, |
||
{ |
{ '[[w:Système universitaire de documentation|SUDOC]]', 269, sudocLink }, |
||
{ |
{ '[[w:Bibliothèque et Archives Canada|BAC]]', 1670, canadianaLink }, |
||
{ |
{ '[[w:Numéro de contrôle de la Bibliothèque du Congrès|LCCN]]', 244, lccnLink }, |
||
{ |
{ '[[w:Gemeinsame Normdatei|GND]]', 227, gndLink }, |
||
{ |
{ '[[w:Institut central pour le registre unique|SNB]]', 396, sbnLink }, |
||
{ |
{ '[[w:Bibliothèque nationale de la Diète|NDL]]', 349, ndlLink }, |
||
{ |
{ '[[w:Bibliothèque nationale australienne|NLA]]', 409, nlaLink }, |
||
{ |
{ '[[w:Base Léonore|Léonore]]', 640, leonoreLink }, |
||
{ '[[w:WorldCat|WorldCat]]', 244, worldcatLink } |
|||
} |
} |
||
Ligne 176 : | Ligne 172 : | ||
function p.authorityControl( frame ) |
function p.authorityControl( frame ) |
||
local |
local item = mw.wikibase.getEntityObject() |
||
--Create rows |
|||
⚫ | |||
local isDepreciated = false --S'il y a un id déprécié |
|||
⚫ | |||
--Catégorisation s'il y a des identifiants "hardcodés" |
|||
return '<div class="error">Le modèle Autorité ne marche que sur les pages liés à une entité Wikidata</div>' |
|||
if parentArgs.VIAF ~= nil |
|||
or parentArgs.GND ~= nil |
|||
or parentArgs.ISNI ~= nil |
|||
or parentArgs.BNF ~= nil |
|||
or parentArgs.SUDOC ~= nil |
|||
or parentArgs.LCCN ~= nil then |
|||
isDepreciated = true |
|||
end |
|||
--Wikidata fallback if requested |
|||
local item = mw.wikibase.getEntityObject() |
|||
⚫ | |||
⚫ | |||
if params[3] ~= 0 then |
|||
local val = parentArgs[params[1]] |
|||
if not val or val == '' then |
|||
local wikidataIds = getIdsFromWikidata( item, 'P' .. params[3] ) |
|||
if wikidataIds[1] then |
|||
parentArgs[params[1]] = wikidataIds[1] |
|||
end |
|||
end |
|||
end |
|||
end |
|||
end |
end |
||
⚫ | |||
--Configured rows |
|||
for _, params in pairs( conf ) do |
for _, params in pairs( conf ) do |
||
local wikidataIds = getIdsFromWikidata( item, 'P' .. params[2] ) |
|||
⚫ | |||
⚫ | |||
if val and val ~= '' then |
|||
⚫ | |||
end |
|||
end |
|||
--Worldcat |
|||
if parentArgs['WORLDCATID'] and parentArgs['WORLDCATID'] ~= '' then |
|||
table.insert( elements, createRow( 'WORLDCATID', 'WorldCat', parentArgs['WORLDCATID'], 'http://www.worldcat.org/identities/' .. parentArgs['WORLDCATID'] ) ) --Validation? |
|||
elseif parentArgs['LCCN'] and parentArgs['LCCN'] ~= '' then |
|||
local lccnParts = splitLccn( parentArgs['LCCN'] ) |
|||
if lccnParts then |
|||
table.insert( elements, createRow( 'LCCN', '', parentArgs['LCCN'], '[//www.worldcat.org/identities/lccn-' .. lccnParts[1] .. lccnParts[2] .. '-' .. lccnParts[3] .. ' WorldCat]' ) ) |
|||
end |
end |
||
end |
end |
||
local str = '' |
local str = '' |
||
if isDepreciated then |
|||
str = str .. '[[Catégorie:Pages utilisant le modèle Autorité avec un paramètre obsolète]]\n' |
|||
end |
|||
if mw.title.getCurrentTitle().namespace == 102 then |
if mw.title.getCurrentTitle().namespace == 102 then |
||
str = str .. '[[Catégorie:Pages « Auteur » utilisant le modèle Autorité]]\n' |
str = str .. '[[Catégorie:Pages « Auteur » utilisant le modèle Autorité]]\n' |
Version du 22 juillet 2015 à 03:46
La documentation de ce module Scribunto écrit en Lua est incluse depuis sa sous-page de documentation.
Ce module contient le code de {{Autorité}}
.
function sbnLink( id )
if not string.match( id, '^IT\\ICCU\\%d%d%d%d%d%d%d%d%d%d$' ) and not string.match( id, '^IT\\ICCU\\%u%u[%d%u]%u\\%d%d%d%d%d%d$' ) then
return false
end
return '[http://opac.sbn.it/opacsbn/opac/iccu/scheda_authority.jsp?bid=' .. id .. ' ' .. id .. ']'
end
function ndlLink( id )
if not string.match( id, '^0?%d%d%d%d%d%d%d%d$' ) then
return false
end
return '[http://id.ndl.go.jp/auth/ndlna/' .. id .. ' ' .. id .. ']'
end
function isniLink( id )
id = validateIsni( id )
if not id then
return false
end
return '[http://isni.org/' .. id .. ' ' .. id:sub( 1, 4 ) .. ' ' .. id:sub( 5, 8 ) .. ' ' .. id:sub( 9, 12 ) .. ' ' .. id:sub( 13, 16 ) .. ']'
end
--Validate ISNI (and ORCID) and retuns it as a 16 characters string or returns false if it's invalid
--See http://support.orcid.org/knowledgebase/articles/116780-structure-of-the-orcid-identifier
function validateIsni( id )
id = id:gsub( '[ %-]', '' ):upper()
if not id:match( '^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$' ) then
return false
end
if getIsniCheckDigit( id ) ~= string.char( id:byte( 16 ) ) then
return false
end
return id
end
--Returns the ISNI check digit isni must be a string where the 15 first elements are digits
function getIsniCheckDigit( isni )
local total = 0
for i = 1, 15 do
local digit = isni:byte( i ) - 48 --Get integer value
total = (total + digit) * 2
end
local remainder = total % 11
local result = (12 - remainder) % 11
if result == 10 then
return "X"
end
return tostring( result )
end
function ulanLink( id )
if not string.match( id, '^%d%d?%d?%d?%d?%d?%d?%d?%d?$' ) then
return false
end
return '[//www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid=' .. id .. ' ' .. id .. ']'
end
function sudocLink( id )
if not string.match( id, '^%d%d%d%d%d%d%d%d[%dxX]$' ) then
return false
end
return '[http://www.idref.fr/' .. id .. ' ' .. 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 .. ' ' .. id .. ']'
end
function viafLink( id )
if not string.match( id, '^%d+$' ) then
return false
end
return '[http://viaf.org/viaf/' .. id .. ' ' .. id .. ']'
end
function lccnLink( id )
if not id:match( '^%l%l?%l?%d%d%d%d%d%d%d%d%d?%d?$' ) then
return false
end
return '[http://id.loc.gov/authorities/' .. id .. ' ' .. id .. ']'
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 .. ' ' .. id .. ']'
end
function nlaLink( id )
return '[//nla.gov.au/anbd.aut-an' .. id .. ' ' .. id .. ']'
end
function leonoreLink( id )
-- Identifiants allant de LH/1/1 à LH/2794/54 (légionnaires)
-- Identifiants allant de C/0/1 à C/0/84 (84 légionnaires célèbres)
-- Identifiants allant de 19800035/1/1 à 19800035/385/51670 (légionnaires décédés entre 1954 et 1977, et quelques dossiers de légionnaires décédés avant 1954)
if not string.match( id, '^LH/%d%d?%d?%d?/%d%d?%d?$' ) and
not string.match( id, '^C/0/%d%d?$' ) and
not string.match( id, '^19800035/%d%d?%d?%d?/%d%d?%d?%d?%d?$' ) then
return false
end
return '[http://www.culture.gouv.fr/public/mistral/leonore_fr?ACTION=CHERCHER&FIELD_1=COTE&VALUE_1=' .. id .. ' ' .. id .. ']'
end
function canadianaLink( id )
if not string.match( id, '^%d%d%d%d[A-Z]%d%d%d%d$' ) then
return false
end
return '[https://www.collectionscanada.gc.ca/canadiana-authorities/index/view?cdnAutNbr=' .. id .. '&format=full&index_name=cdnAutNbr&search_text=' .. id .. '&page=1&filter= ' .. id .. ']'
end
function worldcatLink( id )
if not id:match( '^%l%l?%l?%d%d%d%d%d%d%d%d%d?%d?$' ) then
return false
end
id = id:gsub( '^(%l+%d+)(%d%d%d%d%d%d)$', '%1-%2' )
return '[//www.worldcat.org/identities/lccn-' .. id .. ' lccn-' .. id .. ']'
end
function createRow( label, rawValue, link )
if link then
return '<li>' .. label .. ' : ' .. link .. '</li>'
else
return '<li><span class="error">L\'identifiant ' .. label .. ' ' .. rawValue .. ' n\'est pas valide.</span>[[Catégorie:Pages utilisant le modèle Autorité avec un paramètre erroné]]</li>'
end
end
function getIdsFromWikidata( item, property )
local ids = {}
if not item.claims[property] then
return ids
end
for _, statement in pairs( item.claims[property] ) do
if statement.mainsnak.snaktype == 'value' then
table.insert( ids, statement.mainsnak.datavalue.value )
end
end
return ids
end
--In this order: label, propertyId in Wikidata, formatting function
local conf = {
{ '[[w:Fichier d\'autorité international virtuel|VIAF]]', 214, viafLink },
{ '[[w:International Standard Name Identifier|ISNI]]', 213, isniLink },
{ '[[w:Union List of Artist Names|ULAN]]', 245, ulanLink },
{ '[[w:Bibliothèque nationale de France|BNF]]', 268, bnfLink },
{ '[[w:Système universitaire de documentation|SUDOC]]', 269, sudocLink },
{ '[[w:Bibliothèque et Archives Canada|BAC]]', 1670, canadianaLink },
{ '[[w:Numéro de contrôle de la Bibliothèque du Congrès|LCCN]]', 244, lccnLink },
{ '[[w:Gemeinsame Normdatei|GND]]', 227, gndLink },
{ '[[w:Institut central pour le registre unique|SNB]]', 396, sbnLink },
{ '[[w:Bibliothèque nationale de la Diète|NDL]]', 349, ndlLink },
{ '[[w:Bibliothèque nationale australienne|NLA]]', 409, nlaLink },
{ '[[w:Base Léonore|Léonore]]', 640, leonoreLink },
{ '[[w:WorldCat|WorldCat]]', 244, worldcatLink }
}
local p = {}
function p.authorityControl( frame )
local item = mw.wikibase.getEntityObject()
if item == nil or item.claims == nil then
return '<div class="error">Le modèle Autorité ne marche que sur les pages liés à une entité Wikidata</div>'
end
local elements = {}
for _, params in pairs( conf ) do
local wikidataIds = getIdsFromWikidata( item, 'P' .. params[2] )
for _, id in pairs( wikidataIds ) do
table.insert( elements, createRow( params[1], id, params[3]( id ) ) )
end
end
local str = ''
if mw.title.getCurrentTitle().namespace == 102 then
str = str .. '[[Catégorie:Pages « Auteur » utilisant le modèle Autorité]]\n'
end
if next( elements ) == nil then
str = str .. '[[Catégorie:Pages utilisant le modèle Autorité sans aucun identifiant]]\n'
return str
end
return '<div id="authorityControl" class="catlinks"><div>[[File:Nuvola apps bookcase 2.svg|22px|link=]] Notices d’autorité :<ul>' .. table.concat( elements ) .. '</ul></div></div>\n' .. str
end
return p