Module:Authority control: verschil tussen versies

Uit Wiki Raamsdonks Historie
(per https://www.wikidata.org/wiki/Property:P8189#P1630)
(comment out ISNI grouping code (see talk page))
Regel 1: Regel 1:
require('Module:No globals')
--[[ 
  __  __          _      _          _        _  _                _ _                          _            _
|  \/  | ___  __| |_  _| | ___ _  / \  _  _| |_| |__  ___  _ __(_) |_ _  _    ___ ___  _ __ | |_ _ __ ___ | |
| |\/| |/ _ \ / _` | | | | |/ _ (_) / _ \| | | | __| '_ \ / _ \| '__| | __| | | |  / __/ _ \| '_ \| __| '__/ _ \| |
| |  | | (_) | (_| | |_| | |  __/_ / ___ \ |_| | |_| | | | (_) | |  | | |_| |_| | | (_| (_) | | | | |_| | | (_) | |
|_|  |_|\___/ \__,_|\__,_|_|\___(_)_/  \_\__,_|\__|_| |_|\___/|_|  |_|\__|\__, |  \___\___/|_| |_|\__|_|  \___/|_|
                                                                            |___/                                   
This module is intended to be the engine behind "Template:Authority control".


local displayLabel = 'Bibliografische informatie'
Please do not modify this code without applying the changes first at "Module:Authority control/sandbox" and testing
local displayLink = 'Wikipedia:Bibliografische informatie'
at "Module:Authority control/testcases".
local catNameInvalidID = 'Wikipedia:Pagina\'s met ongeldige authority control id'


local p = {}
Authors and maintainers:
local title = mw.title.getCurrentTitle()
* User:Jarekt - original version
local namespace = title.namespace
local testcases = (string.sub(title.subpageText,1,9) == 'testcases')


--[[==========================================================================]]
]]
--[[                      Property formatting functions                      ]]
--[[==========================================================================]]


function p.iaafLink( id )
local properties = require('Module:Authority control/conf')
--P1146's format regex: [0-9][0-9]* (e.g. 012)
local core      = require('Module:Core')
if not id:match( '^%d+$' ) then
return false
end
return '[https://www.iaaf.org/athletes/_/'..id..' '..id..']'
end


function p.viafLink( id )
-- ==================================================
--P214's format regex: [1-9]\d(\d{0,7}|\d{17,20}) (e.g. 123456789, 1234567890123456789012)
-- === Internal functions ===========================
if not id:match( '^[1-9]%d%d?%d?%d?%d?%d?%d?%d?$' ) and
-- ==================================================
  not id:match( '^[1-9]%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d?%d?%d?$' ) then
return false
end
return '[https://viaf.org/viaf/'..id..' '..id..']'
end


function p.kulturnavLink( id )
local function getSitelink(item, lang)
--P1248's format regex: [0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
    -- get item's siteling in specific language
if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
local langList = mw.language.getFallbacksFor(lang)
return false
table.insert(langList, 1, lang)
end
for _, language in ipairs(langList) do
return '[http://kulturnav.org/'..id..' '..id..']'
local sitelink = mw.wikibase.sitelink( item, language .. 'wiki' )
end
if sitelink then
 
return 'w:'.. language ..':'.. sitelink
function p.sikartLink( id )
end
--P781's format regex: \d{7,9} (e.g. 123456789)
if not id:match( '^%d%d%d%d%d%d%d%d?%d?$' ) then
return false
end
end
return '[http://www.sikart.ch/KuenstlerInnen.aspx?id='..id..'&lng=en '..id..']'
return nil
end
end


function p.tlsLink( id )
-- ==================================================
local id2 = id:gsub(' +', '_')
local function getIdentifierNameLink( lang, item1, item2, label )
--P1362's format regex: \p{Lu}[\p{L}\d_',\.\-\(\)\*/–]{3,59} (e.g. Abcd)
-- Identifier names, like VIAF, LCCN, ISNI, need to be linked to the articles about them if possible
local class = "[%a%d_',%.%-%(%)%*/–]"
-- Alternativly they can be linked to the articles for institutions that issue them
local regex = "^%u"..string.rep(class, 3)..string.rep(class.."?", 56).."$"
local id_name_URL = nil
if not mw.ustring.match( id2, regex ) then
-- 1) try wikipedia sitelink for the identifier in users language and in English
return false
if item1 and item1 ~='' then
id_name_URL = getSitelink(item1, lang)
end
end
return '[http://tls.theaterwissenschaft.ch/wiki/'..id2..' '..id..']'
-- 2) try wikipedia sitelink for the issuedBy property in users language and in English
end
if id_name_URL==nil and item2 and item2 ~='' then -- if no link than
 
id_name_URL = getSitelink(item2, lang)
function p.ciniiLink( id )
--P271's format regex: D[AB]\d{7}[\dX] (e.g. DA12345678)
if not id:match( '^D[AB]%d%d%d%d%d%d%d[%dX]$' ) then
return false
end
end
return '[https://ci.nii.ac.jp/author/'..id..'?l=en '..id..']'
-- 3) if still no links than link to wikidata
end
if id_name_URL then
 
return string.format("[[%s|%s]]", id_name_URL, label) -- link to wikipedia
function p.daaoLink( id )
else   
--P1707's format regex: [a-z\-]+\d* (e.g. rolf-harris)
return string.format("[[d:%s|%s]]", item1, label) -- link to wikidata
if not id:match( '^[a-z%-]+%d*$' ) then
return false
end
end
return '[https://www.daao.org.au/bio/'..id..' '..id..']'
end
end


function p.bneLink( id )
-- ==================================================
--P950's format regex: (XX|FF|a)\d{4,7}|(bima|bimo|bica|bis[eo]|bivi|Mise|Mimo|Mima)\d{10} (e.g. XX1234567)
-- Create link to a single identifier
if not id:match( '^[XF][XF]%d%d%d%d%d?%d?%d?$' ) and
-- INPUTS:
  not id:match( '^a%d%d%d%d%d?%d?%d?$' ) and
--  * val - value of the identifier
  not id:match( '^bi[mcsv][aoei]%d%d%d%d%d%d%d%d%d%d$' ) and
--  * P - property record, with URL_format and optional interwiki_format strings to create links
  not id:match( '^Mi[sm][eoa]%d%d%d%d%d%d%d%d%d%d$' ) then
--  * params - additional parameters related to this type of identifiers. Single item from "conf"
return false
--  * color - color of the link
local function getIdentifierValLink(val, P, params, color)
if not val or val=='' then
return ''
end
end
return '[http://catalogo.bne.es/uhtbin/authoritybrowse.cgi?action=display&authority_id='..id..' '..id..']'
-- check if identifier is in the right format
end
local mismatchStr = ''
 
local val_ = val:gsub( ' ', '' ) -- remove spaces
function p.uscongressLink( id )
if (params.regexp and not val:match( params.regexp )) then
--P1157's format regex: [A-Z]00[01]\d{3} (e.g. A000123)
mismatchStr  = string.format("<span style=\"color:red\">[does not match %s pattern]</span>", params.regexp)
if not id:match( '^[A-Z]00[01]%d%d%d$' ) then
elseif (params.verify) then -- check if special "Verify" function is present
return false
mismatchStr = params.verify(val_) -- add error message if any
end
end
return '[http://bioguide.congress.gov/scripts/biodisplay.pl?index='..id..' '..id..']'
-- identifier_value_URL
end
if color~="blue" then
 
val = string.format('<span style=\"color:%s\">%s</span>', color, val)
function p.naraLink( id )
--P1225's format regex: ^([1-9]\d{0,8})$ (e.g. 123456789)
if not id:match( '^[1-9]%d?%d?%d?%d?%d?%d?%d?%d?$' ) then
return false
end
end
return '[https://catalog.archives.gov/id/'..id..' '..id..']'
local val_link
end
if P.interwiki_format and P.interwiki_format ~= '' then
 
val_link = string.format("[[%s:%s|%s]]", P.interwiki_format, val_, val)
function p.narcisLink( id )
else
--P7449's format regex: PRS\d+ (e.g. PRS1238288)
local val_URL = P.URL_format:gsub('$1', val_)-- URL part of the link for the identifier value
if not id:match( '^PRS%d+$' ) then
val_link = string.format("[%s %s]", val_URL, val)
return false
end
end
return '[https://www.narcis.nl/person/RecordID/'..id..' '..id..']'
return string.format("<span class=\"plainlinks\">%s</span>%s", val_link, mismatchStr) -- link to the identifier's website
end
end  


function p.botanistLink( id )
-- ==================================================
--P428's format regex: ('t )?(d')?(de )?(la )?(van (der )?)?(Ma?c)?(De)?(Di)?\p{Lu}?C?['\p{Ll}]*([-'. ]*(van )?(y )?(d[ae][nr]?[- ])?(Ma?c)?[\p{Lu}bht]?C?['\p{Ll}]*)*\.? ?f?\.? (e.g. L.)
-- Convert between 2 formats of LCCN: "n/79/63767" -> "n79063767"
--not easily/meaningfully implementable in Lua's regex since "(this)?" is not allowed...
-- "n/79/63767" format was used as input by {{Authority Control}} templates
if not mw.ustring.match( id, "^[%u%l%d%. '-]+$" ) then --better than nothing
-- "n79063767" format is used by wikidata
return false
local function fixLCCN(id)
end
  if id then
local id2 = id:gsub(' +', '%%20')
local a, b, c = string.match(id, "([%a%d]*)/([%a%d]*)/([%a%d]*)")
return '[https://www.ipni.org/ipni/advAuthorSearch.do?find_abbreviation='..id2..' '..id..']'
if c then
end
local pad = 6 - string.len(c)
 
if pad > 0 then
function p.mgpLink( id )
c = string.rep("0", pad)..c
--P549's format regex: \d{1,6} (e.g. 123456)
end
if not id:match( '^%d%d?%d?%d?%d?%d?$' ) then
id = a..b..c
return false
end
end
return '[https://genealogy.math.ndsu.nodak.edu/id.php?id='..id..' '..id..']'
end
 
function p.rslLink( id )
--P947's format regex: \d{1,9} (e.g. 123456789)
if not id:match( '^%d%d?%d?%d?%d?%d?%d?%d?%d?$' ) then
return false
end
return '[http://aleph.rsl.ru/F?func=find-b&find_code=SYS&adjacent=Y&local_base=RSL11&request='..id..'&CON_LNG=ENG '..id..']'
end
 
function p.leonoreLink( id )
--P640's format regex: LH//\d{1,4}/\d{1,3}|19800035/\d{1,4}/\d{1,5}(Bis|Ter)?|C/0/\d{1,2} (e.g. LH//2064/18)
if not id:match( '^LH//%d%d?%d?%d?/%d%d?%d?$' ) and            --IDs from      LH/1/1 to        LH//2794/54 (legionaries)
  not id:match( '^19800035/%d%d?%d?%d?/%d%d?%d?%d?%d?$' ) and --IDs from 19800035/1/1 to 19800035/385/51670 (legionnaires who died 1954-1977 & some who died < 1954)
  not id:match( '^C/0/%d%d?$' ) then                          --IDs from        C/0/1 to            C/0/84 (84 famous legionaries)
return false
end
return '[http://www.culture.gouv.fr/public/mistral/leonore_fr?ACTION=CHERCHER&FIELD_1=COTE&VALUE_1='..id..' '..id..']'
end
 
function p.sbnLink( id )
--P396's format regex: \D{2}[A-Z0-3]V\d{6} (e.g. CFIV000163)
if not id:match( '^%u%u[%u0-3]V%d%d%d%d%d%d$' ) then
return false
end
return '[https://opac.sbn.it/opacsbn/opac/iccu/scheda_authority.jsp?bid='..id..' '..id..']'
end
 
function p.nkcLink( id )
--P691's format regex: [a-z]{2,4}[0-9]{2,14} (e.g. abcd12345678901234)
if not id:match( '^[a-z][a-z][a-z]?[a-z]?%d%d%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?$' ) then
return false
end
return '[https://aleph.nkp.cz/F/?func=find-c&local_base=aut&ccl_term=ica='..id..'&CON_LNG=ENG '..id..']'
end
 
function p.nclLink( id )
--P1048's format regex: \d+ (e.g. 1081436)
if not id:match( '^%d+$' ) then
return false
end
return '[http://aleweb.ncl.edu.tw/F/?func=accref&acc_sequence='..id..'&CON_LNG=ENG '..id..']'
end
 
function p.ndlLink( id )
--P349's format regex: 0?\d{8} (e.g. 012345678)
if not id:match( '^0?%d%d%d%d%d%d%d%d$' ) then
return false
end
return '[https://id.ndl.go.jp/auth/ndlna/'..id..' '..id..']'
end
 
function p.ngvLink( id )
--P2041's format regex: \d+ (e.g. 12354)
if not id:match( '^%d+$' ) then
return false
end
return '[https://www.ngv.vic.gov.au/explore/collection/artist/'..id..'/ '..id..']'
end
 
function p.sudocLink( id )
--P269's format regex: (\d{8}[\dX]|) (e.g. 026927608)
if not id:match( '^%d%d%d%d%d%d%d%d[%dxX]$' ) then --legacy: allow lowercase 'x'
return false
end
return '[https://www.idref.fr/'..id..' '..id..']'
end
 
function p.hdsLink( id )
--P902's format regex: \d{6} (e.g. 050123)
if not id:match( '^%d%d%d%d%d%d$' ) then
return false
end
return '[https://hls-dhs-dss.ch/fr/articles/'..id..' '..id..']'
end
 
function p.swissparliamentLink( id )
--P1307's format regex: \d{1,4} (e.g. 2361)
if not id:match( '^%d%d?%d?%d?$' ) then
return false
end
return '[https://www.parlament.ch/fr/biografie/wd/'..id..' '..id..']'
end
 
function p.bdelisLink( id )
--P6231's format regex: \d{5} (e.g. 55864)
if not id:match( '^%d%d%d%d%d$' ) then
return false
end
return '[https://www2.unil.ch/elitessuisses/personne.php?id='..id..' '..id..']'
end
 
function p.lirLink( id )
--P886's format regex: \d+ (e.g. 1)
if not id:match( '^%d+$' ) then
return false
end
return '[http://www.e-lir.ch/e-LIR___Lexicon.'..id..'.450.0.html '..id..']'
end
 
function p.splitLccn( id )
--P244's format regex: (n|nb|nr|no|ns|sh)([4-9][0-9]|00|20[0-1][0-9])[0-9]{6} (e.g. n78039510)
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 p.append(str, c, length)
while str:len() < length do
str = c .. str
end
return str
end
 
function p.lccnLink( id )
local parts = p.splitLccn( id ) --e.g. n78039510
if not parts then
return false
end
local lccnType = parts[1] ~= 'sh' and 'names' or 'subjects'
id = parts[1] .. parts[2] .. p.append( parts[3], '0', 6 )
return '[https://id.loc.gov/authorities/'..lccnType..'/'..id..' '..id..']'
end
 
function p.mbaLink( id )
--P434's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
return false
end
return '[https://musicbrainz.org/artist/'..id..' '..id..']'
end
 
function p.mbareaLink( id )
--P982's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
return false
end
return '[https://musicbrainz.org/area/'..id..' '..id..']'
end
 
function p.mbiLink( id )
--P1330's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
return false
end
return '[https://musicbrainz.org/instrument/'..id..' '..id..']'
end
 
function p.mblLink( id )
--P966's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
return false
end
return '[https://musicbrainz.org/label/'..id..' '..id..']'
end
 
function p.mbpLink( id )
--P1004's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
return false
end
return '[https://musicbrainz.org/place/'..id..' '..id..']'
end
 
function p.mbrgLink( id )
--P436's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
return false
end
return '[https://musicbrainz.org/release-group/'..id..' '..id..']'
end
 
function p.mbsLink( id )
--P1407's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
return false
end
return '[https://musicbrainz.org/series/'..id..' '..id..']'
end
 
function p.mbwLink( id )
--P435's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
return false
end
return '[https://musicbrainz.org/work/'..id..' '..id..']'
end
 
--Returns the ISNI check digit isni must be a string where the 15 first elements are digits, e.g. 0000000066534145
function p.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
function p.validateIsni( id )
--P213 (ISNI) format regex: [0-9]{4} [0-9]{4} [0-9]{4} [0-9]{3}[0-9X] (e.g. 0000-0000-6653-4145)
--P496 (ORCID) format regex: 0000-000(1-[5-9]|2-[0-9]|3-[0-4])\d{3}-\d{3}[\dX] (e.g. 0000-0002-7398-5483)
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 p.getIsniCheckDigit( id ) ~= string.char( id:byte( 16 ) ) then
return false
end
end
return id
return id
end
end -- fixLCCN


function p.isniLink( id )
-- ==================================================
id = p.validateIsni( id ) --e.g. 0000-0000-6653-4145
-- Verify last "check" digit is correct. ISNI and several other
if not id then
-- identifiers use last digit as a verification digit
return false
local function verifyLastDigit( id )
    local total = 0
    for i = 1, #id-1 do
        local digit = id:byte( i ) - 48 --Get integer value
        total = (total + digit) * 2
    end
    --local remainder = total % 11
    local lastDigit = tostring((12 - total % 11) % 11)
    if lastDigit == '10' then
        lastDigit = "X"
    end
    if (lastDigit == string.sub( id, -1)) then
return ''
else
return "<span style=\"color:red\">[last digit should be " .. lastDigit .. "]</span>"
end
end
return '[http://isni.org/isni/'..id..' '..id:sub( 1, 4 )..' '..id:sub( 5, 8 )..' '..id:sub( 9, 12 )..' '..id:sub( 13, 16 )..']'
end
end


function p.orcidLink( id )
-- ==================================================
id = p.validateIsni( id ) --e.g. 0000-0002-7398-5483
-- === Settings =====================================
if not id then
-- ==================================================
return false
-- In order to add a new identifier associated with Wikidata property do the following
end
-- 1) go to [[Template:Authority control/IdentifierList]] and verify that the property number is on the list, if not than edit the page to add it
id = id:sub( 1, 4 )..'-'..id:sub( 5, 8 )..'-'..id:sub( 9, 12 )..'-'..id:sub( 13, 16 )
-- 2) copy code generated at [[Template:Authority control/IdentifierList]] to protected [[Module:Authority control/conf]]
return '[https://orcid.org/'..id..' '..id..']'
-- 3) add the property to the "conf" list below
end


function p.oeibeLink( id )
-- load 'Module:Authority control/conf' which holds hardwired data derived from Wikidata's properties of
--P1764's format regex: [1-9]\d* (e.g. 49951)
-- properties
if not id:match( '^[1-9]%d*$' ) then
return false
end
return '[https://id.erfgoed.net/erfgoedobjecten/'..id..' '..id..']'
end


function p.gndLink( id )
--conf  holds list of identifiers to be displayed
--P227's format regex: 1[0123]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|3\d{7}[0-9X] (e.g. 4079154-3)
local conf = {
if not id:match( '^1[0123]?%d%d%d%d%d%d%d[0-9X]$' ) and
    -- people
  not id:match( '^[47]%d%d%d%d%d%d%-%d$' ) and
{label='VIAF'        , property='P214' , lang=''  , regexp='^%d+$' },
  not id:match( '^[1-9]%d?%d?%d?%d?%d?%d?%d?%-[0-9X]$' ) and
{label='ISNI'        , property='P213' , lang=''  , regexp='^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$', verify=verifyLastDigit },
  not id:match( '^3%d%d%d%d%d%d%d[0-9X]$' ) then
{label='ORCID'      , property='P496' , lang=''  , regexp='^0000%-000[1-3]%-%d%d%d%d%-%d%d%d[%dX]$' },
return false
{label='ULAN'        , property='P245' , lang=''  , regexp='^500%d%d%d%d%d%d$' }, -- 'Union List of Artist Names' by Getty Research Institute
end
{label='ResearcherID', property='P1053', lang=''  , regexp='^[A-Z]+%-%d%d%d%d%-[12][90]%d%d$' },
return '[https://d-nb.info/gnd/'..id..' '..id..']'
{label='LCCN'        , property='P244' , lang='en', regexp='^[ns][broshj]?%d%d%d%d%d%d%d%d%d?%d?$' }, -- Library of Congress Authorities
end
{label='GND'        , property='P227' , lang='de', regexp='^[%dX%-]+$'},
{label='SELIBR'      , property='P906' , lang='se', regexp='^%d+$' }, -- National Library of Sweden
{label='SUDOC'      , property='P269' , lang='fr', regexp='^%d%d%d%d%d%d%d%d[%dxX]$' },   
{label='BNF'        , property='P268' , lang='fr', regexp='^%d+%w?$' }, -- Bibliothèque nationale de France
{label='BPN'        , property='P651' , lang='nl', regexp='^%d%d%d%d%d%d%d%d$' }, -- Biografisch Portaal number
{label='NAID'        , property='P1225', lang='en', regexp='^%d+$' }, -- NARA ID (redirect for US National Archives Identifier (P1225))
{label='Museofile'  , property='P539' , lang='fr', regexp='^M%d%d%d%d%-?%d?%d?$' }, --Ministry of Culture (France)
{label='NDL'        , property='P349' , lang='ja', regexp='^0?%d%d%d%d%d%d%d%d$' }, -- National Diet Library (of Japan)
{label='NLA'        , property='P409' , lang='en', regexp='^[1-9]%d*$' }, -- National Library of Australia
{label='BIBSYS'      , property='P1015', lang='no', regexp='^%d+$' }, -- Norwegian information system BIBSYS
{label='HDS'        , property='P902' , lang='de', regexp='^%d%d%d?%d?%d?%d?$' },  -- Historical Dictionary of Switzerland
{label='MusicBrainz' , property='P434' , lang='en', regexp='^[-%x]+$' },
{label='MGP'        , property='P549' , lang='en', regexp='^%d%d?%d?%d?%d?%d?$' },  -- Mathematics Genealogy Project
{label='NCL'        , property='P1048', lang='zh', regexp='^%d+$' },  --National Central Library (Taiwan)
{label='NKC'        , property='P691' , lang='cs', regexp='^%l%l%l?%l?%d%d%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?$' },  --National Library of the Czech Republic
{label='Léonore'    , property='P640' , lang='fr', regexp='^[LHC%/%d]+$' },
{label='SBN'        , property='P396' , lang='it'},  -- Istituto Centrale per il Catalogo Unico /  National Library Service (SBN) of Italy
{label='RSL'        , property='P947' , lang='ru', regexp='^%d%d%d%d%d%d%d%d%d$' },  --Russian State Library
{label='Botanist'    , property='P428' , lang='en' },
{label='US Congress' , property='P1157', lang='en', regexp='^%u00[01]%d%d%d' },
{label='BNE'        , property='P950' , lang='es', regexp='' }, --Biblioteca Nacional de España
{label='CALIS'      , property='P270' , lang='zh'}, --China Academic Library and Information
{label='CiNii'      , property='P271' , lang='jp', regexp='^DA%d%d%d%d%d%d%d[%dX]$' },
{label='TLS'        , property='P1362', lang='de', regexp='' }, -- Theaterlexikon der Schweiz
{label='SIKART'      , property='P781' , lang='de', regexp='^%d%d%d%d%d%d%d%d?%d?%d?$' }, -- Swiss
{label='NLP'        , property='P1695', lang='pl', regexp='' }, -- National Library of Poland
{label='WGA'        , property='P1882', lang='en', regexp='' }, -- Web Gallery of Art
{label='KulturNav'  , property='P1248', lang='no', regexp='' },
{label='RKD'        , property='P650' , lang='nl', regexp='^[1-9]%d%d?%d?%d?%d?$' }, --Netherlands Institute for Art History#Online artist pages
{label='autores.uy'  , property='P2558', lang='es', regexp='^[1-9]%d?%d?%d?%d?$' },  --autores.uy
{label='J9U'        , property='P8189', lang='he', regexp='' },  --National Library of Israel J9U ID


function p.selibrLink( id )
{label='FIDE'        , property='P1440', lang='en', regexp='' }, -- FIDE database for chess players
--P906's format regex: [1-9]\d{4,5} (e.g. 123456)
{label='Chess Games' , property='P1665', lang='en', regexp='' }, -- Chess Games
if not id:match( '^[1-9]%d%d%d%d%d?$' ) then
return false
end
return '[https://libris.kb.se/auth/'..id..' '..id..']'
end


function p.bnfLink( id )
{label='ISSN'        , property='P236',  lang='', regexp='' }, -- P1629: International Standard Serial Number
--P268's format regex: \d{8}[0-9bcdfghjkmnpqrstvwxz] (e.g. 123456789)
{label='OSM'        , property='P402',  lang='', regexp='' },  -- P1629: OpenStreetMap
if not id:match( '^c?b?%d%d%d%d%d%d%d%d[0-9bcdfghjkmnpqrstvwxz]$' ) then
{label='Joconde'    , property='P347',  lang='fr', regexp='' }, -- Joconde ID
return false
{label='Rijksmonument',property='P359',  lang='nl', regexp='' }, -- Rijksmonument ID
end
{label='IMO'        , property='P458',  lang='', regexp='' }, --IMO ship number
--Add cb prefix if it has been removed
{label='BNCF'        , property='P508',  lang='it', regexp='' }, -- BNCF Thesaurus ID
if not id:match( '^cb.+$' ) then
{label='MMSI'        , property='P587',  lang='', regexp='' }, -- P1629: Maritime Mobile Service Identity
id = 'cb'..id
{label='Open Library', property='P648',  lang='', regexp='' }, -- P1629: Open Library
end
{label='NRHP'        , property='P649',  lang='en', regexp='' }, -- NRHP reference number
return '[https://catalogue.bnf.fr/ark:/12148/'..id..' '..id..'] [https://data.bnf.fr/ark:/12148/'..id..' (data)]'
{label='DBNL'        , property='P723',  lang='', regexp='' }, -- DBNL author ID
end
{label='UNESCO'      , property='P757',  lang='', regexp='' }, -- World Heritage Site ID
{label='BIC'        , property='P808',  lang='', regexp='' }, -- Bien de Interés Cultural (BIC) code
{label='LIR'        , property='P886',  lang='', regexp='' }, -- LIR
{label='BNR'        , property='P1003', lang='ro', regexp='' }, -- NLR (Romania) ID
{label='Koninklijke' , property='P1006', lang='nl', regexp='' }, -- National Thesaurus for Author Names ID
{label='Louvre'      , property='P9394', lang='', regexp='' }, -- Louvre ID
{label='OCLC'        , property='P243',  lang='', regexp='' }, -- OCLC
{label='ISBN-13'    , property='P212',  lang='', regexp='' }, -- ISBN-13
{label='ISBN-10'    , property='P957',  lang='', regexp='' }, -- ISBN-10
{label='Historic England', property='P1216', lang='en', regexp='' }, -- National Heritage List for England number


function p.bpnLink( id )
{label='Oxford Dict.', property='P1415', lang='en', regexp='' }, -- Oxford Dictionary of National Biography ID
--P651's format regex: \d{6,8} (e.g. 00123456)
{label='kulturnoe-nasledie', property='P1483', lang='ru', regexp='' },  -- kulturnoe-nasledie.ru ID
if not id:match( '^%d%d%d%d%d%d%d%d$' ) and --original format regex, changed 8/2019 to
{label='Catalunya'  , property='P1600', lang='ca', regexp='' }, -- Inventari del Patrimoni Arquitectònic de Catalunya code
  not id:match( '^0?%d%d%d%d%d%d%d$' ) and --allow 1-2 leading 0s, allowed by the website
{label='COAM'        , property='P2917', lang='es', regexp='' }, -- COAM structure ID
  not id:match( '^0?0?%d%d%d%d%d%d$' ) then
{label='SIMBAD'      , property='P3083', lang='fr', regexp='' }, -- SIMBAD ID
return false
{label='JCyL'        , property='P3177', lang='es', regexp='' }, -- Patrimonio Web JCyL ID
end
{label='Zaragoza'    , property='P3178', lang='es', regexp='' },  -- Zaragoza monument ID
return '[http://www.biografischportaal.nl/persoon/'..id..' '..id..']'
{label='BDI'        , property='P3318', lang='es', regexp='' }, -- Patrimonio Inmueble de Andalucía ID
end
{label='SIPCA'      , property='P3580', lang='es', regexp='' }, -- SIPCA code
{label='DOCOMOMO'    , property='P3758', lang='', regexp='' }, -- DOCOMOMO Ibérico ID
{label='Czech Monument', property='P4075', lang='cz', regexp='' }, -- Czech Monument Catalogue Number
{label='MEG'        , property='P4157', lang='ch', regexp='' }, -- P1629: Musée d'ethnographie de Genève
{label='Enciclopédia Itaú Cultural' , property='P4399', lang='pt_br', regexp='' }, -- Enciclopédia Itaú Cultural ID
{label='Monumentos de São Paulo'    , property='P4360', lang='pt_br', regexp='' }, -- Monumentos de São Paulo ID
{label='Infopatrimônio'            , property='P4372', lang='pt_br', regexp='' }, -- Infopatrimônio ID
{label="Musée d'Orsay"              , property='P4659', lang='fr'  , regexp='' }, -- Musée d'Orsay artwork ID
{label='MuBE'                      , property='P4721', lang='pt_br', regexp='' }, -- MuBE Virtual ID
{label='Hispania Nostra'            , property='P4868', lang='es'  , regexp='' }, -- Hispania Nostra Red List ID
{label='NLK'            , property='P5034', lang='ko'   , regexp='' }, -- National Library of Korea ID
}


function p.ridLink( id )
-- ==================================================
--P1053's format regex: [A-Z]{1,3}-\d{4}-(19|20)\d\d (e.g. A-1234-1934)
-- === External functions ===========================
if not id:match( '^[A-Z][A-Z]?[A-Z]?%-%d%d%d%d%-19%d%d$' ) and
-- ==================================================
  not id:match( '^[A-Z][A-Z]?[A-Z]?%-%d%d%d%d%-20%d%d$' ) then
local p = {}
return false
end
return '[https://www.researcherid.com/rid/'..id..' '..id..']'
end


function p.bibsysLink( id )
function p.getAuthorityControlTag( lang )
--P1015's format regex: [1-9]\d* or [1-9](\d{0,8}|\d{12}) (e.g. 1234567890123)
-- get a localized interwiki link to article "Authority Control"
--TODO: follow up @ [[d:Property talk:P1015#Discrepancy between the 2 regex constraints]] or escalate/investigate
local field_name = "[[w:en:Help:Authority control|Authority control]]" -- hardwire the default
if not id:match( '^[1-9]%d?%d?%d?%d?%d?%d?%d?%d?$' ) and
if lang~='en' then
  not id:match( '^[1-9]%d%d%d%d%d%d%d%d%d%d%d%d$' ) then
field_name = core.getLabel("Q36524", lang)
return false
end
end
return '[https://authority.bibsys.no/authority/rest/authorities/html/'..id..' '..id..']'
return field_name
end
end


function p.ulanLink( id )
-- ==================================================
--P245's format regex: 500\d{6} (e.g. 500123456)
function p._authorityControl(entity, args, lang, length)
if not id:match( '^500%d%d%d%d%d%d$' ) then
-- INPUTS:
return false
--  * entity - wikidata entity if already created or nil. If provided than you should still provide args.Wikidata
end
--  * args  - structure with identifier fields: args.VIAF, args.LCCN, args.Wikidata, etc.
return '[https://www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid='..id..' '..id..']'
--  * lang  - language code
end
--  * length - maximum length of the identifier array, or number of identifiers to display
-- OUTPUTS:
--  * results - wikicode string equivalent to {{Authority control|...|bare=1 }} call
--  * cats    - wikicode with maintenance categories


function p.nlaLink( id )
  -- count custom parameters (not pulled from Wikidata)
--P409's format regex: [1-9][0-9]{0,11} (e.g. 123456789012)
local nCustomParam = 0  
if not id:match( '^[1-9]%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?$' ) then
for _,params in ipairs( conf ) do
return false
if (args[params.label]~=nil) then
nCustomParam = nCustomParam + 1
end
end
end
return '[https://nla.gov.au/anbd.aut-an'..id..' '..id..']'
end
-- Get entity - record of wikidata related to a single item
 
local q = args.wikidata
function p.troveLink( id )
if not entity and q then
--P1315's format regex: [1-9]\d{5,7} (e.g. 12345678)
entity = mw.wikibase.getEntity(q)
if not id:match( '^[1-9]%d%d%d%d%d%d?%d?$' ) then
return false
end
end
return '[https://trove.nla.gov.au/people/'..id..' '..id..']'
end
-- Check if this is category item
 
local cats = '' -- categories (mismatching and missing)
function p.rkdartistsLink( id )
if entity and entity.claims and entity.claims.P31 then
--P650's format regex: [1-9]\d{0,5} (e.g. 123456)
for _, statement in pairs( entity.claims.P31) do
if not id:match( '^[1-9]%d?%d?%d?%d?%d?$' ) then
if (statement.mainsnak.snaktype == "value") and (statement.mainsnak.datavalue.value.id == 'Q4167836')  then -- P31 == Wikimedia category
return false
cats = '[[Category:Wrong Wikidata ID in authority control data: category item]]'
end
if (statement.mainsnak.snaktype == "value") and (statement.mainsnak.datavalue.value.id == 'Q4167410') then -- P31 == Wikimedia disambiguation page
cats = '[[Category:Wrong Wikidata ID in authority control data: disambiguation item]]'
end
end
end
end
return '[https://rkd.nl/nl/explore/artists/'..id..' '..id..']'
end


function p.snacLink( id )
--compare provided arguments with Wikidata identifiers
--P3430's format regex: \d*[A-Za-z][0-9A-Za-z]* (e.g. A)
local data = {} -- structure similar to "args" but filled with wikidata data
if not id:match( '^%d*[A-Za-z][0-9A-Za-z]*$' ) then
for _,params in ipairs( conf ) do
return false
local label = string.lower(params.label)
data[label] = nil
if entity and entity.claims and params.property and entity.claims[params.property] then -- if we have wikidata item and item has the property
-- capture all Wikidata values for the identifier
--for _, statement in pairs( entity.claims[params.property]) do
for _, statement in pairs( entity:getBestStatements( params.property )) do
if (statement.mainsnak.snaktype == "value") then -- or if statement.mainsnak.datavalue then
local v = statement.mainsnak.datavalue.value
if data[label]==nil then
data[label] = v      -- save the first value
end
if args[label] == v then  -- match between template and wikidata identifiers
data[label] = ''     -- ignore identifier from wikidata
break 
end
end
end
end
end
end
return '[https://snaccooperative.org/ark:/99166/'..id..' '..id..']'
end


function p.dblpLink( id )
--Create string with all the identifiers listed
--P2456's format regex: \d{2,3} /\d+(-\d+)?|[a-z] /[a-zA-Z][0-9A-Za-z]*(-\d+)? (e.g. 123/123)
local results1 = {} -- high priority list
if not id:match( '^%d%d%d?/%d+$' ) and
local results2 = {} -- low  priority list
  not id:match( '^%d%d%d?/%d+%-%d+$' ) and
properties.P214.item = 'Q54919';  -- hardwire link to VIAF
  not id:match( '^[a-z]/[a-zA-Z][0-9A-Za-z]*$' ) and
local today = '+' .. os.date('!%F') .. 'T00:00:00Z/11'
  not id:match( '^[a-z]/[a-zA-Z][0-9A-Za-z]*%-%d+$' ) then
local TransStr = 'https://quickstatements.toolforge.org/#/v1=%s|%s|%%22%s%%22|S143|Q565|S813|'.. today -- QuickStatementts URL
return false
TransStr = '<span class=\"plainlinks\" title=\"Click (+) to copy to wikidata\">['.. TransStr .. ' (+)]</span>'
end
for _,params in ipairs( conf ) do
return '[https://dblp.org/pid/'..id..' '..id..']'
local label = string.lower(params.label)
end
local val1 = args[label] -- identifier value provided to the template
local val2 = data[label] -- identifier value pulled from wikidata
if val1 or val2 then
local P = properties[params.property] -- properties of wikidata identifier propertyc
-- name_link - link for the identifier name
local name_link = getIdentifierNameLink( lang, P.item, P.issuedBy, params.label )
-- val_link - identifier value or values
local transfer = ''
local val3 = string.gsub(val1 or '', ' ', '' ) -- remove spaces
local val_link
if not val1 then
val_link = getIdentifierValLink(val2, P, params, 'blue') -- wikidata only no local identifier
elseif val2=='' then
val_link = getIdentifierValLink(val1, P, params, 'magenta') -- match was found
elseif val2 then
val_link = getIdentifierValLink(val1, P, params, 'darkgreen') .. "/"..getIdentifierValLink(val2, P, params, 'blue')
cats  = string.format("%s[[Category:Pages using authority control with identifiers mismatching Wikidata]]\n", cats)
transfer  = string.format(TransStr, q, params.property, val3)
elseif not val2 and entity then
val_link = getIdentifierValLink(val1, P, params, 'darkgreen')
cats  = string.format("%s[[Category:Pages using authority control with identifiers missing from Wikidata]]\n", cats)
transfer  = string.format(TransStr, q, params.property, val3)
else
val_link = getIdentifierValLink(val1, P, params, 'blue') -- local identifier and no wikidata q-code
end


function p.dgo4Link( id )
-- combine them all
--P1133's format regex: \d{5}-[A-Z]{3}-\d{4}-\d{2}
local lineStr = string.format("\n*%s:&thinsp;<span class=\"uid\">%s</span>%s", name_link, val_link, transfer)
if not id:match( '^%d%d%d%d%d%-[A-Z][A-Z][A-Z]%-%d%d%d%d%-%d%d$' ) then
if (params.lang==lang) or (params.lang=='') then
return false
table.insert(results1, lineStr) -- add to high priority list
else
table.insert(results2, lineStr) -- add to low priority list
end
end
end -- for all sources
-- merge high and low priority lists, trim them if needed and convert to string
--table.insert(results1, "\n*End list 1") -- for debuging
--table.insert(results2, "\n*End list 2")
for _,v in pairs(results2) do table.insert(results1, v) end
local results = table.concat(results1, "", 1, math.min(#results1, length or #results1))
-- Add Link to wikidata
if q then
results = string.format("\n*[[File:Wikidata-logo.svg|20px|wikidata:%s|link=wikidata:%s]]: [[d:%s|%s]]%s",q,q,q,q,results)
end
end
return '[https://lampspw.wallonie.be/dgo4/site_thema/index.php/dossier/view/BC_PAT/'..id..' '..id..']'
end
-- Add link to Worldcat
 
if (args.worldcatid==nil and (args.lccn or data.lccn))  then
function p.aagLink( id )
args.worldcatid = 'lccn-' .. (args.lccn or data.lccn)
--P3372's format regex: \d+ (e.g. 1)
if not id:match( '^%d+$' ) then
return false
end
end
return '[http://www.aucklandartgallery.com/explore-art-and-ideas/artist/'..id..'/ '..id..']'
if args.worldcatid  then
end
results = string.format("%s\n*<span class=\"uid\">[//www.worldcat.org/identities/%s WorldCat]</span>", results, args.worldcatid)
 
function p.acmLink( id )
--P864's format regex: \d{11} (e.g. 12345678901)
if not id:match( '^%d%d%d%d%d%d%d%d%d%d%d$' ) then
return false
end
end
return '[https://dl.acm.org/author_page.cfm?id='..id..' '..id..']'
end
-- Add maintenance categories
 
if q == nil then
function p.adbLink( id )
cats = string.format("%s[[Category:Pages using authority control without Wikidata link]]\n", cats)
--P1907's format regex: [a-z][-a-z]+-([1-2]\d|[1-9])\d{0,3} (e.g. barton-sir-edmund-toby-71)
if not id:match( '^[a-z][-a-z]+-[1-2]%d%d?%d?%d?$' ) and
  not id:match( '^[a-z][-a-z]+-[1-9]%d?%d?%d?%d?$' ) then
return false
end
end
return '[http://adb.anu.edu.au/biography/'..id..' '..id..']'
if nCustomParam>0 then
end
if cats=='' and entity ~= nil then
 
cats = string.format("%s[[Category:Pages using authority control with all identifiers matching Wikidata]]\n", cats)
function p.agsaLink( id )
end
--P6804's format regex: [1-9]\d* (e.g. 3625)
if string.find(results, "<span style=\"color:red\">") then  
if not id:match( '^[1-9]%d*$' ) then
cats = string.format("%s[[Category:Pages using authority control with badly formated identifier]]\n", cats)
return false
end
return '[https://www.agsa.sa.gov.au/collection-publications/collection/creators/_/'..id..'/ '..id..']'
end
 
function p.autoresuyLink( id )
--P2558's format regex: [1-9]\d{0,4} (e.g. 12345)
if not id:match( '^[1-9]%d?%d?%d?%d?$' ) then
return false
end
return '[https://autores.uy/autor/'..id..' '..id..']'
end
 
function p.awrLink( id )
--P4186's format regex: (([A-Z]{3}\d{4})|([A-Z]{2}\d{5}))[a-z] (e.g. PR00768b)
if not id:match( '^[A-Z][A-Z][A-Z]%d%d%d%d[a-z]$' ) and
  not id:match( '^[A-Z][A-Z]%d%d%d%d%d[a-z]$' ) then
return false
end
return '[http://www.womenaustralia.info/biogs/'..id..'.htm '..id..']'
end
 
function p.picLink( id )
--P2750's format regex: [1-9]\d* (e.g. 1)
if not id:match( '^[1-9]%d*$' ) then
return false
end
return '[https://pic.nypl.org/constituents/'..id..' '..id..']'
end
 
function p.bildLink( id )
--P2092's format regex: \d+ (e.g. 1)
if not id:match( '^%d+$' ) then
return false
end
return '[https://www.bildindex.de/document/obj'..id..' '..id..']'
end
 
function p.jocondeLink( id )
--P347's format regex: [\-0-9A-Za-z]{11} (e.g. 12345678901)
local regex = '^'..string.rep('[%-0-9A-Za-z]', 11)..'$'
if not id:match( regex ) then
return false
end
return '[https://www.pop.culture.gouv.fr/notice/joconde/'..id..' '..id..']'
end
 
function p.rkdidLink( id )
--P350's format regex: [1-9]\d{0,5} (e.g. 123456)
if not id:match( '^[1-9]%d?%d?%d?%d?%d?$' ) then
return false
end
return '[https://rkd.nl/nl/explore/images/'..id..' '..id..']'
end
 
function p.balatLink( id )
--P3293's format regex: \d+ (e.g. 1)
if not id:match( '^%d+$' ) then
return false
end
return '[http://balat.kikirpa.be/object/104257'..id..' '..id..']'
end
 
function p.lnbLink( id )
--P1368's format regex: \d{9} (e.g. 123456789)
if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then
return false
end
return '[https://kopkatalogs.lv/F?func=direct&local_base=lnc10&doc_number='..id..'&P_CON_LNG=ENG '..id..']'
end
 
function p.nskLink( id )
--P1375's format regex: \d{9} (e.g. 123456789)
if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then
return false
end
return '[http://katalog.nsk.hr/F/?func=direct&doc_number='..id..'&local_base=nsk10 '..id..']'
end
 
function p.iciaLink( id )
--P1736's format regex: \d+ (e.g. 1)
if not id:match( '^%d+$' ) then
return false
end
return '[https://www.imj.org.il/artcenter/newsite/en/?artist='..id..' '..id..']'
end
 
function p.ta98Link( id )
--P1323's format regex: A\d{2}\.\d\.\d{2}\.\d{3}[FM]? (e.g. A12.3.45.678)
if not id:match( '^A%d%d%.%d%.%d%d%.%d%d%d[FM]?$' ) then
return false
end
return '[http://tools.wmflabs.org/wikidata-externalid-url/?p=1323&url_prefix=https:%2F%2Fwww.unifr.ch%2Fifaa%2FPublic%2FEntryPage%2FTA98%20Tree%2FEntity%20TA98%20EN%2F&url_suffix=%20Entity%20TA98%20EN.htm&id='..id..' '..id..']'
end
 
function p.tdviaLink( id )
--P7314's format regex: [a-z/-]+] (e.g. barkan-omer-lutfi)
if not id:match( '^[a-z/-]+$' ) then
return false
end
return '[https://islamansiklopedisi.org.tr/'..id..' '..id..']'
end
 
function p.teLink( id )
--P1693's format regex: E[1-8]\.\d{1,2}\.\d{1,2}\.\d{1,2}\.\d{1}\.\d{1}\.\d{1,3} (e.g. E1.23.45.67.8.9.0)
local e1, e2 = id:match( '^E([1-8])%.(%d%d?)%.%d%d?%.%d%d?%.%d%.%d%.%d%d?%d?$' )
if not e1 then
return false
end
local TEnum = 'TEe0'..e1 --no formatter URL in WD, probably due to this complexity
if e1 == '5' or e1 == '7' then
if #e2 == 1 then e2 = '0'..e2 end
TEnum = TEnum..e2
end
return '[http://www.unifr.ch/ifaa/Public/EntryPage/ViewTE/'..TEnum..'.html '..id..']'
end
 
function p.tepapaLink( id )
--P3544's format regex: \d+ (e.g. 1)
if not id:match( '^%d+$' ) then
return false
end
return '[https://collections.tepapa.govt.nz/agent/'..id..' '..id..']'
end
 
function p.thLink( id )
--P1694's format regex: H\d\.\d{2}\.\d{2}\.\d\.\d{5} (e.g. H1.23.45.6.78901)
local h1, h2 = id:match( '^H(%d)%.(%d%d)%.%d%d%.%d%.%d%d%d%d%d$' )
if not h1 then
return false
end
local THnum = 'THh'..h1..h2 --no formatter URL in WD, probably due to this complexity
return '[http://www.unifr.ch/ifaa/Public/EntryPage/ViewTH/'..THnum..'.html '..id..']'
end
 
function p.dsiLink( id )
--P2349's format regex: [1-9]\d* (e.g. 1538)
if not id:match( '^[1-9]%d*$' ) then
return false
end
return '[http://www.uni-stuttgart.de/hi/gnt/dsi2/index.php?table_name=dsi&function=details&where_field=id&where_value='..id..' '..id..']'
end
 
function p.fnzaLink( id )
--P6792's format regex: [1-9]\d* (e.g. 9785)
if not id:match( '^[1-9]%d*$' ) then
return false
end
return '[https://findnzartists.org.nz/artist/'..id..'/ '..id..']'
end
 
function p.s2authoridLink( id )
--P4012's format regex: [1-9]\d* (e.g. 1796130)
if not id:match( '^[1-9]%d*$' ) then
return false
end
return '[https://www.semanticscholar.org/author/'..id..' '..id..']'
end
 
function p.nliLink( id )
--P8189's format regex: 98\d{12}5171 (e.g. 987007305652505171)
if not id:match( '^98%d%d%d%d%d%d%d%d%d%d%d%d5171$' ) then
return false
end
return '[http://olduli.nli.org.il/F/?func=find-b&local_base=NLX10&find_code=UID&request='..id..' '..id..']'
end
 
function p.nlpLink( id )
--P1695's format regex: a[0-9]{13}
if not id:match( '^a%d%d%d%d%d%d%d%d%d%d%d%d%d$' ) then
return false
end
return '[https://dbn.bn.org.pl/descriptor-details/'..id..' '..id..']'
end
 
function p.reroLink( id )
--P3065's format regex: 0[1-2]-[A-Z0-9]{1,10} (e.g. 02-A012345678)
if not id:match( '^0[1-2]%-[A-Z%d][A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?$' ) then
return false
end
return '[http://data.rero.ch/'..id..' '..id..']'
end
 
function p.rmnLink( id )
--P359's format regex: [1-9]\d* (e.g. 49951)
if not id:match( '^[1-9]%d*$' ) then
return false
end
return '[https://monumentenregister.cultureelerfgoed.nl/monumenten/'..id..' '..id..']'
end
 
function p.rmcnLink( id )
--P7135's format regex: [1-9]\d* (e.g. 49951)
if not id:match( '^[1-9]%d*$' ) then
return false
end
return '[https://monumentenregister.cultureelerfgoed.nl/complexen/'..id..' '..id..']'
end
 
function p.nlrLink( id )
--P1003's format regex: \d{9} (e.g. 123456789)
if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then
return false
end
return '[http://alephnew.bibnat.ro:8991/F?func=find-b&request='..id..'&find_code=SYS&adjacent=Y&local_base=NLR10 '..id..']'
end
 
function p.ntaLink( id )
--P1006's format regex: \d{8}[\dX] (e.g. 12345678X)
if not id:match( '^%d%d%d%d%d%d%d%d[%dX]$' ) then
return false
end
return '[http://data.bibliotheken.nl/id/thes/p'..id..' '..id..']'
end
 
function p.bncLink( id )
--P1890's format regex: \d{9} (e.g. 123456789)
if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then
return false
end
return '[http://www.bncatalogo.cl/F?func=direct&local_base=red10&doc_number='..id..' '..id..']'
end
 
function p.canticLink( id )
--P9984's format regex: \d{18} (e.g. 981058614775106706)
if not id:match( '^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d$' ) then
return false
end
return '[https://cantic.bnc.cat/registre/'..id..' '..id..']'
end
 
function p.dbnlLink( id )
--P723's format regex: [a-z][a-z_]{3}[0-9]{3} (e.g. moza001)
if not id:match( '^[a-z][a-z_][a-z_][a-z_]%d%d%d$' ) then
return false
end
return '[http://www.dbnl.org/auteurs/auteur.php?id='..id..' '..id..']'
end
 
function p.siprojurisLink( id )
--P4892's format regex: [1-9]\d* (e.g. 49951)
if not id:match( '^[1-9]%d*$' ) then
return false
end
return '[http://siprojuris.symogih.org/siprojuris/enseignant/'..id..' '..id..']'
end
 
function p.parlcomLink( id )
--P1749's format regex: [\da-z]{12} (e.g. vg9fgoprkxw3)
if not id:match( '^[%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l]$' ) then
return false
end
return '[https://www.parlement.com/id/'..id..' '..id..']'
end
 
function p.odisLink( id )
--P2372's format regex: (AE|OR|EV|OB|PS|PB)_[1-9]\d{1,5} (e.g. PS_13750)
if not id:match( '^[AEOP][BERSV]_[1-9]%d+$' ) then
return false
end
return '[https://www.odis.be/lnk/'..id..' '..id..']'
end
 
--[[==========================================================================]]
--[[          Wikidata, navigation bar, and documentation functions          ]]
--[[==========================================================================]]
 
function p.getIdsFromWikidata( itemId, property )
local ids = {}
local statements = mw.wikibase.getBestStatements( itemId, property )
if statements then
for _, statement in ipairs( statements ) do
if statement.mainsnak.datavalue then
table.insert( ids, statement.mainsnak.datavalue.value )
end
end
end
end
end
return ids
end


function p.matchesWikidataRequirements( itemId, reqs )
-- return results
for _, group in ipairs( reqs ) do
if results~='' then -- if there are any results than wrap them in <div> tag
local property = 'P'..group[1]
results  = string.format('<div class="hlist">%s\n</div>', results)
local qid = group[2]
local statements = mw.wikibase.getBestStatements( itemId, property )
if statements then
for _, statement in ipairs( statements ) do
if statement.mainsnak.datavalue then
if statement.mainsnak.datavalue.value['numeric-id'] == qid then
return true
end end end end end
return false
end
 
function p.createRow( id, label, rawValue, link, withUid )
if link then
if withUid then
return '<li><b>'..label..'</b> <span class="uid">'..link..'</span></li>'
end
return '<li><b>'..label..'</b> '..link..'</li>'
end
end
 
return results, cats
return '<li class="error">The '..id..' id '..rawValue..' is not valid.</li>'..
'[[Category:'..catNameInvalidID..'|'..id..']]' --sorting in category by authority short name
end
end


--[[==========================================================================]]
--[[                              Configuration                              ]]
--[[==========================================================================]]
-- Check that the Wikidata item has this property-->value before adding it
local reqs = {}
-- Parameter format: { 'parameter name', 'label', propertyId # in Wikidata, formatting/validation function }
p.conf = {
{ 'AAG', '[[Auckland Art Gallery Toi o Tāmaki]]', 3372, p.aagLink },
{ 'ACM-DL', '[[Association for Computing Machinery]]', 864, p.acmLink },
{ 'ADB', '[[Australian Dictionary of Biography]]', 1907, p.adbLink },
{ 'AGSA', '[[Art Gallery of South Australia]]', 6804, p.agsaLink },
{ 'autores.uy', '[[autores.uy]]', 2558, p.autoresuyLink },
{ 'AWR', '[[Australian Women\'s Register]]', 4186, p.awrLink },
{ 'BALaT', '[[Koninklijk Instituut voor het Kunstpatrimonium]]', 3293, p.balatLink },
{ 'BDELIS', '[[Base de données des élites suisses]]', 6231, p.bdelisLink },
{ 'BIBSYS', '[[Bibsys]]', 1015, p.bibsysLink },
{ 'Bildindex', '[[Marburg Picture Index]]', 2092, p.bildLink },
{ 'BNC', '[[Biblioteca Nacional de Chile]]', 1890, p.bncLink },
{ 'BNE', '[[Biblioteca Nacional de España]]', 950, p.bneLink },
{ 'BNF', '[[Bibliothèque nationale de France]]', 268, p.bnfLink },
{ 'Botanist', '[[Author citation (botany)]]', 428, p.botanistLink },
{ 'BPN', '[[Biografisch Portaal]]', 651, p.bpnLink },
{ 'CANTIC', "[[Catàleg d'autoritats de noms i títols de Catalunya]]", 9984, p.canticLink },
{ 'CINII', '[[CiNii]]', 271, p.ciniiLink },
{ 'DAAO', '[[Dictionary of Australian Artists]]', 1707, p.daaoLink },
{ 'DBNL', '[[Digitale Bibliotheek voor de Nederlandse Letteren]]', 723, p.dbnlLink },
{ 'DBLP', '[[DBLP]]', 2456, p.dblpLink },
{ 'DGO4', '[[:d:Property:P1133|Monument Wallonië DGO4]]', 1133, p.dgo4Link },
{ 'DSI', '[[Stuttgart Database of Scientific Illustrators 1450–1950]]', 2349, p.dsiLink },
{ 'FNZA', '[[:d:Property:P6792|Find NZ Artists]]', 6792, p.fnzaLink },
{ 'GND', '[[Gemeinsame Normdatei]]', 227, p.gndLink },
{ 'HDS', '[[Historisch woordenboek van Zwitserland]]', 902, p.hdsLink },
{ 'IAAF', '[[World Athletics]]', 1146, p.iaafLink },
{ 'ICIA', '[[Information Center for Israeli Art]]', 1736, p.iciaLink },
{ 'ISNI', '[[International Standard Name Identifier]]', 213, p.isniLink },
{ 'Joconde', '[[Joconde]]' , 347, p.jocondeLink },
{ 'KULTURNAV', '[[KulturNav]]', 1248, p.kulturnavLink },
{ 'LCCN', '[[Library of Congress Control Number]]', 244, p.lccnLink },
{ 'LIR', '[[Historical Dictionary of Switzerland#Lexicon_Istoric_Retic]]', 886, p.lirLink },
{ 'LNB', '[[Nationale Bibliotheek van Letland]]', 1368, p.lnbLink },
{ 'Léonore', '[[Base Léonore]]', 640, p.leonoreLink },
{ 'MBA', '[[MusicBrainz]]', 434, p.mbaLink },
{ 'MBAREA', '[[MusicBrainz]]', 982, p.mbareaLink },
{ 'MBI', '[[MusicBrainz]]', 1330, p.mbiLink },
{ 'MBL', '[[MusicBrainz]]', 966, p.mblLink },
{ 'MBP', '[[MusicBrainz]]', 1004, p.mbpLink },
{ 'MBRG', '[[MusicBrainz]] release group', 436, p.mbrgLink },
{ 'MBS', '[[MusicBrainz]]', 1407, p.mbsLink },
{ 'MBW', '[[MusicBrainz]] work', 435, p.mbwLink },
{ 'MGP', '[[Mathematics Genealogy Project]]', 549, p.mgpLink },
{ 'NARA', '[[National Archives and Records Administration]]', 1225, p.naraLink },
{ 'NARCIS', '[[NARCIS]]', 7449, p.narcisLink },
{ 'NCL', '[[National Central Library]]', 1048, p.nclLink },
{ 'NDL', '[[Bibliotheek van het Japanse parlement]]', 349, p.ndlLink },
{ 'NGV', '[[National Gallery of Victoria]]', 2041, p.ngvLink },
{ 'NKC', '[[Nationale Bibliotheek van Tsjechië]]', 691, p.nkcLink },
{ 'NLA', '[[Nationale bibliotheek van Australië]]', 409, p.nlaLink },
{ 'NLI', '[[Nationale Bibliotheek van Israël]]', 8189, p.nliLink },
{ 'NLP', '[[Nationale Bibliotheek van Polen]]', 1695, p.nlpLink },
{ 'NLR', '[[Nationale Bibliotheek van Roemenië]]', 1003, p.nlrLink },
{ 'NSK', '[[Nationale en Universitaire bibliotheek Zagreb]]', 1375, p.nskLink },
{ 'NTA', '[[:d:Property:P1006|Nederlandse Thesaurus van Auteursnamen Persoon]]', 1006, p.ntaLink },
-- { 'ODIS', [[ODIS]], 2372, p.odisLink },
{ 'OEIBE', '[[Inventaris van het Bouwkundig Erfgoed|Inventaris van het Bouwkundig Erfgoed (Vlaanderen)]]', 1764, p.oeibeLink },
{ 'ORCID', '[[ORCID]]', 496, p.orcidLink },
{ 'PARLCOM', '[[Parlement.com]]', 1749, p.parlcomLink },
{ 'PIC', '[[:d:Q23892012|PIC]]', 2750, p.picLink },
{ 'RID', '[[ResearcherID]]', 1053, p.ridLink },
{ 'RERO', '[[RÉRO|Réseau des bibliothèques de Suisse occidentale]]', 3065, p.reroLink },
{ 'RMN', '[[Rijksmonumentenregister|Rijksmonument]]', 359, p.rmnLink },
{ 'RMCN', '[[Rijksmonumentcomplex]]', 7135, p.rmcnLink },
{ 'RKDartists', '[[RKD-Nederlands Instituut voor Kunstgeschiedenis]]', 650, p.rkdartistsLink },
{ 'RKDID', '[[:d:Q17299580|RKDimages]]', 350, p.rkdidLink },
{ 'RSL', '[[Russische Staatsbibliotheek]]', 947, p.rslLink },
{ 'SBN', '[[Istituto Centrale per il Catalogo Unico]]', 396, p.sbnLink },
{ 'SELIBR', '[[LIBRIS]]', 906, p.selibrLink },
{ 'SIKART', '[[SIKART]]', 781, p.sikartLink },
{ 'SIPROJURIS', '[[Siprojuris]]', 4892, p.siprojurisLink },
{ 'SNAC-ID', '[[SNAC]]', 3430, p.snacLink },
{ 'SUDOC', '[[Système universitaire de documentation]]', 269, p.sudocLink },
{ 'Swiss parliament', '[[Bondsvergadering (Zwitserland)|Zwitserse Bondsvergadering]]', 1307, p.swissparliamentLink },
{ 'S2AuthorId', '[[Semantic Scholar]]', 4012, p.s2authoridLink },
{ 'TA98', '[[Terminologia Anatomica]]', 1323, p.ta98Link },
{ 'TDVİA', '[[:d:Q21527102|TDVİA]]', 7314, p.tdviaLink },
{ 'TE', '[[Terminologia Embryologica]]', 1693, p.teLink },
{ 'TePapa', '[[Museum of New Zealand Te Papa Tongarewa]]', 3544, p.tepapaLink },
{ 'TH', '[[Terminologia Histologica]]', 1694, p.thLink },
{ 'TLS', '[[Theaterlexikon der Schweiz]]', 1362, p.tlsLink },
{ 'Trove', '[[Trove]]', 1315, p.troveLink }, --formerly NLA-person
{ 'ULAN', '[[Union List of Artist Names]]', 245, p.ulanLink },
{ 'USCongress', '[[Biographical Directory of the United States Congress]]', 1157, p.uscongressLink },
{ 'VIAF', '[[Virtual International Authority File]]', 214, p.viafLink },
}


-- Legitimate aliases to p.conf, for convenience
-- ===========================================================================
-- Format: { 'alias', 'parameter name in p.conf' }
-- === Version of the function to be called from template namespace
p.aliases = {
-- ===========================================================================
{ 'RLS', 'RSL' },
function p.authorityControl(frame)
{ 'MusicBrainz', 'MBA' },
-- prepare arguments
{ 'MusicBrainz artist', 'MBA' },
local args = core.getArgs(frame)
{ 'MusicBrainz label', 'MBL' },
local bare = core.yesno(args.bare,false)        
{ 'MusicBrainz release group', 'MBRG' },
{ 'MusicBrainz work', 'MBW' },
{ 'Leonore', 'Léonore' },
{ 'TDVIA', 'TDVİA' },
}
 
-- Deprecated aliases to p.conf; tracked in [[Category:Wikipedia articles with deprecated authority control identifiers]]
-- Format: { 'deprecated parameter name', 'replacement parameter name in p.conf' }
p.deprecated = {
{ 'GKD', 'GND' },
{ 'PND', 'GND' },
{ 'SWD', 'GND' },
{ 'NARA-organization', 'NARA' },
{ 'NARA-person', 'NARA' },
}
 
--[[==========================================================================]]
--[[                                  Main                                  ]]
--[[==========================================================================]]
 
function p.authorityControl( frame )
local resolveEntity = require( "Module:ResolveEntityId" )
local parentArgs = frame:getParent().args
local elements = {} --create/insert rows later
local worldcatCat = ''
local suppressedIdCat = ''
local deprecatedIdCat = ''
--Redirect deprecated parameters to proper parameter names, and assign tracking cat
-- Convert template arguments to the same format as used on wikidata
for _, d in pairs( p.deprecated ) do
if args.bnf then
local dep, param = d[1], d[2]
args.bnf = string.sub(args.bnf, 3) -- trim first 2 characters
if (parentArgs[param] == nil or parentArgs[param] == '') and parentArgs[dep] then
parentArgs[param] = parentArgs[dep]
end
end
end
-- if args.isni then -- group in sets of 4
--Use QID= parameter for testing/example purposes only
-- args.isni = string.sub(args.isni, 1, 4).." "..string.sub(args.isni, 5, 8)
local itemId = nil
--     .." "..string.sub(args.isni, 9,12).." "..string.sub(args.isni,13,16)
if namespace ~= 0 then
-- end
local qid = parentArgs['qid'] or parentArgs['QID']
if args.isbn then
if qid then
local isbn = isbn.gsub( ' ', '' )
itemId = 'Q'..mw.ustring.gsub(qid, '^[Qq]', '')
if #isbn==10 then
itemId = resolveEntity._id(itemId) --nil if unresolvable
args['isbn-10'] = args.isbn
elseif #isbn==13 then
args['isbn-13'] = args.isbn
end
end
else
args.isbn = nil
itemId = mw.wikibase.getEntityIdForCurrentPage()
end
end
args.gnd  = args.gnd or args.pnd --redirect PND to GND
args.lccn = fixLCCN(args.lccn)
args.wikidata = args.wikidata or args.q or nil
--Wikidata fallback if requested
-- call the inner "core" function
if itemId then
local results, cats = p._authorityControl(nil, args, args.lang, args.length)
for _, params in ipairs( p.conf ) do
local namespace = mw.title.getCurrentTitle().namespace
if params[3] > 0 then
local LUT = {[2]='user', [6]='file', [10]='template', [828]='module'}
local val = parentArgs[params[1]]
if (LUT[namespace] or math.fmod(namespace,2)==1) then
if val == nil or val == '' then
-- lets not add categories to some namespaces, or talk pages and concentrate
local canUseWikidata = nil
-- on templates and categories instead
if reqs[params[1]] then
cats = ''  
canUseWikidata = p.matchesWikidataRequirements( itemId, reqs[params[1]] )
else
canUseWikidata = true
end
if canUseWikidata then
local wikidataIds = p.getIdsFromWikidata( itemId, 'P'..params[3] )
if wikidataIds[1] then
if val == '' and (namespace == 0 or testcases) then
suppressedIdCat = ''
else
parentArgs[params[1]] = wikidataIds[1]
end end end end end end end
--Configured rows
local rct = 0
for _, params in ipairs( p.conf ) do
local val = parentArgs[params[1]]
if val and val ~= '' then
table.insert( elements, p.createRow( params[1], params[2]..':', val, params[4]( val ), true ) )
rct = rct + 1
end
end
end
--WorldCat
--package results as a infobox if not "bare"
local worldcatId = parentArgs['WORLDCATID']
if not bare then
if worldcatId and worldcatId ~= '' then --if present & unsuppressed
-- Get field name for authority control
table.insert( elements, p.createRow( 'WORLDCATID', '', worldcatId, '<b>[[WorldCat Identities]]</b>: [https://www.worldcat.org/identities/'..worldcatId..' '..worldcatId..']', false ) ) --Validation?
local field_name = p.getAuthorityControlTag(args.lang)
worldcatCat = ''
 
elseif worldcatId == nil then --if absent & unsuppressed
-- build table
local viafId = parentArgs['VIAF']
results = string.format('<tr><td class="type fileinfo-paramfield">%s</td><td>\n%s\n</td></tr>', field_name, results)
local lccnId = parentArgs['LCCN']
local dir  = mw.language.new( args.lang ):getDir()   -- get text direction
if viafId and viafId ~= '' and p.viafLink( viafId ) then --VIAF must be present, unsuppressed, & validated
local style = 'class="toccolours mw-content-%s layouttemplate commons-file-information-table" style="width: 100%%;" dir="%s" lang="%s"'  
table.insert( elements, p.createRow( 'VIAF', '', viafId, '<b>[[WorldCat Identities]]</b> (via VIAF): [https://www.worldcat.org/identities/containsVIAFID/'..viafId..' '..viafId..']', false ) )
style = string.format(style, dir, dir, args.lang)
if namespace == 0 then
results = string.format('<table %s>\n%s\n</table>\n', style, results)
worldcatCat = ''
else
end
results = string.format('\n%s\n', results)
elseif lccnId and lccnId ~= '' and p.lccnLink( lccnId ) then --LCCN must be present, unsuppressed, & validated
local lccnParts = p.splitLccn( lccnId )
if lccnParts and lccnParts[1] ~= 'sh' then
local lccnIdFmtd = lccnParts[1]..lccnParts[2]..'-'..lccnParts[3]
table.insert( elements, p.createRow( 'LCCN', '', lccnId, '<b>[[WorldCat Identities]]</b> (via LCCN): [https://www.worldcat.org/identities/lccn-'..lccnIdFmtd..' '..lccnIdFmtd..']', false ) )
if namespace == 0 then
worldcatCat = ''
end
end
end
end
local outString = ''
if #elements > 0 then
local args = {}
if testcases and itemId then args = { qid = itemId } end --expensive
local nav = mw.html.create( 'div' )
local navTitle = mw.html.create( 'div' )
local navContent = mw.html.create( 'div' )
nav
:attr( 'class', 'navigatie navbox mw-collapsible mw-collapsed' )
:attr( 'role', 'navigation' )
:attr( 'aria-labelledby', displayLabel )
:attr( 'data-collapsetext', 'Inklappen' )
:attr( 'data-expandtext', 'Uitklappen' )
navTitle
:attr( 'id', displayLabel )
:attr( 'class', 'navigatie-titel' )
:wikitext( '[['..displayLink..'|'..displayLabel..']]' )
navContent
:attr( 'class', 'navigatie-inhoud mw-collapsible-content plainlist ta-left' )
:tag( 'ul' )
:css( 'column-width', '36em' )
:wikitext( table.concat(elements) )
nav:node( navTitle )
nav:node( navContent )
    outString = mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = 'Navigatie/styles.css' }
} .. tostring( nav )
end
end
return results..cats
return outString
end
end


return p
return p

Versie van 3 jan 2024 00:02

Door middel van deze module wordt er een box gemaakt waarin bibliografische informatie wordt getoond.

Gebruik

Deze module wordt gebruikt door Sjabloon:Bibliografische informatie. Zie aldaar voor meer informatie.


--[[  
  __  __           _       _           _         _   _                _ _                           _             _ 
 |  \/  | ___   __| |_   _| | ___ _   / \  _   _| |_| |__   ___  _ __(_) |_ _   _    ___ ___  _ __ | |_ _ __ ___ | |
 | |\/| |/ _ \ / _` | | | | |/ _ (_) / _ \| | | | __| '_ \ / _ \| '__| | __| | | |  / __/ _ \| '_ \| __| '__/ _ \| |
 | |  | | (_) | (_| | |_| | |  __/_ / ___ \ |_| | |_| | | | (_) | |  | | |_| |_| | | (_| (_) | | | | |_| | | (_) | |
 |_|  |_|\___/ \__,_|\__,_|_|\___(_)_/   \_\__,_|\__|_| |_|\___/|_|  |_|\__|\__, |  \___\___/|_| |_|\__|_|  \___/|_|
                                                                            |___/                                    
This module is intended to be the engine behind "Template:Authority control".

Please do not modify this code without applying the changes first at "Module:Authority control/sandbox" and testing 
at "Module:Authority control/testcases".

Authors and maintainers:
* User:Jarekt - original version 

]]

local properties = require('Module:Authority control/conf')
local core       = require('Module:Core')

-- ==================================================
-- === Internal functions ===========================
-- ==================================================

local function getSitelink(item, lang)
    -- get item's siteling in specific language
	local langList = mw.language.getFallbacksFor(lang)
	table.insert(langList, 1, lang)
	for _, language in ipairs(langList) do 
		local sitelink = mw.wikibase.sitelink( item, language .. 'wiki' )
		if sitelink then 
			return 'w:'.. language ..':'.. sitelink
		end
	end
	return nil
end

-- ==================================================
local function getIdentifierNameLink( lang, item1, item2, label )
-- Identifier names, like VIAF, LCCN, ISNI, need to be linked to the articles about them if possible
-- Alternativly they can be linked to the articles for institutions that issue them
	local id_name_URL = nil
	-- 1) try wikipedia sitelink for the identifier in users language and in English
	if item1 and item1 ~='' then
		id_name_URL = getSitelink(item1, lang)
	end
	-- 2) try wikipedia sitelink for the issuedBy property in users language and in English
	if id_name_URL==nil and item2 and item2 ~='' then -- if no link than
		id_name_URL = getSitelink(item2, lang)
	end
	-- 3) if still no links than link to wikidata
	if id_name_URL then	
		return string.format("[[%s|%s]]", id_name_URL, label) -- link to wikipedia
	else    
		return string.format("[[d:%s|%s]]", item1, label) -- link to wikidata
	end
