Module:Authority control: Difference between revisions

From The Goon Show Depository

m (1 revision imported)
en>MSGJ
(drop support for deprecated parameters, allow qid on any unconnected page, remove an unrequired tracking category, make id suppression work better)
Line 25: Line 25:
end
end


local function getIdsFromWikidata(itemId,property)
local function getIdsFromWikidata(qid,property)
local ids = {}
local ids = {}
if not mw.wikibase or not itemId then
if not mw.wikibase or not qid then
return ids
return ids
end
end
local statements = mw.wikibase.getBestStatements( itemId, property )
local statements = mw.wikibase.getBestStatements(qid,property)
if statements then
if statements then
for _, statement in ipairs( statements ) do
for _, statement in ipairs( statements ) do
Line 86: Line 86:
--[[                                  Main                                  ]]
--[[                                  Main                                  ]]
--[[==========================================================================]]
--[[==========================================================================]]
function p.authorityControl(frame)
function p.authorityControl(frame)
local config = require("Module:Authority control/config")
local config = require("Module:Authority control/config")
local conf = config.config
local conf = config.config
local sectionOrder = config.sectionOrder
local sectionNames = config.sectionNames
local aliases = config.aliases
local deprecated = config.deprecated
local resolveEntity = require( 'Module:ResolveEntityId' )
local resolveEntity = require( 'Module:ResolveEntityId' )
local parentArgs = frame:getParent().args --WD IDs added here later
local parentArgs = frame:getParent().args --WD IDs added here later
local iParentArgs = 0 --count original/manual parent args only later
local iParentArgs = 0 --count original/manual parent args only later
local suppressedIdCount = 0
local iMatches,suppressedIdCount = 0,0
local iMatches = 0
local auxCats = ''
local auxCats = ''
local rct = 0
local rct = 0 -- total number of links returned
local sections = {{},{},{},{},{},{},{},{}}
local numqids = 4 -- support for 4 additional qids
 
local totsect = #sectionNames + numqids
--redirect aliases to proper parameter names
local sections = {}
for _, a in pairs(aliases) do
for _ = 1,totsect do table.insert(sections,{}) end
local alias, param = a[1], a[2]
if (parentArgs[param] == nil or parentArgs[param] == '') and parentArgs[alias] then
-- check for suppressed identifiers
parentArgs[param] = parentArgs[alias]
local suppress = {}
end
if parentArgs.suppress then
end
local suppresslist = mw.text.split(parentArgs.suppress,"%s*,%s*") -- split parameter by comma
 
for _,v in ipairs(suppresslist) do
--redirect deprecated parameters to proper parameter names, and assign tracking cat
if v:match("^%d+$") then
for _, d in pairs( deprecated ) do
v = "P"..tostring(v)
local dep, param = d[1], d[2]
else
if (parentArgs[param] == nil or parentArgs[param] == '') and parentArgs[dep] then
v = string.upper(v)
parentArgs[param] = parentArgs[dep]
if namespace == 0 then
auxCats = auxCats .. '[[Category:Articles with deprecated authority control identifiers|'..dep..']]'
end
end
suppress[v] = true -- index table by identifier name
end
end
end
end
 
