Title: Module:Category handler - freem URL Source: https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler Markdown Content: From freem _Documentation for this module may be created at [Module:Category handler/doc](https://freemwiki.com/index.php?title=Module:Category\_handler/doc&action=edit&redlink=1 "Module:Category handler/doc (page does not exist)")_ [](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-1)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-2)-- --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-3)-- CATEGORY HANDLER --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-4)-- --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-5)-- This module implements the {{[category handler](https://freemwiki.com/wiki/Template:Category_handler "Template:Category handler")}} template in Lua, --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-6)-- with a few improvements: all namespaces and all namespace aliases --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-7)-- are supported, and namespace names are detected automatically for --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-8)-- the local wiki. This module requires [[[Module:Namespace detect]]](https://freemwiki.com/wiki/Module:Namespace_detect "Module:Namespace detect") --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-9)-- and [[[Module:Yesno]]](https://freemwiki.com/wiki/Module:Yesno "Module:Yesno") to be available on the local wiki. It can be --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-10)-- configured for different wikis by altering the values in --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-11)-- [[[Module:Category handler/config]]](https://freemwiki.com/wiki/Module:Category_handler/config "Module:Category handler/config"), and pages can be blacklisted --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-12)-- from categorisation by using [[[Module:Category handler/blacklist]]](https://freemwiki.com/wiki/Module:Category_handler/blacklist "Module:Category handler/blacklist"). --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-13)-- --[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-14)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-15)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-16)-- Load required modules[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-17)local yesno = require(['Module:Yesno'](https://freemwiki.com/wiki/Module:Yesno))[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-18)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-19)-- Lazily load things we don't always need[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-20)local mShared, mappings[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-21)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-22)local p = {}[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-23)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-24)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-25)-- Helper functions[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-26)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-27)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-28)local function trimWhitespace(s, removeBlanks)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-29)if type(s) ~= 'string' then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-30)return s[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-31)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-32)s = s:match('^%s*(.-)%s*$')[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-33)if removeBlanks then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-34)if s ~= '' then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-35)return s[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-36)else[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-37)return nil[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-38)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-39)else[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-40)return s[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-41)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-42)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-43)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-44)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-45)-- CategoryHandler class[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-46)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-47)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-48)local CategoryHandler = {}[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-49)CategoryHandler.__index = CategoryHandler[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-50)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-51)function CategoryHandler.new(data, args)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-52)local obj = setmetatable({ _data = data, _args = args }, CategoryHandler)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-53)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-54)-- Set the title object[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-55)do[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-56)local pagename = obj:parameter('demopage')[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-57)local success, titleObj[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-58)if pagename then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-59)success, titleObj = pcall(mw.title.new, pagename)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-60)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-61)if success and titleObj then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-62)obj.title = titleObj[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-63)if titleObj == mw.title.getCurrentTitle() then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-64)obj._usesCurrentTitle = true[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-65)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-66)else[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-67)obj.title = mw.title.getCurrentTitle()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-68)obj._usesCurrentTitle = true[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-69)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-70)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-71)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-72)-- Set suppression parameter values[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-73)for _, key in ipairs{'nocat', 'categories'} do[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-74)local value = obj:parameter(key)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-75)value = trimWhitespace(value, true)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-76)obj['_' .. key] = yesno(value)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-77)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-78)do[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-79)local subpage = obj:parameter('subpage')[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-80)local category2 = obj:parameter('category2')[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-81)if type(subpage) == 'string' then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-82)subpage = mw.ustring.lower(subpage)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-83)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-84)if type(category2) == 'string' then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-85)subpage = mw.ustring.lower(category2)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-86)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-87)obj._subpage = trimWhitespace(subpage, true)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-88)obj._category2 = trimWhitespace(category2) -- don't remove blank values[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-89)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-90)return obj[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-91)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-92)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-93)function CategoryHandler:parameter(key)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-94)local parameterNames = self._data.parameters[key][](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-95)local pntype = type(parameterNames)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-96)if pntype == 'string' or pntype == 'number' then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-97)return self._args[parameterNames][](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-98)elseif pntype == 'table' then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-99)for _, name in ipairs(parameterNames) do[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-100)local value = self._args[name][](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-101)if value ~= nil then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-102)return value[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-103)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-104)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-105)return nil[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-106)else[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-107)error(string.format([](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-108)'invalid config key "%s"',[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-109)tostring(key)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-110)), 2)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-111)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-112)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-113)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-114)function CategoryHandler:isSuppressedByArguments()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-115)return[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-116)-- See if a category suppression argument has been set.[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-117)self._nocat == true[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-118)or self._categories == false[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-119)or ([](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-120)self._category2[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-121)and self._category2 ~= self._data.category2Yes[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-122)and self._category2 ~= self._data.category2Negative[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-123))[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-124)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-125)-- Check whether we are on a subpage, and see if categories are[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-126)-- suppressed based on our subpage status.[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-127)or self._subpage == self._data.subpageNo and self.title.isSubpage[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-128)or self._subpage == self._data.subpageOnly and not self.title.isSubpage[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-129)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-130)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-131)function CategoryHandler:shouldSkipBlacklistCheck()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-132)-- Check whether the category suppression arguments indicate we[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-133)-- should skip the blacklist check.[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-134)return self._nocat == false[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-135)or self._categories == true[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-136)or self._category2 == self._data.category2Yes[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-137)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-138)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-139)function CategoryHandler:matchesBlacklist()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-140)if self._usesCurrentTitle then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-141)return self._data.currentTitleMatchesBlacklist[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-142)else[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-143)mShared = mShared or require(['Module:Category handler/shared'](https://freemwiki.com/wiki/Module:Category_handler/shared))[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-144)return mShared.matchesBlacklist([](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-145)self.title.prefixedText,[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-146)mw.loadData(['Module:Category handler/blacklist'](https://freemwiki.com/wiki/Module:Category_handler/blacklist))[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-147))[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-148)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-149)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-150)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-151)function CategoryHandler:isSuppressed()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-152)-- Find if categories are suppressed by either the arguments or by[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-153)-- matching the blacklist.[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-154)return self:isSuppressedByArguments()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-155)or not self:shouldSkipBlacklistCheck() and self:matchesBlacklist()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-156)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-157)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-158)function CategoryHandler:getNamespaceParameters()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-159)if self._usesCurrentTitle then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-160)return self._data.currentTitleNamespaceParameters[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-161)else[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-162)if not mappings then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-163)mShared = mShared or require(['Module:Category handler/shared'](https://freemwiki.com/wiki/Module:Category_handler/shared))[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-164)mappings = mShared.getParamMappings(true) -- gets mappings with mw.loadData[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-165)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-166)return mShared.getNamespaceParameters([](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-167)self.title,[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-168)mappings[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-169))[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-170)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-171)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-172)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-173)function CategoryHandler:namespaceParametersExist()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-174)-- Find whether any namespace parameters have been specified.[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-175)-- We use the order "all" --> namespace params --> "other" as this is what[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-176)-- the old template did.[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-177)if self:parameter('all') then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-178)return true[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-179)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-180)if not mappings then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-181)mShared = mShared or require(['Module:Category handler/shared'](https://freemwiki.com/wiki/Module:Category_handler/shared))[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-182)mappings = mShared.getParamMappings(true) -- gets mappings with mw.loadData[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-183)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-184)for ns, params in pairs(mappings) do[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-185)for i, param in ipairs(params) do[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-186)if self._args[param] then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-187)return true[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-188)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-189)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-190)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-191)if self:parameter('other') then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-192)return true[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-193)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-194)return false[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-195)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-196)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-197)function CategoryHandler:getCategories()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-198)local params = self:getNamespaceParameters()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-199)local nsCategory[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-200)for i, param in ipairs(params) do[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-201)local value = self._args[param][](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-202)if value ~= nil then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-203)nsCategory = value[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-204)break[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-205)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-206)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-207)if nsCategory ~= nil or self:namespaceParametersExist() then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-208)-- Namespace parameters exist - advanced usage.[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-209)if nsCategory == nil then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-210)nsCategory = self:parameter('other')[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-211)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-212)local ret = {self:parameter('all')}[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-213)local numParam = tonumber(nsCategory)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-214)if numParam and numParam >= 1 and math.floor(numParam) == numParam then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-215)-- nsCategory is an integer[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-216)ret[#ret + 1] = self._args[numParam][](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-217)else[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-218)ret[#ret + 1] = nsCategory[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-219)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-220)if #ret < 1 then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-221)return nil[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-222)else[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-223)return table.concat(ret)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-224)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-225)elseif self._data.defaultNamespaces[self.title.namespace] then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-226)-- Namespace parameters don't exist, simple usage.[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-227)return self._args[1][](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-228)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-229)return nil[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-230)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-231)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-232)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-233)-- Exports[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-234)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-235)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-236)local p = {}[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-237)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-238)function p._exportClasses()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-239)-- Used for testing purposes.[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-240)return {[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-241)CategoryHandler = CategoryHandler[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-242)}[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-243)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-244)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-245)function p._main(args, data)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-246)data = data or mw.loadData(['Module:Category handler/data'](https://freemwiki.com/wiki/Module:Category_handler/data))[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-247)local handler = CategoryHandler.new(data, args)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-248)if handler:isSuppressed() then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-249)return nil[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-250)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-251)return handler:getCategories()[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-252)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-253)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-254)function p.main(frame, data)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-255)data = data or mw.loadData(['Module:Category handler/data'](https://freemwiki.com/wiki/Module:Category_handler/data))[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-256)local args = require(['Module:Arguments'](https://freemwiki.com/wiki/Module:Arguments)).getArgs(frame, {[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-257)wrappers = data.wrappers,[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-258)valueFunc = function (k, v)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-259)v = trimWhitespace(v)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-260)if type(k) == 'number' then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-261)if v ~= '' then[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-262)return v[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-263)else[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-264)return nil[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-265)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-266)else[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-267)return v[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-268)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-269)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-270)})[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-271)return p._main(args, data)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-272)end[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-273)[](https://freemwiki.com/index.php?oldid=580040&title=Module%3ACategory_handler#L-274)return p