모듈:Authority control/documentation
보이기
require('strict')
local p = {}
local title = mw.title.getCurrentTitle()
local namespace = title.namespace
local testcases = (string.sub(title.subpageText,1,3) == '시험장')
local makelink = require('Module:Authority control').makelink
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 = '[[분류:'..cat..'|' .. sortkey .. title.text .. ']]'
else
cat = '[[분류:'..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('유효하지 않은 구성 파일',0) end
local getlink = require("Module:Wikidata table")._getLink
local function checkcat(category,label)
local ret='[[:분류:'..category..'|'..label..']]'
if mw.title.new(category,14).exists == false then
ret = ret..' <span class="plainlinks" style="font-size:85%;">[['..tostring(mw.uri.fullUrl('분류:'..category,'action=edit&preload=틀:전거_통제/preload'))..' 만들기]]</span>'
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 = category..' 식별자를 포함한 위키백과 문서'
local articleCount = mw.site.stats.pagesInCategory(articleCat,'pages')
local errorCat = conf.errorcat or '잘못된 '..(conf.category or conf[1])..' 식별자를 포함한 위키백과 문서'
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 = mw.getCurrentFrame():expandTemplate{title = "Hlist", args = {'\n' .. makelink(conf,{id=example},1)}} .. '\n'
end
local name = mw.wikibase.getBestStatements('P'..conf.property,"P1629")
if name and name[1] and name[1].mainsnak.datavalue.value.id then
name = getlink(name[1].mainsnak.datavalue.value.id)
else
name = ''
end
local out = ''
if conf.remark then
out = out .. '<tr><td rowspan=2>'
else
out = out .. '<tr><td>'
end
out = out .. name .. '</td>' ..
'<td style="text-align: center">' .. config.sections[conf.section].name .. '</td>' ..
'<td data-sort-value=' .. conf.property .. '>' .. frame:expandTemplate{title='위키데이터 속성 링크',args={id='f',conf.property}} .. '</td>' ..
'<td>' .. example .. '</td>'
if count then
out = out .. '<td style="text-align: right;">'..checkcat(articleCat,lang:formatNum(articleCount))..' ('..checkcat(errorCat,errorCount)..')</td>'
end
out = out .. '</tr>'
if conf.remark then
out = out .. "<tr class='expand-child'><td colspan=" .. columns .. ">'''설명:''' " .. frame:preprocess{text = conf.remark} .. "</td></tr>"
end
return out
end
local doc = '<table class="wikitable sortable">' ..
'<tr><th>식별자</th>' ..
'<th>구분</th>' ..
'<th data-sort-type=number>위키데이터 속성</th>' ..
'<th>표시</th>'
if count then
doc = doc .. '<th>[[:분류:전거 통제 정보를 포함한 위키백과 문서|문서]] ([[:분류:잘못된 전거 통제 정보를 포함한 위키백과 문서|잘못된 문서]])</th>'
end
doc = doc .. '</tr>'
for _, conf in pairs(config.config) do
doc = doc .. row(conf)
end
if count then
doc = doc .. '<tr><th style="text-align: right;" colspan=' .. columns-1 .. '>전체</th>' ..
'<th style="text-align: right;">' .. P .. '</th>' ..
'<th style="text-align: right;">' .. lang:formatNum(a) .. ' ([[:분류:잘못된 전거 통제 정보를 포함한 모든 위키백과 문서|' .. f .. ']])</th></tr>'
end
doc = doc .. '</table>'
return doc
end
function p.errorTable(frame)
local config = loadConfig(frame.args.config)
if not config then return error('유효하지 않은 구성 파일',0) end
local Table = '<table class="wikitable sortable">'..
'<tr><th>위키데이터 속성</th>'..
'<th>잘못된 ID</th>'..
'<th>[[:분류:잘못된 전거 통제 정보를 포함한 모든 위키백과 문서|추적 분류]]</th></tr>'
local f, P = 0, 0, 0 --cumulative sums
for _, conf in pairs(config.config) do
local category = conf.errorcat or '잘못된 '..(conf.category or conf[1])..' 식별자를 포함한 위키백과 문서'
local count = mw.site.stats.pagesInCategory(category,'pages')
if count > 0 then
P = P + 1
f = f + count
Table = Table..'<tr><td>'..frame:expandTemplate{ title = '위키데이터 속성 링크', args = { id = 'f', conf.property } } .. '</td>'..
'<td style="text-align:center;">'..tostring(count)..'</td>'..
'<td>[[:분류:'..category..']]</td></tr>'
end
end
Table = Table..'<tr><th>전체</th>'..
'<th style="text-align:center;">' .. '[[:분류:잘못된 전거 통제 정보를 포함한 모든 위키백과 문서|' .. tostring(f) .. ']]</th>'..
'<th style="text-align:center;">'..tostring(P)..'</th></tr></table>'
return Table
end
function p.whitelisttable(frame)
local config = loadConfig(frame.args.config)
if not config then return error('유효하지 않은 구성 파일',0) end
local Table = '<table class="wikitable sortable">'..
'<tr><th>코드</th>'..
'<th>주제</th>'..
'<th>식별자</th></tr>'
for code, wlist in pairs(config.whitelists) do
Table = Table .. '<tr><th>' .. code .. '</th>'..
'<td>[[' .. mw.wikibase.getSitelink('Q' .. wlist.topic) .. ']]</td>'
local plist = {}
for _, property in pairs(wlist.properties) do
table.insert(plist,frame:expandTemplate{title='위키데이터 속성 링크', args={'P' .. property}})
end
Table = Table .. '<td>' .. table.concat(plist,', ') .. '</td></tr>'
end
Table = Table .. '</table>'
return Table
end
function p.sectiontable(frame)
local config = loadConfig(frame.args.config)
if not config then return error('유효하지 않은 구성 파일',0) end
local Table = '<table class="wikitable sortable">'..
'<tr><th>구분</th>'..
'<th>설명</th>'..
'<th>식별자</th></tr>'
for number,section in ipairs(config.sections) do
Table = Table .. '<tr><th>' .. number .. '</th>' .. '<td>' .. section.name .. '</td>'
local plist = {}
for _,id in pairs(config.config) do
if id.section == number then
table.insert(plist,frame:expandTemplate{title='위키데이터 속성 링크', args={'P' .. id.property}})
end
end
Table = Table .. '<td>' .. table.concat(plist,', ') .. '</td></tr>'
end
Table = Table .. '</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('유효하지 않은 구성 파일',0) end
local function whichTOC( frame ) -- standardize TOC behavior via {{CatAutoTOC}}
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 [[분류:Articles with faulty authority control information]], i.e. on [[분류:Articles with faulty VIAF identifiers]]
local function wpfaulty( frame, id )
for _, conf in pairs(ac_conf) do
if conf.category == id or mw.ustring.lower(conf[1]) == mw.ustring.lower(id) then
local outString = frame:expandTemplate{ title = '분류 설명', args = {'위키백과:전거 통제', conf.idlink or conf[1]..' (식별자)', ':d:Property:P'..conf.property} }
.. frame:expandTemplate{ title = '빈 분류' }
.. frame:expandTemplate{ title = '위키백과 분류', args = { hidden = 'yes', tracking = 'yes' } }
.. frame:expandTemplate{ title = 'Polluted category' }
.. whichTOC( frame )
.. '\n이 분류에 속한 문서들은 [[모듈:Authority control]]을 통해 추가되어야 합니다.'
.. addCat(id..' 식별자를 포함한 위키백과 문서')
.. addCat('잘못된 전거 통제 정보를 포함한 위키백과 문서',id)
return outString
end
end
return ''
end
--For use in [[분류:Articles with authority control information]], i.e. on [[분류:Articles with VIAF identifiers]]
local function wp(frame, id )
for _, conf in pairs( ac_conf ) do
if conf.category == id or mw.ustring.lower(conf[1]) == mw.ustring.lower(id) then
local link = '[[' .. (conf.idlink or conf[1] .. ' (식별자)') .. '|' .. conf[1] .. ']]'
local outString = frame:expandTemplate{ title = 'Category explanation', args = {link..' 식별자를 포함한 문서([[위키백과:분류|하위 분류]]를 추가하지 말아 주십시오.)'} }
.. frame:expandTemplate{ title = '분류 설명', args = {'위키백과:전거 통제', ':d:Property:P'..conf.property} }
.. frame:expandTemplate{ title = '빈 분류' }
.. frame:expandTemplate{ title = '위키백과 분류', args = { hidden = 'yes', tracking = 'yes' } }
.. whichTOC( frame )
.. '\n이 분류에 속한 문서들은 [[모듈:Authority control]]을 통해 추가되어야 합니다.'
.. addCat('전거 통제 정보를 포함한 위키백과 문서',id)
return outString
end
end
return ''
end
if namespace == 14 then --cat space
local wpfaultyID = mw.ustring.match(title.text, '잘못된 ([%w%.%- ]+) 식별자를 포함한 위키백과 문서')
local wpID = mw.ustring.match(title.text, '([%w%.%- ]+) 식별자를 포함한 위키백과 문서')
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
return p