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 --==========================================================================

function p.getCatForId( id ) local catName = '' if namespace == 0 then catName = 'FAMEPedia articles with '..id..' identifiers' elseif namespace == 2 and not title.isSubpage then catName = 'User pages with '..id..' identifiers' else catName = 'Miscellaneous pages with '..id..' identifiers' end return ''..p.redCatLink(catName) end

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

function p.createRow( id, rawValues, link, links, withUid, specialCat, prefix) local catName = 'FAMEPedia 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. '..p.redCatLink(catName) 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. '..p.redCatLink(catName)..'\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-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?$' ) then return false end return ..(label or 'Australia')....p.getCatForId( 'ADB' ) 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.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.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 local id2 = 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.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.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 'Integrated Authority File (Germany)')....p.getCatForId( 'GND' ) 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: IT\\ICCU\\(\d{10}|\D\D[\D\d]\D\\\d{6}) (e.g. IT\ICCU\CFIV\000163) if not id:match( '^IT\\ICCU\\%d%d%d%d%d%d%d%d%d%d$' ) and not id:match( '^IT\\ICCU\\%u%u[%u%d]%u\\%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.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.leonoreLink( id, label ) --P251'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( '^19800035/%d%d?%d?%d?/%d%d?%d?%d?%d?Bis$' ) and --IDs from ? not id:match( '^19800035/%d%d?%d?%d?/%d%d?%d?%d?%d?Ter$' ) and --IDs from ? not id:match( '^C/0/%d%d?$' ) then                            --IDs from        C/0/1 to             C/0/84 (84 famous legionaries) return false end return ..(label or 'Léonore (France)')....p.getCatForId( 'Léonore' ) --no https as of 9/2019 end

function p.maLink( id, label ) --P377's format regex: [1-9]\d{3,9} (e.g. 1498221862) if not id:match( '^[1-9]%d%d%d%d?%d?%d?%d?%d?%d?$' ) then return false end return ..(label or 'Microsoft Academic')....p.getCatForId( 'MA' ) 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.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.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.nliLink( id, label ) --P269'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 'Israel')....p.getCatForId( 'NLI' ) 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.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.s2authoridLink( id, label ) --P273's format regex: [1-9]\d* (e.g. 1796130) if not id:match( '^[1-9]%d*$' ) then return false end return ..(label or 'Semantic Scholar')....p.getCatForId( 'Semantic Scholar author' ) --special cat name 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: [a-z/-]+] (e.g. barkan-omer-lutfi) if not id:match( '^[a-z/-]+$' ) then return false end return ..(label or 'Encyclopedia of Islam')....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,59} (e.g. Abcd) local class = "[%a%d_',%.%-%(%)%*/–]" local regex = '^%u'..string.rep(class, 3)..string.rep(class..'?', 56)..'$' 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.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

--=========================== 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

--========================================================================== --                   FAMEData & documentation functions --==========================================================================

function p.getIdsFromFAMEData( 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 return ids 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 = '{| class="wikitable sortable"\n'.. '! rowspan=2 | Parameter\n'.. '! rowspan=2 | Section\n'.. '! rowspan=2 | Appears as\n'.. '! rowspan=2; data-sort-type=number | FAMEData property\n'.. '! colspan=4 | Tracking categories and page counts\n'.. '|-\n'.. '! '..      'Articles\n'.. '! '..              'User pages\n'.. '! '..     'Misc. pages\n'.. '! '..'Faulty IDs\n'.. '|-\n' local lang = mw.getContentLanguage for _, conf in pairs( p.conf ) do		local param, pid, section = conf[1], conf[2], conf[4] local appearsAs if param == 'WORLDCATID' then -- WorldCat is special appearsAs = 'WorldCat' elseif conf.prefix then appearsAs = conf.prefix else appearsAs = conf[3](conf[5]) end local link = conf.link or param..' (identifier)' local category = conf.category or param local args = { id = 'f', pid } local wpl = frame:expandTemplate{ title = 'FAMEData property link', args = args } --cats local articleCat = 'FAMEPedia articles with '..category..' identifiers' local userCat =   'User pages with '..category..' identifiers' local miscCat =   'Miscellaneous pages with '..category..' identifiers' local faultyCat = 'FAMEPedia articles with faulty '..category..' identifiers' --counts local articleCount = lang:formatNum( mw.site.stats.pagesInCategory(articleCat, 'pages') ) local userCount =   lang:formatNum( mw.site.stats.pagesInCategory(userCat, 'pages') ) local miscCount =   lang:formatNum( mw.site.stats.pagesInCategory(miscCat, 'pages') ) local faultyCount = lang:formatNum( mw.site.stats.pagesInCategory(faultyCat, 'pages') )

--concat wikiTable = wikiTable..'\n'.. '|-\n'.. '||'..param..''.. '||'..section.. '||'..appearsAs.. '||data-sort-value='..pid..'|'..wpl.. '||style="text-align: right;"|'..articleCount..''.. '||style="text-align: right;"|'..  userCount..''.. '||style="text-align: right;"|'..  miscCount..''.. '||style="text-align: right;"|'.. faultyCount..'' end --append derivative WorldCat cats local wcd = { 'WorldCat-LCCN', 'WorldCat-VIAF' } for _, w in pairs(wcd) do		local articleCat = 'FAMEPedia articles with '..w..' identifiers' local articleCount = lang:formatNum( mw.site.stats.pagesInCategory(articleCat, 'pages') ) local appearsAs if w == 'WorldCat-LCCN' then appearsAs = 'WorldCat (via Library of Congress)' else appearsAs = 'WorldCat (via VIAF)' end wikiTable = wikiTable..'\n'.. '|-\n'.. '||'..'—'..					'||General'.. '||'..appearsAs.. '||data-sort-value='..w..'|'..'—'.. '||style="text-align: right;"|'..articleCount..''.. '||style="text-align: right;"|—'.. '||style="text-align: right;"|—'.. '||style="text-align: right;"|—' end return require('Module:Suppress categories').main(wikiTable)..'\n|}' 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 FAMEData, 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' }, { 'AGSA', 216, p.agsaLink, 'Art galleries and museums', '3625' }, { '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' }, { 'Botanist', 228, p.botanistLink, 'Scientific databases', 'L.' }, { 'BPN', 229, p.bpnLink, 'Biographical dictionaries', '12345678' }, { 'CANTIC', 230, p.canticLink, 'National libraries', 'a12345678' }, { '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' }, { '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, 'General', '4079154-3' }, { 'HDS', 242, p.hdsLink, 'Other', '050123' }, { 'IAAF', 243, p.iaafLink, 'Other', '123' }, { 'ICCU', 306, p.iccuLink, 'National libraries', 'IT\\ICCU\\CFIV\\000163' }, --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' }, { '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' }, { 'Léonore', 251, p.leonoreLink, 'Other', 'LH//1/1', prefix = 'Léonore (France)' }, { 'MA', 377, p.maLink, 'Other', '123456789' }, { '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' }, { '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' }, { 'NLI', 269, p.nliLink, 'National libraries', '123456789' }, { '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' }, { '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)' }, { 'S2AuthorId', 273, p.s2authoridLink, 'Scientific databases', '1796130', category = 'Semantic Scholar author' }, --special cat name { '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' }, { '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, nil, 'General', nil, link = 'WorldCat Identities (identifier)' }, }

