FANDOM


-- <nowiki>
--------------------------------------------------------------------------------
-- Takes the name of a page, removes any leading or trailing whitespace, makes
-- it case-insensitive, and splits it into a prefix and root. If no prefix is
-- given, the canonical namespace name is used instead.
--------------------------------------------------------------------------------
local p = {}
 
-- Load dependencies
local checkType = require("libraryUtil").checkType
 
-- Reduce table lookups
local namespaces = mw.site.namespaces
local uLower = mw.ustring.lower
local lang = mw.getContentLanguage()
 
--------------------------------------------------------------------------------
-- Generic function to normalize the name of a page.
--------------------------------------------------------------------------------
local function normalize(name, nsNumber, ...)
    checkType("normalize", 1, name, "string")
    checkType("normalize", 2, nsNumber, "number")
 
    -- Generate a set of valid prefixes for a given namespace, `nsNumber`:
    -- `ns.canonicalName` is the canonical prefix
    -- `ns.name` is the prefix in your language
    -- `...` is an optional list of extra prefixes
    local ns = namespaces[nsNumber]
    local canonicalPrefix = ns.canonicalName
    local validPrefixes = {}
 
    for i, v in ipairs{canonicalPrefix, ns.name, ...} do
        if i > 2 then
            checkType("normalize", i, v, "string")
        end
 
        validPrefixes[uLower(v) .. ":"] = true
    end
 
    -- Split `name` into two parts:
    -- `prefix` - everything up to and including the first colon
    -- `root` - everything after `prefix`
    local prefix, root = mw.text.trim(name):match("^([^:]+:)(.+)$")
    prefix = uLower(prefix or "")
 
    -- Use the default prefix if `name` has none
    if not validPrefixes[prefix] then
        prefix = canonicalPrefix
        root = name
    end
 
    return lang:ucfirst(prefix), lang:ucfirst(root)
end
 
--------------------------------------------------------------------------------
-- Normalization for "Module:" pages.
--------------------------------------------------------------------------------
function p.module(name)
    return normalize(name, 828, "Dev")
end
 
return p
 
-- </nowiki>
-- (Add categories here.)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.