Module:Category handler: Difference between revisions
mNo edit summary |
overhaul logic for suffixes? |
||
| Line 72: | Line 72: | ||
-- Accepts an opiontal table, containing additional suffixes to suppress | -- Accepts an opiontal table, containing additional suffixes to suppress | ||
-- Suffix and custom suffixes are lowercased to guarantee matching | -- Suffix and custom suffixes are lowercased to guarantee matching | ||
--[[ | |||
local function has_suppressed_suffix(suffixes_override) | local function has_suppressed_suffix(suffixes_override) | ||
local title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
| Line 102: | Line 103: | ||
return false | return false | ||
end | end | ||
]]-- | |||
-- "Main" function; can be called by other modules | -- "Main" function; can be called by other modules | ||
| Line 110: | Line 112: | ||
local cats = cats or {} | local cats = cats or {} | ||
local is_debug = yesno(is_debug, false) | local is_debug = yesno(is_debug, false) | ||
local title = mw.title.getCurrentTitle() | |||
-- | |||
-- | -- Don't bother if if: | ||
-- | -- - In debug mode | ||
-- - In a suppressed namespace | |||
-- | -- - On a subpage like /doc or /sandbox (but not if transcluded) | ||
-- | -- - Not a "content" page (IE, not a main/module/template page) | ||
if is_suppressed_namespace(ns_override) | if is_debug | ||
or | or is_suppressed_namespace(ns_override) | ||
or not title.isContentPage | |||
then | |||
return '' | return '' | ||
end | end | ||
-- | -- Categorize | ||
local result = '' | local result = '' | ||
for _, cat in ipairs(cats) do | for _, cat in ipairs(cats) do | ||
| Line 134: | Line 137: | ||
return result | return result | ||
end | end | ||
-- Wrapper for templates calling via #invoke | -- Wrapper for templates calling via #invoke | ||
| Line 141: | Line 143: | ||
local cats_unparsed = args["categories" ] or "" | local cats_unparsed = args["categories" ] or "" | ||
local excluded_ns_unparsed = args["excluded_ns"] or "" | local excluded_ns_unparsed = args["excluded_ns"] or "" | ||
local suffixes_unparsed = args["suffixes" ] or "" | --local suffixes_unparsed = args["suffixes" ] or "" | ||
local is_debug = yesno(args["debug"], false) -- Parse debug mode; setting this to TRUE disables all categories | local is_debug = yesno(args["debug"], false) -- Parse debug mode; setting this to TRUE disables all categories | ||
| Line 166: | Line 168: | ||
-- Parse excluded suffixes | -- Parse excluded suffixes | ||
--[[ | |||
local suffixes = {} | local suffixes = {} | ||
for suffix in mw.text.gsplit(suffixes_unparsed, "[;\n]") do | for suffix in mw.text.gsplit(suffixes_unparsed, "[;\n]") do | ||
| Line 173: | Line 176: | ||
end | end | ||
end | end | ||
]]-- | |||
return p._category_handler(cats, ns_override, suffixes, is_debug) | return p._category_handler(cats, ns_override, suffixes, is_debug) | ||