Module:Authority control/documentation/sandbox explained

require('strict')local p = local configfile = 'Module:Authority control/config' -- default configuation modulelocal arg = mw.getCurrentFrame.args.configif arg and arg~= then configfile = 'Module:Authority control/config/' .. argendlocal configif mw.title.new(configfile).exists then config = mw.loadData(configfile)else return error('Invalid configuration file',0)endlocal title = mw.title.getCurrentTitlelocal namespace = title.namespacelocal testcases = title.subpageText

config.i18n.testcaseslocal makelink = require(config.i18n.ACmodule .. '/' .. config.i18n.sandbox).makelinklocal lang = mw.getContentLanguage

local function needsAttention(sortkey) return '' .. sortkey .. title.text .. ''end

local function addCat(cat,sortkey) if cat and cat ~= and (namespace

0 or namespace

14 or testcases) then local redlinkcat = if testcases

false and mw.title.new(cat, 14).exists

false then redlinkcat = needsAttention('N') end if sortkey then cat = '' .. sortkey .. title.text .. '' else cat = '' end cat = cat .. redlinkcat return cat else return endend

-- Creates a human-readable standalone wikitable version of conf, and tracking categories with page counts, for use in the documentationfunction p.docConfTable(frame) local function checkcat(category,label) local ret=''..label..'' --if mw.title.new(category,14).exists

false then --ret = ret..'

[['..tostring(mw.uri.fullUrl('Category:'..category,'action=edit&preload=Template:Authority_control/preload'))..' create]]' --end return ret end local doc = local a, P, f = 0, 0, 0 --cumulative sums local count = frame.args.count or false local columns = 3 + (count and 1 or 0) local row = function(conf) local category = conf.category or conf[1] local articleCat = string.format(config.i18n.cat,category) local articleCount = mw.site.stats.pagesInCategory(articleCat,config.i18n.pages) local errorCat = conf.errorcat or string.format(config.i18n.cat, config.i18n.faulty .. ' ' .. category ) local errorCount = mw.site.stats.pagesInCategory(errorCat,config.i18n.pages) P = P + 1 --property count a = a + articleCount f = f + errorCount local getstatement = function(id,propid,qualid) local statement = mw.wikibase.getBestStatements('P' .. id, 'P' .. propid) local value if statement and statement[1] and statement[1].mainsnak.datavalue.value.id then value = statement[1].mainsnak.datavalue.value.id local qual if qualid and statement[1].qualifiers['P' .. qualid][1].datavalue.value then qual = statement[1].qualifiers['P' .. qualid][1].datavalue.value end return value, qual end end local _, example = getstatement(conf.property, 1855, conf.property) if not example then example = end example = frame:expandTemplate .. '\n' local getname = function(nameprop) local name = getstatement(conf.property,nameprop) if name then return frame:expandTemplate end end local name = getname(1629) or getname(10726) or local out = if conf.remark then out = out .. '' else out = out .. '' end out = out .. name .. '' .. '' .. config.sections[conf.section].name .. '' .. '' .. frame:expandTemplate .. '' .. '' .. example .. '' if count then out = out .. ''..checkcat(articleCat,lang:formatNum(articleCount))..' ('..checkcat(errorCat,errorCount)..')' end out = out .. '' if conf.remark then out = out .. "Remarks: " .. frame:preprocess .. "" end return out end local doc = '
' .. lang:ucfirst(config.i18n.identifier) .. '' .. config.i18n.Section .. '' .. config.i18n.WDproperty .. '' .. config.i18n.Appears_as .. '' .. config.i18n.Articles .. ' ' .. '(' .. config.i18n.Faults .. ')
' .. config.i18n.Totals .. '' .. P .. '' .. lang:formatNum(a) .. ' (' .. f .. ')
' return docend

function p.errorTable(frame) local Table = '

' .. config.i18n.WDproperty .. '' .. lang:ucfirst(config.i18n.faulty) .. ' ' .. config.i18n.identifiers .. '' .. config.i18n.Tracking_category .. '
'..frame:expandTemplate .. ''..tostring(count)..'
' .. config.i18n.Totals .. '' .. '' .. tostring(f) .. ''..tostring(P)..'
' return Tableend

function p.whitelisttable(frame) local Table = '

' .. config.i18n.Code .. '' .. config.i18n.Topic .. '' .. lang:ucfirst(config.i18n.identifiers) .. '
' .. code .. '' .. mw.wikibase.getSitelink('Q' .. wlist.topic) .. '' .. table.concat(plist,', ') .. '
' return Tableend

function p.sectiontable(frame) local Table = '

' .. config.i18n.Section .. '' .. config.i18n.Description .. '' .. lang:ucfirst(config.i18n.identifiers) .. '
' .. number .. '' .. section.name .. '' .. table.concat(plist,', ') .. '
' return Tableend

-- Main/External Call for Pages with authority control identifiersfunction p.autoDetect(frame) local function whichTOC(frame) -- standardize TOC behavior via return frame:expandTemplate end local function wpa(frame,id,faulty) for _,conf in pairs(config.config) do if conf.category

id or conf[1]

id then local getname = function(nameprop) local name = mw.wikibase.getBestStatements('P'..conf.property,nameprop) if name and name[1] and name[1].mainsnak.datavalue.value.id then return frame:expandTemplate end end local name = getname('P1629') or getname('P10726') or local outString = frame:expandTemplate .. frame:expandTemplate .. frame:expandTemplate .. frame:expandTemplate .. frame:expandTemplate .. whichTOC(frame) if faulty then outString = outString .. addCat(config.i18n.faultcat,id) .. addCat(string.format(config.i18n.cat, id)) else outString = outString .. addCat(config.i18n.maincat,id) end return outString end end end if namespace

14 then --cat space local wpfaultyID = mw.ustring.match(title.text, 'Articles with faulty (.+) identifiers') local wpID = mw.ustring.match(title.text, 'Articles with (.+) identifiers') if wpfaultyID then return wpa(frame,wpfaultyID,true)-- must be before wpID check, in case they both match elseif wpID then return wpa(frame,wpID,false) else return needsAttention('U') end endend

function p.idproposal(frame) local property = frame.args.property or local out = '

' return outend

return p