Module:Authority control/documentation

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

local function needsAttention(sortkey) return '' 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 = '' else cat = '' end cat = cat .. redlinkcat return cat else return '' end end

local loadConfig = function(arg) local configfile = 'Module:Authority control/config' -- default configuation module if arg and arg~='' then configfile = 'Module:Authority control/config/' .. arg end if mw.title.new(configfile).exists then return mw.loadData(configfile) else return false end 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 config = loadConfig(frame.args.config) if not config then return error('Invalid configuration file',0)	end local getlink = require("Module:Wikidata table")._getLink local function checkcat(category,label) local ret=..label.. --if mw.title.new(category,14).exists == false then --ret = ret..' &#91;['..tostring(mw.uri.fullUrl('Category:'..category,'action=edit&preload=Template:Authority_control/preload'))..' create]&#93; ' --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 lang = mw.getContentLanguage local row = function(conf) local category = conf.category or conf[1] local articleCat = 'Articles with '..category..' identifiers' local articleCount = mw.site.stats.pagesInCategory(articleCat,'pages') local errorCat = conf.errorcat or 'Articles with faulty '..(conf.category or conf[1])..' identifiers' local errorCount = mw.site.stats.pagesInCategory(errorCat,'pages') P = P + 1 --property count a = a + articleCount f = f + errorCount local example = mw.wikibase.getBestStatements('P'..conf.property,'P1855') or '' if example then example = example[1].qualifiers['P'..conf.property][1].datavalue.value example = frame:expandTemplate{title = "Hlist", args = {'\n' .. makelink(conf,{id=example},1)}} .. '\n' end 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{title='Wikidata fallback link',args={name[1].mainsnak.datavalue.value.id}} end end local name = getname('P1629') or getname('P10726') or '' local out = '' if conf.remark then out = out .. ' '		else out = out .. ' '		end out = out .. name .. ' ' ..			'' .. config.sections[conf.section].name .. ' ' ..			'' .. frame:expandTemplate{title='Wikidata property link',args={id='f',conf.property}} .. ' ' ..			' ' .. 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{text = conf.remark} .. " "		end return out end local doc = ' ' return doc end

function p.errorTable(frame) local config = loadConfig(frame.args.config) if not config then return error('Invalid configuration file',0)	end local Table = ' ' return Table end

function p.whitelisttable(frame) local config = loadConfig(frame.args.config) if not config then return error('Invalid configuration file',0)	end local Table = ' ' return Table end

function p.sectiontable(frame) local config = loadConfig(frame.args.config) if not config then return error('Invalid configuration file',0)	end local Table = ' ' return Table end

-- Main/External Call for Pages with authority control identifiers function p.autoDetect(frame) local config = loadConfig(frame.args.config) if not config then return error('Invalid configuration file',0)	end local function whichTOC(frame) -- standardize TOC behavior via return frame:expandTemplate{ title = 'CatAutoTOC', args = { align = 'center' } } end local ac_conf = require('Module:Authority control/config').config local rmCats = require('Module:Suppress categories').main --For use in, i.e. on 	local function wpfaulty( frame, id ) for _, conf in pairs(ac_conf) do			if conf.category == id or conf[1] == id then local outString = frame:expandTemplate{ title = 'Cat more', args = {'Wikipedia:Authority control', conf.idlink or conf[1]..' (identifier)', ':d:Property:P'..conf.property} } .. frame:expandTemplate{ title = 'Possibly empty category' } .. frame:expandTemplate{ title = 'Wikipedia category', args = { hidden = 'yes', tracking = 'yes' } } .. frame:expandTemplate{ title = 'Polluted category' } .. whichTOC( frame ) .. '\nPages in this category should only be added by Module:Authority control.' .. addCat('Articles with '..id..' identifiers') .. addCat('Articles with faulty authority control information',id) return outString end end return '' end --For use in, i.e. on 	local function wp(frame,id ) for _, conf in pairs( ac_conf ) do			if conf.category == id or conf[1] == id then local link =  .. conf[1] ..  local outString = frame:expandTemplate{ title = 'Category explanation', args = {'articles with '..link..' identifiers.'..' Please do not add subcategories.'} } .. frame:expandTemplate{ title = 'Cat more', args = {'Wikipedia:Authority control', ':d:Property:P'..conf.property} } .. frame:expandTemplate{ title = 'Possibly empty category' } .. frame:expandTemplate{ title = 'Wikipedia category', args = { hidden = 'yes', tracking = 'yes' } } .. whichTOC( frame ) .. '\nPages in this category should only be added by Module:Authority control.' .. addCat('Articles with authority control information',id) return outString end end return '' end if namespace == 14 then --cat space local wpfaultyID = mw.ustring.match(title.text, 'Articles with faulty ([%w%.%- ]+) identifiers') local wpID      = mw.ustring.match(title.text, 'Articles with ([%w%.%- ]+) identifiers') if wpfaultyID then return wpfaulty(frame,wpfaultyID)-- must be before wpID check, in case they both match elseif wpID then return wp(frame, wpID)-- to keep the regex simple else return needsAttention('U') end end return '' end

function p.idproposal(frame) local config = loadConfig(frame.args.config) if not config then return error('Invalid configuration file',0)	end local property = frame.args.property or '' local out = 'Wikidata property: ' .. frame:expandTemplate{title='Wikidata property link', args={'P' .. property}} .. '' out = out .. 'Section: ' local section = frame.args.section or '' if section~='' then out = out .. config.sections[section].name .. ' (' .. section .. ')' else out = out .. 'Not specified' end out = out .. 'Link: ' local link = frame.args.link or '' if link=='' then link = mw.wikibase.getBestStatements('P'..property,'P1630') or '' link = link[1].mainsnak.datavalue.value end if link~='' then out = out .. ' '	else out = out .. 'Not specified' end out = out .. 'Label: ' local label = frame.args.label or '' if label~='' then out = out .. label else out = out .. 'Not specified' end out = out .. 'Example: ' local example = mw.wikibase.getBestStatements('P'..property,'P1855') or '' if example then example = example[1].qualifiers['P'..property][1].datavalue.value example = frame:expandTemplate{title = "Hlist", args = {'\n' .. makelink({[1]='',link=link,label=label},{id=example},1)}} .. '\n' out = out .. example else out = out .. 'Not available' end out = out .. '</ul>' return out end

return p