Jump to content

Module:R from fictional object multi

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gonnym (talk | contribs) at 13:56, 19 December 2019 (synced from sandbox). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local getArgs = require('Module:Arguments').getArgs

local categoryList = {
	["CATEGORY"] = "[[Category:%s %s %s]]",				-- Example: [[Category:Arrow (TV series) character redirect to lists]]
	["CATEGORY_SORT"] = "[[Category:%s %s %s|%s]]",		-- Example: [[Category:Arrow (TV series) character redirect to lists|sortKey]]
}

local p = {}

--[[
Local function which creates the relevent category, either with or without a sort key.
--]]
local function createCategory(name, objectType, suffix, sortKey)
	if (sortKey) then
		return string.format(categoryList["CATEGORY_SORT"], name, objectType, suffix, sortKey)
	else
		return string.format(categoryList["CATEGORY"], name, objectType, suffix)
	end
end

--[[
Local function which handles the main process.

Parameters:
	-- |1...8=		— required; Positional or numbered parameters for each series name.
	-- |sort=		— optinal; A sort key for the category.
--]]
local function _main(objectType, args)
	local suffix = "redirects to lists"
	-- Location categories are named differently for some reason.
	if (objectType == "location") then
		suffix = "redirects"
	end
	
	local categories = ""
	for i = 1, 10 do
		if (args[i]) then
			categories = categories .. createCategory(args[i], objectType, suffix, args["sort"])
		end
	end

	return categories
end

--[[
Entry point for character redirects.
--]]
function p.character(frame)
	local args = getArgs(frame)
	return _main("character", args)
end

--[[
Entry point for element redirects.
--]]
function p.element(frame)
	local args = getArgs(frame)
	return _main("element", args)
end

--[[
Entry point for location redirects.
--]]
function p.location(frame)
	local args = getArgs(frame)
	return _main("location", args)
end

return p