end

-- ==================================================
-- Create link to a single identifier
-- INPUTS:
--  * val - value of the identifier
--  * P - property record, with URL_format and optional interwiki_format strings to create links
--  * params - additional parameters related to this type of identifiers. Single item from "conf"
--  * color - color of the link
local function getIdentifierValLink(val, P, params, color)
	if not val or val=='' then
		return ''
	end
	-- check if identifier is in the right format
	local mismatchStr = ''
	local val_ = val:gsub( ' ', '' ) -- remove spaces
	if (params.regexp and not val:match( params.regexp )) then
		mismatchStr  = string.format("<span style=\"color:red\">[does not match %s pattern]</span>", params.regexp)
	elseif (params.verify) then -- check if special "Verify" function is present
		mismatchStr = params.verify(val_) -- add error message if any
	end
	-- identifier_value_URL
	if color~="blue" then
		val = string.format('<span style=\"color:%s\">%s</span>', color, val)
	end
	local val_link
	if P.interwiki_format and P.interwiki_format ~= '' then
		val_link = string.format("[[%s:%s|%s]]", P.interwiki_format, val_, val)
	else
		local val_URL = P.URL_format:gsub('$1', val_)-- URL part of the link for the identifier value
		val_link = string.format("[%s %s]", val_URL, val)
	end
	return string.format("<span class=\"plainlinks\">%s</span>%s", val_link, mismatchStr) -- link to the identifier's website
