Module:Pages with authority control identifiers

require('Module:No globals') local p = {} local ac_conf = require('Module:Authority control').conf local rmCats = require('Module:Suppress categories').main local currentTitle = mw.title.getCurrentTitle local title = currentTitle.text

-- Local Utility Functions local function whichTOC( frame ) -- standardize TOC behavior via return frame:expandTemplate{ title = 'CatAutoTOC', args = { align = 'center' } } end

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

local function addCat( cat, id ) if id and id ~= '' then return ''..redCatCheck(cat) else return ''..redCatCheck(cat) end end

--For use in, i.e. on local function gp( frame, id ) for _, conf in pairs( ac_conf ) do		if conf.category == id or conf[1] == id then local linktarget = conf.link or conf[1]..' (identifier)' local link   = ..conf[1].. local gdpl   = ':d:Property:P'..conf[2] local example = 'The '..conf[1]..' identifier appears as '.. rmCats(conf[3](conf[5]))..' in the '..conf[4]..' section.' local txCatExplain = frame:expandTemplate{ title = 'Category explanation', args = {'articles with '..link..' identifiers.'..example..' Please do not add subcategories.'} } local txCatMore   = frame:expandTemplate{ title = 'Cat more', args = {'Gratispaideia:Authority control', gdpl} } local txEmptyCat  = frame:expandTemplate{ title = 'Possibly empty category' } local txGPCat     = frame:expandTemplate{ title = 'Gratispaideia category', args = { hidden = 'yes', tracking = 'yes' } } local txTOC = whichTOC( frame ) local gpCat = 'Articles with authority control information' local outString = txCatExplain..txCatMore..txEmptyCat..txGPCat..txTOC..'\n'..'Pages in this category should only be added by Module:Authority control.'..addCat(gpCat, id) return outString end end return '' end

--For use in, i.e. on local function gpfaulty( frame, id ) for _, conf in pairs( ac_conf ) do		if conf.category == id or conf[1] == id then local linktarget = conf.link or conf[1]..' (identifier)' local gdpl      = ':d:Property:P'..conf[2] local txCatMore = frame:expandTemplate{ title = 'Cat more', args = {'Gratispaideia:Authority control', linktarget, gdpl} } local txEmptyCat = frame:expandTemplate{ title = 'Possibly empty category' } local txGPCat   = frame:expandTemplate{ title = 'Gratispaideia category', args = { hidden = 'yes', tracking = 'yes' } } local txDirtyCat = frame:expandTemplate{ title = 'Polluted category' } local txTOC = whichTOC( frame ) local idCat = 'Articles with '..id..' identifiers' local gpfCat = 'Articles with faulty authority control information' local outString = txCatMore..txEmptyCat..txGPCat..txDirtyCat..txTOC..'\n'.. 'Pages in this category should only be added by Module:Authority control.'.. addCat(idCat)..addCat(gpfCat, id) return outString end end return '' end

-- Main/External Call function p.autoDetect( frame ) if currentTitle.namespace == 14 then --cat space local gpfaultyID = mw.ustring.match(title, 'Articles with faulty ([%w%.%- ]+) identifiers') local gpID      = mw.ustring.match(title, 'Articles with ([%w%.%- ]+) identifiers') if gpfaultyID then return gpfaulty( frame, gpfaultyID )    --must be before gpID check, in case they both match elseif gpID      then return gp( frame, gpID )             --to keep the regex simple else  return '' end end return '' end

return p