FANDOM


--<nowiki>
-- See the talk page for documentation.
 
local p = {}
 
--% This function is meant to be called with the names of the namespaces that pages can be categorized in.
--% It returns a function to be used to categorize pages, which accepts any number of category names.
function p.categorize_in_namespaces(...)
    local namespaces = {...}
    return function(...)
        local result = ''
        if mw.title.getCurrentTitle():inNamespaces(unpack(namespaces)) then
            for _, category in next, {...} do
                result = result .. "[[Category:" .. category .. "]]"
            end
        end
        return result
    end
end
 
--% This function can be called with any number of category names.
--% If the current page is in a content namespace, it returns a string with links to each of the categories. Otherwise, it returns an empty string.
--% The function is especially meant for templates that can be used on non-article pages, for example in the User namespace, and where such pages should not be added to article categories.
function p.categorize_if_content_page(...)
    local result = ""
    if mw.title.getCurrentTitle().isContentPage then
        for _, category in next, {...} do
            result = result .. "[[Category:" .. category .. "]]"
        end
    end
    return result
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.