Jump to content

Module:R from fictional object multi/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gonnym (talk | contribs) at 12:10, 19 December 2019. 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]]",
	["CATEGORY_SORT"] = "[[Category:%s %s %s|%s]]",
}

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.
--]]
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