--use QID= parameter for testing/example purposes only
local function makeSections(qid,additional)
local itemId
local tval = {}
local function resolveQID(qid)
local function parameter_is_used(property)
if qid then
local used = false
itemId = 'Q'..mw.ustring.gsub(qid, '^[Qq]', '')
if property then
itemId = resolveEntity._id(itemId) --nil if unresolvable
if tval[property] then
end
if tval[property][1] then
return qid
used = true
end
end
if namespace ~= 0 then
elseif tval[property] == false then -- property has been manually suppressed
local qid = parentArgs['qid'] or parentArgs['QID']
qid = resolveQID(qid)
elseif mw.wikibase then
itemId = mw.wikibase.getEntityIdForCurrentPage()
end
local tval = {}
local function parameter_is_used(property)
local used = false
if property then
if tval[property] then
if tval[property][1] then
used = true
used = true
end
end
end
end
return used
end
end
return used
for _, params in ipairs(conf) do
end
tval[params.property] = getIdsFromWikidata(qid, 'P' .. params.property) -- setup table for values with property number as key
for _, params in ipairs(conf) do
if additional then
tval[params.property] = getIdsFromWikidata(itemId, 'P' .. params.property) -- setup table for values with property number as key
if suppress["P"..tostring(params.property)] or suppress[string.upper(params[1])] then
local val = parentArgs[mw.ustring.lower(params[1])] or parentArgs[params[1]]
tval[params.property] = false -- indicates the identifier is suppressed
if val == '' then
if tval[params.property][1] and (namespace == 0 or testcases) then
suppressedIdCount = suppressedIdCount + 1
if parentArgs['arts'] ~= 'arts' then
auxCats = auxCats .. '[[Category:Articles with suppressed authority control identifiers|'..params[1]..']]'
end
end
end
tval[params.property] = false -- indicates the identifier is suppressed
elseif val then -- add local parameter to wikidata
iParentArgs = iParentArgs + 1
local bnew = true
for _, w in pairs(tval[params.property]) do
if val == w then
bnew = false
end
end
if bnew then -- add new value to table
if tval[params.property][1] then
auxCats = auxCats .. '[[Category:Pages using authority control with parameters different on Wikidata|'..params[1]..']]'
end
table.insert(tval[params.property],val)
else
else
iMatches = iMatches+1
local val = parentArgs[mw.ustring.lower(params[1])] or parentArgs[params[1]]
end
if suppress["P"..tostring(params.property)] or suppress[string.upper(params[1])] or val == '' then
end
if tval[params.property][1] and (namespace == 0 or testcases) then
local suppress=false
suppressedIdCount = suppressedIdCount + 1
if params.suppressedbyproperty then
if parentArgs['arts'] ~= 'arts' then
for _,sc in ipairs(params.suppressedbyproperty) do
auxCats = auxCats .. '[[Category:Articles with suppressed authority control identifiers|'..params[1]..']]'
if parameter_is_used(sc) then
end
suppress = true
end
tval[params.property] = false -- indicates the identifier is suppressed
elseif val then -- add local parameter to wikidata
iParentArgs = iParentArgs + 1
local bnew = true
for _, w in pairs(tval[params.property]) do
if val == w then
bnew = false
end
end
if bnew then -- add new value to table
if tval[params.property][1] then
auxCats = auxCats .. '[[Category:Pages using authority control with parameters different on Wikidata|'..params[1]..']]'
end
table.insert(tval[params.property],val)
else
iMatches = iMatches+1
end
end
end
end
end
end
local suppress = false
if not tval[params.property] == false and not suppress then
if params.suppressedbyproperty then
local tlinks = {} -- setup table for links
for _,sc in ipairs(params.suppressedbyproperty) do
local nextIdVal = 1
if parameter_is_used(sc) then
for _,val in ipairs(tval[params.property]) do
suppress = true
local link = makelink(params,val,nextIdVal)
end
local cat = params.category or params[1]
if link then -- add category unless link==false
link = link .. getCatForId(cat)
end
end
table.insert(tlinks,link)
nextIdVal = nextIdVal + 1
end
end
if tval[params.property][1] then -- assemble
if not tval[params.property] == false and not suppress then
local row = ''
local tlinks = {} -- setup table for links
if params.prefix then
local nextIdVal = 1
row = row..'*'..params.prefix
for _,val in ipairs(tval[params.property]) do
local link = makelink(params,val,nextIdVal)
local cat = params.category or params[1]
if link then -- add category unless link==false
link = link .. getCatForId(cat)
end
table.insert(tlinks,link)
nextIdVal = nextIdVal + 1
end
end
for i, l in ipairs(tlinks) do
if tval[params.property][1] then -- assemble
if i==1 and not params.prefix then
local row = ''
row = row..'*'
if params.prefix then
else
row = row..'*'..params.prefix
row = row..'\n**'
end
for i, l in ipairs(tlinks) do
if i==1 and not params.prefix then
row = row..'*'
else
row = row..'\n**'
end
row = row .. l
end
end
row = row .. l
row = row..'\n'
end
local sec = additional or params.section -- uses section 9 for qid2, section 10 for qid3, etc.
row = row..'\n'
table.insert(sections[sec],row)
table.insert(sections[params.section],row)
rct = rct + 1
rct = rct + 1
if tval[params.property][2] then
auxCats = auxCats .. getCatForId('multiple')
end
end
end
end
end
end
end
local function pencil(qid)
if not qid then
return ''
end
local args = { pid = 'identifiers' } -- #target the list of identifiers
args.qid = qid
return require('Module:EditAtWikidata')._showMessage(args)
end
local function resolveQID(qid)
if qid then
qid = 'Q'..mw.ustring.gsub(qid, '^[Qq]', '')
qid = resolveEntity._id(qid) --nil if unresolvable
end
return qid
end
local qids = {}
qids[1] = mw.wikibase.getEntityIdForCurrentPage()
if not qids[1] then
qids[1] = resolveQID(parentArgs['qid']) --use qid parameter if no wikidata item is connected
end
makeSections(qids[1],false)
for c = 2,5 do
qids[c] = resolveQID(parentArgs['qid' .. c])
if qids[c] then makeSections(qids[c],totsect-numqids+c-1) end
end
end
if iMatches > 0 and iMatches == iParentArgs then
if iMatches > 0 and iMatches == iParentArgs then
Line 231: Line 244:
--configure Navbox
--configure Navbox
local outString = ''
local outString = ''
local extrap = true
if rct > 0 then -- there is at least one link to display
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 Navbox = require('Module:Navbox')
local sectionID = 1
local sect,lastsect = 0,0
local args = { pid = 'identifiers' } -- #target the list of identifiers
if testcases and itemId then args.qid = itemId end --expensive
local pencil = require('Module:EditAtWikidata')._showMessage(args)
local navboxArgs = {
local navboxArgs = {
name  = 'Authority control',
name  = 'Authority control',
Line 249: Line 254:
navbar = 'off'
navbar = 'off'
}
}
for c, sectName in ipairs(sectionOrder) do
for c=1,totsect do
if #sections[c] ~= 0 then
if #sections[c] ~= 0 then -- section is non-empty
navboxArgs['group'..sectionID] = sectName
sect = sect + 1
navboxArgs['list'..sectionID] = table.concat(sections[c])
lastsect = c
sectionID = sectionID + 1
local sectname
end
if c <= totsect - numqids then -- regular section
end
sectname = sectionNames[c]
if extrap then
else -- section from additional qid
if parentArgs.extragroup then
sectname = mw.wikibase.getLabel(qids[c-totsect+numqids+1]) .. pencil(qids[c-totsect+numqids +1])
navboxArgs['group'..sectionID] = parentArgs.extragroup
end
else
navboxArgs['group' .. c] = sectname
navboxArgs['group'..sectionID] = 'Additional'
navboxArgs['list' .. c] = table.concat(sections[c])
end
end
navboxArgs['list'..sectionID] = extra
sectionID = sectionID + 1
end
end
if navboxArgs.list2 then
local aclink = '[[Help:Authority control|Authority control]]'
navboxArgs.title = '[[Help:Authority control|Authority control]]'..pencil
if sect == 1 then -- special display when only one section
else
if lastsect == 1 or lastsect == 8 then -- no special label when only general or other IDs are present
local sect = navboxArgs.group1
navboxArgs['group' .. lastsect] = aclink .. pencil(qids[1])
if sect == 'General' or sect == 'Other' or sect == 'Additional' then
elseif lastsect <= totsect - numqids  then -- other regular section
-- Just say "Authority control" with no label if only general or only other IDs are present
navboxArgs['group' .. lastsect] = aclink .. ': ' .. sectionNames[lastsect] .. pencil(qids[1])
-- since "general" is redundant and "other" is silly when there's nothing to contrast it with
else -- section from additional qid
navboxArgs.group1 = '[[Help:Authority control|Authority control]]'..pencil
navboxArgs['group' .. lastsect] = aclink .. ': ' .. navboxArgs['group' .. lastsect]
else
navboxArgs.group1 = '[[Help:Authority control|Authority control: '..sect..']] '..pencil
end
end
else -- add title to navbox
navboxArgs.title = aclink .. pencil(qids[1])
end
end
outString = Navbox._navbox(navboxArgs)
outString = Navbox._navbox(navboxArgs)
Line 313: Line 316:
function p.docConfTable(frame)
function p.docConfTable(frame)
local wikiTable = '<table class="wikitable sortable">'..
local wikiTable = '<table class="wikitable sortable">'..
  '<tr><th rowspan=2>Parameter</th>'..
  '<tr><th rowspan=2>Identifier</th>'..
  '<th rowspan=2>Remark</th>'..
  '<th rowspan=2>Section</th>'..
  '<th rowspan=2>Section</th>'..
  '<th rowspan=2>Appears as</th>'..
  '<th rowspan=2>Appears as</th>'..
