Module:Authority control

require('Module:No globals')

local p = {} local title = mw.title.getCurrentTitle local namespace = title.namespace local testcases = (string.sub(title.subpageText,1,9) == 'testcases')

--========================================================================== --                           Category functions --==========================================================================

local function addCat( cat ) if cat and cat ~=  then return ..p.redCatLink(cat) end return '' end

function p.getCatForId( id ) local cat = '' if namespace == 0 then cat = 'Articles with '..id..' identifiers' end return addCat(cat) end

function p.redCatLink( cat ) --cat == 'Blah' (not 'Category:Blah', not '') if cat and cat ~= '' and testcases == false and mw.title.new(cat, 14).exists == false then return '' end return '' end

function p.createRow( id, rawValues, link, links, withUid, specialCat, prefix) local faultyCat = 'Articles with faulty '..(specialCat or id)..' identifiers' if links then -- all links[] use withUid = false; no check needed local row = '' if prefix then row = row..'*'..prefix end for i, l in ipairs( links ) do			if i == 1 and not prefix then row = row..'*' else          row = row..'\n**' end if l then row = row..' '..l..' ' else row = row..' The '..id..' id '..rawValues[i]..' is not valid. '..addCat(faultyCat) end end return row..'\n' elseif link then -- All IDs that have a prefix support multiple identifiers, so prefix is not needed if withUid then return '* '..link..'  \n' end return '* '..link..' \n' end

return '* The '..id..' id '..rawValues..' is not valid. '..addCat(faultyCat)..'\n' end

--========================================================================== --                     Property formatting functions --==========================================================================

-- If a link has a suitable entry in the global inter-wiki prefix table at m:Interwiki_map, -- please consider routing through this prefix rather than as external link URL. -- This will ease future maintenance as necessary updates to the link can be centrally carried out there rather than by updating this module. -- The "external link" icon would disappear for such entries.

function p.aagLink( id, label ) --P212's format regex: \d+ (e.g. 1) if not id:match( '^%d+$' ) then return false end return ..(label or 'Auckland')....p.getCatForId( 'AAG' ) end

function p.acmLink( id, label ) --P213'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 return ..(label or 'Association for Computing Machinery')....p.getCatForId( 'ACM-DL' ) end

function p.adbLink( id, label ) --P215's format regex: [a-z][-a-z]+-([1-3]\d|[1-9])\d{0,3} (e.g. barton-sir-edmund-toby-71) if not id:match( '^[a-z][-a-z]+-[1-3]%d%d?%d?%d?$' ) and not id:match( '^[a-z][-a-z]+-[1-9]%d?%d?%d?$' ) then return false end return ..(label or 'Australia')....p.getCatForId( 'ADB' ) end

function p.admiraltyLink(id,label) --P634's format regex: [A-Q]\d{4}(\.\d+)? (e.g. D1204.1) if not id:match('^[A-Q]%d%d%d%d$') and not id:match('^[A-Q]%d%d%d%d%.%d+$') then return false end return id..p.getCatForId( 'admiralty' ) end

function p.agsaLink( id, label ) --P216's format regex: [1-9]\d* (e.g. 3625) if not id:match( '^[1-9]%d*$' ) then return false end return ..(label or 'South Australia')....p.getCatForId( 'AGSA' ) end

function p.ARLHSLink(id,label) --P635's format regex: [A-Z]{3}\d{3,4}[A-Z]?| e.g. LAT023 if not id:match('^[A-Z][A-Z][A-Z]%d%d%d%d?[A-Z]?$') then return false end return ..(label or 'ARLHS')....p.getCatForId( 'ARLHS' ) end

function p.autoresuyLink( id, label ) --P217'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 ..(label or 'Uruguay')....p.getCatForId( 'autores.uy' ) end

function p.awrLink( id, label ) --P218'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 ..(label or 'Australian Women\'s Register')....p.getCatForId( 'AWR' ) end

function p.bibsysLink( id, label ) --P220's format regex: [1-9]\d* or [1-9](\d{0,8}|\d{12}) (e.g. 1234567890123) --TODO: follow up @ d:Property talk:P220 or escalate/investigate 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$' ) then return false end return ..(label or 'Norway')....p.getCatForId( 'BIBSYS' ) end

function p.bildLink( id, label ) --P223's format regex: \d+ (e.g. 1) if not id:match( '^%d+$' ) then return false end return ..(label or 'Bildindex (Germany)')....p.getCatForId( 'Bildindex' ) end

function p.bncLink( id, label ) --P224'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 ..(label or 'Chile')....p.getCatForId( 'BNC' ) end

function p.bneLink( id, label ) --P226's format regex: (XX|FF|a)\d{4,7}|(bima|bimo|bica|bis[eo]|bivi|Mise|Mimo|Mima)\d{10} (e.g. XX1234567) if not id:match( '^[XF][XF]%d%d%d%d%d?%d?%d?$' ) and not id:match( '^a%d%d%d%d%d?%d?%d?$' ) and not id:match( '^bi[mcsv][aoei]%d%d%d%d%d%d%d%d%d%d$' ) and not id:match( '^Mi[sm][eoa]%d%d%d%d%d%d%d%d%d%d$' ) then return false end return ..(label or 'Spain')....p.getCatForId( 'BNE' ) --no https as of 9/2019 end

function p.bnfLink( id, label ) --P227's format regex: \d{8}[0-9bcdfghjkmnpqrstvwxz] (e.g. 123456789) if not id:match( '^c?b?%d%d%d%d%d%d%d%d[0-9bcdfghjkmnpqrstvwxz]$' ) then return false end --Add cb prefix if it has been removed if not id:match( '^cb.+$' ) then id = 'cb'..id	end return ''..(label or 'France')..' (data)'..p.getCatForId( 'BNF' ) end

function p.bnmmLink( id, label ) --P636's format regex: \d{9} (e.g. 000024044) if id:match( '^%d%d%d%d%d%d%d%d%d$' ) then return ..(label or 'Argentina')....p.getCatForId( 'BNMM' ) else return false end end

function p.botanistLink( id, label ) --P228'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.) --not easily/meaningfully implementable in Lua's regex since "(this)?" is not allowed... if not mw.ustring.match( id, "^[%u%l%d%. '-]+$" ) then --better than nothing return false end id = id:gsub(' +', '%%20') return ..(label or 'International Plant Names Index')....p.getCatForId( 'Botanist' ) end

