Title: Module:Namespace detect/data - freem URL Source: https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata Published Time: Sat, 27 Jun 2026 08:41:17 GMT Markdown Content: _Documentation for this module may be created at [Module:Namespace detect/data/doc](https://freemwiki.com/index.php?title=Module:Namespace\_detect/data/doc&action=edit&redlink=1 "Module:Namespace detect/data/doc (page does not exist)")_ [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-1)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-2)-- Namespace detect data --[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-3)-- This module holds data for [[[Module:Namespace detect]]](https://freemwiki.com/wiki/Module:Namespace_detect "Module:Namespace detect") to be loaded per --[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-4)-- page, rather than per #invoke, for performance reasons. --[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-5)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-6)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-7)local cfg = require(['Module:Namespace detect/config'](https://freemwiki.com/wiki/Module:Namespace_detect/config))[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-8)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-9)local function addKey(t, key, defaultKey)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-10)if key ~= defaultKey then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-11)t[#t + 1] = key[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-12)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-13)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-14)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-15)-- Get a table of parameters to query for each default parameter name.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-16)-- This allows wikis to customise parameter names in the cfg table while[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-17)-- ensuring that default parameter names will always work. The cfg table[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-18)-- values can be added as a string, or as an array of strings.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-19)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-20)local defaultKeys = {[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-21)'main',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-22)'talk',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-23)'other',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-24)'subjectns',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-25)'demospace',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-26)'demopage'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-27)}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-28)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-29)local argKeys = {}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-30)for i, defaultKey in ipairs(defaultKeys) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-31)argKeys[defaultKey] = {defaultKey}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-32)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-33)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-34)for defaultKey, t in pairs(argKeys) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-35)local cfgValue = cfg[defaultKey][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-36)local cfgValueType = type(cfgValue)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-37)if cfgValueType == 'string' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-38)addKey(t, cfgValue, defaultKey)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-39)elseif cfgValueType == 'table' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-40)for i, key in ipairs(cfgValue) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-41)addKey(t, key, defaultKey)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-42)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-43)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-44)cfg[defaultKey] = nil -- Free the cfg value as we don't need it any more.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-45)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-46)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-47)local function getParamMappings()[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-48)--[[[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-49) -- Returns a table of how parameter names map to namespace names. The keys[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-50) -- are the actual namespace names, in lower case, and the values are the[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-51) -- possible parameter names for that namespace, also in lower case. The[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-52) -- table entries are structured like this:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-53) -- {[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-54) -- [''] = {'main'},[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-55) -- ['wikipedia'] = {'wikipedia', 'project', 'wp'},[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-56) -- ...[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-57) -- }[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-58) --]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-59)local mappings = {}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-60)local mainNsName = mw.site.subjectNamespaces[0].name[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-61)mainNsName = mw.ustring.lower(mainNsName)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-62)mappings[mainNsName] = mw.clone(argKeys.main)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-63)mappings['talk'] = mw.clone(argKeys.talk)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-64)for nsid, ns in pairs(mw.site.subjectNamespaces) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-65)if nsid ~= 0 then -- Exclude main namespace.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-66)local nsname = mw.ustring.lower(ns.name)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-67)local canonicalName = mw.ustring.lower(ns.canonicalName)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-68)mappings[nsname] = {nsname}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-69)if canonicalName ~= nsname then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-70)table.insert(mappings[nsname], canonicalName)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-71)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-72)for _, alias in ipairs(ns.aliases) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-73)table.insert(mappings[nsname], mw.ustring.lower(alias))[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-74)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-75)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-76)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-77)return mappings[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-78)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-79)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-80)return {[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-81)argKeys = argKeys,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-82)cfg = cfg,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-83)mappings = getParamMappings()[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&title=Module%3ANamespace_detect%2Fdata#L-84)}