Module:Category handler: Difference between revisions
overhaul logic for suffixes? |
No edit summary |
||
| Line 110: | Line 110: | ||
-- suppressed suffix (subpage) | -- suppressed suffix (subpage) | ||
function p._category_handler(cats, ns_override, suffixes, is_debug) | function p._category_handler(cats, ns_override, suffixes, is_debug) | ||
local cats = cats or {} | |||
local is_debug = yesno(is_debug, false) | |||
local frame = mw.getCurrentFrame() | |||
-- Get the page where the template/module is being used (parent frame) | |||
local parent_title = frame:getParent() and mw.title.new(frame:getParent():getTitle()) or mw.title.getCurrentTitle() | |||
local parent_ns = parent_title.nsText | |||
-- Don't categorize if: | |||
-- - Debug mode is on (force suppress) | |||
-- - Parent page is in suppressed namespace | |||
-- - Parent page is NOT a content page (e.g. subpages like /doc, /sandbox) | |||
if is_debug | |||
or is_suppressed_namespace(ns_override, parent_ns) | |||
or not parent_title.isContentPage | |||
then | |||
return '' | |||
end | |||
-- Categorize | |||
local result = '' | |||
for _, cat in ipairs(cats) do | |||
cat = mw.text.trim(cat or '') | |||
if cat ~= '' then | |||
result = result .. string.format('[[Category:%s]]', cat) | |||
end | |||
end | |||
return result | |||
end | end | ||