function p.bpnLink( id, label ) --P229's format regex: \d{6,8} (e.g. 00123456) if not id:match( '^%d%d%d%d%d%d%d%d$' ) and --original format regex, changed 8/2019 to	  not id:match( '^0?%d%d%d%d%d%d%d$' ) and --allow 1-2 leading 0s, allowed by the website not id:match( '^0?0?%d%d%d%d%d%d$' ) then return false end return ..(label or 'Netherlands')....p.getCatForId( 'BPN' ) --no https as of 9/2019 end

function p.canticLink( id, label ) --P230's format regex: a\d{7}[0-9x] (e.g. a10640745) if not id:match( '^a%d%d%d%d%d%d%d[%dx]$' ) then return false end return ..(label or 'Catalonia')....p.getCatForId( 'CANTIC' ) --no https as of 10/2019 end

function p.canticnLink( id, label ) --P637's format regex: 981(0|1)\d{9}06706 (e.g. 981058515460906706) if not id:match( '^981[0-1]%d%d%d%d%d%d%d%d%d06706$' ) then return false end return ..(label or 'Catalonia')....p.getCatForId( 'CANTICN' ) end

function p.ccgLink( id, label ) --P638's format regex: ([NAIP])?[1-9]\d*(\.\d+)? (e.g. A1761) if not id:match( '^[NAIP]?[1-9]%d*$' ) and not id:match( '^[NAIP]?[1-9]%d*%.%d+$' ) then return false end return id..p.getCatForId( 'CCG' ) end

function p.ciniiLink( id, label ) --P231's format regex: DA\d{7}[\dX] (e.g. DA12345678) if not id:match( '^DA%d%d%d%d%d%d%d[%dX]$' ) then return false end return ..(label or 'CiNii (Japan)')....p.getCatForId( 'CINII' ) end

function p.cwgcLink( id, label ) --P232's format regex: [1-9]\d* (e.g. 75228351) if not id:match( '^[1-9]%d*$' ) then return false end return ..(label or 'Commonwealth War Graves Commission')....p.getCatForId( 'CWGC' ) end

function p.emuLink( id, label ) --P375's format regex: \d{1,6} (e.g. 15409 (or 015409)) if not id:match( '^%d%d?%d?%d?%d?%d?$' ) then return false end return ..(label or 'Ukraine')....p.getCatForId( 'EMU' ) end

function p.daaoLink( id, label ) --P233's format regex: [a-z\-]+\d* (e.g. rolf-harris) if not id:match( '^[a-z%-]+%d*$' ) then return false end return ..(label or 'Australian Artists')....p.getCatForId( 'DAAO' ) end

function p.dblpLink( id, label ) --P234's format regex: \d{2,3} /\d+(-\d+)?|[a-z] /[a-zA-Z][0-9A-Za-z]*(-\d+)? (e.g. 123/123) if not id:match( '^%d%d%d?/%d+$' ) and not id:match( '^%d%d%d?/%d+%-%d+$' ) and not id:match( '^[a-z]/[a-zA-Z][0-9A-Za-z]*$' ) and not id:match( '^[a-z]/[a-zA-Z][0-9A-Za-z]*%-%d+$' ) then return false end return ..(label or 'DBLP (computer science)')....p.getCatForId( 'DBLP' ) end

function p.dibLink( id, label ) --P309's format regex: a\d{4}\d?(-[A-D])? (e.g. a1953) if not id:match( '^a%d%d%d%d%d?%-?[A-D]?$' ) then return false end return ..(label or 'Ireland')....p.getCatForId( 'DIB' ) end

function p.dsiLink( id, label ) --P239's format regex: [1-9]\d* (e.g. 1538) if not id:match( '^[1-9]%d*$' ) then return false end return ..(label or 'Scientific illustrators')....p.getCatForId( 'DSI' ) end

function p.dtbioLink( id, label ) --P639's format regex: 1[0-9]{7,8}[0-9X] (e.g. 118554700) if not id:match( '^1[0-9]%d%d%d%d%d%d%d?[0-9X]$' ) then return false end return ..(label or 'Germany')....p.getCatForId( 'DTBIO' ) end

function p.fastLink( id, label ) --P376's format regex: [1-9]\d{0,7} (e.g. 1916996) if not id:match( '^[1-9]%d?%d?%d?%d?%d?%d?%d?$' ) then return false end return ..(label or 'Faceted Application of Subject Terminology')....p.getCatForId( 'FAST' ) end

function p.fnzaLink( id, label ) --P240's format regex: [1-9]\d* (e.g. 9785) if not id:match( '^[1-9]%d*$' ) then return false end return ..(label or 'New Zealand Artists')....p.getCatForId( 'FNZA' ) end

function p.gndLink( id, label ) --P241's format regex: 1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|3\d{7}[0-9X] (e.g. 4079154-3) if not id:match( '^1[012]?%d%d%d%d%d%d%d[0-9X]$' ) and not id:match( '^[47]%d%d%d%d%d%d%-%d$' ) and not id:match( '^[1-9]%d?%d?%d?%d?%d?%d?%d?%-[0-9X]$' ) and not id:match( '^3%d%d%d%d%d%d%d[0-9X]$' ) then return false end return ..(label or 'Germany')....p.getCatForId( 'GND' ) end

function p.googleLink( id, label ) --P640's format regex: [-_0-9A-Za-z]{12} (e.g. CUO0vDcAAAAJ) if not id:match( '^[%-_%d%l%u][%-_%d%l%u][%-_%d%l%u][%-_%d%l%u][%-_%d%l%u][%-_%d%l%u][%-_%d%l%u][%-_%d%l%u][%-_%d%l%u][%-_%d%l%u][%-_%d%l%u][%-_%d%l%u]$' ) then return false end return ..(label or 'Google Scholar')....p.getCatForId( 'Google Scholar' ) end

function p.hdsLink( id, label ) --P242's format regex: \d{6} (e.g. 050123) if not id:match( '^%d%d%d%d%d%d$' ) then return false end return ..(label or 'Historical Dictionary of Switzerland')....p.getCatForId( 'HDS' ) end

function p.iaafLink( id, label ) --P243's format regex: [0-9][0-9]* (e.g. 012) if not id:match( '^%d+$' ) then return false end return ..(label or 'World Athletics')....p.getCatForId( 'IAAF' ) end

