Module:R from fictional object multi/sandbox
Appearance
![]() | This is the module sandbox page for Module:R from fictional object multi (diff). See also the companion subpage for test cases (run). |
![]() | This module depends on the following other modules: |
Module:R from fictional object multi is used by {{R from fictional character}}, {{R from fictional element}} and {{R from fictional location}} to handle multiple series tagged with the same redirect.
Usage
{{#invoke:R from fictional object multi|main|category=|1=|2=|3=|4=|5=|6=|7=|8=|sort=}}
Parameter list
Parameter | Explanation |
---|---|
1...8
|
Positional or numbered parameters for each series name. |
category
|
The redirect category scheme to be used. |
sort
|
An optional sort key for the category. |
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