Module:FileInfo/File Redirect

-- This was separated from Module:File and Module:FileInfo for job queue optimization -- See Guidelines:Modules local p = {}

local Data = mw.loadData("Module:FileInfo/Data")

local Franchise = require("Module:Franchise") local utilsArg = require("Module:UtilsArg") local utilsTable = require("Module:UtilsTable")

local CATEGORY_INVALID_ARGS = ""

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates["File Redirect"]) local categories = err and err.categoryText or ""

if not args.game and not args.type then categories = categories.."" end if args.game and not args.type then local utilsError = require("Module:UtilsError") utilsError.warn(" must be set when   is set.") categories = categories..CATEGORY_INVALID_ARGS end local gameName = args.game and Franchise.shortName(args.game) if gameName then categories = categories.."" end local type = args.type local typeCategory = Data.types[type] and Data.types[type].category if gameName and typeCategory then categories = categories..string.format("", gameName, typeCategory) end return categories end

p.Templates = { ["File Redirect"] = { purpose = "This template is added to file redirects to properly categorize them.", params = { [1] = {				name = "game", desc = "A game code.", type = "string", enum = Franchise.enum({ includeSeries = true }), trim = true, nilIfEmpty = true, },			[2] = {				name = "type", desc = "The file type. This should be set if  is set.", type = "string", enum = utilsTable.merge({ reference = "Module:FileInfo/Data" }, utilsTable.keys(Data.types)), trim = true, nilIfEmpty = true, },		},		examples = { {"MM", "Model"}, {},			{				desc = "Error handling", args = {"not a game", "Model"}, },			{"MM", "not a type"}, {"MM"}, },	} }

return p