The editors' meeting has been canceled for technical reasons.
Module:SafeCate
Jump to navigation
Jump to search
This module is designed to address classification issues caused by occasional template expansion errors combined with the caching system on this site.
This module is only applicable in the template namespace.
Parameters
- **1**: The name of the category to be added.
- **2**: Category index, usually used to adjust sorting or prioritize the main entry of a series in the category page.
- **nsid**: The namespace(s) in which the template is effective. Use numeric codes as defined in Help:Namespace. Supports the use of half-width commas as separators.
- **nsidExclude**: Namespaces to exclude. If the **nsid** parameter is filled and not empty, this parameter will not take effect.
- **noSubpage**: Excludes subpages, which can help handle incorrect template references on users' main pages.
- **strict**: Used for wrappers other than {{SafeCate}}, such as {{TemplateCate}}. This parameter must be set for the template to take effect, ensuring strict namespace restrictions.
local module = {}
local function _isvalid(value)
return value ~= nil and type(value) == "string" and mw.text.trim(value) ~= ""
end
function module.main(frame)
local strict = frame
local parent = frame:getParent()
if not _isvalid(frame.args[1]) then
if not (parent and _isvalid(parent.args[1])) then return end
local title = parent:getTitle()
if title == "Template:SafeCate" then
strict, frame = parent, parent
elseif mw.title.new(title).namespace == 10 and frame.args["strict"]=="1" then
frame = parent
else return end
end
local cate = frame.args[1]
local mod = frame.args[2]
local nsMap = { }
local bExclude, nsids = false, nil
if strict.args["nsid"] then
nsids = mw.text.split(strict.args["nsid"], ",", true)
elseif strict.args["nsidExclude"] then
bExclude = true
nsids = mw.text.split(strict.args["nsidExclude"], ",", true)
end
if nsids then
for _, value in ipairs(nsids) do
nsMap[tonumber(value)] = true
end
else
nsMap[0] = true
end
local noSubpage = (strict).args["noSubpage"]=="1"
local title = mw.title.getCurrentTitle()
local curNsid = title.namespace
if ((nsMap[curNsid] and (not bExclude)) or ((not nsMap[curNsid]) and bExclude)) and ((not noSubpage) or (not title.isSubpage)) then
if curNsid == 10 and title.isSubpage and title.subpageText == "doc" then return end
if mod then
return "[[Category:"..cate.."|"..mod.."]]"
else
return "[[Category:"..cate.."]]"
end
end
end
return module