Module:Autorité
Wikimedia module / De Wikipedia, l'encyclopédie encyclopedia
local wd = require( 'Module:Wikidata' ) local Outils = require( 'Module:Outils' )
--nombre maximum de référence "autorité" qui doivent être affichée. La valeur de 18 a été acté par défaut en 2017. local nbMaxReferenceParPage = 18
local function blbnbUrl( id ) if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then return false end return 'http://acervo.bn.br/sophia_web/autoridade/detalhe/' .. id end
local function nlgUrl( id ) if not id:match( '^[1-9]%d*$' ) then return false end return 'https://catalogue.nlg.gr/Authority/Record?id=au.' .. id end
local function bneUrl( id ) if not id:match( '^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 id:match( '^%u%u[%u%d]%u%d%d%d%d%d%d$' ) then return false end return 'https://opac.sbn.it/nome/' .. id end
local function ndlUrl( id ) if not id:match( '^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 ntaUrl( id ) if not id:match( '^%d%d%d%d%d%d%d%d.$' ) then return false end return 'http://data.bibliotheken.nl/id/thes/p' .. id end
local function nlpUrl( id ) -- nouveau format valide - 9810[0-9]\d* : 981066973640560 if id:match( '^981%d%d%d%d%d%d%d%d05606$' ) then return 'http://mak.bn.org.pl/cgi-bin/KHW/makwww.exe?BM=01&IM=04&NU=01&WI=' .. id -- ancien format Wikidata - A[0-9]{7}[0-9X] : A11107844, A1157477X elseif id:match( '^A?%d%d%d%d%d%d%d[%dX]$' ) then return 'http://mak.bn.org.pl/cgi-bin/KHW/makwww.exe?BM=01&IM=05&TX=&NU=01&WI=' .. id else return false end end
local function nliUrl( id ) if not id:match( '^9870[01]%d%d%d%d%d%d%d%d05171$' ) then return false end return 'http://uli.nli.org.il/F/?func=find-b&local_base=NLX10&find_code=UID&request=' .. id end
local function nukatUrl( id ) if not id:match( '^n%d%d%d%d%d%d%d%d$' ) and not id:match( '^n%d%d%d%d%d%d%d%d%d%d$' ) and not id:match( '^p %d%d%d%d%d%d%d%d$' ) and not id:match( '^p %d%d%d%d%d%d%d%d%d%d$' ) and not id:match( '^s %d%d%d%d%d%d%d%d$' ) and not id:match( '^s %d%d%d%d%d%d%d%d%d%d$' ) then return false end id = id:gsub( ' ', '%%20' ) -- pour les ids commencent par s ou p if id:len() == 9 then id = id:gsub( 'n', 'n%%20%%20' ) -- pour les ids commencent par n else id = id:gsub( 'n', 'n%%20' ) -- pour les ids commencent par n20 end return 'http://nukat.edu.pl/aut/' .. id end
local function catalUrl( id) if not id:match( '^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d$' ) then if not id:match( '^a?%d%d%d%d%d%d%d.$' ) then return false end return 'https://cantic.bnc.cat/registres/CUCId/' .. id end return 'https://cantic.bnc.cat/registre/' .. id end
local function selibrUrl( id ) if not id:match( '^[1-9]%d%d%d%d$' ) and not id:match( '^[1-9]%d%d%d%d%d$' ) then return false end return 'http://libris.kb.se/auth/' .. id end
local function reroUrl( id ) --exemple d'un code valide est 01-R008412216, 02-A000173676 if not id:match( '^0[1234]%-[AR]%d%d%d%d%d%d%d%d%d$' ) then return false end return 'http://data.rero.ch/' .. id end
local function bavUrl( id ) --exemple d'un code valide est 494/9793 if not id:match( '^49%d/[1-9]%d*$' ) then -- 49\d\/[1-9]\d{0,5} return false end id = id:gsub( '/', '_' ) return 'https://opac.vatlib.it/auth/detail/' .. id end
local function idCanadia( id ) --exemple d'un code valide est 1024H9993 if not id:match( '^%d%d%d%d[A-Z]%d%d%d%d[EF]?$' ) then return false end return 'https://www.collectionscanada.gc.ca/canadiana-authorities/index/view?index_name=cdnAutNbr&lang=fr&search_text=' .. id .. '&page=1&cdnAutNbr' .. id end
local function nlaUrl( id ) --exemple d'un code valide est nm1942312 if not id:match( '^%d+$' ) then return false end return 'http://nla.gov.au/anbd.aut-an' .. id end
--[=[ en attendant que la bibliothèque du Québec ait une page sur son site web pour les articles référencés par l'idBAnQ (actuellement, page du site Viaf local function idBAnQa( id ) exemple d'un code valide est 0001215324 if not id:match( '^%d%d%d%d%d+$' ) then return false
end
return 'http://viaf.org/processed/B2Q%7C' .. id end ]=]
local function bibsysUrl( id )
-- exemple d'un code valide est 0001215324
if not id:match( '^%d+$' ) then
return false
end
return 'https://authority.bibsys.no/authority/rest/authorities/html/' .. id end
local function n6iUrl( id ) -- exemple d'un code valide est vtls000033830 mais pas de format officiel précisé pour les tests dans le module if not id:match( '^vtls%d+$' ) then return false
end
return 'http://catalogue.nli.ie/Record/' .. id end
local function nskUrl( id ) -- exemple d'un code valide est 000339950 if not id:match( '^%d+$' ) then return false
end
return 'http://katalog.nsk.hr/F/?func=direct&doc_number=' .. id .. '&local_base=nsk10' end
--Bibliothèque Nationale de Russie (NLR ou RSL) local function rslUrl( id ) -- exemple d'un code valide est 000080362 if not id:match( '^%d+$' ) then return false
end
return 'http://aleph.rsl.ru/F?func=find-b&find_code=SYS&adjacent=Y&local_base=RSL11&request=' .. id end --Bibliothèque Nationale Tchèque (NKCL) local function nkcUrl( id ) -- exemple d'un code valide est jcu2014834887 format [a-z]{2,4}[0-9]{2,14} if not id:match( '^%a%a+%d%d+$' ) then return false
end
return 'http://aut.nkp.cz/' .. id end --Bibliothèque Nationale du Québec pour les ouvrages local function idBAnQo( id ) --exemple d'un code valide est 1986863 if not id:match( '^%d+$' ) then return false
end
return 'http://collections.banq.qc.ca/ark:/52327/%7C' .. id end --Bibliothèque Nationale du Danemark --[=[ en attendant que la bibliothèque du Québec ait une page sur son site web pour les articles référencés par l'idDBC (actuellement, page du site Viaf local function idDbc( id ) --exemple d'un code valide est 87097968101751 if not id:match( '^87%d+$' ) then return false
end
return 'https://viaf.org/processed/DBC%7C' .. id end ]=] --Bibliothèque Nationale du Chili local function idBnchl( id ) --exemple d'un code valide est 10000000000000000063660 if not id:match( '^%d+$' ) then return false
end
return 'http://www.bncatalogo.cl/F?func=direct&local_base=BNC01&doc_number=' .. id end --Bibliothèque Nationale du Portugal local function idPtbnp( id ) --exemple d'un code valide est 130325 if not id:match( '^%d%d+$' ) then return false
end
return 'http://urn.bn.pt/nca/unimarc-authorities/txt?id=' .. id end --Bibliothèque nationale de Lettonie local function idLnb( id ) --exemple d'un code valide est 000001327 if not id:match( '^%d%d+$' ) then return false
end
return 'https://kopkatalogs.lv/F/?func=direct&local_base=lnc10&doc_number=' .. id end
--Bibliothèque nationale du Luxembourg local function idBNL( id ) --exemple d'un code valide est 000035166 if not id:match( '^%d%d+$' ) then return false
end
return 'http://viaf.org/processed/BNL%7C' .. id end
local function idworldcat( id ) --exemple d'un code valide est viaf-000001327 if not id:match( '^viaf.%d+$' ) and not id:match( '^lccn.n[a-z]?[0-9\-]+$') and not id:match( '^n[pc]..+$') then return false end return 'https://www.worldcat.org/identities/' .. id end local function idOclc( id ) --exemple d'un code valide est 000001327 if not id:match( '^0*[1-9]%d*$' ) then return false
end
return 'http://www.worldcat.org/oclc/' .. id end
***********************************************************************************************************************
-- ajouter ici les nouvelles fonctions pour références
***********************************************************************************************************************
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 id:match( '^LH/%d%d?%d?%d?/%d%d?%d?$' ) and not id:match( '^C/0/%d%d?$' ) and not id:match( '^19800035/%d%d?%d?%d?/%d%d?%d?%d?%d?$' ) and not id:match( '^19800035/%d%d?%d?%d?/%d%d?%d?%d?%d?Bis$' ) 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 returns 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 ciniiUrl( id ) return 'http://ci.nii.ac.jp/author/' .. id .. '?l=en' end
local function sudocUrl( id ) if not id:match( '^%d%d%d%d%d%d%d%d[%dxX]$' ) then return false end return 'http://www.idref.fr/' .. id end
local function archivesnationalesUrl( id ) if not id:match( '^FRAN_NP_%d%d%d%d%d%d$' ) then return false end return 'https://www.siv.archives-nationales.culture.gouv.fr/siv/NP/' .. id end
local function bnfUrls( id ) --Add cb prefix if it has been removed if not id:match( '^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 id:match( '^%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 nszlUrl( id ) if not id:match( '^%d%d%d%d%d%d%d%d%d%d%d%d$' ) then return false end return 'https://viaf.org/processed/NSZL%7C' .. id end
local function ltiUrl( id ) if not id:match( '^[1-9]%d*$' ) then return false end return 'https://library.ltikorea.or.kr/node/' .. id end
local function krnlkUrl( id ) if not id:match( '^KAB%d%d%d%d%a?%d%d%d%d%d?%d?$' ) and not id:match( '^KAC%d%d%d%d%a?%d%d%d%d%d?%d?$' ) and not id:match( '^KSH%d%d%d%d%a?%d%d%d%d%d?%d?$' ) then return false end return 'https://lod.nl.go.kr/resource/' .. id end
local function bnaUrl( id ) if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then return false end return 'https://catalogo.bn.gov.ar/F/?func=direct&doc_number=' .. id ..'&local_base=GENER' end
local function bnsUrl( id ) if not id:match( '^[1-9]%d*$' ) then return false end return 'https://www.helveticarchives.ch/detail.aspx?ID=' .. id end
local function arbabnUrl( id ) if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then return false end return 'https://catalogo.bn.gov.ar/F/?func=direct&local_base=BNA10&doc_number=' .. id end --Bibliothèque Nationale d'Arménie, en 3 modules distincts local function nlaBookUrl( id ) if not id:match( '^[1-9]%d*$' ) then return false end return 'http://haygirk.nla.am/cgi-bin/koha/opac-detail.pl?biblionumber=' .. id end local function nlaPersUrl( id ) if not id:match( '^[1-9]%d*$' ) then return false end return 'http://armunicat.nla.am/cgi-bin/koha/opac-authoritiesdetail.pl?marc=1&authid=' .. id end local function nlaResUrl( id ) if not id:match( '^[1-9]%d*$' ) then return false end return 'http://tert.nla.am/cgi-bin/koha/opac-detail.pl?biblionumber=' .. id end
local function glottoUrl( id ) if not id:match( '^[a-z][a-z][a-z][a-z]%d%d%d%d$' ) then return false end return 'https://glottolog.org/resource/languoid/id/' .. 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 url then return makeLink( url, label ) else local cat = if mw.title.getCurrentTitle().namespace == 0 then cat = '' end return 'L\'identifiant ' .. id .. ' "' .. rawValue .. '" n\'est pas valide.' .. cat end end
local function getIdsFromWikidata( entity, property ) local ids = {} for _, statement in ipairs(mw.wikibase.getBestStatements(entity, property)) do if type( statement.mainsnak.datavalue ) == 'table' then table.insert( ids, statement.mainsnak.datavalue.value ) end end return ids end
local BiblioNat = "Bibliothèque nationale" --In this order: name of the parameter, label, propertyId in Wikidata, formatting function
-- optionally, a named parameter "condition" that is a predicate function with the entity object as a parameter -- this function specifies conditions on which the identifier url should be shown, for example only if a person is dead local conf = { { 'VIAF', 'Fichier d’autorité international virtuel', 214, viafUrl }, { 'ISNI', 'International Standard Name Identifier', 213, isniUrl }, { 'CINII', 'CiNii', 271, ciniiUrl }, { 'BNF', { BiblioNat .. ' de France', 'données' }, 268, bnfUrls }, { 'AN', 'Archives nationales (France)', 3599, archivesnationalesUrl }, { 'SUDOC', 'Système universitaire de documentation', 269, sudocUrl }, { 'LCCN', 'Bibliothèque du Congrès', 244, lccnUrl }, { 'GND', 'Gemeinsame Normdatei', 227, gndUrl }, { 'SBN', 'Service bibliothécaire national', 396, sbnUrl }, { 'NDL', BiblioNat .. ' de la Diète', 349, ndlUrl }, { 'BNE', BiblioNat .. ' d’Espagne', 950, bneUrl }, { 'NTA', 'Bibliothèque royale des Pays-Bas', 1006, ntaUrl }, { 'NLP1', BiblioNat .. ' de Pologne', 1695, nlpUrl }, --ancien identifiant { 'NLP', BiblioNat .. ' de Pologne', 7293, nlpUrl }, --nouvel identifiant { 'NLI', BiblioNat .. ' d’Israël', 8189, nliUrl }, { 'NUKAT', 'Bibliothèque universitaire de Pologne', 1207, nukatUrl }, { 'CATAL', BiblioNat .. ' de Catalogne', 9984, catalUrl, 1273 }, { 'SELIBR', BiblioNat .. ' de Suède', 906, selibrUrl }, -- { 'RERO', 'Réseau des bibliothèques de Suisse occidentale', 3065, reroUrl }, { 'BAV', 'Bibliothèque apostolique vaticane', 8034, bavUrl }, { 'LAC', 'Autorités Canadiana', 1670, idCanadia }, { 'NLA', BiblioNat .. ' d’Australie', 409, nlaUrl }, --{ 'BAnQa', 'Bibliothèque nationale du Québec', 3280, idBAnQa }, -- pour les auteurs -- à activer si BAnQ crée un espace dédié sur son site web. { 'BIBSYS', 'Base de bibliothèque norvégienne', 1015, bibsysUrl }, --{ 'N6I', 'Bibliothèque nationale d’Irlande', 1946, n6iUrl }, -- propriété supprimé de wikidata, ne concerne pas les auteurs, voir https://www.wikidata.org/wiki/Wikidata:Requests_for_deletions/Archive/2019/Properties/1#P1946_(P1946) { 'NSK', 'Bibliothèque universitaire de Zagreb', 1375, nskUrl }, { 'RSL', BiblioNat .. ' de Russie', 947, rslUrl }, { 'NKC', BiblioNat .. ' tchèque', 691, nkcUrl }, { 'BAnQo', BiblioNat .. ' du Québec', 1823, idBAnQo }, --pour les ouvrages --{ 'DBC', BiblioNat .. ' du Danemark', 3846, idDbc }, -- à activer si DBC crée un espace dédié sur son site web. { 'BNCHL', BiblioNat .. ' du Chili', 1966, idBnchl }, { 'PTBNP', BiblioNat .. ' du Portugal', 1005, idPtbnp }, { 'LNB', BiblioNat .. ' de Lettonie', 1368, idLnb }, { 'BNL', BiblioNat .. ' du Luxembourg', 7028, idBNL }, { 'BLBNB', BiblioNat .. ' du Brésil', 4619, blbnbUrl }, { 'NLG', BiblioNat .. ' de Grèce', 3348, nlgUrl }, --{ 'NSZL', BiblioNat .. ' de Hongrie', 951, nszlUrl }, -- à activer si NSZL crée un espace dédié sur son site web. { 'LTI', 'Identifiant LTI de Corée', 4760, ltiUrl }, { 'KRNLK', BiblioNat .. ' de Corée', 5034, krnlkUrl }, { 'BN', BiblioNat .. ' d’Argentine', 1143, bnaUrl }, { 'BNS', BiblioNat .. ' Suisse', 1255, bnsUrl }, { 'ARBABN', BiblioNat .. ' d’Argentine', 3788, arbabnUrl }, -- La bibliothèque d'Arménie fournit 3 sites web différents pour 3 types de documents différents Livre, Personne et ouvrage) { 'NLABOOK', BiblioNat .. ' d’Arménie', 9398, nlaBookUrl }, { 'NLAPERS', BiblioNat .. ' d’Arménie', 8833, nlaPersUrl }, { 'NLARES', BiblioNat .. ' d’Arménie', 9147, nlaResUrl }, { 'WORLDCATID', 'WorldCat Id', 7859 , idworldcat }, { 'OCLC', 'WorldCat', 243, idOclc }, { 'GLOTTOLANG', 'Glottocode', 1394 , glottoUrl },
***********************************************************************************************************************
--- ajouter ici les nouvelles références (appels des fonctions construisant les URL)
***********************************************************************************************************************
}
local p = {}
function p.authorityControl( frame ) local args = Outils.extractArgs(frame)
--Build a map of valid local arguments local goodArgs = {} for _, params in ipairs( conf ) do goodArgs[params[1]] = true end goodArgs.entity = true goodArgs.id = true goodArgs.wikidata = true
local hasLocalArgs = false local hasInvalidArgs = false for name, value in pairs( args ) do if name ~= 'id' and name ~= 'wikidata' and name ~= 'entity' then --"entity" parameter doesn't add to category hasLocalArgs = true end if not goodArgs[name] then hasInvalidArgs = true end end
local entityArg = Outils.validTextArg(args , 'id', 'wikidata', 'entity')
local entity -- The entity id string variable if entityArg then if entityArg ~= '-' then entity = entityArg:upper() else entity = nil end else entity = mw.wikibase.getEntityIdForCurrentPage() -- (if nil, no entity for current page ) end
if entity then for _, params in ipairs( conf ) do if params[3] ~= 0 then local val = args[params[1]] if not val or val == then local wikidataIds = getIdsFromWikidata( entity, 'P' .. params[3] ) if wikidataIds[1] then args[params[1]] = wikidataIds[1] elseif params[5] ~= nil and params[5] ~= 0 then wikidataIds = getIdsFromWikidata( entity, 'P' .. params[5] ) if wikidataIds[1] then args[params[1]] = wikidataIds[1] end end end end end end
--Create rows local elements = {}
--compteur utilisé pour les références aujouté dans le module "autorité". Ce nombre est <= à nbMaxReferenceParPage local nbReferenceValide = 0 --Configured rows for _, params in ipairs( conf ) do --l'id OCLC (ou WORLDCATID) est affiché en dernier par le code spécifique WorldCat en dehors de cette boucle. if params[1] ~= 'OCLC' and params[1] ~= 'WORLDCATID' then local val = args[params[1]] if val and val ~= and nbReferenceValide < nbMaxReferenceParPage then local show_authority = params["condition"] or function() return true end if show_authority(entity) then elements[#elements+1] = createRow( params[1], params[2], val, params[4](val) ) nbReferenceValide = nbReferenceValide+1 end end end end
--Worldcat if args['WORLDCATID'] and args['WORLDCATID'] ~= then if args['WORLDCATID'] ~= '-' then elements[#elements+1] = createRow( 'WORLDCATID', 'WorldCat', args['WORLDCATID'], idworldcat(args['WORLDCATID']) ) -- avec vérification de la validité du paramètre. end elseif args['LCCN'] and args['LCCN'] ~= then local lccnParts = splitLccn( args['LCCN'] ) if lccnParts and lccnParts[1] ~= 'sh' then elements[#elements+1] = createRow( 'LCCN', 'WorldCat', args['LCCN'], 'http://www.worldcat.org/identities/lccn-' .. lccnParts[1] .. lccnParts[2] .. '-' .. lccnParts[3] ) -- L'éventuelle invalidité de la valeur du paramètre aurait déjà déclenché un message d'erreur plus haut lors de l'affichage du lien « Bibliothèque du Congrès ». end elseif args['OCLC'] and args['OCLC'] ~= then elements[#elements+1] = createRow( 'OCLC', 'WorldCat', args['OCLC'], idOclc(args['OCLC']) ) end
local entityInfo = if entityArg and entityArg ~= '-' and entity ~= mw.wikibase.getEntityIdForCurrentPage() then --Has "entity" parameter local label = mw.wikibase.getLabel(entity) local link = wd.siteLink(entity) if label then if link then entityInfo = ' (pour ' .. label .. ')' else entityInfo = ' (pour ' .. label .. ')' end elseif link then entityInfo = ' (pour ' .. link .. ')' end end
if #elements == 0 then return '' end
local cats = "" if hasLocalArgs then cats = cats .. '' end if hasInvalidArgs then cats = cats .. '' end
local title = wd.addLinkBack("Notices d'autorité" .. entityInfo, entity, "identifiers") local elementsHtml = mw.html.create('div') :addClass('liste-horizontale') :wikitext(title .. ' : ') :tag('ul') for _, element in pairs(elements) do elementsHtml:tag('li'):wikitext(element):done():wikitext(' ') end
return tostring(elementsHtml:allDone()) .. cats end
return p