local p = {}
local util = {}
local row = {}
local section = {}
local image = {}
local dates = {}
local normdata = {}
local paramMap = {
["ime"] = "ime",
["name"] = "ime",
["rođenje"] = "rodjenje",
["rodjenje"] = "rodjenje",
["mjesto rođenja"] = "mjesto_rodjenja",
["mjesto_rodjenja"] = "mjesto_rodjenja",
["smrt"] = "smrt",
["mjesto smrti"] = "mjesto_smrti",
["mjesto_smrti"] = "mjesto_smrti",
["zanimanje"] = "zanimanje",
["nacionalnost"] = "nacionalnost",
["slika"] = "slika",
["opis slike"] = "opis_slike",
["opis_slike"] = "opis_slike",
["viaf"] = "viaf",
["eb"] = "eb"
}
local function normalizeArgs(args)
local out = {}
for k, v in pairs(args) do
local nk = paramMap[k] or k
out[nk] = v
end
return out
end
function util.isEmpty(v)
return v == nil or v == '' or mw.text.trim(v) == ''
end
function util.showIf(label, value)
if util.isEmpty(value) then
return ''
end
return row.render(label, value)
end
function row.render(label, value)
return string.format(
'<tr><th>%s</th><td>%s</td></tr>',
label,
value
)
end
function p.renderHeader(args)
local name = args.ime or args.name or mw.title.getCurrentTitle().text
return string.format(
'<tr class="infobox-header"><th colspan="2">%s</th></tr>',
name
)
end
function image.render(args)
if util.isEmpty(args.slika) then
return ''
end
local caption = args.opis_slike or ''
return string.format(
'<tr><td colspan="2" class="infobox-image">%s<div class="infobox-caption">%s</div></td></tr>',
args.slika,
caption
)
end
function dates.format(date)
if util.isEmpty(date) then return '' end
-- ISO format → odmah vrati
if date:match("^%d%d%d%d%-%d%d%-%d%d$") then
return mw.getContentLanguage():formatDate('j. F Y', date)
end
-- Format: 1.7.1980 ili 01.07.1980
local d, m, y = date:match("^(%d%d?)%.(%d%d?)%.(%d%d%d%d)$")
if d and m and y then
return mw.getContentLanguage():formatDate('j. F Y', string.format("%04d-%02d-%02d", y, m, d))
end
-- Format: 1/7/1980 ili 1-7-1980
d, m, y = date:match("^(%d%d?)[/%-](%d%d?)[/%-](%d%d%d%d)$")
if d and m and y then
return mw.getContentLanguage():formatDate('j. F Y', string.format("%04d-%02d-%02d", y, m, d))
end
-- Format: 1. srpnja 1980 (hrvatski mjeseci)
local mjeseci = {
["siječnja"]=1, ["veljače"]=2, ["ožujka"]=3, ["travnja"]=4,
["svibnja"]=5, ["lipnja"]=6, ["srpnja"]=7, ["kolovoza"]=8,
["rujna"]=9, ["listopada"]=10, ["studenoga"]=11, ["prosinca"]=12
}
d, m, y = date:match("^(%d%d?)%. (%a+) (%d%d%d%d)$")
if d and m and y and mjeseci[m] then
return mw.getContentLanguage():formatDate(
'j. F Y',
string.format("%04d-%02d-%02d", y, mjeseci[m], d)
)
end
-- fallback: pokušaj formatDate direktno
return mw.getContentLanguage():formatDate('j. F Y', date)
end
function util.linkPlace(text)
if util.isEmpty(text) then return '' end
-- ako već sadrži [[ ]] → ne diraj
if text:match("%[%[") then
return text
end
local parts = mw.text.split(text, ",")
for i, p in ipairs(parts) do
p = mw.text.trim(p)
parts[i] = string.format("[[%s]]", p)
end
return table.concat(parts, ", ")
end
function normdata.render(args)
local out = {}
if not util.isEmpty(args.viaf) then
table.insert(out, '[https://viaf.org/viaf/' .. args.viaf .. ' VIAF]')
end
if not util.isEmpty(args.eb) then
table.insert(out, '[https://enciklopedija.cc/EB/' .. args.eb .. ' EB]')
end
if #out == 0 then
return ''
end
return '<tr><th>Normativni nadzor</th><td>' .. table.concat(out, ' · ') .. '</td></tr>'
end
function p.render(args, mode)
local output = {}
table.insert(output, p.renderHeader(args))
table.insert(output, image.render(args))
table.insert(output, section.render(args, mode))
table.insert(output, normdata.render(args))
return table.concat(output, "\n")
end
function section.render(args, mode)
local out = {}
-- Osnovni biografski podatci
table.insert(out, util.showIf('Mjesto rođenja', util.linkPlace(args.mjesto_rodjenja)))
table.insert(out, util.showIf('Mjesto smrti', util.linkPlace(args.mjesto_smrti)))
table.insert(out, util.showIf('Smrt', dates.format(args.smrt)))
table.insert(out, util.showIf('Mjesto smrti', args.mjesto_smrti))
table.insert(out, util.showIf('Zanimanje', args.zanimanje))
table.insert(out, util.showIf('Nacionalnost', args.nacionalnost))
-- Proširenja
table.insert(out, util.showIf('Obrazovanje', args.obrazovanje))
table.insert(out, util.showIf('Poznata djela', args.djela))
table.insert(out, util.showIf('Nagrade', args.nagrade))
table.insert(out, util.showIf('Aktivno razdoblje', args.aktivno))
table.insert(out, util.showIf('Organizacije', args.organizacije))
return table.concat(out, "\n")
end
function p.biography(frame)
local raw = frame:getParent().args
local args = normalizeArgs(raw)
return p.render(args, "biography")
end
return p