Lua error in Modul:Dokumentacija at line 99: attempt to call upvalue 'getArgs' (a nil value).
require('strict')
local p = {}
-- Učitavamo konfiguraciju (date_names, id_handlers, whitelist...)
local cfg = require('Module:Citation/CS1/Configuration')
--------------------------------------------------------------------------------
-- POMOĆNE FUNKCIJE
--------------------------------------------------------------------------------
-- Vrati prvi ne-prazan parametar iz liste mogućih imena
local function getArg(args, names)
for _, name in ipairs(names) do
local val = args[name]
if type(val) == 'string' then
val = mw.text.trim(val)
if val ~= '' then
return val, name
end
end
end
return nil, nil
end
-- Omotaj tekst u wikitext kurziv
local function italic(text)
if not text or text == '' then
return nil
end
return "''" .. text .. "''"
end
-- Omotaj tekst u navodnike
local function quote(text)
if not text or text == '' then
return nil
end
-- hrvatski navodnici
return '„' .. text .. '“'
end
-- Spoji dijelove s razmacima, ignorirajući nil/prazno
local function joinWithSpace(parts)
local out = {}
for _, part in ipairs(parts) do
if part and part ~= '' then
table.insert(out, part)
end
end
return table.concat(out, ' ')
end
-- Spoji dijelove s točkom i razmakom, brinući o završnoj točki
local function joinSentences(parts)
local out = {}
for _, part in ipairs(parts) do
if part and part ~= '' then
-- Dodaj točku ako ne završava s točkom ili upitnikom ili uskličnikom
if not part:match('[%.%!%?]$') then
part = part .. '.'
end
table.insert(out, part)
end
end
return table.concat(out, ' ')
end
-- Formatiraj godinu/datum
local function formatDate(args)
-- podrška za |date= i |year=
local date = args['date']
local year = args['year']
if date and mw.text.trim(date) ~= '' then
return mw.text.trim(date)
end
if year and mw.text.trim(year) ~= '' then
return mw.text.trim(year)
end
return nil
end
-- Formatiraj autore (samo osnovno: author / author1 / author2 / author3)
local function formatAuthors(args)
local names = {}
local mainAuthor = getArg(args, {'author', 'last1', 'surname1'})
if mainAuthor then
table.insert(names, mainAuthor)
end
-- ostali autori
for i = 2, 9 do
local a = args['author' .. i] or args['last' .. i] or args['surname' .. i]
if a and mw.text.trim(a) ~= '' then
table.insert(names, mw.text.trim(a))
end
end
if #names == 0 then
return nil
end
if #names == 1 then
return names[1]
elseif #names == 2 then
return names[1] .. ' i ' .. names[2]
else
-- npr. "Ivić, Horvat i drugi"
local last = table.remove(names)
return table.concat(names, ', ') .. ' i ' .. last
end
end
-- Formatiraj identifikatore (ISBN, DOI, PMID...)
local function formatIds(args)
local parts = {}
for idName, handler in pairs(cfg.id_handlers or {}) do
local lower = idName:lower()
local val = args[lower] or args[idName]
if val and mw.text.trim(val) ~= '' then
val = mw.text.trim(val)
if handler.link then
table.insert(parts, string.format('%s: [%s %s]', idName, handler.link:gsub('$1', val), val))
else
table.insert(parts, string.format('%s: %s', idName, val))
end
end
end
if #parts == 0 then
return nil
end
return table.concat(parts, ' · ')
end
--------------------------------------------------------------------------------
-- GLAVNA FUNKCIJA
--------------------------------------------------------------------------------
function p.citation(frame)
local parent = frame:getParent()
local args = parent and parent.args or frame.args
-- Uzimamo standardne parametre
local authors = formatAuthors(args)
local title = getArg(args, {'title'})
local work = getArg(args, {'work', 'journal', 'website'})
local publisher = getArg(args, {'publisher'})
local date = formatDate(args)
local url = getArg(args, {'url'})
local accessDate = getArg(args, {'access-date', 'accessdate'})
local language = getArg(args, {'language', 'lang'})
local quoteText = getArg(args, {'quote'})
local idText = formatIds(args)
-- Dijelovi citata
local firstPart = {}
if authors then
table.insert(firstPart, authors)
end
if date then
-- godina/datum u zagradama
table.insert(firstPart, '(' .. date .. ')')
end
if title then
table.insert(firstPart, italic(title))
end
local mainLine = joinWithSpace(firstPart)
local secondParts = {}
if work then
table.insert(secondParts, italic(work))
end
if publisher then
table.insert(secondParts, publisher)
end
if language then
table.insert(secondParts, 'Na jeziku: ' .. language)
end
if idText then
table.insert(secondParts, idText)
end
local secondLine = joinWithSpace(secondParts)
local urlPart = nil
if url then
if accessDate then
urlPart = string.format('[%s %s] (pristupljeno %s)', url, url, accessDate)
else
urlPart = string.format('[%s %s]', url, url)
end
end
local quotePart = nil
if quoteText then
quotePart = quote(quoteText)
end
-- Sastavi sve "rečenice"
local sentences = {}
if mainLine ~= '' then
table.insert(sentences, mainLine)
end
if secondLine ~= '' then
table.insert(sentences, secondLine)
end
if urlPart then
table.insert(sentences, urlPart)
end
if quotePart then
table.insert(sentences, quotePart)
end
-- Ako baš ništa nema, vrati poruku
if #sentences == 0 then
return '<span class="error">Greška u citatu: nedostaju osnovni parametri (npr. title, url).</span>'
end
return joinSentences(sentences)
end
--------------------------------------------------------------------------------
-- EXPORT
--------------------------------------------------------------------------------
return {
citation = p.citation
}