« Module:Autorité » : différence entre les versions
ajout lien "données BnF", per même discussion |
renomme "link" en "url" pour éviter confusion avec éléments liens |
||
| Ligne 1 : | Ligne 1 : | ||
local wd = require('Module:Wikidata') | local wd = require('Module:Wikidata') | ||
local function | local function bneUrl( id ) | ||
if not string.match( id, '^XX%d%d%d%d%d%d?%d?$' ) then | if not string.match( id, '^XX%d%d%d%d%d%d?%d?$' ) then | ||
return false | return false | ||
| Ligne 8 : | Ligne 8 : | ||
end | end | ||
local function | local function sbnUrl( 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 | 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 | return false | ||
| Ligne 15 : | Ligne 15 : | ||
end | end | ||
local function | local function ndlUrl( id ) | ||
if not string.match( id, '^0?%d%d%d%d%d%d%d%d$' ) then | if not string.match( id, '^0?%d%d%d%d%d%d%d%d$' ) then | ||
return false | return false | ||
| Ligne 22 : | Ligne 22 : | ||
end | end | ||
local function | local function leonoreUrl( id ) | ||
-- Identifiants allant de LH/1/1 à LH/2794/54 (légionnaires) | -- 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 C/0/1 à C/0/84 (84 légionnaires célèbres) | ||
| Ligne 63 : | Ligne 63 : | ||
end | end | ||
local function | local function isniUrl( id ) | ||
id = validateIsni( id ) | id = validateIsni( id ) | ||
if not id then | if not id then | ||
| Ligne 71 : | Ligne 71 : | ||
end | end | ||
local function | local function orcidUrl( id ) | ||
id = validateIsni( id ) | id = validateIsni( id ) | ||
if not id then | if not id then | ||
| Ligne 80 : | Ligne 80 : | ||
end | end | ||
local function | local function ciniiUrl( id ) | ||
return 'http://ci.nii.ac.jp/author/' .. id .. '?l=en' | return 'http://ci.nii.ac.jp/author/' .. id .. '?l=en' | ||
end | end | ||
local function | local function ulanUrl( id ) | ||
if not string.match( id, '^%d%d?%d?%d?%d?%d?%d?%d?%d?$' ) then | if not string.match( id, '^%d%d?%d?%d?%d?%d?%d?%d?%d?$' ) then | ||
return false | return false | ||
| Ligne 91 : | Ligne 91 : | ||
end | end | ||
local function | local function sudocUrl( id ) | ||
if not string.match( id, '^%d%d%d%d%d%d%d%d[%dxX]$' ) then | if not string.match( id, '^%d%d%d%d%d%d%d%d[%dxX]$' ) then | ||
return false | return false | ||
| Ligne 98 : | Ligne 98 : | ||
end | end | ||
local function | local function bnfUrls( id ) | ||
--Add cb prefix if it has been removed | --Add cb prefix if it has been removed | ||
if not string.match( id, '^cb.+$' ) then | if not string.match( id, '^cb.+$' ) then | ||
| Ligne 108 : | Ligne 108 : | ||
end | end | ||
local function | local function viafUrl( id ) | ||
if not string.match( id, '^%d+$' ) then | if not string.match( id, '^%d+$' ) then | ||
return false | return false | ||
| Ligne 129 : | Ligne 129 : | ||
end | end | ||
local function | local function lccnUrl( id ) | ||
local parts = splitLccn( id ) | local parts = splitLccn( id ) | ||
if not parts then | if not parts then | ||
| Ligne 138 : | Ligne 138 : | ||
end | end | ||
local function | local function gndUrl( id ) | ||
return 'http://d-nb.info/gnd/' .. id | return 'http://d-nb.info/gnd/' .. id | ||
end | end | ||
local function | local function frenchsculptureUrl( id ) | ||
return 'http://frenchsculpture.org/fr/artist/' .. id | return 'http://frenchsculpture.org/fr/artist/' .. id | ||
end | end | ||
local function makeLink( | local function makeLink(url, label) | ||
return '<span class="nowrap uid">[' .. | return '<span class="nowrap uid">[' .. url .. ' ' .. label .. ']</span>' | ||
end | end | ||
local function createRow( id, label, rawValue, | local function createRow( id, label, rawValue, url ) | ||
if type( | if type(url) == 'table' then | ||
return makeLink( | return makeLink(url[1], label[1]) .. ' (' .. makeLink(url[2], label[2]) .. ')' | ||
elseif link then | elseif link then | ||
return makeLink( | return makeLink(url, label) | ||
else | else | ||
local cat = '' | local cat = '' | ||
| Ligne 179 : | Ligne 179 : | ||
--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 | ||
local conf = { | local conf = { | ||
{ 'VIAF', 'Fichier d\'autorité international virtuel', 214, | { 'VIAF', 'Fichier d\'autorité international virtuel', 214, viafUrl }, | ||
{ 'ISNI', 'International Standard Name Identifier', 213, | { 'ISNI', 'International Standard Name Identifier', 213, isniUrl }, | ||
{ 'ORCID', 'ORCID', 496, | { 'ORCID', 'ORCID', 496, orcidUrl }, | ||
{ 'CINII', 'CiNii', 271, | { 'CINII', 'CiNii', 271, ciniiUrl }, | ||
{ 'ULAN', 'Union List of Artist Names', 245, | { 'ULAN', 'Union List of Artist Names', 245, ulanUrl }, | ||
{ 'BNF', { 'Bibliothèque nationale de France', 'données' }, 268, | { 'BNF', { 'Bibliothèque nationale de France', 'données' }, 268, bnfUrls }, | ||
{ 'SUDOC', 'Système universitaire de documentation', 269, | { 'SUDOC', 'Système universitaire de documentation', 269, sudocUrl }, | ||
{ 'LCCN', 'Bibliothèque du Congrès', 244, | { 'LCCN', 'Bibliothèque du Congrès', 244, lccnUrl }, | ||
{ 'GND', 'Gemeinsame Normdatei', 227, | { 'GND', 'Gemeinsame Normdatei', 227, gndUrl }, | ||
{ 'SBN', 'Institut central pour le registre unique', 396, | { 'SBN', 'Institut central pour le registre unique', 396, sbnUrl }, | ||
{ 'NDL', 'Bibliothèque nationale de la Diète', 349, | { 'NDL', 'Bibliothèque nationale de la Diète', 349, ndlUrl }, | ||
{ 'BNE', 'Bibliothèque nationale d\'Espagne', 950, | { 'BNE', 'Bibliothèque nationale d\'Espagne', 950, bneUrl }, | ||
{ 'Léonore', 'Base Léonore', 640, | { 'Léonore', 'Base Léonore', 640, leonoreUrl }, -- Légion d'honneur de la France | ||
{ 'SWD', 'Schlagwortnormdatei', 0, | { 'SWD', 'Schlagwortnormdatei', 0, swdUrl }, | ||
{ 'French Sculpture Census ID', 'Répertoire de sculpture française', 2380, | { 'French Sculpture Census ID', 'Répertoire de sculpture française', 2380, frenchsculptureUrl }, | ||
} | } | ||
Version du 21 juin 2016 à 04:08
local wd = require('Module:Wikidata')
local function bneUrl( id )
if not string.match( id, '^XX%d%d%d%d%d%d?%d?$' ) then
return false
end
return 'http://catalogo.bne.es/uhtbin/authoritybrowse.cgi?action=display&authority_id=' .. id
end
local function sbnUrl( 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
end
local function ndlUrl( 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
end
local function leonoreUrl( 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
end
--Returns the ISNI check digit isni must be a string where the 15 first elements are digits
local 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
--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 local 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
local function isniUrl( id )
id = validateIsni( id )
if not id then
return false
end
return 'http://isni.org/isni/' .. id
end
local function orcidUrl( id )
id = validateIsni( id )
if not id then
return false
end
id = id:sub( 1, 4 ) .. '-' .. id:sub( 5, 8 ) .. '-' .. id:sub( 9, 12 ) .. '-' .. id:sub( 13, 16 )
return 'http://orcid.org/' .. id
end
local function ciniiUrl( id )
return 'http://ci.nii.ac.jp/author/' .. id .. '?l=en'
end
local function ulanUrl( 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
end
local function sudocUrl( 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
end
local function bnfUrls( 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,
'http://data.bnf.fr/ark:/12148/' .. id }
end
local function viafUrl( id )
if not string.match( id, '^%d+$' ) then
return false
end
return 'http://viaf.org/viaf/' .. id
end
local 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
local function padLeft( str, c, length )
return c:rep( length - #str ) .. str
end
local function lccnUrl( id )
local parts = splitLccn( id )
if not parts then
return false
end
id = parts[1] .. parts[2] .. padLeft( parts[3], '0', 6 )
return 'http://id.loc.gov/authorities/' .. id
end
local function gndUrl( id )
return 'http://d-nb.info/gnd/' .. id
end
local function frenchsculptureUrl( id )
return 'http://frenchsculpture.org/fr/artist/' .. id
end
local function makeLink(url, label)
return '[' .. url .. ' ' .. label .. ']'
end
local function createRow( id, label, rawValue, url )
if type(url) == 'table' then
return makeLink(url[1], label[1]) .. ' (' .. makeLink(url[2], label[2]) .. ')'
elseif link then
return makeLink(url, label)
else
local cat =
if mw.title.getCurrentTitle().namespace == 0 then
cat = '\n'
end
return 'L\'identifiant ' .. id .. ' ' .. rawValue .. ' n\'est pas valide.' .. cat
end
end
local function getIdsFromWikidata( item, property )
local ids = {}
if not item.claims[property] then
return ids
end
for _, statement in pairs( item.claims[property] ) do
if type( statement.mainsnak.datavalue ) == 'table' then
table.insert( ids, statement.mainsnak.datavalue.value )
end
end
return ids
end
--In this order: name of the parameter, label, propertyId in Wikidata, formatting function local conf = {
{ 'VIAF', 'Fichier d\'autorité international virtuel', 214, viafUrl },
{ 'ISNI', 'International Standard Name Identifier', 213, isniUrl },
{ 'ORCID', 'ORCID', 496, orcidUrl },
{ 'CINII', 'CiNii', 271, ciniiUrl },
{ 'ULAN', 'Union List of Artist Names', 245, ulanUrl },
{ 'BNF', { 'Bibliothèque nationale de France', 'données' }, 268, bnfUrls },
{ 'SUDOC', 'Système universitaire de documentation', 269, sudocUrl },
{ 'LCCN', 'Bibliothèque du Congrès', 244, lccnUrl },
{ 'GND', 'Gemeinsame Normdatei', 227, gndUrl },
{ 'SBN', 'Institut central pour le registre unique', 396, sbnUrl },
{ 'NDL', 'Bibliothèque nationale de la Diète', 349, ndlUrl },
{ 'BNE', 'Bibliothèque nationale d\'Espagne', 950, bneUrl },
{ 'Léonore', 'Base Léonore', 640, leonoreUrl }, -- Légion d'honneur de la France
{ 'SWD', 'Schlagwortnormdatei', 0, swdUrl },
{ 'French Sculpture Census ID', 'Répertoire de sculpture française', 2380, frenchsculptureUrl },
}
local p = {}
function p.authorityControl( frame )
local parentArgs = frame:getParent().args
--Create rows
local elements = {}
local hasDepreciated = false --S'il y a un id déprécié
local hasLocalArgs = false
for _,_ in pairs( parentArgs ) do
hasLocalArgs = true
break
end
--Redirection des identifiants de la Bibliothèque Nationale d'Allemagne vers GND
if parentArgs.GND == nil or parentArgs.GND == then
if parentArgs.DNB ~= nil and parentArgs.DNB ~= then
parentArgs.GND = parentArgs.DNB
hasDepreciated = true
elseif parentArgs.PND ~= nil and parentArgs.PND ~= then
parentArgs.GND = parentArgs.PND
hasDepreciated = true
elseif parentArgs.GKD ~= nil and parentArgs.GKD ~= then
parentArgs.GND = parentArgs.GKD
hasDepreciated = true
elseif parentArgs['GKD-V1'] ~= nil and parentArgs['GKD-V1'] ~= then
parentArgs.GND = parentArgs['GKD-V1']
hasDepreciated = true
end
end
--Wikidata fallback if requested
local item = mw.wikibase.getEntityObject()
if item ~= nil and item.claims ~= nil then
for _, params in pairs( conf ) do
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
--Configured rows
for _, 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 ) ) )
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 and lccnParts[1] ~= 'sh' then
table.insert( elements, createRow( 'LCCN', 'WorldCat', parentArgs['LCCN'], 'http://www.worldcat.org/identities/lccn-' .. lccnParts[1] .. lccnParts[2] .. '-' .. lccnParts[3] ) )
end
end
local str =
if hasDepreciated then
str = str .. '\n'
end
if hasLocalArgs then
str = str .. '\n'
end
return wd.addLinkback( "Notices d'autorité", nil, "identifiers" ) .. " : " .. table.concat( elements, ' • ' ) .. str
end
return p