Module:maintenance category

From Linguifex
Revision as of 09:40, 31 July 2024 by Sware (talk | contribs) (Created page with "local format_categories = require("Module:utilities").format_categories local match = string.match local process_params = require("Module:parameters").process local title local export = {} local function ret(name, cat) return cat and format_categories({name}, nil, "-", nil, true) or name end function export.get_category(name, cat) title = title or mw.title.getCurrentTitle() -- All talkpages. if title.isTalkPage then return ret(name .. "/hidden", cat) end loca...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:maintenance category/doc

local format_categories = require("Module:utilities").format_categories
local match = string.match
local process_params = require("Module:parameters").process

local title

local export = {}

local function ret(name, cat)
	return cat and format_categories({name}, nil, "-", nil, true) or name
end

function export.get_category(name, cat)
	title = title or mw.title.getCurrentTitle()
	-- All talkpages.
	if title.isTalkPage then
		return ret(name .. "/hidden", cat)
	end
	local namespace = title.namespace
	-- User:, Thread:, and Summary:
	if namespace == 2 or namespace == 90 or namespace == 92 then
		return ret(name .. "/hidden", cat)
	-- Template: and Module:.
	elseif not (namespace == 10 or namespace == 828) then
		return ret(name, cat)
	end
	local title_text = title.text
	if (
		-- Template:User: and Module:User:.
		match(title_text, "^User:") or
		-- Any template/module sandboxes (which can be numbered and/or followed by further subpages), including any templates/modules with the name sandbox.
		match(title_text, "%f[^%z/][sS][aA][nN][dD][bB][oO][xX] ?%d*%f[%z/]") or
		-- Any template/module testcases (which can be numbered and/or followed by further subpages).
		match(title_text, "/[tT][eE][sS][tT][cC][aA][sS][eE][sS]? ?%d*%f[%z/]")
	) then
		return ret(name .. "/hidden", cat)
	end
	return ret(name, cat)
end

function export.template(frame)
	local args = process_params(frame:getParent().args, {
		[1] = {required = true, default = ""},
		["cat"] = {type = "boolean", default = false}
	})
	return export.get_category(args[1], args.cat)
end

return export