Line 324: Line 328:
local config = require("Module:Authority control/config")
local config = require("Module:Authority control/config")
local conf = config.config
local conf = config.config
local sectionOrder = config.sectionOrder
local sectionNames = config.sectionNames
local function checkcat(category,label)
local function checkcat(category,label)
local ret='[[:Category:'..category..'|'..label..']]'
local ret='[[:Category:'..category..'|'..label..']]'
Line 333: Line 337:
end
end
for _, conf in pairs(conf) do
for _, conf in pairs(conf) do
local param, pid, section = conf[1], conf.property, sectionOrder[conf.section]
local category = conf.category or conf[1]
local appearsAs = makelink(conf,conf.example,1)
local wpl = frame:expandTemplate{ title = 'Wikidata property link', args = { id = 'f', conf.property } }
local link = conf.idlink or param..' (identifier)'
local category = conf.category or param
local args = { id = 'f', pid }
local wpl = frame:expandTemplate{ title = 'Wikidata property link', args = args }
local articleCat = 'Articles with '..category..' identifiers'
local articleCat = 'Articles with '..category..' identifiers'
local faultyCat =  'Articles with faulty '.. (conf.errorcat or category) ..' identifiers'
local faultyCat =  'Articles with faulty '.. (conf.errorcat or category) ..' identifiers'
Line 346: Line 346:
a = a + lang:parseFormattedNumber(articleCount)
a = a + lang:parseFormattedNumber(articleCount)
f = f + lang:parseFormattedNumber(faultyCount)
f = f + lang:parseFormattedNumber(faultyCount)
wikiTable = wikiTable..'<tr><td>[['..link..'|'..param..']]</td>'..
wikiTable = wikiTable..'<tr><td>[['..(conf.idlink or conf[1]..' (identifier)')..'|'..conf[1]..']]</td>'..
'<td>'..section..'</td>'..
'<td>'..(conf.remark or '')..'</td>'..
'<td>'..appearsAs..'</td>'..
'<td>'..sectionNames[conf.section]..'</td>'..
'<td data-sort-value='..pid..'>'..wpl..'</td>'..
'<td>'..makelink(conf,conf.example,1)..'</td>'..
'<td data-sort-value='..conf.property..'>'..wpl..'</td>'..
'<td style="text-align: right;">'..checkcat(articleCat,articleCount)..'</td>'..
'<td style="text-align: right;">'..checkcat(articleCat,articleCount)..'</td>'..
'<td style="text-align: right;">'..checkcat(faultyCat,faultyCount)..'</td></tr>'
'<td style="text-align: right;">'..checkcat(faultyCat,faultyCount)..'</td></tr>'
end
end
wikiTable = wikiTable..'<tr><th style="text-align: right;" colspan=3>Totals</th>'..
wikiTable = wikiTable..'<tr><th style="text-align: right;" colspan=4>Totals</th>'..
'<th style="text-align: right;">'..lang:formatNum(P)..'</th>'..
'<th style="text-align: right;">'..lang:formatNum(P)..'</th>'..
'<th style="text-align: right;">'..lang:formatNum(a)..'</th>'..
'<th style="text-align: right;">'..lang:formatNum(a)..'</th>'..