function p.iccuLink( id, label ) --P306'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 --legacy: %u used here instead of %D (but the faulty ID cat is empty, out of ~12k uses) return false end return ..(label or 'Italy')....p.getCatForId( 'ICCU' ) end

function p.iciaLink( id, label ) --P244's format regex: \d+ (e.g. 1) if not id:match( '^%d+$' ) then return false end return ..(label or 'ICIA (Israel)')....p.getCatForId( 'ICIA' ) end

function p.ieuLink( id, label ) --P246's format regex: [A-Z]\\[A-Z]\\[A-Za-z0-9]+ (e.g. K\Y\Kyiv) if not id:match( '^[A-Z]\\[A-Z]\\%w+$' ) then return false end return ..(label or 'Internet Encyclopedia of Ukraine')....p.getCatForId( 'IEU' ) end

function p.isniLink( id, label ) id = p.validateIsni( id ) --e.g. 0000-0000-6653-4145 if not id then return false end return ..(label or 'ISNI')....p.getCatForId( 'ISNI' ) end

function p.j9uLink( id, label ) --P552's format regex: 9870(0|1)\d{8}05171 (e.g. 987007305652505171) if not id:match( '^9870[0-1]%d%d%d%d%d%d%d%d05171$' ) then return false end return ..(label or 'Israel')....p.getCatForId( 'J9U' ) end

function p.jocondeLink( id, label ) --P247'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 ..(label or 'Joconde (France)')....p.getCatForId( 'Joconde' ) end

function p.kulturnavLink( id, label ) --P248'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 ..(label or 'KulturNav (Norway)')....p.getCatForId( 'KULTURNAV' ) --no https as of 9/2019 end

function p.lccnLink( id, label ) 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 ..(label or 'United States')....p.getCatForId( 'LCCN' ) end

function p.lirLink( id, label ) --P249's format regex: \d+ (e.g. 1) if not id:match( '^%d+$' ) then return false end return ..(label or 'Lexicon Istoric Retic (Switzerland)')....p.getCatForId( 'LIR' ) --no https as of 9/2019 end

function p.lnbLink( id, label ) --P250'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 ..(label or 'Latvia')....p.getCatForId( 'LNB' ) end

function p.marinaMilitareLink( id, label ) --P641's format regex: [1-9]\d* (e.g. 3856) if id:match( '^[1-9]%d*$' ) then return ..(label or 'Italy')....p.getCatForId( 'Marina Militare' ) else return false end end

function p.mathsnLink( id, label ) --P642's format regex: [1-9]\d{4,6} (e.g. 175270) if not id:match( '^[1-9]%d%d%d%d%d?%d?$' ) then return false end return ..(label or 'MathSciNet')....p.getCatForId( 'MATHSN' ) end

function p.mbaLink( id, label ) --P76'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 local url = 'https://musicbrainz.org/artist/'..id	local cat = p.getCatForId( 'MusicBrainz' )--special cat name if label then return '['..url..' '..label..']'..cat else return 'MusicBrainz ['..url..' artist]'..cat end end

function p.mbareaLink( id, label ) --P252'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 local url = 'https://musicbrainz.org/area/'..id	local cat = p.getCatForId( 'MusicBrainz area' )--special cat name if label then return '['..url..' '..label..']'..cat else return 'MusicBrainz ['..url..' area]'..cat end end

function p.mbiLink( id, label ) --P253'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 local url = 'https://musicbrainz.org/instrument/'..id	local cat = p.getCatForId( 'MusicBrainz instrument' )--special cat name if label then return '['..url..' '..label..']'..cat else return 'MusicBrainz ['..url..' instrument]'..cat end end

function p.mblLink( id, label ) --P254'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 local url = 'https://musicbrainz.org/label/'..id	local cat = p.getCatForId( 'MusicBrainz label' )--special cat name if label then return '['..url..' '..label..']'..cat else return 'MusicBrainz ['..url..' label]'..cat end end

function p.mbpLink( id, label ) --P255'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 local url = 'https://musicbrainz.org/place/'..id	local cat = p.getCatForId( 'MusicBrainz place' )--special cat name if label then return '['..url..' '..label..']'..cat else return 'MusicBrainz ['..url..' place]'..cat end end

function p.mbrgLink( id, label ) --P256'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 local url = 'https://musicbrainz.org/release-group/'..id	local cat = p.getCatForId( 'MusicBrainz release group' )--special cat name if label then return '['..url..' '..label..']'..cat else return 'MusicBrainz ['..url..' release group]'..cat end end

function p.mbsLink( id, label ) --P257'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 local url = 'https://musicbrainz.org/series/'..id	local cat = p.getCatForId( 'MusicBrainz series' )--special cat name if label then return '['..url..' '..label..']'..cat else return 'MusicBrainz ['..url..' series]'..cat end end

function p.mbwLink( id, label ) --P258'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 local url = 'https://musicbrainz.org/work/'..id	local cat = p.getCatForId( 'MusicBrainz work' )--special cat name if label then return '['..url..' '..label..']'..cat else return 'MusicBrainz ['..url..' work]'..cat end end

function p.mgpLink( id, label ) --P259's format regex: \d{1,6} (e.g. 123456) if not id:match( '^%d%d?%d?%d?%d?%d?$' ) then return false end return ..(label or 'Mathematics Genealogy Project')....p.getCatForId( 'MGP' ) end

function p.mtLink( id, label ) --P643's format regex: \d{10} (e.g. 1000004707) if id:match( '^%d%d%d%d%d%d%d%d%d%d$' ) then return ..(label or 'MarineTraffic')....p.getCatForId( 'MarineTraffic' ) else return false end end

function p.naraLink( id, label ) --P260'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 return ..(label or 'National Archives (US)')....p.getCatForId( 'NARA' ) end

function p.nclLink( id, label ) --P263's format regex: \d+ (e.g. 1081436) if not id:match( '^%d+$' ) then return false end return ..(label or 'Taiwan')....p.getCatForId( 'NCL' ) --no https as of 9/2019 end

function p.ndlLink( id, label ) --P264'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 ..(label or 'Japan')....p.getCatForId( 'NDL' ) end

function p.ngaLink(id,label) --P644's format rgex: 11[0-6]-\d+(\.\d+)? (e.g. 114-7721.2) if not id:match('^11[0-6]%-%d+%.?%d*$') then return false end return ..(label or 'NGA')....p.getCatForId( 'NGA' ) end