end 

-- ==================================================
-- Convert between 2 formats of LCCN: "n/79/63767" -> "n79063767"
-- "n/79/63767" format was used as input by {{Authority Control}} templates
-- "n79063767" format is used by wikidata
local function fixLCCN(id)
  if id then
		local a, b, c = string.match(id, "([%a%d]*)/([%a%d]*)/([%a%d]*)")
		if c then
			local pad = 6 - string.len(c)
			if pad > 0 then
				c = string.rep("0", pad)..c
			end
			id = a..b..c
		end
	end
	return id
end -- fixLCCN

-- ==================================================
-- Verify last "check" digit is correct. ISNI and several other 
-- identifiers use last digit as a verification digit
local function verifyLastDigit( id )
    local total = 0
    for i = 1, #id-1 do
        local digit = id:byte( i ) - 48 --Get integer value
        total = (total + digit) * 2
    end
	
    --local remainder = total % 11
    local lastDigit = tostring((12 - total % 11) % 11)
    if lastDigit == '10' then
        lastDigit = "X"
    end
	
    if (lastDigit == string.sub( id, -1)) then
		return ''
	else
		return "<span style=\"color:red\">[last digit should be " .. lastDigit .. "]</span>"
	end
end

-- ==================================================
-- === Settings =====================================
-- ==================================================
-- In order to add a new identifier associated with Wikidata property do the following 
-- 1) go to [[Template:Authority control/IdentifierList]] and verify that the property number is on the list, if not than edit the page to add it
-- 2) copy code generated at [[Template:Authority control/IdentifierList]] to protected [[Module:Authority control/conf]]
-- 3) add the property to the "conf" list below

