---------------------------------------------------------------------------------- ---- This meta-module which automatically detects namespaces, and allows ---- for a great deal of customisation. It can easily be ported to other ---- wikis by changing the values in the . ---- ------------------------------------------------------------------------------------ Load config.local cfg = mw.loadData('Module:Pagetype/config')
-- Load required modules.local yesno = require('Module:Yesno')local p =
-- Look up a namespace argument in the args table.local function lookUpNamespaceArg(args, key) local arg = args[key] -- Convert "yes", "1" etc. to true, "no", "0" etc. to false, and leave -- other values the same. return yesno(arg, arg)end
-- Append multiple values to an arraylocal function appendMultiple(target, source) for _, value in ipairs(source) do table.insert(target, value) endend
-- Get argument keys for a title's namespacelocal function getNamespaceArgKeys(title) local nsInfo = mw.site.namespaces[title.namespace] local customAliases = cfg.customNamespaceAliases[title.namespace] or local keys = if nsInfo.name ~= then table.insert(keys, nsInfo.name) end if nsInfo.canonicalName ~= nsInfo.name and nsInfo.canonicalName ~= then table.insert(keys, nsInfo.canonicalName) end appendMultiple(keys, nsInfo.aliases) appendMultiple(keys, customAliases) return keysend
-- Get the argument for a title's namespace, if it was specified in the args table.local function getNamespaceArg(title, args) if title.isTalkPage then return lookUpNamespaceArg(args, cfg.talk) end for _, key in ipairs(getNamespaceArgKeys(title)) do local arg = lookUpNamespaceArg(args, mw.ustring.lower(key)) if arg ~= nil then return arg end end return nilend
-- Look up a page type specific to the title's namespacelocal function getExplicitPageType(title) if title.isTalkPage then return cfg.talkDefault else return cfg.pagetypes[title.namespace] endend
-- Get a default page type that is not specific to the title's namespacelocal function getDefaultPageType(args) local other = lookUpNamespaceArg(args, cfg.other) if type(other)
local function detectRedirects(title, args) local redirect = lookUpNamespaceArg(args, cfg.redirect) if redirect
-- Allow custom values for redirects. if not title.isRedirect then return nil elseif type(redirect)
local function capitalize(pageType) local first = mw.ustring.sub(pageType, 1, 1) local rest = mw.ustring.sub(pageType, 2) return mw.ustring.upper(first) .. restend
local function pluralize(pageType) if cfg.irregularPlurals[pageType] then return cfg.irregularPlurals[pageType] else return pageType .. cfg.plural -- often 's' endend
local function parseContent(title, args, optionsList) if title.namespace
nil then return nil end local templates -- lazily evaluated for _, options in next, optionsList do local list, parameter, default, articleOnly = unpack(options, 1, 4) if not articleOnly or title.namespace
"string" or (out ~= false and default) then -- ...and if we actually have anything to say about them if not templates then templates = -- do our delayed evaluation now that we are required to content = require('Module:Wikitext Parsing').PrepareText(content) -- disregard templates which do not have any affect for template in string.gmatch(content, "