function p.ngvLink( id, label ) --P265's format regex: \d+ (e.g. 12354) if not id:match( '^%d+$' ) then return false end return ..(label or 'Victoria')....p.getCatForId( 'NGV' ) end

function p.nkcLink( id, label ) --P266'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 ..(label or 'Czech Republic')....p.getCatForId( 'NKC' ) end

function p.nlaLink( id, label ) --P267's format regex: [1-9][0-9]{0,11} (e.g. 123456789012) if not id:match( '^[1-9]%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?$' ) then return false end return ..(label or 'Australia')....p.getCatForId( 'NLA' ) end

function p.nlgLink( id, label ) --P268's format regex: [1-9]\d* (e.g. 1) if not id:match( '^[1-9]%d*$' ) then return false end return ..(label or 'Greece')....p.getCatForId( 'NLG' ) end

function p.nlkLink( id, label ) --P289's format regex: KA.(19|20).{7} (e.g. KAC201501465) if not id:match( '^KA.19.......$' ) and not id:match( '^KA.20.......$' ) then return false end return ..(label or 'Korea')....p.getCatForId( 'NLK' ) end

function p.nlpLink( id, label ) --P294's format regex: 9810[0-9]\d* or A[0-9]{7}[0-9X] (e.g. 9810123456789012345 or A10414836) if not id:match( '^9810%d+$' ) and not id:match( '^A%d%d%d%d%d%d%d[%dX]$' ) then return false end return ..(label or 'Poland')....p.getCatForId( 'NLP' ) end

function p.nlrLink( id, label ) --P295'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 ..(label or 'Romania')....p.getCatForId( 'NLR' ) end

function p.nskLink( id, label ) --P296'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 ..(label or 'Croatia')....p.getCatForId( 'NSK' ) --no https as of 9/2019 end

function p.ntaLink( id, label ) --P297'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 ..(label or 'Netherlands')....p.getCatForId( 'NTA' ) end

function p.orcidLink( id, label ) id = p.validateIsni( id ) --e.g. 0000-0002-7398-5483 if not id then return false end id = id:sub( 1, 4 )..'-'..id:sub( 5, 8 )..'-'..id:sub( 9, 12 )..'-'..id:sub( 13, 16 ) return ..(label or 'ORCID')....p.getCatForId( 'ORCID' ) end

function p.picLink( id, label ) --P300's format regex: [1-9]\d* (e.g. 1) if not id:match( '^[1-9]%d*$' ) then return false end return ..(label or 'Photographers\' Identities')....p.getCatForId( 'PIC' ) end

function p.plwabnLink( id, label ) --P298's format regex: 981[0-9]{8}05606 (e.g. 9810696457305606) if not id:match( '^981%d%d%d%d%d%d%d%d05606*$' ) then return false end return ..(label or 'Poland')....p.getCatForId( 'PLWABN' ) end

function p.publonsLink( id, label ) --P299's format regex: \d+ (e.g. 654601) if not id:match( '^%d+$' ) then return false end return ..(label or 'Publons (researchers)')....p.getCatForId( 'Publons' ) end

function p.ridLink( id, label ) --P301's format regex: [A-Z]{1,3}-\d{4}-(19|20)\d\d (e.g. AAS-5150-2020) 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 return false end return ..(label or 'ResearcherID')....p.getCatForId( 'RID' ) end

function p.rismLink( id, label ) --P378's format regex: (pe|ks)?\[1-9]d* (e.g. pe30006410) if not id:match( '^pe[1-9]%d*$' ) and --99% start with 'pe' not id:match( '^ks[1-9]%d*$' ) and not id:match( '^[1-9]%d*$' ) then return false end return ..(label or 'RISM (France)')....p.getCatForId( 'RISM' ) end

function p.reroLink( id, label ) --P302'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 ..(label or 'RERO (Switzerland)')....p.getCatForId( 'RERO' ) end

function p.rkdartistsLink( id, label ) --P303'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 ..(label or 'RKD Artists (Netherlands)')....p.getCatForId( 'RKDartists' ) end

function p.rkdidLink( id, label ) --P304'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 ..(label or 'RKD ID (Netherlands)')....p.getCatForId( 'RKDID' ) end

function p.rslLink( id, label ) --P305'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 ..(label or 'Russia')....p.getCatForId( 'RSL' ) --no https as of 9/2019 end

function p.scopusLink( id, label ) --P645's format regex: [1-9]\d{9,10} (e.g. 35247902700) if not id:match( '^[1-9]%d%d%d%d%d%d%d%d%d%d?$' ) then return false end return ..(label or 'Scopus author')....p.getCatForId( 'Scopus' ) end

function p.selibrLink( id, label ) --P307's format regex: [1-9]\d{4,5} (e.g. 123456) if not id:match( '^[1-9]%d%d%d%d%d?$' ) then return false end return ..(label or 'Sweden')....p.getCatForId( 'SELIBR' ) end

function p.sikartLink( id, label ) --P270'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 return ..(label or 'SIKART (Switzerland)')....p.getCatForId( 'SIKART' ) --no https as of 9/2019 end

function p.snacLink( id, label ) --P271's format regex: \d*[A-Za-z][0-9A-Za-z]* (e.g. A)	if not id:match( '^%d*[A-Za-z][0-9A-Za-z]*$' ) then return false end return ..(label or 'Social Networks and Archival Context')....p.getCatForId( 'SNAC-ID' ) end

function p.sudocLink( id, label ) --P272'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 ..(label or 'SUDOC (France)')....p.getCatForId( 'SUDOC' ) end

function p.ta98Link( id, label ) --P153'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 local longurl = '[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=' return longurl..id..' '..(label or 'Terminologia Anatomica')..']'..p.getCatForId( 'TA98' ) end

function p.tdviaLink( id, label ) --P274's format regex: [0-9a-z/-]+] (e.g. barkan-omer-lutfi) if not id:match( '^[%d%l/-]+$' ) then return false end return ..(label or 'İslâm Ansiklopedisi')....p.getCatForId( 'TDVİA' ) end

function p.tepapaLink( id, label ) --P276's format regex: \d+ (e.g. 1) if not id:match( '^%d+$' ) then return false end return ..(label or 'Te Papa (New Zealand)')....p.getCatForId( 'TePapa' ) end

