Modul:Infobox
Aspect

--
-- This module implements {{Infobox}}
--
local p = {}
local args = {}
p.infobox = function(frame)
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
else
origArgs = frame
end
local child = origArgs["child"] or "no"
local bodyclass = origArgs["bodyclass"] or "infocaseta"
local antet = origArgs["antet"] or "default"
local aboveclass = origArgs["aboveclass"] or antet
local abovestyle = origArgs["abovestyle"] or ""
local culoare_cadru = origArgs["culoare cadru"] or "F5F5DC"
local culoare_text = origArgs["culoare text"] or "000000"
local titlestyle = origArgs["titlestyle"] or ""
local title = origArgs["title"] or ""
local above = origArgs["above"] or ""
local out = ""
if child ~= "yes" then
out = out .. "<table class=\"" .. bodyclass .. "\" cellspacing=\"2\">"
-- caption
out = out .. "<tr><td colspan=\"2\" class=\"antet " .. aboveclass .. "\" style=\"background-color:#" .. culoare_cadru .. ";color:#" .. culoare_text .. ";" .. titlestyle .. "\">" .. title .. "</td></tr>"
-- header
if above ~= "" then
out = out .. "<tr><td colspan=\"2\" class=\"" .. aboveclass .. "\" style=\"text-align:center; font-size: 125%; font-weight: bold; " .. abovestyle .. "\">" .. above .. "</td></tr>"
end
else
if title ~= "" then
out = out .. "\'\'\'" .. title .. "\'\'\'"
end
end
--subheaders
local subheaders = {}
subheaders[1] = origArgs["subheader"] or origArgs["subheader1"] or ""
local subhIndex = 2
while (origArgs["subheader" .. tostring(subhIndex)] or "") ~= "" do
subheaders[subhIndex] = origArgs["subheader" .. tostring(subhIndex)] or ""
subhIndex = subhIndex + 1
end
local subheaderstyle = origArgs["subheaderstyle"] or ""
local subheaderclass = origArgs["subheaderclass"] or ""
for i = 1,#subheaders do
if subheaders[i] ~= "" then
out = out .. "<tr><td colspan=\"2\" class=\"" .. subheaderclass .. "\" style=\"text-align:center; " .. subheaderstyle .. "\">" .. subheaders[i] .. "</td></tr>"
end
end
--images
local images = {}
local captions = {}
images[1] = origArgs["image"] or ""
captions[1] = origArgs["caption"] or ""
local imgIndex = 2
while (origArgs["image" .. tostring(imgIndex)] or "") ~= "" do
images[imgIndex] = origArgs["image" .. tostring(imgIndex)]
captions[imgIndex] = origArgs["caption" .. tostring(imgIndex)] or ""
imgIndex = imgIndex + 1
end
local imageclass = origArgs["imageclass"] or ""
local imagestyle = origArgs["imagestyle"] or ""
local captionstyle = origArgs["captionstyle"] or ""
for i = 1,#images do
if images[i] ~= "" then
out = out .. "<tr><td colspan=\"2\" class=\"" .. imageclass .. "\" style=\"text-align:center; " .. imagestyle .. "\"> " .. images[i] .. " "
if captions[i] ~= "" then
out = out .. "<br /><span style=\"" .. captionstyle .. "\">" .. captions[i] .. "</span>"
end
out = out .. "</td></tr>"
end
end
-- rows
local labelstyle = origArgs["labelstyle"] or ""
local datastyle = origArgs["datastyle"] or ""
local elementIndex = 1
local headers = {}
local data = {}
local labels = {}
local classes = {}
local processingOrder = {}
for k,v in pairs(origArgs) do
local headerStart
local headerEnd
local labelStart
local labelEnd
local dataStart
local dataEnd
--mw.log('Processing arg ' .. k .. '=' .. v)
headerStart, headerEnd = mw.ustring.find(k, "header")
labelStart, labelEnd = mw.ustring.find(k, "label")
dataStart, dataEnd = mw.ustring.find(k, "data")
local nr = ""
if dataStart == 1 then
nr = mw.ustring.sub(k, 1 + dataEnd, mw.ustring.len(k))
elseif labelStart == 1 then
nr = mw.ustring.sub(k, 1 + labelEnd, mw.ustring.len(k))
elseif headerStart == 1 then
nr = mw.ustring.sub(k, 1 + headerEnd, mw.ustring.len(k))
end
--mw.log('Nr=' .. nr)
if nr ~= "" and processingOrder[nr] == nil and tonumber(nr) ~= nil then
headers[elementIndex] = origArgs["header" .. nr] or ""
labels[elementIndex] = origArgs["label" .. nr] or ""
data[elementIndex] = origArgs["data" .. nr] or ""
classes[elementIndex] = origArgs["class" .. nr] or ""
processingOrder[tonumber(nr)] = elementIndex
elementIndex = elementIndex + 1
end
end
--mw.logObject(data)
--mw.logObject(labels)
local processingElement = 1
while processingElement <= table.maxn(processingOrder) do
elementIndex = processingOrder[processingElement]
if elementIndex ~= nil then
local crtHeader = headers[elementIndex]
local crtData = data[elementIndex]
local crtLabel = labels[elementIndex]
local crtClass = classes[elementIndex]
if crtHeader ~= "" then
out = out .. "<tr><th colspan=\"2\" style=\"text-align:center; background-color:#" .. culoare_cadru .. ";color:#" .. culoare_text .. "\">" .. crtHeader .. "</th></tr>"
elseif crtLabel ~= "" then
if crtData ~= "" then
out = out .. "<tr><th style=\"" .. labelstyle .. "\">" .. crtLabel .. "</th><td class=\"" .. crtClass .. "\" style=\"" .. datastyle .. "\">" .. crtData .. "</td></tr>"
end
elseif crtData ~= "" then
out = out .. "<tr><td colspan=\"2\" class=\"" .. crtClass .. "\" style=\"text-align:center; " .. datastyle .. "\">" .. crtData .. "</td></tr>"
end
end
processingElement = processingElement + 1
end
--below
local belowstyle = origArgs["belowstyle"] or ""
local below = origArgs["below"] or ""
if below ~= "" then
out = out .. "<tr><td colspan=\"2\" style=\"text-align:center; " .. belowstyle .. "\">" .. below .. "</td></tr>"
end
--tnavbar
local name = origArgs["name"] or ""
if name ~= "" then
out = out .. "<tr><td style=\"text-align:right;\" colspan=\"2\">" .. mw.getCurrentFrame():expandTemplate{title = "Tnavbar", args = { name }} .. "</td></tr>"
end
if child ~= "yes" then
local doc = origArgs["doc"] or ""
if doc ~= "" then
out = out .. "<tr>" .. mw.getCurrentFrame():expandTemplate{title = "infodoc", args = {colspan = "2", culoare = culoare_cadru, link = doc }} .. "</tr>"
end
out = out .. "</table>"
end
return out
end
return p