Module:maintenance category: Difference between revisions
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..." |
mNo edit summary |
||
| Line 1: | Line 1: | ||
local | local export = {} | ||
local | local pages_module = "Module:pages" | ||
local parameters_module = "Module:parameters" | |||
local utilities_module = "Module:utilities" | |||
local | local new_title = mw.title.new | ||
local uses_hidden_category -- Defined below. | |||
local function | --[==[ | ||
return | Loaders for functions in other modules, which overwrite themselves with the target function when called. This ensures modules are only loaded when needed, retains the speed/convenience of locally-declared pre-loaded functions, and has no overhead after the first call, since the target functions are called directly in any subsequent calls.]==] | ||
end | local function format_categories(...) | ||
format_categories = require(utilities_module).format_categories | |||
return format_categories(...) | |||
end | |||
local function is_sandbox(...) | |||
is_sandbox = require(pages_module).is_sandbox | |||
return is_sandbox(...) | |||
end | |||
local function is_testcase_page(...) | |||
is_testcase_page = require(pages_module).is_testcase_page | |||
return is_testcase_page(...) | |||
end | |||
local function process_params(...) | |||
process_params = require(parameters_module).process | |||
return process_params(...) | |||
end | |||
function | --[==[ | ||
Loaders for objects, which load data (or some other object) into some variable, which can then be accessed as "foo or get_foo()", where the function get_foo sets the object to "foo" and then returns it. This ensures they are only loaded when needed, and avoids the need to check for the existence of the object each time, since once "foo" has been set, "get_foo" will not be called again.]==] | |||
local current_title | |||
local function get_current_title() | |||
return | current_title, get_current_title = mw.title.getCurrentTitle(), nil | ||
return current_title | |||
end | end | ||
function export.uses_hidden_category(title) | |||
local namespace = title.namespace | local namespace = title.namespace | ||
-- | -- Thread: and Summary: pages are named "Thread:PAGE" or "Summary:PAGE", | ||
-- where PAGE is the page they relate to. How we treat them therefore | |||
-- depends on what that page is. | |||
-- | while namespace == 90 or namespace == 92 do | ||
title = new_title(title.text) | |||
namespace = title.namespace | |||
end | end | ||
-- User: and all talk namespaces, as well as all sandboxes and testcase pages (including their documentation pages). | |||
return ( | |||
namespace == 2 or | |||
title.isTalkPage or | |||
is_sandbox(title, "include documentation") or | |||
is_testcase_page(title, "include documentation") | |||
) and true or false | |||
end | |||
) then | uses_hidden_category = export.uses_hidden_category | ||
function export.get_category(name, cat) | |||
if uses_hidden_category(current_title or get_current_title()) then | |||
name = name .. "/hidden" | |||
end | end | ||
return | return cat and format_categories(name, nil, "-", nil, true) or name | ||
end | end | ||