Module:Articles by quality
Appearance
This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This module depends on the following other modules: |
This module implements Template:Articles by Quality. Please refer to the documentation of that template.
require('strict')
local p = {}
local classes = {'FA', 'A', 'GA', 'B', 'C', 'Start', 'Stub', 'FL', 'AL', 'BL', 'CL', 'List', 'SIA', 'Future', 'Category', 'Disambig', 'Draft', 'FM', 'File', 'Portal', 'Project', 'Redirect', 'Template', 'User', 'NA'}
p.main = function(frame)
local args = require('Module:Arguments').getArgs(frame)
local yesno = require('Module:Yesno')
local title = args.page and mw.title.new(page) or mw.title.getCurrentTitle()
local class, topic, typ = title.text:match('^(%a+)-Class (.+) (%a+)$')
if not class then -- try to match unassessed category
class, topic, typ = title.text:match('^(Unassessed) (.+) (%a+)$')
end
if not topic then
topic = title.text:match('^(.+) articles by quality$')
end
local out, exist, cats = '', {}, {}
local add_category = function(cat, sort)
local link = '[[Category:' .. cat .. (sort and ('|' .. sort) or '') .. ']]'
table.insert(cats, link)
end
if args.class and class and args.topic and topic and (args.class:lower()~=class:lower() or args.topic~=topic) then
add_category('WikiProject assessment categories needing attention')
end
topic = topic or args.topic or ''
class = class or args.class or ''
typ = typ or 'articles'
if title.namespace==14 and not title.text:match('^' .. topic .. ' articles by quality$') then
out = frame:expandTemplate{title='Possibly empty category'}
end
local add_category = function(cat, sort)
local link = '[[Category:' .. cat .. (sort and ('|' .. sort)) .. ']]'
table.insert(cats, link)
end
local cat_in_use = function(cat)
local cat_title = mw.title.new('Category:' .. cat)
return cat_title and cat_title.exists or mw.site.stats.pagesInCategory(cat, 'pages')>0
end
for _, class in ipairs(classes) do
if cat_in_use(class .. '-Class' .. ' ' .. topic .. ' pages') then
exist[class] = 'pages'
elseif cat_in_use(class .. '-Class' .. ' ' .. topic .. ' articles') then
exist[class] = 'articles'
else
exist[class] = false
end
end
local class_template = function(class, page)
return frame:expandTemplate{
title = 'class',
args = {
[1] = class,
topic = topic,
category = topic .. ' ' .. page,
bold = 'no'
}
}
end
local header_row = mw.html.create('tr')
for _, class in ipairs(classes) do
if exist[class] then
header_row:node(class_template(class, exist[class]))
end
end
if args.custom1 then
header_row:node(class_template(args.custom1, 'articles'))
end
if args.custom2 then
header_row:node(class_template(args.custom2, 'articles'))
end
local total_cell = mw.html.create('td'):attr('align', 'center'):wikitext('Total')
header_row:node(class_template('Unassessed', 'articles'))
:node(total_cell)
local total = 0
local col_num = function(n)
return mw.html.create('td')
:attr('align', 'center')
:wikitext(mw.language.getContentLanguage():formatNum(n))
end
local pages_in_cat = function(cat)
local pages = mw.site.stats.pagesInCategory(cat, 'pages')
total = total + pages
return col_num(pages)
end
local second_row = mw.html.create('tr')
for _, class in ipairs(classes) do
if exist[class] then
second_row:node(pages_in_cat(class .. '-Class' .. ' ' .. topic .. ' ' .. exist[class]))
end
end
if args.custom1 then
second_row:node(pages_in_cat(args.custom1 .. '-Class' .. ' ' .. topic .. ' articles'))
end
if args.custom2 then
second_row:node(pages_in_cat(args.custom2 .. '-Class' .. ' ' .. topic .. ' articles'))
end
second_row:node(pages_in_cat('Unassessed ' .. topic .. ' articles'))
:node(col_num(total))
local caption
if args.project then -- display caption
local text = '[[Wikipedia:WikiProject ' .. args.project .. '|WikiProject ' .. args.project .. ']] '
.. (
mw.title.new('Category:' .. topic .. ' articles by quality').exists
and '[[:Category:' .. topic .. ' articles by quality|articles by quality]]'
or 'articles by quality'
) .. string.rep(' ', 3)
.. '<small>' .. frame:expandTemplate{title = 'Purge', args = {'Refresh'}} .. '</small>'
caption = mw.html.create('caption')
:attr('align', 'bottom')
:wikitext(text)
end
local tab = mw.html.create('table')
:addClass(args.format or 'wikitable') -- add custom CSS class if specified
:addClass('toccolours'):addClass('nomobile')
:css('table-layout', 'fixed')
:css('margin', '1em auto')
:node(header_row)
:node(second_row)
:node(caption)
if class and class~='' and class~='nocat' then
add_category(args.parent or (topic .. ' articles by quality'), class)
add_category(class .. (class:lower()=='unassessed' and '' or '-Class') .. ' ' .. typ, args.sort or topic)
end
return out .. tostring(tab) .. table.concat(cats)
end
return p