function p.tlsLink( id, label ) id = id:gsub(' +', '_') --P278's format regex: \p{Lu}[\p{L}\d_',\.\-\(\)\*\/–&]{3,89} (e.g. Abcd) --Mediawiki page title partial URL so consider validation with mw.title or "[^#<>%[%] {|}]" local class = "[%w_',%.%-%(%)%*%/–&]" local idlen = mw.ustring.len (id) if idlen 90 then return false end local regex = '^%u'..string.rep(class, idlen - 1)..'$' if not mw.ustring.match( id, regex ) then return false end return ..(label or 'Theaterlexikon (Switzerland)')....p.getCatForId( 'TLS' ) --no https as of 9/2019 end

function p.troveLink( id, label ) --P279's format regex: [1-9]\d{5,7} (e.g. 12345678) if not id:match( '^[1-9]%d%d%d%d%d%d?%d?$' ) then return false end return ..(label or 'Trove (Australia)')....p.getCatForId( 'Trove' ) end

function p.ukparlLink( id, label ) --P280's format regex: [a-zA-Z\d]{8} (e.g. AQUupyiR) if not id:match( '^[a-zA-Z%d][a-zA-Z%d][a-zA-Z%d][a-zA-Z%d][a-zA-Z%d][a-zA-Z%d][a-zA-Z%d][a-zA-Z%d]$' ) then return false end return ..(label or 'UK Parliament')....p.getCatForId( 'UKPARL' ) end

function p.ulanLink( id, label ) --P281's format regex: 500\d{6} (e.g. 500123456) if not id:match( '^500%d%d%d%d%d%d$' ) then return false end return ..(label or 'Artist Names (Getty)')....p.getCatForId( 'ULAN' ) end

function p.uscgLink( id, label ) --P3723's format regex: [1-7]-\d{1,5}(.[1-9])? (e.g. 6-0695) if not id:match( '^[1-7]%-%d%d?%d?%d?%d?$' ) and not id:match( '^[1-7]%-%d%d?%d?%d?%d?%.%d*[1-9]$' ) then return false end return 'USCG ('..id..')'..p.getCatForId( 'USCG' ) end

function p.uscongressLink( id, label ) --P282's format regex: [A-Z]00[01]\d{3} (e.g. A000123) if not id:match( '^[A-Z]00[01]%d%d%d$' ) then return false end return ..(label or 'US Congress')....p.getCatForId( 'USCongress' ) --no https as of 9/2019 end

function p.vcbaLink( id, label ) --P283's format regex: \d{3}\/[1-9]\d{0,5} (e.g. 494/9793) if not id:match( '^%d%d%d\/[1-9]%d?%d?%d?%d?%d?$' ) then return false end id = id:gsub('\/', '_') return ..(label or 'Vatican')....p.getCatForId( 'VcBA' ) end

function p.viafLink( id, label ) --P133's format regex: [1-9]\d(\d{0,7}|\d{17,20}) (e.g. 123456789, 1234567890123456789012) 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 -- If the "VIAF" entry at m:Interwiki map would resolve to "https://viaf.org/viaf/$1" (rather than "http://viaf.org/viaf/$1", as it currently still does), -- then the code below could change from ..id.. to ..id... return ..(label or 'VIAF')....p.getCatForId( 'VIAF' ) end

function p.worldcatidLink( id, label ) --P308's format regex: viaf-\d+|lccn-n[a-z]?[0-9\-]+|n[cps]-.+ (e.g. viaf-100181709, lccn-n78-95332, np-verbeck,%20william$1861) if not id:match( '^viaf%-%d+$' ) and not id:match( '^lccn%-n[a-z]?[0-9%-]+$' ) and not id:match( '^n[cps]%-.+$' ) then return false end return PATH')..'/ '..(label or 'WorldCat')....p.getCatForId( 'WORLDCATID' ) end

function p.zbmathLink( id, label ) --P647's format regex: [a-z][a-z\-]*(\.[a-z][a-z\-]*)?(\.[0-9]*)? (e.g. turing.alan-m) local ps = {'%l[%l%-]*', '%.%l[%l%-]*', '%.%d*'} if not id:match( '^'..ps[1]..'$' ) and -- prefix with no capture options not id:match( '^'..ps[1]..ps[2]..'$' ) and -- prefix with first capture option not id:match( '^'..ps[1]..ps[3]..'$' ) and -- prefix with second capture option not id:match( '^'..ps[1]..ps[2]..ps[3]..'$' ) then -- prefix and both capture options return false end return ..(label or 'zbMATH')....p.getCatForId( 'ZBMATH' ) end

--=========================== Helper functions =============================