-- load 'Module:Authority control/conf' which holds hardwired data derived from Wikidata's properties of 
-- properties

--conf  holds list of identifiers to be displayed
local conf = {
    -- people 
	{label='VIAF'        , property='P214' , lang=''  , regexp='^%d+$' },
	{label='ISNI'        , property='P213' , lang=''  , regexp='^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$', verify=verifyLastDigit }, 
	{label='ORCID'       , property='P496' , lang=''  , regexp='^0000%-000[1-3]%-%d%d%d%d%-%d%d%d[%dX]$' },
	{label='ULAN'        , property='P245' , lang=''  , regexp='^500%d%d%d%d%d%d$' }, -- 'Union List of Artist Names' by Getty Research Institute
	{label='ResearcherID', property='P1053', lang=''  , regexp='^[A-Z]+%-%d%d%d%d%-[12][90]%d%d$' }, 
	{label='LCCN'        , property='P244' , lang='en', regexp='^[ns][broshj]?%d%d%d%d%d%d%d%d%d?%d?$' }, -- Library of Congress Authorities
	{label='GND'         , property='P227' , lang='de', regexp='^[%dX%-]+$'},
	{label='SELIBR'      , property='P906' , lang='se', regexp='^%d+$' }, -- National Library of Sweden
	{label='SUDOC'       , property='P269' , lang='fr', regexp='^%d%d%d%d%d%d%d%d[%dxX]$' },    
	{label='BNF'         , property='P268' , lang='fr', regexp='^%d+%w?$' }, -- Bibliothèque nationale de France
	{label='BPN'         , property='P651' , lang='nl', regexp='^%d%d%d%d%d%d%d%d$' }, -- Biografisch Portaal number
	{label='NAID'        , property='P1225', lang='en', regexp='^%d+$' }, -- NARA ID (redirect for US National Archives Identifier (P1225))
	{label='Museofile'   , property='P539' , lang='fr', regexp='^M%d%d%d%d%-?%d?%d?$' }, --Ministry of Culture (France)
	{label='NDL'         , property='P349' , lang='ja', regexp='^0?%d%d%d%d%d%d%d%d$' }, -- National Diet Library (of Japan)
	{label='NLA'         , property='P409' , lang='en', regexp='^[1-9]%d*$' }, -- National Library of Australia
	{label='BIBSYS'      , property='P1015', lang='no', regexp='^%d+$' }, -- Norwegian information system BIBSYS
	{label='HDS'         , property='P902' , lang='de', regexp='^%d%d%d?%d?%d?%d?$' },  -- Historical Dictionary of Switzerland
	{label='MusicBrainz' , property='P434' , lang='en', regexp='^[-%x]+$' }, 
	{label='MGP'         , property='P549' , lang='en', regexp='^%d%d?%d?%d?%d?%d?$' },  -- Mathematics Genealogy Project
	{label='NCL'         , property='P1048', lang='zh', regexp='^%d+$' },  --National Central Library (Taiwan)
	{label='NKC'         , property='P691' , lang='cs', regexp='^%l%l%l?%l?%d%d%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?$' },  --National Library of the Czech Republic
	{label='Léonore'     , property='P640' , lang='fr', regexp='^[LHC%/%d]+$' }, 
	{label='SBN'         , property='P396' , lang='it'},  -- Istituto Centrale per il Catalogo Unico /  National Library Service (SBN) of Italy
	{label='RSL'         , property='P947' , lang='ru', regexp='^%d%d%d%d%d%d%d%d%d$' },  --Russian State Library
	{label='Botanist'    , property='P428' , lang='en' }, 
	{label='US Congress' , property='P1157', lang='en', regexp='^%u00[01]%d%d%d' }, 
	{label='BNE'         , property='P950' , lang='es', regexp='' }, --Biblioteca Nacional de España
	{label='CALIS'       , property='P270' , lang='zh'}, --China Academic Library and Information 
	{label='CiNii'       , property='P271' , lang='jp', regexp='^DA%d%d%d%d%d%d%d[%dX]$' }, 
	{label='TLS'         , property='P1362', lang='de', regexp='' }, -- Theaterlexikon der Schweiz
	{label='SIKART'      , property='P781' , lang='de', regexp='^%d%d%d%d%d%d%d%d?%d?%d?$' }, -- Swiss
	{label='NLP'         , property='P1695', lang='pl', regexp='' }, -- National Library of Poland
	{label='WGA'         , property='P1882', lang='en', regexp='' }, -- Web Gallery of Art
	{label='KulturNav'   , property='P1248', lang='no', regexp='' }, 
	{label='RKD'         , property='P650' , lang='nl', regexp='^[1-9]%d%d?%d?%d?%d?$' }, --Netherlands Institute for Art History#Online artist pages
	{label='autores.uy'  , property='P2558', lang='es', regexp='^[1-9]%d?%d?%d?%d?$' },   --autores.uy
	{label='J9U'         , property='P8189', lang='he', regexp='' },  --National Library of Israel J9U ID

	{label='FIDE'        , property='P1440', lang='en', regexp='' }, -- FIDE database for chess players
	{label='Chess Games' , property='P1665', lang='en', regexp='' }, -- Chess Games

	{label='ISSN'        , property='P236',  lang='', regexp='' }, -- P1629: International Standard Serial Number
	{label='OSM'         , property='P402',  lang='', regexp='' },  -- P1629: OpenStreetMap
	{label='Joconde'     , property='P347',  lang='fr', regexp='' }, -- Joconde ID
	{label='Rijksmonument',property='P359',  lang='nl', regexp='' }, -- Rijksmonument ID
	{label='IMO'         , property='P458',  lang='', regexp='' }, --IMO ship number
	{label='BNCF'        , property='P508',  lang='it', regexp='' }, -- BNCF Thesaurus ID
	{label='MMSI'        , property='P587',  lang='', regexp='' }, -- P1629: Maritime Mobile Service Identity
	{label='Open Library', property='P648',  lang='', regexp='' }, -- P1629: Open Library
	{label='NRHP'        , property='P649',  lang='en', regexp='' }, -- NRHP reference number
	{label='DBNL'        , property='P723',  lang='', regexp='' }, -- DBNL author ID
	{label='UNESCO'      , property='P757',  lang='', regexp='' }, -- World Heritage Site ID
	{label='BIC'         , property='P808',  lang='', regexp='' }, -- Bien de Interés Cultural (BIC) code
	{label='LIR'         , property='P886',  lang='', regexp='' }, -- LIR
	{label='BNR'         , property='P1003', lang='ro', regexp='' }, -- NLR (Romania) ID
	{label='Koninklijke' , property='P1006', lang='nl', regexp='' }, -- National Thesaurus for Author Names ID
	{label='Louvre'      , property='P9394', lang='', regexp='' }, -- Louvre ID
	
	{label='OCLC'        , property='P243',  lang='', regexp='' }, -- OCLC
	{label='ISBN-13'     , property='P212',  lang='', regexp='' }, -- ISBN-13
	{label='ISBN-10'     , property='P957',  lang='', regexp='' }, -- ISBN-10
	{label='Historic England', property='P1216', lang='en', regexp='' }, -- National Heritage List for England number

	{label='Oxford Dict.', property='P1415', lang='en', regexp='' }, -- Oxford Dictionary of National Biography ID
	{label='kulturnoe-nasledie', property='P1483', lang='ru', regexp='' },  -- kulturnoe-nasledie.ru ID
	{label='Catalunya'   , property='P1600', lang='ca', regexp='' }, -- Inventari del Patrimoni Arquitectònic de Catalunya code
	{label='COAM'        , property='P2917', lang='es', regexp='' }, -- COAM structure ID
	{label='SIMBAD'      , property='P3083', lang='fr', regexp='' }, -- SIMBAD ID
	{label='JCyL'        , property='P3177', lang='es', regexp='' }, -- Patrimonio Web JCyL ID
	{label='Zaragoza'    , property='P3178', lang='es', regexp='' },  -- Zaragoza monument ID
	{label='BDI'         , property='P3318', lang='es', regexp='' }, -- Patrimonio Inmueble de Andalucía ID
	{label='SIPCA'       , property='P3580', lang='es', regexp='' }, -- SIPCA code
	{label='DOCOMOMO'    , property='P3758', lang='', regexp='' }, -- DOCOMOMO Ibérico ID
	{label='Czech Monument', property='P4075', lang='cz', regexp='' }, -- Czech Monument Catalogue Number
	{label='MEG'         , property='P4157', lang='ch', regexp='' }, -- P1629: Musée d'ethnographie de Genève
	{label='Enciclopédia Itaú Cultural' , property='P4399', lang='pt_br', regexp='' }, -- Enciclopédia Itaú Cultural ID
	{label='Monumentos de São Paulo'    , property='P4360', lang='pt_br', regexp='' }, -- Monumentos de São Paulo ID
	{label='Infopatrimônio'             , property='P4372', lang='pt_br', regexp='' }, -- Infopatrimônio ID
	{label="Musée d'Orsay"              , property='P4659', lang='fr'   , regexp='' }, -- Musée d'Orsay artwork ID
	{label='MuBE'                       , property='P4721', lang='pt_br', regexp='' }, -- MuBE Virtual ID
	{label='Hispania Nostra'            , property='P4868', lang='es'   , regexp='' }, -- Hispania Nostra Red List ID
	{label='NLK'            , property='P5034', lang='ko'   , regexp='' }, -- National Library of Korea ID
	}

