if link then
if withUid then
return '*<span>'..label..' <span>'..link..'</span></span>\n'
end
return '*<span>'..label..' '..link..'</span>\n'
end  
local catName = 'Wikipedia articles with faulty '..(specialCat or id)..' identifiers'
return '* <span>The '..id..' id '..rawValue..' is not valid.</span>'..p.redCatLink(catName)..'\n'
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
local wikiTable = '{|\n'..
'! rowspan=2 | Parameter\n'..
'! rowspan=2 | Label\n'..
'! rowspan=2; data-sort-type=number | Wikidata 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, link, pid = conf[1], conf[2], conf[3]
local category = conf.category or param
local args = { id = 'f', pid }
local wpl = :expandTemplate{ title = 'Wikidata property link', args = args }
--cats
local articleCat = 'Wikipedia articles with '..category..' identifiers'
local userCat = 'User pages with '..category..' identifiers'
local miscCat = 'Miscellaneous pages with '..category..' identifiers'
local faultyCat = 'Wikipedia 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..
'||'..link..
'||data-sort-value='..pid..'|'..wpl..
'|||'..articleCount..''..
'|||'.. userCount..''..
'|||'.. miscCount..''..
'|||'.. faultyCount..''
end
return wikiTable..'\n|}'
end  
--==========================================================================
-- Configuration
--==========================================================================  
-- If a specific "(identifier) redirect" exists for an identifier, please route through this particular redirect rather than linking directly to the target page. This reduces clutter in "What links here" and improves reverse lookup of articles where a manifestation of this particular identifier is used.  
-- Check that the Wikidata item has this property-->value before adding it
local reqs = {}  
-- Parameter format: { 'parameter name', 'label', propertyId # in Wikidata, formatting/validation function }
p.conf = {
{ 'AAG', 'AAG', 3372, p.aagLink },
{ 'ACM-DL', 'ACM DL', 864, p.acmLink },
{ 'ADB', 'ADB', 1907, p.adbLink },
{ 'AGSA', 'AGSA', 6804, p.agsaLink },
{ 'autores.uy', 'autores.uy', 2558, p.autoresuyLink },
{ 'AWR', 'AWR', 4186, p.awrLink },
{ 'BALaT', 'BALaT', 3293, p.balatLink },
{ 'BIBSYS', 'BIBSYS', 1015, p.bibsysLink },
{ 'Bildindex', 'Bildindex', 2092, p.bildLink },
{ 'BNC', 'BNC', 1890, p.bncLink },
{ 'BNE', 'BNE', 950, p.bneLink },
{ 'BNF', 'BNF', 268, p.bnfLink },
{ 'Botanist', 'Botanist', 428, p.botanistLink },
{ 'BPN', 'BPN', 651, p.bpnLink },
{ 'CANTIC', 'CANTIC', 1273, p.canticLink },
{ 'CINII', 'CiNii', 271, p.ciniiLink },
{ 'DAAO', 'DAAO', 1707, p.daaoLink },
{ 'DBLP', 'DBLP', 2456, p.dblpLink },
{ 'DSI', 'DSI', 2349, p.dsiLink },
{ 'FNZA', 'FNZA', 6792, p.fnzaLink },
{ 'GND', 'GND', 227, p.gndLink },
{ 'HDS', 'HDS', 902, p.hdsLink },
{ 'IAAF', 'World Athletics', 1146, p.iaafLink },
{ 'ICCU', 'ICCU', 396, p.iccuLink }, --formerly SBN
{ 'ICIA', 'ICIA', 1736, p.iciaLink },
{ 'ISNI', 'ISNI', 213, p.isniLink },
{ 'Joconde', 'Joconde' , 347, p.jocondeLink },
{ 'KULTURNAV', 'KulturNav', 1248, p.kulturnavLink },
{ 'LCCN', 'LCCN', 244, p.lccnLink },
{ 'LIR', 'LIR', 886, p.lirLink },
{ 'LNB', 'LNB', 1368, p.lnbLink },
{ 'Léonore', 'Léonore', 640, p.leonoreLink },
{ 'MBA', 'MusicBrainz', 434, p.mbaLink, category = 'MusicBrainz' }, --special category name
{ 'MBAREA', 'MusicBrainz', 982, p.mbareaLink, category = 'MusicBrainz area' }, --special category name
{ 'MBI', 'MusicBrainz', 1330, p.mbiLink, category = 'MusicBrainz instrument' }, --special category name
{ 'MBL', 'MusicBrainz', 966, p.mblLink, category = 'MusicBrainz label' }, --special category name
{ 'MBP', 'MusicBrainz', 1004, p.mbpLink, category = 'MusicBrainz place' }, --special category name
{ 'MBRG', 'MusicBrainz release group', 436, p.mbrgLink, category = 'MusicBrainz release group' }, --special category name
{ 'MBS', 'MusicBrainz', 1407, p.mbsLink, category = 'MusicBrainz series' }, --special category name
{ 'MBW', 'MusicBrainz work', 435, p.mbwLink, category = 'MusicBrainz work' }, --special category name
{ 'MGP', 'MGP', 549, p.mgpLink },
{ 'NARA', 'NARA', 1225, p.naraLink },
{ 'NCL', 'NCL', 1048, p.nclLink },
{ 'NDL', 'NDL', 349, p.ndlLink },
{ 'NGV', 'NGV', 2041, p.ngvLink },
{ 'NKC', 'NKC', 691, p.nkcLink },
{ 'NLA', 'NLA', 409, p.nlaLink },
{ 'NLG', 'NLG', 3348, p.nlgLink },
{ 'NLI', 'NLI', 949, p.nliLink },
{ 'NLK', 'NLK', 5034, p.nlkLink },
{ 'NLP', 'NLP', 1695, p.nlpLink },
{ 'NLR', 'NLR', 1003, p.nlrLink },
{ 'NSK', 'NSK', 1375, p.nskLink },
{ 'NTA', 'NTA', 1006, p.ntaLink },
{ 'ORCID', 'ORCID', 496, p.orcidLink },
{ 'PIC', 'PIC', 2750, p.picLink },
{ 'RID', 'ResearcherID', 1053, p.ridLink },
{ 'RERO', 'RERO', 3065, p.reroLink },
{ 'RKDartists', 'RKD', 650, p.rkdartistsLink },
{ 'RKDID', 'RKDimages ID', 350, p.rkdidLink },
{ 'RSL', 'RSL', 947, p.rslLink },
{ 'SELIBR', 'SELIBR', 906, p.selibrLink },
{ 'SIKART', 'SIKART', 781, p.sikartLink },
{ 'SNAC-ID', 'SNAC', 3430, p.snacLink },
{ 'SUDOC', 'SUDOC', 269, p.sudocLink },
{ 'S2AuthorId', 'S2AuthorId', 4012, p.s2authoridLink, category = 'Semantic Scholar author' }, --special category name
{ 'TA98', 'TA98', 1323, p.ta98Link },
{ 'TDVİA', 'TDVİA', 7314, p.tdviaLink },
{ 'TE', 'TE', 1693, p.teLink },
{ 'TePapa', 'TePapa', 3544, p.tepapaLink },
{ 'TH', 'TH', 1694, p.thLink },
{ 'TLS', 'TLS', 1362, p.tlsLink },
{ 'Trove', 'Trove', 1315, p.troveLink }, --formerly NLA-person
{ 'UKPARL', 'UKPARL', 6213, p.ukparlLink },
{ 'ULAN', 'ULAN', 245, p.ulanLink },
{ 'USCongress', 'US Congress', 1157, p.uscongressLink },
{ 'VcBA', 'VcBA', 8034, p.vcbaLink },
{ 'VIAF', 'VIAF', 214, p.viafLink },
{ 'WORLDCATID', 'WorldCat Identities', 7859, nil },
}  
-- Legitimate aliases to p.conf, for convenience
-- Format: { 'alias', 'parameter name in p.conf' }
p.aliases = {
{ 'MusicBrainz', 'MBA' },
{ 'MusicBrainz artist', 'MBA' },
{ 'MusicBrainz label', 'MBL' },
{ 'MusicBrainz release group', 'MBRG' },
{ 'MusicBrainz work', 'MBW' },
{ 'Leonore', 'Léonore' }, --alias name without diacritics
{ 'leonore', 'Léonore' }, --lowercase variant without diacritics
{ '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
local resolveEntity = require( "Module:ResolveEntityId" )
local parentArgs = :getParent.args
local elements = {} --create/insert rows later
local worldcatCat = ''
local suppressedIdCat = ''
local deprecatedIdCat = ''  
--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