24,542
ARTICLES
ON THIS WIKI
ON THIS WIKI
Module:Infobox
This is the Lua module for Template:Infobox. Below is the documentation for that template. |
Parameters[edit]
-
name
: Mod name and infobox title. Should only be used if actual name differs from page title. Default:{{PAGENAME}}
. -
Box title
: Deprecated. Alternative name for{{{name}}}
. Only left in for backwards compatibility. -
img
: Image to display in the infobox (withoutFile:
or square brackets). A semicolon-separated file list may be given to cycle through multiple images. Replaces{{{image}}}
. Default: Hidden. -
image
: Deprecated. Alias for{{{img}}}
, only left in for backwards compatibility. -
imgwidth
: Width of the image/s. Ignored if{{{image}}}
is used. Default:Full width
. -
fullimage
: Deprecated. Image with full syntax, includingFile:
and square brackets. Replaced by{{{img}}}
and{{{imgwidth}}}
. -
caption
: Caption that appears under the image. May also be displayed if no image is present. Default: Hidden. -
rows
: Additional info rows besides Name. Consists of multiple {{Infobox/Row}}s, separated by single line breaks. Default: Hidden. Example|rows={{Infobox/Row|Mod|[[Equivalent Exchange 2]]}}{{Infobox/Row|Type|Mechanic}}
-
Row # title
: Deprecated. Titles for up to ten info rows, with # being the row number.{{{rows}}}
should be used instead. Default: Hidden (each row is treated separately). -
Row # info
: Deprecated. Info for up to ten info rows, with # being the row number.{{{rows}}}
should be used instead. Default: Hidden, respective info title will be centered instead (each row is treated separately).
local p = {}
local g = require("Module:Common")
-- returns MW code for an infobox header
function p.header(name, attrs)
if g.isGiven(name) then
return "|-\n! class=\"infobox-header\" colspan=\"2\" " .. (attrs or "") .. " | " .. name .. "\n"
else
return ""
end
end
-- wrapper for p.header, can be called from MW code
function p.mainHeader(frame)
local frame, args = g.getFrameAndArgs(frame)
return p.header(args[1], args[2])
end
-- returns MW code for one infobox row, must be used inside a 2 column wikitable
function p.row(name, value, nameattrs, valueattrs)
local r = ""
if (g.isGiven(name) or g.isGiven(value)) and value ~= "nil" then
if g.isGiven(value) then
r = r .. "|- class=\"infobox-inforow\"\n| class=\"infobox-infoname\" " .. (nameattrs or "")
else
r = r .. "|- \n| colspan=\"2\" class=\"infobox-centertext\" " .. (nameattrs or "")
end
r = r .. " | " .. (name or "")
if g.isGiven(value) then
r = r .. " || class=\"infobox-infovalue\" " .. (valueattrs or "") .. " | " .. value
end
r = r .. "\n"
end
return r
end
-- wrapper for p.row, can be called from MW code
function p.mainRow(frame)
local frame, args = g.getFrameAndArgs(frame)
return p.row(args[1], args[2], args[3], args[4])
end
function p.mainRowTest(frame)
local s = ""
local frame, args = g.getFrameAndArgs(frame)
s = s .. "frame\n"
for k, v in pairs(frame) do
s = s .. tostring(k) .. "=" .. tostring(v) .. "\n"
end
s = s .. "frame.args\n"
for k, v in pairs(frame.args) do
s = s .. tostring(k) .. "=" .. tostring(v) .. "\n"
end
s = s .. "args\n"
for k, v in pairs(args) do
s = s .. tostring(k) .. "=" .. tostring(v) .. "\n"
end
return s .. p.row(unpack(args, 1, 4))
end
-- condaitional variant of p.row
-- returns regular row if value is given
-- if given value is blank it is replaced by default
-- if default is also not given an empty string is returned
function p.condRow(name, value, default)
if g.isGiven(value) then
return p.row(name, value)
elseif g.isGiven(default) then
return p.row(name, default)
else
return ""
end
end
-- wrapper for p.infobox, can be called from MW code
function p.main(frame)
local frame, args = g.getFrameAndArgs(frame)
local usesdeprecated = false
if g.isGiven(args.name) then
--
elseif g.isGiven(args["Box title"]) then
args.name = args["Box title"]
args["Box title"] = nil
usesdeprecated = true
else
args.name = tostring(mw.title.getCurrentTitle())
end
local r = "{| class=\"infobox\"\n"
r = r .. p.header(args.name, "class=\"infobox-header infobox-mainheader\"")
if not g.isGiven(args.img) then
args.img = args.image
args.image = nil
usesdeprecated = usesdeprecated or g.isGiven(args.image)
end
if g.isGiven(args.fullimage) then
usesdeprecated = true
end
local imgstr = ""
if g.isGiven(args.img) then
if string.find(args.img, ";") then
imgstr = g.anim(args.img, args.imgwidth)
else
if g.isGiven(args.imgwidth) then
imgstr = "[[File:" .. args.img .. "|" .. args.imgwidth
else
imgstr = "[[File:" .. args.img
end
imgstr = imgstr .. "|alt=" .. (args.name or args.img) .. "|hover=" .. (args.name or args.img) .. "|" .. (args.name or args.img) .. "]]"
end
elseif g.isGiven(args.fullimage) then
if string.find(args.fullimage, ";") then
imgstr = g.anim(args.fullimage, args.imgwidth)
else
imgstr = args.fullimage
end
end
if g.isGiven(imgstr) then
r = r .. p.row(imgstr, nil, "class=\"infobox-centertext infobox-image\"")
end
if g.isGiven(args.caption) then
r = r .. p.row(args.caption, nil, "class=\"infobox-centertext infobox-caption\"")
end
r = r .. p.row("Name", args.name)
for i = 1, 10 do
if g.isGiven(args["Row " .. i .. " title"]) or g.isGiven(args["Row " .. i .. " info"]) then
r = r .. p.row(args["Row " .. i .. " title"], args["Row " .. i .. " info"])
usesdeprecated = true
end
end
r = r .. (args.rows or "") .. "\n|}"
if usesdeprecated then
r = r .. "[[Category:Infoboxes with deprecated params]]"
end
return r
end
return p
View All FTB Twitter Feed
Discussion
To discuss the topics on this wiki, you can visit our community forums!