Module:Infobox

local p = {} local utilsCode = require("Module:UtilsCode")

-- "fields" is structured as such: -- fields = {{caption = "", content = "", type = ""}, --        {caption = "", content = "", type = ""}, --        {caption = "", content = "", type = ""}} -- type can be "inline", "list", or "wide"

function p.CreateInfobox(name, image, fields) local result = mw.html.create("table") :addClass("infobox-table box") -- Name result:node(mw.html.create("tr")		:node(mw.html.create("th") :addClass("infobox-name") :attr("colspan", "2") :wikitext(name))) -- Image if not utilsCode.IsEmpty(image["content"]) then if string.sub(image["content"], 1, 5) == "File:" then local size = "" local imageFile = mw.title.new(image["content"]).file if imageFile.exists == true then if imageFile.width > imageFile.height then if imageFile.width > 300 then size = "300px" end else size = "x300px" end image["content"] = "" .. size .. "" else image["content"] = "" .. image["content"] .. "" end end result:node(mw.html.create("tr")		:node(mw.html.create("td") :addClass("infobox-image") :attr("colspan", "2") :wikitext(image["content"]))) if not utilsCode.IsEmpty(image["caption"]) then result:node(mw.html.create("tr")				:node(mw.html.create("td") :addClass("infobox-image-caption") :attr("colspan", "2") :wikitext(image["caption"]))) end end -- Other fields for key, field in ipairs(fields) do		if not utilsCode.IsEmpty(field["content"]) then -- row local row = mw.html.create("tr") :addClass("infobox-field") :addClass(field["type"]) -- caption local caption = mw.html.create("th") :addClass("infobox-field-caption") :wikitext(field["caption"]) -- content local content = mw.html.create("td") :addClass("infobox-field-content") :wikitext(field["content"]) -- if wide, we set colspan to 2 if field["type"] == "wide" then caption:attr("colspan", "2") content:attr("colspan", "2") row:node(caption) local row2 = mw.html.create("tr") :addClass("infobox-field wide") :node(content) result:node(row):node(row2) else result:node(row:node(caption):node(content)) end end end return result end

return p