Jump to content

Module:Articles by class

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MSGJ (talk | contribs) at 17:54, 19 December 2024 (use Template:class). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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+$')
	local exist = {}
	for _, class in ipairs(classes) do
		local cat_art = mw.title.new(class .. '-Class' .. topic .. articles)
		local cat_pag = mw.title.new(class .. '-Class' .. topic .. pages)
		if cat_art.exists then
			exist[class] = 'articles'
		elseif cat_pag.exists then
			exist[class] = 'pages'
		else
			exist[class] = false
		end
	end
	for _, class in ipairs(classes) do
		if exist[class] then
			local cell = frame:expandTemplate{
				title = 'class',
				args = {
					topic = topic,
					category = topic .. exist[class],
					bold = 'no'
				}
			}
		end
	end
end

return p