-- Legitimate aliases to p.conf, for convenience -- Format: { 'alias', 'parameter name in p.conf' } p.aliases = { { 'DNB', 'GND' }, --Deutsche Nationalbibliothek -> Gemeinsame Normdatei { 'Leonore', 'Léonore' }, --alias name without diacritics { 'leonore', 'Léonore' }, --lowercase variant without diacritics { '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 --FD IDs added here later local iParentArgs = 0 --count original/manual parent args only later local worldcatCat = '' local multipleIdCat = '' local suppressedIdCat = '' local deprecatedIdCat = '' local differentOnFDCat = '' local sameOnFDCat = '' --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 else itemId = mw.wikibase.getEntityIdForCurrentPage end --FAMEData fallback if requested if itemId then 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 famedataIds = p.getIdsFromFAMEData( itemId, 'P'..params[2] ) if famedataIds[1] then if val == '' and (namespace == 0 or testcases) then suppressedIdCat = '' else parentArgs[params[1]] = famedataIds[1] --add ID from FD						end end else iParentArgs = iParentArgs + 1 local famedataIds = p.getIdsFromFAMEData( itemId, 'P'..params[2] ) if famedataIds[1] and differentOnFDCat == '' then local bMatch = false for _, fd in pairs( famedataIds ) do							if val == fd then iMatches = iMatches + 1 bMatch = true end end if bMatch == false then differentOnFDCat = '' end	end	end	end	end if iMatches > 0 and iMatches == iParentArgs then sameOnFDCat = '' end end --Configured rows local rct = 0 local sectionOrder = {'General','National libraries','Art galleries and museums', 'Art research institutes','Biographical dictionaries','Scientific databases', 'Other'} local sections = { ['General'] = {}, ['National libraries'] = {}, ['Art galleries and museums'] = {}, ['Art research institutes'] = {}, ['Biographical dictionaries'] = {}, ['Scientific databases'] = {}, ['Other'] = {} }	-- Don't show NLP is 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 FD, if present if itemId and tval[1] then local nextIdVal = 2 local famedataIds = p.getIdsFromFAMEData( itemId, 'P'..params[2] ) for _, v in pairs( famedataIds ) 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 local worldcatId = parentArgs['worldcatid'] or parentArgs['WORLDCATID'] if worldcatId and worldcatId ~= '' then --if WORLDCATID present & unsuppressed table.insert( sections['General'], p.createRow( 'WORLDCATID', worldcatId, ''PATH')..' WorldCat', nil, false ) ) --Validation? worldcatCat = p.getCatForId( 'WORLDCATID' ) rct = rct + 1 elseif 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 elseif worldcatId == '' then --if WORLDCATID suppressed suppressedIdCat = '' end local Navbox = require('Module:Navbox') local elementsCat = '' if rct == 0 or rct >= 25 then local eCat = 'AC with '..rct..' elements' elementsCat = ''..p.redCatLink(eCat) end local outString = '' if rct > 0 then local sectionID = 1 local args = { pid = 'identifiers' } -- #target the list of identifiers if testcases and itemId then args = { pid = 'identifiers', qid = itemId } end --expensive local pencil = frame:expandTemplate{ title = 'EditAtFAMEData', args = 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 navboxArgs.group2 then navboxArgs.title = 'Authority control'..pencil else local sect = navboxArgs.group1 if sect == 'General' or sect == 'Other' 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 local auxCats = worldcatCat..elementsCat..multipleIdCat..suppressedIdCat.. deprecatedIdCat..differentOnFDCat..sameOnFDCat if testcases then auxCats = mw.ustring.gsub(auxCats, '(%[%[)(Category)', '%1:%2') --for easier checking end outString = outString..auxCats if namespace ~= 0 then outString = mw.ustring.gsub(outString, '(%[%[)(Category:FAMEPedia articles)', '%1:%2') --by definition end return outString end

return p