模組:Articles by Quality and Importance/sandbox
外观
![]() | 这是Module:Articles by Quality and Importance(差异)的沙盒。 |
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local classList = {
{'fa', score = 10},
{'a', score = 9},
{'ga', score = 8},
{'bplus', score = 7.9, disabled = true},
{'b', score = 7},
{'c', score = 5},
{'start', score = 3},
{'stub', score = 1},
{'fl', score = 10},
{'al', score = 9, disabled = true},
{'bl', score = 7, disabled = true},
{'cl', score = 5, disabled = true},
{'list', score = 3},
{'sl', score = 1, disabled = true},
{'category'},
{'disambig'},
{'draft'},
{'file',},
{'portal'},
{'project'},
{'template'},
{'na'},
{'unassessed', score = 0},
}
local importanceList = {
{'top'},
{'high'},
{'mid'},
{'low'},
{'bottom', disabled = true},
{'no', disabled = true},
{'na'},
{'unknown'},
}
local function getClassName(class, writingSystem)
if class == 'ALL' then return '' end
return require('Module:Class/convert')._main({class, writingSystem}) .. (writingSystem == 'trad' and '級' or '级')
end
local function getImportanceName(importance, writingSystem)
if importance == 'ALL' then return '' end
return require('Module:Importance/convert')._main({importance, writingSystem}) .. '重要度'
end
local function categoryName(args, class, importance)
local categoryNamingFormat
local writingSystem = yesno(args.trad) and 'trad' or 'simp'
if args.format == 'ICT' then
categoryNamingFormat = getImportanceName(importance, writingSystem) .. getClassName(class, writingSystem)
else
categoryNamingFormat = getClassName(class, writingSystem) .. getImportanceName(importance, writingSystem)
end
return string.format('%s%s%s', categoryNamingFormat, args.project, writingSystem == 'trad' and '條目' or '条目')
end
local function pageNumberOfClassAndImportance(args, class, importance)
if tonumber(args[class..'_'..importance]) then
return tonumber(args[class..'_'..importance])
end
return tonumber(mw.site.stats.pagesInCategory( categoryName(args, class, importance), 'pages' ))
end
local function pageNumberWithLink(args, class, importance)
local pageNumber = mw.language.new('zh'):formatNum(pageNumberOfClassAndImportance(args, class, importance))
if yesno(args.displayZero) == true and pageNumber == 0 then
return
end
if yesno(args.link) == false then
return pageNumber
end
if args.link == 'catscan' then
-- 等会再做
end
if args.link == 'catscan_main' then
-- 等会再做
end
if args.link == 'bluelinkonly' then
if mw.title.makeTitle('Category', categoryName(args, class, importance)).exists then
return string.format('[[:Category:%s|%s]]', categoryName(args, class, importance), pageNumber)
end
return
end
return string.format('[[:Category:%s|%s]]', categoryName(args, class, importance), pageNumber)
end
local p = {}
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
local builder
local enabledClassList, enabledImportanceList = {}, {}
for i, v in ipairs(classList) do
if args[v[1] .. '_'] == 'false' then
v.disabled = true
elseif args[v[1] .. '_'] == 'true' then
v.disabled = false
end
end
for i, v in ipairs(importanceList) do
if args['_' .. v[1]] == 'false' then
v.disabled = true
elseif args['_' .. v[1]] == 'true' then
v.disabled = false
end
end
for i, v in ipairs(classList) do
if v.disabled ~= true then
table.insert(enabledClassList, v[1])
end
end
for i, v in ipairs(importanceList) do
if v.disabled ~= true then
table.insert(enabledImportanceList, v[1])
end
end
for i, v in ipairs(enabledClassList) do
for j, w in ipairs(enabledImportanceList) do
args[v .. '_' .. w] = pageNumberOfClassAndImportance(args, v, w)
args[v .. '_ALL'] = (args[v .. '_ALL'] or 0) + args[v .. '_' .. w]
args['ALL_' .. w] = (args['ALL_' .. w] or 0) + args[v .. '_' .. w]
end
end
builder = mw.html.create('table')
:addClass('wikitable')
builder:tag('caption'):wikitext( (args.project or '') .. '专题条目状态')
builder:tag('tr')
:tag('th'):attr('rowspan', 2):wikitext('重要度')
:tag('th'):attr('colspan', table.maxn(enabledImportanceList) + 2):wikitext('质量')
for i, v in ipairs(enabledImportanceList) do
builder:tag('td'):wikitext(v)
end
builder:tag('td'):wikitext('合計')
builder:tag('tr'):tag('td'):wikitext('sss')
return builder
end
return p