Module:Articles by class
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This module depends on the following other modules: |
This module implements the following templates:
- Template:Articles by Quality,
- Template:Articles by Importance and
- Template:Articles by Quality and Importance.
Please refer to the documentation of those templates.
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', 'Needed', 'Portal', 'Project', 'Redirect', 'Template', 'User', 'NA'}
p.main = function(frame)
local args = require('Module:Arguments').getArgs(frame)
local title = args.page and mw.title.new(page) or mw.title.getCurrentTitle()
local class, topic = title.text:match('^(%a+)-Class (%a+) %a+$')
if args.topic then -- override topic
topic = args.topic
end
local exist = {}
local out = ''
local cat_in_use = function(cat)
local title = mw.title.new('Category:' .. cat)
return title.exists or mw.site.stats.pagesInCategory(cat, 'pages')>0
end
for _, class in ipairs(classes) do
if cat_in_use(class .. '-Class' .. ' ' .. topic .. ' articles') then
exist[class] = 'articles'
elseif cat_in_use(class .. '-Class' .. ' ' .. topic .. ' pages') then
exist[class] = 'pages'
else
exist[class] = false
end
end
local header_row = mw.html.create('tr')
local class_template = function(class, page)
return frame:expandTemplate{
title = 'class',
args = {
[1] = class,
topic = topic,
category = topic .. ' ' .. page,
bold = 'no'
}
}
end
for _, class in ipairs(classes) do
if exist[class] then
header_row:node(class_template(class, exist[class]))
end
end
header_row:node(class_template('Unassessed', 'articles'))
local tab = mw.html.create('table')
:addClass('toccolours'):addClass('nomobile')
:css('table-layout', 'fixed')
:css('margin', '1em auto')
:node(header_row)
return out .. tostring(tab)
end
return p