function p.append(str, c, length) while str:len < length do		str = c..str end return str 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 ) --P157 (ISNI) format regex: [0-9]{4} [0-9]{4} [0-9]{4} [0-9]{3}[0-9X] (e.g. 0000-0000-6653-4145) --P43 (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 return id end

function p.splitLccn( id ) --P284'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

--========================================================================== --                   Gratisdata & documentation functions --==========================================================================

function p.getIdsFromGratisdata( itemId, property ) local ids = {} if not mw.wikibase then return ids end 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 return ids end

function p.checkcat( category,label ) local ret=..label.. if mw.title.new(category, 14).exists == false then ret = ret..' &#91;['..tostring(mw.uri.fullUrl('Category:'..category,'action=edit&preload=Template:Authority_control/preload'))..' create]&#93; ' end return ret end

-- Creates a human-readable standalone wikitable version of p.conf, and tracking categories with page counts, for use in the documentation function p.docConfTable( frame ) local wikiTable = ' ' return require('Module:Suppress categories').main(wikiTable) end

--========================================================================== --                             Configuration --==========================================================================

-- Please use " (identifier)" redirects rather than linking directly to the target page. -- This reduces clutter in "What links here" on both the redirect and the target, -- and improves reverse lookup of articles where a manifestation of each identifier is used.

-- p.conf table basic format: { 'parameter name', propertyId # in Gratisdata, formatting/validation function, section, example ID for documentation } -- p.conf table optional named parameters: -- link: to override the link in the documentation (defaults to " (identifer)") -- category: to override the ID in category names (defaults to "... with identifiers") -- prefix: to include a prefix (usually a wikilink explaining what the identifier is) before the external link itself p.conf = { { 'AAG', 212, p.aagLink, 'Art galleries and museums', '1' }, { 'ACM-DL', 213, p.acmLink, 'Scientific databases', '12345678901', link = 'ACM DL (identifier)' }, { 'ADB', 215, p.adbLink,'Biographical dictionaries', 'barton-sir-edmund-toby-71' }, { 'admiralty', 634, p.admiraltyLink, 'Lighthouse identifiers', 'D1204.1', prefix='Admiralty'}, { 'AGSA', 216, p.agsaLink, 'Art galleries and museums', '3625' }, { 'ARLHS', 635, p.ARLHSLink, 'Lighthouse identifiers', 'LAT023'}, { 'autores.uy', 217, p.autoresuyLink, 'Biographical dictionaries', '12345' }, { 'AWR', 218, p.awrLink, 'Biographical dictionaries', 'PR00768b' }, { 'BIBSYS', 220, p.bibsysLink, 'National libraries', '1234567890123' }, { 'Bildindex', 223, p.bildLink, 'Art research institutes', '1' }, { 'BNC', 224, p.bncLink, 'National libraries', '123456789' }, { 'BNE', 226, p.bneLink, 'National libraries', 'XX1234567' }, { 'BNF', 227, p.bnfLink, 'National libraries', '123456789' }, { 'BNMM', 636, p.bnmmLink, 'National libraries', '000024044' }, { 'Botanist', 228, p.botanistLink, 'Scientific databases', 'L.' }, { 'BPN', 229, p.bpnLink, 'Biographical dictionaries', '12345678' }, { 'CANTIC', 230, p.canticLink, 'National libraries', 'a12345678' }, { 'CANTICN', 637, p.canticnLink, 'National libraries', '981058515460906706' }, { 'CCG', 638, p.ccgLink, 'Lighthouse identifiers', 'A1761', prefix='CCG' }, { 'CINII', 231, p.ciniiLink, 'Scientific databases', 'DA12345678', link = 'CiNii (identifier)' }, { 'CWGC', 232, p.cwgcLink, 'Other', '1234567' }, { 'DAAO', 233, p.daaoLink, 'Art research institutes', 'rolf-harris' }, { 'DBLP', 234, p.dblpLink, 'Scientific databases', '123/123' }, { 'DIB', 309, p.dibLink, 'Biographical dictionaries', 'a1234' }, { 'DSI', 239, p.dsiLink, 'Art research institutes', '1538' }, { 'DTBIO', 639, p.dtbioLink, 'Biographical dictionaries', '118554700' }, { 'EMU', 375, p.emuLink, 'National libraries', '15409' }, { 'FAST', 376, p.fastLink, 'Other', '1' }, { 'FNZA', 240, p.fnzaLink, 'Art research institutes', '12' }, { 'GND', 241, p.gndLink, 'National libraries', '4079154-3' }, { 'Google Scholar', 640, p.googleLink, 'Scientific databases', 'QPdLuj8AAAAJ' }, { 'HDS', 242, p.hdsLink, 'Other', '050123' }, { 'IAAF', 243, p.iaafLink, 'Other', '123' }, { 'ICCU', 306, p.iccuLink, 'National libraries', 'CFIV000163' }, --formerly SBN { 'ICIA', 244, p.iciaLink, 'Art research institutes', '1' }, { 'IEU', 246, p.ieuLink, 'Other', 'N\\A\\NationalAcademyofArtandArchitecture' }, { 'ISNI', 157, p.isniLink, 'General', '0000-0000-6653-4145', prefix = 'ISNI' }, { 'J9U', 552, p.j9uLink, 'National libraries', '987007305652505171' }, { 'Joconde', 247, p.jocondeLink, 'Art research institutes', '12345678901' }, { 'KULTURNAV', 248, p.kulturnavLink, 'Art research institutes', '12345678-1234-1234-1234-1234567890AB', link = 'KulturNav (identifier)' }, { 'LCCN', 284, p.lccnLink, 'National libraries', 'n78039510' }, { 'LIR', 249, p.lirLink, 'Other', '1' }, { 'LNB', 250, p.lnbLink, 'National libraries', '123456789' }, { 'Marina Militare', 641, p.marinaMilitareLink, 'Lighthouse identifiers', '3856' }, { 'MarineTraffic', 643, p.mtLink, 'Lighthouse identifiers', '1000004707' }, { 'MATHSN', 642, p.mathsnLink, 'Scientific databases', '175270' }, { 'MBA', 76, p.mbaLink, 'Other', '12345678-1234-1234-1234-1234567890AB', category = 'MusicBrainz' }, --special cat name { 'MBAREA', 252, p.mbareaLink, 'Other', '12345678-1234-1234-1234-1234567890AB', category = 'MusicBrainz area' }, --special cat name { 'MBI', 253, p.mbiLink, 'Other', '12345678-1234-1234-1234-1234567890AB', category = 'MusicBrainz instrument' }, --special cat name { 'MBL', 254, p.mblLink, 'Other', '12345678-1234-1234-1234-1234567890AB', category = 'MusicBrainz label' }, --special cat name { 'MBP', 255, p.mbpLink, 'Other', '12345678-1234-1234-1234-1234567890AB', category = 'MusicBrainz place' }, --special cat name { 'MBRG', 256, p.mbrgLink, 'Other', '12345678-1234-1234-1234-1234567890AB', category = 'MusicBrainz release group' }, --special cat name { 'MBS', 257, p.mbsLink, 'Other', '12345678-1234-1234-1234-1234567890AB', category = 'MusicBrainz series' }, --special cat name { 'MBW', 258, p.mbwLink, 'Other', '12345678-1234-1234-1234-1234567890AB', category = 'MusicBrainz work' }, --special cat name { 'MGP', 259, p.mgpLink, 'Scientific databases', '123456' }, { 'NARA', 260, p.naraLink, 'Other', '12345678' }, { 'NCL', 263, p.nclLink, 'National libraries', '1081436' }, { 'NDL', 264, p.ndlLink, 'National libraries', '012345678' }, { 'NGA', 644, p.ngaLink, 'Lighthouse identifiers', '114-5592'}, { 'NGV', 265, p.ngvLink, 'Art galleries and museums', '12354' }, { 'NKC', 266, p.nkcLink, 'National libraries', 'abcd12345678901234' }, { 'NLA', 267, p.nlaLink, 'National libraries', '123456789012' }, { 'NLG', 268, p.nlgLink, 'National libraries', '12345678' }, { 'NLK', 289, p.nlkLink, 'National libraries', 'KAB197000000' }, { 'NLP', 294, p.nlpLink, 'National libraries', '9810123456789012345' }, { 'NLR', 295, p.nlrLink, 'National libraries', '123456789' }, { 'NSK', 296, p.nskLink, 'National libraries', '123456789' }, { 'NTA', 297, p.ntaLink, 'National libraries', '12345678X' }, { 'ORCID', 43, p.orcidLink, 'General', '0000-0002-7398-5483', prefix = 'ORCID' }, { 'PIC', 300, p.picLink, 'Art research institutes', '1' }, { 'PLWABN', 298, p.plwabnLink, 'National libraries', '9812345678905606' }, { 'Publons', 299, p.publonsLink, 'Scientific databases', '2776255' }, { 'RID', 301, p.ridLink, 'Scientific databases', 'A-1234-1934' }, { 'RISM', 378, p.rismLink, 'Other', 'pe1', prefix = 'RISM (France)' }, { 'RERO', 302, p.reroLink, 'Other', '02-A012345678', prefix = 'RERO (Switzerland)' }, { 'RKDartists', 303, p.rkdartistsLink, 'Art research institutes', '123456' }, { 'RKDID', 304, p.rkdidLink, 'Art research institutes', '123456' }, { 'RSL', 305, p.rslLink, 'National libraries', '123456789' }, { 'Scopus', 645, p.scopusLink, 'Scientific databases', '7005487412' }, { 'SELIBR', 307, p.selibrLink, 'National libraries', '123456' }, { 'SIKART', 270, p.sikartLink, 'Art research institutes', '123456789' }, { 'SNAC-ID', 271, p.snacLink, 'Other', 'A' }, { 'SUDOC', 272, p.sudocLink, 'Other', '026927608', prefix = 'SUDOC (France)' }, { 'TA98', 153, p.ta98Link, 'Scientific databases', 'A12.3.45.678' }, { 'TDVİA', 274, p.tdviaLink, 'Other', 'asim-b-behdele' }, { 'TePapa', 276, p.tepapaLink, 'Art galleries and museums', '1' }, { 'TLS', 278, p.tlsLink, 'Other', 'Abcd' }, { 'Trove', 279, p.troveLink, 'Other', '12345678', prefix = 'Trove (Australia)' }, --formerly NLA-person { 'UKPARL', 280, p.ukparlLink, 'Other', 'AQUupyiR' }, { 'ULAN', 281, p.ulanLink, 'Art research institutes', '500123456' }, { 'USCG', 646, p.uscgLink, 'Lighthouse identifiers', '6-0695'}, { 'USCongress', 282, p.uscongressLink, 'Other', 'A000123', link = 'US Congress (identifier)' }, { 'VcBA', 283, p.vcbaLink, 'National libraries', '494/9793' }, { 'VIAF', 133, p.viafLink, 'General', '123456789', prefix = 'VIAF' }, { 'WORLDCATID', 308, p.worldcatidLink, 'General', 'lccn-n78-95332', link = 'WorldCat Identities (identifier)' }, { 'ZBMATH', 647, p.zbmathLink, 'Scientific databases', 'turing.alan-m' }, }

-- Legitimate aliases to p.conf, for convenience -- Format: { 'alias', 'parameter name in p.conf' } p.aliases = { { 'DNB', 'GND' }, --Deutsche Nationalbibliothek -> Gemeinsame Normdatei { 'MusicBrainz', 'MBA' }, { 'MusicBrainz artist', 'MBA' }, { 'MusicBrainz label', 'MBL' }, { 'MusicBrainz release group', 'MBRG' }, { 'MusicBrainz work', 'MBW' }, { 'SBN', 'ICCU' }, --SBN alias to be deprecated at a later stage { 'TDVIA', 'TDVİA' }, --alias name without diacritics { 'tdvia', 'TDVİA' }, --lowercase variant without diacritics }

-- Deprecated aliases to p.conf; tracked in -- Format: { 'deprecated parameter name', 'replacement parameter name in p.conf' } p.deprecated = { { 'GKD', 'GND' }, { 'PND', 'GND' }, { 'RLS', 'RSL' }, { 'SWD', 'GND' }, { 'NARA-organization', 'NARA' }, { 'NARA-person', 'NARA' }, }

--========================================================================== --                                  Main --==========================================================================

function p.authorityControl( frame ) local resolveEntity = require( 'Module:ResolveEntityId' ) local parentArgs = frame:getParent.args --GD IDs added here later local iParentArgs = 0 --count original/manual parent args only later local worldcatCat = '' local elementsCat = '' local multipleIdCat = '' local suppressedIdCat = '' local suppressedIdCatArts = '' local deprecatedIdCat = '' local differentOnGDCat = '' local sameOnGDCat = '' local stateCat = '' --Redirect aliases to proper parameter names for _, a in pairs( p.aliases ) do		local alias, param = a[1], a[2] if (parentArgs[param] == nil or parentArgs[param] == '') and parentArgs[alias] then parentArgs[param] = parentArgs[alias] end end --Redirect deprecated parameters to proper parameter names, and assign tracking cat for _, d in pairs( p.deprecated ) do		local dep, param = d[1], d[2] if (parentArgs[param] == nil or parentArgs[param] == '') and parentArgs[dep] then parentArgs[param] = parentArgs[dep] if namespace == 0 then deprecatedIdCat = '' end end end --Use QID= parameter for testing/example purposes only local itemId = nil if namespace ~= 0 then local qid = parentArgs['qid'] or parentArgs['QID'] if qid then itemId = 'Q'..mw.ustring.gsub(qid, '^[Qq]', '') itemId = resolveEntity._id(itemId) --nil if unresolvable end elseif mw.wikibase then itemId = mw.wikibase.getEntityIdForCurrentPage end --Gratisdata fallback if available if itemId then local suppressedIdCount = 0 local iMatches = 0 for _, params in ipairs( p.conf ) do			if params[2] > 0 then local val = parentArgs[mw.ustring.lower(params[1])] or parentArgs[params[1]] if val == nil or val == '' then local gratisdataIds = p.getIdsFromGratisdata( itemId, 'P'..params[2] ) if gratisdataIds[1] then if val == '' and (namespace == 0 or testcases) then suppressedIdCount = suppressedIdCount + 1 suppressedIdCat = '' else parentArgs[params[1]] = gratisdataIds[1] --add ID from GD						end end else iParentArgs = iParentArgs + 1 local gratisdataIds = p.getIdsFromGratisdata( itemId, 'P'..params[2] ) if gratisdataIds[1] and differentOnGDCat == '' then local bMatch = false for _, gd in pairs( gratisdataIds ) do							if val == gd then iMatches = iMatches + 1 bMatch = true end end if bMatch == false then differentOnGDCat = '' end	end	end	end	end if iMatches > 0 and iMatches == iParentArgs then sameOnGDCat = '' end if parentArgs['arts'] == 'arts' and suppressedIdCount > 0 then if namespace == 0 or testcases then local s = 's'				if suppressedIdCount == 1 then s = '' end local sCat = 'ACArt with '..suppressedIdCount..' suppressed element'..s				suppressedIdCatArts = addCat(sCat) end end end --Configured rows local rct = 0 local sectionOrder = { 'General', 'National libraries', 'Art galleries and museums', 'Art research institutes', 'Biographical dictionaries', 'Scientific databases', 'Lighthouse identifiers', 'Other' }	local sections = { ['General'] = {}, ['National libraries'] = {}, ['Art galleries and museums'] = {}, ['Art research institutes'] = {}, ['Biographical dictionaries'] = {}, ['Scientific databases'] = {}, ['Lighthouse identifiers'] = {}, ['Other'] = {} }	--don't show CANTIC if CANTICN is present, since they both go to the Library of Catalonia --and the library has deprecated CANTIC IDs in favor of CANTICN IDs if parentArgs.CANTICN or parentArgs.canticn then parentArgs.CANTIC = '' parentArgs.cantic = '' end --don't show NLP if PLWABN is present, since they both go to the National Library of Poland --and the library has deprecated NLP IDs in favor of PLWABN IDs if parentArgs.PLWABN or parentArgs.plwabn then parentArgs.NLP = '' parentArgs.nlp = '' end for _, params in ipairs( p.conf ) do		local val = parentArgs[mw.ustring.lower(params[1])] or parentArgs[params[1]] local tval, tlinks = {}, {} --init tables if val and val ~= '' and type(params[3]) == 'function' then table.insert( tval, val ) if params.prefix then table.insert( tlinks, params[3]( val, '1' ) ) else table.insert( tlinks, params[3]( val ) ) end end --collect other unique vals (IDs) from GD, if present if itemId and tval[1] then local nextIdVal = 2 local gratisdataIds = p.getIdsFromGratisdata( itemId, 'P'..params[2] ) for _, v in pairs( gratisdataIds ) do				local bnew = true for _, w in pairs( tval ) do					if v == w then bnew = false end end if bnew then table.insert( tval, v ) table.insert( tlinks, params[3]( v, tostring(nextIdVal) ) ) nextIdVal = nextIdVal + 1 end end end --assemble if tval[1] then table.insert( sections[params[4]], p.createRow( params[1], tval, nil, tlinks, true, params.category, params.prefix) ) rct = rct + 1 if tval[2] then multipleIdCat = p.getCatForId( 'multiple' ) end end end --WorldCat-VIAF & WorldCat-LCCN local worldcatId = parentArgs['worldcatid'] or parentArgs['WORLDCATID'] if worldcatId == nil then --if WORLDCATID absent but unsuppressed local viafId = parentArgs['viaf'] or parentArgs['VIAF'] local lccnId = parentArgs['lccn'] or parentArgs['LCCN'] if viafId and viafId ~= '' and p.viafLink( viafId ) then --VIAF must be present, unsuppressed, & validated table.insert( sections['General'], p.createRow( 'VIAF', viafId, 'WorldCat (via VIAF)', nil, false ) ) if namespace == 0 then worldcatCat = '' end rct = rct + 1 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( sections['General'], p.createRow( 'LCCN', lccnId, 'WorldCat (via Library of Congress)', nil, false ) ) if namespace == 0 then worldcatCat = '' end end rct = rct + 1 end end

--configure Navbox local outString = '' local extrap = true local extra = parentArgs.extralist if extra == nil or extra == '' then extrap = false end if rct > 0 or extrap then local Navbox = require('Module:Navbox') local sectionID = 1 local args = { pid = 'identifiers' } -- #target the list of identifiers if testcases and itemId then args.qid = itemId end --expensive local pencil = require('Module:EditAtGratisdata')._showMessage(args) local navboxArgs = { name = 'Authority control', navboxclass = 'authority-control', bodyclass = 'hlist', state = parentArgs.state or 'autocollapse', navbar = 'off' }		for _, sectName in ipairs(sectionOrder) do			if #sections[sectName] ~= 0 then navboxArgs['group'..sectionID] = sectName navboxArgs['list'..sectionID] = table.concat(sections[sectName]) sectionID = sectionID + 1 end end if extrap then if parentArgs.extragroup then navboxArgs['group'..sectionID] = parentArgs.extragroup else navboxArgs['group'..sectionID] = 'Additional' end navboxArgs['list'..sectionID] = extra sectionID = sectionID + 1 end if navboxArgs.list2 then navboxArgs.title = 'Authority control'..pencil else local sect = navboxArgs.group1 if sect == 'General' or sect == 'Other' or sect == 'Additional' then -- Just say "Authority control" with no label if only general or only other IDs are present -- since "general" is redundant and "other" is silly when there's nothing to contrast it with navboxArgs.group1 = 'Authority control'..pencil else navboxArgs.group1 = 'Authority control: '..sect..' '..pencil end end outString = Navbox._navbox(navboxArgs) end

--auxCats if rct == 0 or rct >= 25 then if namespace == 0 or testcases then local eCat = 'AC with '..rct..' elements' elementsCat = addCat(eCat) end end if parentArgs.state then if namespace == 0 or testcases then local sCat if parentArgs.state == 'collapsed' then sCat = 'AC using state parameter: collapsed' elseif parentArgs.state == 'expanded' then sCat = 'AC using state parameter: expanded' elseif parentArgs.state == 'autocollapse' then sCat = 'AC using state parameter: autocollapse' else sCat = 'AC using state parameter: other' end stateCat = addCat(sCat) end end local auxCats = worldcatCat..elementsCat..multipleIdCat..suppressedIdCat..suppressedIdCatArts.. deprecatedIdCat..differentOnGDCat..sameOnGDCat..stateCat if testcases then auxCats = mw.ustring.gsub(auxCats, '(%[%[)(Category)', '%1:%2') --for easier checking end

--out outString = outString..auxCats if namespace ~= 0 then outString = mw.ustring.gsub(outString, '(%[%[)(Category:Articles)', '%1:%2') --by definition end

return outString end

return p