-- ==================================================
-- === External functions ===========================
-- ==================================================
local p = {}

function p.getAuthorityControlTag( lang )
-- get a localized interwiki link to article "Authority Control"
	local field_name = "[[w:en:Help:Authority control|Authority control]]" -- hardwire the default
	if lang~='en' then
		field_name = core.getLabel("Q36524", lang)
	end
	return field_name
end

-- ==================================================
function p._authorityControl(entity, args, lang, length)
-- INPUTS:
--  * entity - wikidata entity if already created or nil. If provided than you should still provide args.Wikidata
--  * args   - structure with identifier fields: args.VIAF, args.LCCN, args.Wikidata, etc.
--  * lang   - language code
--  * length - maximum length of the identifier array, or number of identifiers to display
-- OUTPUTS:
--  * results - wikicode string equivalent to {{Authority control|...|bare=1 }} call
--  * cats    - wikicode with maintenance categories

  -- count custom parameters (not pulled from Wikidata)
	local nCustomParam = 0 
	for _,params in ipairs( conf ) do
		if (args[params.label]~=nil) then
			nCustomParam = nCustomParam + 1
		end
	end
	
	-- Get entity - record of wikidata related to a single item
	local q = args.wikidata
	if not entity and q then
		entity = mw.wikibase.getEntity(q)
	end
	
	-- Check if this is category item
	local cats = '' -- categories (mismatching and missing)
	if entity and entity.claims and entity.claims.P31 then 
		for _, statement in pairs( entity.claims.P31) do
			if (statement.mainsnak.snaktype == "value") and (statement.mainsnak.datavalue.value.id == 'Q4167836')  then -- P31 == Wikimedia category 
				cats = '[[Category:Wrong Wikidata ID in authority control data: category item]]'
			end
			if (statement.mainsnak.snaktype == "value") and (statement.mainsnak.datavalue.value.id == 'Q4167410')  then -- P31 == Wikimedia disambiguation page 
				cats = '[[Category:Wrong Wikidata ID in authority control data: disambiguation item]]'
			end
		end
	end

	--compare provided arguments with Wikidata identifiers
	local data = {} -- structure similar to "args" but filled with wikidata data
	for _,params in ipairs( conf ) do
		local label = string.lower(params.label)
		data[label] = nil
		if entity and entity.claims and params.property and entity.claims[params.property] then -- if we have wikidata item and item has the property
			-- capture all Wikidata values for the identifier
			--for _, statement in pairs( entity.claims[params.property]) do
			for _, statement in pairs( entity:getBestStatements( params.property )) do
				if (statement.mainsnak.snaktype == "value") then -- or if statement.mainsnak.datavalue then 
					local v = statement.mainsnak.datavalue.value
					if data[label]==nil then
						data[label] = v       -- save the first value
					end
					if args[label] == v then  -- match between template and wikidata identifiers
						data[label] = ''      -- ignore identifier from wikidata
						break  
					end
				end
			end
		end
	end

	--Create string with all the identifiers listed
	local results1 = {} -- high priority list
	local results2 = {} -- low  priority list
	properties.P214.item = 'Q54919';   -- hardwire link to VIAF
	local today = '+' .. os.date('!%F') .. 'T00:00:00Z/11'
	local TransStr = 'https://quickstatements.toolforge.org/#/v1=%s|%s|%%22%s%%22|S143|Q565|S813|'.. today -- QuickStatementts URL
	TransStr = '<span class=\"plainlinks\" title=\"Click (+) to copy to wikidata\">['.. TransStr .. ' (+)]</span>'
	for _,params in ipairs( conf ) do
		local label = string.lower(params.label)
		local val1 = args[label] -- identifier value provided to the template
		local val2 = data[label] -- identifier value pulled from wikidata
		if val1 or val2 then
			local P = properties[params.property] -- properties of wikidata identifier propertyc
			-- name_link - link for the identifier name
			local name_link = getIdentifierNameLink( lang, P.item, P.issuedBy, params.label )
			
			-- val_link - identifier value or values
			local transfer = ''
			local val3 = string.gsub(val1 or '', ' ', '' ) -- remove spaces
			local val_link
			if not val1 then
				val_link = getIdentifierValLink(val2, P, params, 'blue') -- wikidata only no local identifier
			elseif val2=='' then
				val_link = getIdentifierValLink(val1, P, params, 'magenta') -- match was found
			elseif val2 then
				val_link = getIdentifierValLink(val1, P, params, 'darkgreen') .. "/"..getIdentifierValLink(val2, P, params, 'blue')
				cats  = string.format("%s[[Category:Pages using authority control with identifiers mismatching Wikidata]]\n", cats)
				transfer  = string.format(TransStr, q, params.property, val3)
			elseif not val2 and entity then
				val_link = getIdentifierValLink(val1, P, params, 'darkgreen')
				cats  = string.format("%s[[Category:Pages using authority control with identifiers missing from Wikidata]]\n", cats)
				transfer  = string.format(TransStr, q, params.property, val3)
			else
				val_link = getIdentifierValLink(val1, P, params, 'blue') -- local identifier and no wikidata q-code
			end

			-- combine them all
			local lineStr = string.format("\n*%s:&thinsp;<span class=\"uid\">%s</span>%s", name_link, val_link, transfer)
			if (params.lang==lang) or (params.lang=='') then
				table.insert(results1, lineStr) -- add to high priority list
			else
				table.insert(results2, lineStr) -- add to low priority list
			end
		end
	end -- for all sources
	
	-- merge high and low priority lists, trim them if needed and convert to string 
	--table.insert(results1, "\n*End list 1") -- for debuging
	--table.insert(results2, "\n*End list 2")
	for _,v in pairs(results2) do table.insert(results1, v) end
	local results = table.concat(results1, "", 1, math.min(#results1, length or #results1)) 
	
	-- Add Link to wikidata 
	if q then
		results = string.format("\n*[[File:Wikidata-logo.svg|20px|wikidata:%s|link=wikidata:%s]]: [[d:%s|%s]]%s",q,q,q,q,results)
	end
	
	-- Add link to Worldcat
	if (args.worldcatid==nil and (args.lccn or data.lccn))  then
		args.worldcatid = 'lccn-' .. (args.lccn or data.lccn)
	end
	if args.worldcatid  then
		results = string.format("%s\n*<span class=\"uid\">[//www.worldcat.org/identities/%s WorldCat]</span>", results, args.worldcatid)
	end
	
	-- Add maintenance categories
	if q == nil then
		cats = string.format("%s[[Category:Pages using authority control without Wikidata link]]\n", cats)
	end
	if nCustomParam>0 then
		if cats=='' and entity ~= nil then
			cats = string.format("%s[[Category:Pages using authority control with all identifiers matching Wikidata]]\n", cats)
		end
		if string.find(results, "<span style=\"color:red\">") then 
			cats = string.format("%s[[Category:Pages using authority control with badly formated identifier]]\n", cats)
		end
	end

	-- return results
	if results~='' then -- if there are any results than wrap them in <div> tag
		results  = string.format('<div class="hlist">%s\n</div>', results)
	end
	return results, cats
end


-- ===========================================================================
-- === Version of the function to be called from template namespace
-- ===========================================================================
function p.authorityControl(frame)
	-- prepare arguments
	local args = core.getArgs(frame)
	local bare = core.yesno(args.bare,false)         
	
	-- Convert template arguments to the same format as used on wikidata
	if args.bnf then
		args.bnf = string.sub(args.bnf, 3) -- trim first 2 characters
	end
--	if args.isni then -- group in sets of 4
--		args.isni = string.sub(args.isni, 1, 4).." "..string.sub(args.isni, 5, 8)
--		     .." "..string.sub(args.isni, 9,12).." "..string.sub(args.isni,13,16)
--	end
	if args.isbn then
		local isbn = isbn.gsub( ' ', '' )
		if #isbn==10 then
			args['isbn-10'] = args.isbn
		elseif #isbn==13 then
			args['isbn-13'] = args.isbn
		end
		args.isbn = nil
	end
	args.gnd  = args.gnd or args.pnd --redirect PND to GND
	args.lccn = fixLCCN(args.lccn)
	args.wikidata = args.wikidata or args.q or nil
	
	-- call the inner "core" function
	local results, cats = p._authorityControl(nil, args, args.lang, args.length)
	local namespace = mw.title.getCurrentTitle().namespace
	local LUT = {[2]='user', [6]='file', [10]='template', [828]='module'}
	if (LUT[namespace] or math.fmod(namespace,2)==1) then
		-- lets not add categories to some namespaces, or talk pages and concentrate
		-- on templates and categories instead
		cats = '' 
	end
	
	--package results as a infobox if not "bare"
	if not bare then
		-- Get field name for authority control
		local field_name = p.getAuthorityControlTag(args.lang)

		-- build table
		results = string.format('<tr><td class="type fileinfo-paramfield">%s</td><td>\n%s\n</td></tr>', field_name, results)
		local dir   = mw.language.new( args.lang ):getDir()    -- get text direction
		local style = 'class="toccolours mw-content-%s layouttemplate commons-file-information-table" style="width: 100%%;" dir="%s" lang="%s"' 
		style = string.format(style, dir, dir, args.lang)
		results = string.format('<table %s>\n%s\n</table>\n', style, results)
	else
		results = string.format('\n%s\n', results)
	end
	return results..cats
end

return p