For the need of editing the documentation page, see Module:Categorization/doc.

Description[edit source]

  • Module: Categorization
  • Author: Atvelonis, Rupuzioks
  • Description: Automatically adds categories to articles, using Lua tables to implement two associative arrays

Bases categorization on user input in the infobox. Module invoked per each infobox variable Does not affect the format of the input, so links are not automatically generated, etc. Multiple dictionaries are used to prevent behavior like "Category:Skyrim: Skyrim" and other issues Associative arrays are global to allow template invocation to call upon specific arrays; This solution is necessary to prevent very frequent interference between similarly named infobox inputs

Functionality[edit source]

At least two loops needed as gmatch will search whole table if just an if statement is in the loop body:

  • First loop iterates table (allows for multiple categories per infobox parameter)
  • Second loop (i) specifies which index in the table is being looked at, so that gmatch only focuses on that
  • Third and fourth loop (j) repeat that for the game

Using "mw.loadData" to load the data tables only once per page instead of once per invoke.

Usage[edit source]

{{#invoke:module name|module function name|frame.args[1]|frame.args[2]|frame.args[3]}}
  • module name will always be "Categorization"
  • module function name will always be "categorization" unless more functions will be added into the module.
  • frame.args[1] – a string is used to match any pattern in the "gameNames" data table to generate a category for a specific game; Online templates specify the string with a {{{dlc}}} parameter.
  • frame.args[2] – a string, usually called from the {{{race}}} or {{{gender}}} template parameters, is used to match any pattern in any other data table than the "gameNames" to generate a specific type category.
  • frame.args[3] – a data table name to decide what patterns to match in frame.args[2].
    • If the table name for the frame.args[3] is "articleType" then it only returns the generated categories, otherwise it will return a string called for a comparison in frame.args[2] and the generated categories. This is mostly for the Online categories to prevent behavior like "Category:Online,ESO Morrowind: Characters" if multiple dlc names are provided.

Examples[edit source]

{{#invoke:Categorization|categorization|Battlespire|{{{race}}}|characterRaces}}
{{#invoke:Categorization|categorization|{{{dlc}}}|{{{gender}}}|characterGenders}}
{{#invoke:Categorization|categorization|{{{dlc}}}|Characters|articleType}}
{{#invoke:Categorization|categorization|{{{dlc}}}|Map Image Needed|articleType}}

-- <nowiki>
local p = {}

function p.categorization(frame) -- The first parameter invoked in the template
    local game = frame.args[1] -- Second parameter
    local category = frame.args[2] -- Third parameter
    local dictionary = mw.loadData('Module:Categorization/Data')[frame.args[3]] -- To tell it which dictionary to use (allows global call)
    local gameNames = mw.loadData('Module:Categorization/Data').gameNames
    local categories = {}

    for categoryIndex, categoryValue in pairs(dictionary) do
        for i in category:gmatch(categoryIndex) do
            for gameIndex, gameValue in pairs(gameNames) do
                for j in game:gmatch(gameIndex) do
                    table.insert(categories, ("[[Category:%s: %s]]"):format(gameValue, categoryValue))
                end
            end
        end
    end
    if frame.args[3] == 'articleType' then
    	return table.concat(categories)
    else
    	return category .. table.concat(categories)
    end
end

return p
--</nowiki>
*Disclosure: Some of the links above are affiliate links, meaning, at no additional cost to you, Fandom will earn a commission if you click through and make a purchase. Community content is available under CC-BY-SA unless otherwise noted.