Revision as of 10:39, 20 December 2022

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

local function addCat(cat)
	if cat and cat ~= '' then
		local redlinkcat = ''
		if testcases == false and mw.title.new(cat, 14).exists == false then
			redlinkcat = '[[Category:Pages with red-linked authority control categories]]'
		end
		return '[[Category:'..cat..']]'..redlinkcat
	else
		return ''
	end
end

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

local function getIdsFromWikidata(qid,property)
	local ids = {}
	if not mw.wikibase or not qid then
		return ids
	end
	local statements = mw.wikibase.getBestStatements(qid,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

local function makelink(conf,val,nextid) --validate values and create a link
	local link
	if conf.link2 then -- use function to validate and generate link
		link = conf.link2(val)
	else
		local valid_value
		if conf.pattern then -- use pattern to determine validity if defined
			valid_value = val:match(conf.pattern)
		elseif conf.patterns then
			for i = 1,#conf.patterns do
				valid_value = val:match(conf.patterns[i])
				if valid_value then break end
			end
		elseif conf.valid then -- otherwise use function to determine validity
			valid_value = conf.valid(val)
		else -- no validation possible
			valid_value = val
		end
		if valid_value then
			local label = conf.label
			if not label or nextid>1 then
				label = tostring(nextid)
			end
			if conf.link then
				valid_value = valid_value:gsub('%%', '%%%%')
				link = '[' .. mw.ustring.gsub(conf.link,'%$1',valid_value) .. ' ' .. label .. ']'
			else
				link = valid_value
			end
		else
			link = false
		end
	end
	if link then
		link = '<span class="uid">'..link..'</span>'
	else
		local faultyCat = 'Articles with faulty '..(conf.errorcat or conf.category or conf[1])..' identifiers'
		link = '<span class="error">The '..conf[1]..' id '..val..' is not valid.</span>'..addCat(faultyCat)
	end
	return link
end

--[[==========================================================================]]
--[[                                   Main                                   ]]
--[[==========================================================================]]
function p.authorityControl(frame)
	local config = require("Module:Authority control/config")
	local conf = config.config
	local sectionNames = config.sectionNames
	local resolveEntity = require( 'Module:ResolveEntityId' )
	local parentArgs = frame:getParent().args --WD IDs added here later
	local iParentArgs = 0 --count original/manual parent args only later
	local iMatches,suppressedIdCount = 0,0
	local auxCats = ''
	local rct = 0 -- total number of links returned
	local numqids = 4 -- support for 4 additional qids
	local totsect = #sectionNames + numqids
	local sections = {}
	for _ = 1,totsect do table.insert(sections,{}) end
	
	-- check for suppressed identifiers
	local suppress = {}
	if parentArgs.suppress then
		local suppresslist = mw.text.split(parentArgs.suppress,"%s*,%s*") -- split parameter by comma
		for _,v in ipairs(suppresslist) do
			if v:match("^%d+$") then
				v = "P"..tostring(v)
			else
				v = string.upper(v)
			end
			suppress[v] = true -- index table by identifier name
		end
	end
	
	local function makeSections(qid,additional)
		local tval = {}
		local function parameter_is_used(property)
			local used = false
			if property then
				if tval[property] then
					if tval[property][1] then
						used = true
					end
				elseif tval[property] == false then -- property has been manually suppressed
					used = true
				end
			end
			return used
		end
		for _, params in ipairs(conf) do
			tval[params.property] = getIdsFromWikidata(qid, 'P' .. params.property) -- setup table for values with property number as key
			if additional then
				if suppress["P"..tostring(params.property)] or suppress[string.upper(params[1])] then
					tval[params.property] = false -- indicates the identifier is suppressed
				end
			else
				local val = parentArgs[mw.ustring.lower(params[1])] or parentArgs[params[1]]
				if suppress["P"..tostring(params.property)] or suppress[string.upper(params[1])] or val == '' then
					if tval[params.property][1] and (namespace == 0 or testcases) then
						suppressedIdCount = suppressedIdCount + 1
						if parentArgs['arts'] ~= 'arts' then
							auxCats = auxCats .. '[[Category:Articles with suppressed authority control identifiers|'..params[1]..']]'
						end
					end
					tval[params.property] = false -- indicates the identifier is suppressed
				elseif val then -- add local parameter to wikidata 
					iParentArgs = iParentArgs + 1
					local bnew = true
					for _, w in pairs(tval[params.property]) do
						if val == w then
							bnew = false
						end
					end
					if bnew then -- add new value to table
						if tval[params.property][1] then
							auxCats = auxCats .. '[[Category:Pages using authority control with parameters different on Wikidata|'..params[1]..']]'
						end
						table.insert(tval[params.property],val)
					else
						iMatches = iMatches+1
					end
				end
			end
			local suppress = false
			if params.suppressedbyproperty then
				for _,sc in ipairs(params.suppressedbyproperty) do
					if parameter_is_used(sc) then
						suppress = true
					end
				end
			end
			if not tval[params.property] == false and not suppress then
				local tlinks = {} -- setup table for links
				local nextIdVal = 1
				for _,val in ipairs(tval[params.property]) do
					local link = makelink(params,val,nextIdVal)
					local cat = params.category or params[1]
					if link then -- add category unless link==false
						link = link .. getCatForId(cat)
					end
					table.insert(tlinks,link)
					nextIdVal = nextIdVal + 1
				end
				if tval[params.property][1] then -- assemble
					local row = ''
					if params.prefix then
						row = row..'*'..params.prefix
					end
					for i, l in ipairs(tlinks) do
						if i==1 and not params.prefix then
							row = row..'*'
						else
							row = row..'\n**'
						end
						row = row .. l
					end
					row = row..'\n'
					local sec = additional or params.section -- uses section 9 for qid2, section 10 for qid3, etc.
					table.insert(sections[sec],row)
					rct = rct + 1
				end
			end
		end
	end
	local function pencil(qid)
		if not qid then
			return ''
		end
		local args = { pid = 'identifiers' } -- #target the list of identifiers
		args.qid = qid
		return require('Module:EditAtWikidata')._showMessage(args)
	end

	local function resolveQID(qid)
		if qid then
			qid = 'Q'..mw.ustring.gsub(qid, '^[Qq]', '')
			qid = resolveEntity._id(qid) --nil if unresolvable
		end
		return qid
	end
	local qids = {}
	qids[1] = mw.wikibase.getEntityIdForCurrentPage()
	if not qids[1] then
		qids[1] = resolveQID(parentArgs['qid']) --use qid parameter if no wikidata item is connected
	end
	makeSections(qids[1],false)
	for c = 2,5 do
		qids[c] = resolveQID(parentArgs['qid' .. c])
		if qids[c] then makeSections(qids[c],totsect-numqids+c-1) end
	end
	if iMatches > 0 and iMatches == iParentArgs then
		auxCats = auxCats .. '[[Category:Pages using authority control with parameters all matching Wikidata]]'
	end
	if parentArgs['arts'] == 'arts' and suppressedIdCount > 0 then
		if namespace == 0 or testcases then
			local s = 's'
			if suppressedIdCount == 1 then s = '' end
			auxCats = auxCats .. addCat('ACArt with '..suppressedIdCount..' suppressed element'..s)
		end
	end

	--configure Navbox
	local outString = ''
	if rct > 0 then -- there is at least one link to display
		local Navbox = require('Module:Navbox')
		local sect,lastsect = 0,0
		local navboxArgs = {
			name  = 'Authority control',
			navboxclass = 'authority-control',
			bodyclass = 'hlist',
			state = parentArgs.state or 'autocollapse',
			navbar = 'off'
		}
		for c=1,totsect do
			if #sections[c] ~= 0 then -- section is non-empty
				sect = sect + 1
				lastsect = c
				local sectname
				if c <= totsect - numqids then -- regular section
					sectname = sectionNames[c]
				else -- section from additional qid
					sectname = mw.wikibase.getLabel(qids[c-totsect+numqids+1]) .. pencil(qids[c-totsect+numqids +1])
				end
				navboxArgs['group' .. c] = sectname
				navboxArgs['list' .. c] = table.concat(sections[c])
			end
		end
		local aclink = '[[Help:Authority control|Authority control]]'
		if sect == 1 then -- special display when only one section
			if lastsect == 1 or lastsect == 8 then -- no special label when only general or other IDs are present
				navboxArgs['group' .. lastsect] = aclink .. pencil(qids[1])
			elseif lastsect <= totsect - numqids  then -- other regular section
				navboxArgs['group' .. lastsect] = aclink .. ': ' .. sectionNames[lastsect] .. pencil(qids[1])
			else -- section from additional qid
				navboxArgs['group' .. lastsect] = aclink .. ': ' .. navboxArgs['group' .. lastsect]
			end
		else -- add title to navbox
			navboxArgs.title = aclink .. pencil(qids[1])
		end
		outString = Navbox._navbox(navboxArgs)
	end

	--auxCats
	if rct == 0 or rct >= 25 then
		if namespace == 0 or testcases then
			auxCats = auxCats .. addCat('AC with '..rct..' elements')
		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
			auxCats = auxCats .. addCat(sCat)
		end
	end
	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

-- Creates a human-readable standalone wikitable version of conf, and tracking categories with page counts, for use in the documentation
function p.docConfTable(frame)
	local wikiTable = '<table class="wikitable sortable">'..
	  '<tr><th rowspan=2>Identifier</th>'..
	  '<th rowspan=2>Remark</th>'..
	  '<th rowspan=2>Section</th>'..
	  '<th rowspan=2>Appears as</th>'..
	  '<th rowspan=2 data-sort-type=number>Wikidata property</th>'..
	  '<th colspan=2>Tracking categories and page counts</th></tr>'..
	  '<tr><th>[[:Category:Articles with authority control information|Articles]]</th>'..
	  '<th>[[:Category:Articles with faulty authority control information|Faulty IDs]]</th></tr>'
	local lang = mw.getContentLanguage()
	local a, f, P = 0, 0, 0 --cumulative sums
	local config = require("Module:Authority control/config")
	local conf = config.config
	local sectionNames = config.sectionNames
	local function checkcat(category,label)
		local ret='[[:Category:'..category..'|'..label..']]'
		if mw.title.new(category, 14).exists == false then
			ret = ret..' <span class="plainlinks" style="font-size:85%;">&#91;['..tostring(mw.uri.fullUrl('Category:'..category,'action=edit&preload=Template:Authority_control/preload'))..' create]&#93;</span>'
		end
		return ret
	end
	for _, conf in pairs(conf) do
		local category = conf.category or conf[1]
		local wpl = frame:expandTemplate{ title = 'Wikidata property link', args = { id = 'f', conf.property } }
		local articleCat = 'Articles with '..category..' identifiers'
		local faultyCat =  'Articles with faulty '.. (conf.errorcat or category) ..' identifiers'
		local articleCount = lang:formatNum( mw.site.stats.pagesInCategory(articleCat, 'pages') )
		local faultyCount =  lang:formatNum( mw.site.stats.pagesInCategory(faultyCat, 'pages') )
		P = P + 1 --property count
		a = a + lang:parseFormattedNumber(articleCount)
		f = f + lang:parseFormattedNumber(faultyCount)
		wikiTable = wikiTable..'<tr><td>[['..(conf.idlink or conf[1]..' (identifier)')..'|'..conf[1]..']]</td>'..
			'<td>'..(conf.remark or '')..'</td>'..
			'<td>'..sectionNames[conf.section]..'</td>'..
			'<td>'..makelink(conf,conf.example,1)..'</td>'..
			'<td data-sort-value='..conf.property..'>'..wpl..'</td>'..
			'<td style="text-align: right;">'..checkcat(articleCat,articleCount)..'</td>'..
			'<td style="text-align: right;">'..checkcat(faultyCat,faultyCount)..'</td></tr>'
	end
	wikiTable = wikiTable..'<tr><th style="text-align: right;" colspan=4>Totals</th>'..
		'<th style="text-align: right;">'..lang:formatNum(P)..'</th>'..
		'<th style="text-align: right;">'..lang:formatNum(a)..'</th>'..
		'<th style="text-align: right;">'..lang:formatNum(f)..'</th></tr></table>'
	return require('Module:Suppress categories').main(wikiTable)
end

return p