Modul:Citiranje: razlika između inačica
Prijeđi na navigaciju
Prijeđi na pretraživanje
Stvorena nova stranica sa sadržajem: »local p = {} local function safe(v) if v == nil or v == "" then return nil end return mw.text.trim(v) end function p.knjiga(frame) local args = frame:getParent().args local last = safe(args.last) local first = safe(args.first) local author = safe(args.author) local authorlink = safe(args.authorlink) local year = safe(args.year) local month = safe(args.month) local date = safe(args.date) local title =...«. |
mNema sažetka uređivanja |
||
| Redak 1: | Redak 1: | ||
local p = {} | local p = {} | ||
-------------------------------------------------------------------- | |||
-- Utility | |||
-------------------------------------------------------------------- | |||
local function safe(v) | local function safe(v) | ||
if v | if not v or v == "" then return nil end | ||
return mw.text.trim(v) | return mw.text.trim(v) | ||
end | end | ||
function | local function join(list) | ||
local args = | return table.concat(list, "") | ||
end | |||
-------------------------------------------------------------------- | |||
-- Autor formatiranje (više autora) | |||
-------------------------------------------------------------------- | |||
local function formatAuthors(args) | |||
local authors = {} | |||
-- Ako postoji "author", koristi ga | |||
if safe(args.author) then | |||
table.insert(authors, args.author) | |||
end | |||
-- Ako postoji last/first | |||
if safe(args.last) then | |||
local name = args.last | |||
if safe(args.first) then | |||
name = name .. ", " .. args.first | |||
end | |||
table.insert(authors, name) | |||
end | |||
-- Author1, Author2, Author3... | |||
local i = 1 | |||
while args["author" .. i] do | |||
local a = safe(args["author" .. i]) | |||
if a then table.insert(authors, a) end | |||
i = i + 1 | |||
end | |||
-- Ako postoji authorlink | |||
if safe(args.authorlink) and authors[1] then | |||
authors[1] = string.format("[[%s|%s]]", args.authorlink, authors[1]) | |||
end | |||
if #authors == 0 then return nil end | |||
return table.concat(authors, "; ") | |||
end | |||
-------------------------------------------------------------------- | |||
-- Identifikatori (DOI, ISSN, OCLC, PMID) | |||
-------------------------------------------------------------------- | |||
local function formatIDs(args) | |||
local out = {} | local out = {} | ||
if safe(args.doi) then | |||
if | table.insert(out, " DOI: " .. args.doi) | ||
table.insert(out, | end | ||
if safe(args.issn) then | |||
if | table.insert(out, " ISSN " .. args.issn) | ||
end | |||
if safe(args.oclc) then | |||
table.insert(out, " OCLC " .. args.oclc) | |||
end | end | ||
if | if safe(args.pmid) then | ||
table.insert(out, " PMID " .. args.pmid) | |||
end | |||
if #out == 0 then return nil end | |||
return table.concat(out, ";") | |||
end | |||
-------------------------------------------------------------------- | |||
-- Datum | |||
-------------------------------------------------------------------- | |||
local function formatDate(args) | |||
if safe(args.date) then | |||
return " (" .. args.date .. ")" | |||
end | |||
if safe(args.year) then | |||
if safe(args.month) then | |||
return " (" .. args.month .. " " .. args.year .. ")" | |||
end | end | ||
return " (" .. args.year .. ")" | |||
end | |||
return nil | |||
end | |||
-------------------------------------------------------------------- | |||
-- Naslov (s URL-om) | |||
-------------------------------------------------------------------- | |||
local function formatTitle(args) | |||
local title = safe(args.title) or safe(args.Title) | |||
if not title then return nil end | |||
if safe(args.url) then | |||
return ". ''[" .. args.url .. " " .. title .. "]''" | |||
end | end | ||
-- | return ". ''" .. title .. "''" | ||
if | end | ||
-------------------------------------------------------------------- | |||
-- Glavni format citata | |||
-------------------------------------------------------------------- | |||
local function buildCitation(parts) | |||
local out = {} | |||
for _, v in ipairs(parts) do | |||
if v then table.insert(out, v) end | |||
end | end | ||
-- | table.insert(out, ".") -- završna točka | ||
if | |||
table.insert(out, " | return '<cite class="citation" style="font-style:normal">' .. | ||
table.concat(out, "") .. | |||
if | "</cite>" | ||
table.insert(out, " | end | ||
-------------------------------------------------------------------- | |||
-- FUNKCIJE ZA POJEDINE VRSTE IZVORA | |||
-------------------------------------------------------------------- | |||
------------------------- | |||
-- KNJIGA | |||
------------------------- | |||
function p.knjiga(frame) | |||
local args = frame:getParent().args | |||
local out = {} | |||
table.insert(out, formatAuthors(args)) | |||
table.insert(out, formatDate(args)) | |||
table.insert(out, formatTitle(args)) | |||
if safe(args.edition) then | |||
table.insert(out, ", " .. args.edition .. ". izd.") | |||
end | |||
if safe(args.publisher) then | |||
if safe(args.location) then | |||
table.insert(out, ", " .. args.location .. ": " .. args.publisher) | |||
else | else | ||
table.insert(out, " | table.insert(out, ", " .. args.publisher) | ||
end | end | ||
end | end | ||
-- | if safe(args.pages) then | ||
if | table.insert(out, ", str. " .. args.pages) | ||
table.insert(out, | end | ||
table.insert(out, formatIDs(args)) | |||
return buildCitation(out) | |||
end | |||
------------------------- | |||
-- WEB | |||
------------------------- | |||
function p.web(frame) | |||
local args = frame:getParent().args | |||
local out = {} | |||
table.insert(out, formatAuthors(args)) | |||
table.insert(out, formatDate(args)) | |||
table.insert(out, formatTitle(args)) | |||
if safe(args.website) then | |||
table.insert(out, ", " .. args.website) | |||
end | end | ||
- | if safe(args["access-date"]) then | ||
table.insert(out, " (pristupljeno " .. args["access-date"] .. ")") | |||
table.insert(out, ". | |||
end | end | ||
-- | table.insert(out, formatIDs(args)) | ||
if | |||
return buildCitation(out) | |||
end | |||
------------------------- | |||
-- ČASOPIS | |||
------------------------- | |||
function p.casopis(frame) | |||
local args = frame:getParent().args | |||
local out = {} | |||
table.insert(out, formatAuthors(args)) | |||
table.insert(out, formatDate(args)) | |||
table.insert(out, formatTitle(args)) | |||
if safe(args.journal) then | |||
table.insert(out, ", ''" .. args.journal .. "''") | |||
end | |||
if safe(args.volume) then | |||
table.insert(out, ", " .. args.volume) | |||
end | end | ||
if safe(args.issue) then | |||
if | table.insert(out, "(" .. args.issue .. ")") | ||
table.insert(out, " | |||
end | end | ||
if safe(args.pages) then | |||
if | table.insert(out, ", " .. args.pages) | ||
end | end | ||
-- | table.insert(out, formatIDs(args)) | ||
if | |||
table.insert(out, ", | return buildCitation(out) | ||
end | |||
------------------------- | |||
-- NOVINE | |||
------------------------- | |||
function p.novine(frame) | |||
local args = frame:getParent().args | |||
local out = {} | |||
table.insert(out, formatAuthors(args)) | |||
table.insert(out, formatDate(args)) | |||
table.insert(out, formatTitle(args)) | |||
if safe(args.newspaper) then | |||
table.insert(out, ", " .. args.newspaper) | |||
end | end | ||
-- | table.insert(out, formatIDs(args)) | ||
if | |||
table.insert(out, ", | return buildCitation(out) | ||
end | |||
------------------------- | |||
-- ENCIKLOPEDIJA | |||
------------------------- | |||
function p.enciklopedija(frame) | |||
local args = frame:getParent().args | |||
local out = {} | |||
table.insert(out, formatTitle(args)) | |||
if safe(args.encyclopedia) then | |||
table.insert(out, ", " .. args.encyclopedia) | |||
end | end | ||
- | if safe(args["access-date"]) then | ||
table.insert(out, " (pristupljeno " .. args["access-date"] .. ")") | |||
table.insert(out, ". " .. | |||
end | end | ||
table.insert(out, formatIDs(args)) | |||
table.insert(out, | |||
return buildCitation(out) | |||
end | |||
------------------------- | |||
-- OPĆI IZVOR | |||
------------------------- | |||
function p.izvor(frame) | |||
local args = frame:getParent().args | |||
local out = {} | |||
table.insert(out, formatAuthors(args)) | |||
table.insert(out, formatDate(args)) | |||
table.insert(out, formatTitle(args)) | |||
table.insert(out, formatIDs(args)) | |||
return buildCitation(out) | |||
end | end | ||
return p | return p | ||
Inačica od 12. siječanj 2026. u 12:17
Script error: The function "nonexistent" does not exist.
local p = {}
--------------------------------------------------------------------
-- Utility
--------------------------------------------------------------------
local function safe(v)
if not v or v == "" then return nil end
return mw.text.trim(v)
end
local function join(list)
return table.concat(list, "")
end
--------------------------------------------------------------------
-- Autor formatiranje (više autora)
--------------------------------------------------------------------
local function formatAuthors(args)
local authors = {}
-- Ako postoji "author", koristi ga
if safe(args.author) then
table.insert(authors, args.author)
end
-- Ako postoji last/first
if safe(args.last) then
local name = args.last
if safe(args.first) then
name = name .. ", " .. args.first
end
table.insert(authors, name)
end
-- Author1, Author2, Author3...
local i = 1
while args["author" .. i] do
local a = safe(args["author" .. i])
if a then table.insert(authors, a) end
i = i + 1
end
-- Ako postoji authorlink
if safe(args.authorlink) and authors[1] then
authors[1] = string.format("[[%s|%s]]", args.authorlink, authors[1])
end
if #authors == 0 then return nil end
return table.concat(authors, "; ")
end
--------------------------------------------------------------------
-- Identifikatori (DOI, ISSN, OCLC, PMID)
--------------------------------------------------------------------
local function formatIDs(args)
local out = {}
if safe(args.doi) then
table.insert(out, " DOI: " .. args.doi)
end
if safe(args.issn) then
table.insert(out, " ISSN " .. args.issn)
end
if safe(args.oclc) then
table.insert(out, " OCLC " .. args.oclc)
end
if safe(args.pmid) then
table.insert(out, " PMID " .. args.pmid)
end
if #out == 0 then return nil end
return table.concat(out, ";")
end
--------------------------------------------------------------------
-- Datum
--------------------------------------------------------------------
local function formatDate(args)
if safe(args.date) then
return " (" .. args.date .. ")"
end
if safe(args.year) then
if safe(args.month) then
return " (" .. args.month .. " " .. args.year .. ")"
end
return " (" .. args.year .. ")"
end
return nil
end
--------------------------------------------------------------------
-- Naslov (s URL-om)
--------------------------------------------------------------------
local function formatTitle(args)
local title = safe(args.title) or safe(args.Title)
if not title then return nil end
if safe(args.url) then
return ". ''[" .. args.url .. " " .. title .. "]''"
end
return ". ''" .. title .. "''"
end
--------------------------------------------------------------------
-- Glavni format citata
--------------------------------------------------------------------
local function buildCitation(parts)
local out = {}
for _, v in ipairs(parts) do
if v then table.insert(out, v) end
end
table.insert(out, ".") -- završna točka
return '<cite class="citation" style="font-style:normal">' ..
table.concat(out, "") ..
"</cite>"
end
--------------------------------------------------------------------
-- FUNKCIJE ZA POJEDINE VRSTE IZVORA
--------------------------------------------------------------------
-------------------------
-- KNJIGA
-------------------------
function p.knjiga(frame)
local args = frame:getParent().args
local out = {}
table.insert(out, formatAuthors(args))
table.insert(out, formatDate(args))
table.insert(out, formatTitle(args))
if safe(args.edition) then
table.insert(out, ", " .. args.edition .. ". izd.")
end
if safe(args.publisher) then
if safe(args.location) then
table.insert(out, ", " .. args.location .. ": " .. args.publisher)
else
table.insert(out, ", " .. args.publisher)
end
end
if safe(args.pages) then
table.insert(out, ", str. " .. args.pages)
end
table.insert(out, formatIDs(args))
return buildCitation(out)
end
-------------------------
-- WEB
-------------------------
function p.web(frame)
local args = frame:getParent().args
local out = {}
table.insert(out, formatAuthors(args))
table.insert(out, formatDate(args))
table.insert(out, formatTitle(args))
if safe(args.website) then
table.insert(out, ", " .. args.website)
end
if safe(args["access-date"]) then
table.insert(out, " (pristupljeno " .. args["access-date"] .. ")")
end
table.insert(out, formatIDs(args))
return buildCitation(out)
end
-------------------------
-- ČASOPIS
-------------------------
function p.casopis(frame)
local args = frame:getParent().args
local out = {}
table.insert(out, formatAuthors(args))
table.insert(out, formatDate(args))
table.insert(out, formatTitle(args))
if safe(args.journal) then
table.insert(out, ", ''" .. args.journal .. "''")
end
if safe(args.volume) then
table.insert(out, ", " .. args.volume)
end
if safe(args.issue) then
table.insert(out, "(" .. args.issue .. ")")
end
if safe(args.pages) then
table.insert(out, ", " .. args.pages)
end
table.insert(out, formatIDs(args))
return buildCitation(out)
end
-------------------------
-- NOVINE
-------------------------
function p.novine(frame)
local args = frame:getParent().args
local out = {}
table.insert(out, formatAuthors(args))
table.insert(out, formatDate(args))
table.insert(out, formatTitle(args))
if safe(args.newspaper) then
table.insert(out, ", " .. args.newspaper)
end
table.insert(out, formatIDs(args))
return buildCitation(out)
end
-------------------------
-- ENCIKLOPEDIJA
-------------------------
function p.enciklopedija(frame)
local args = frame:getParent().args
local out = {}
table.insert(out, formatTitle(args))
if safe(args.encyclopedia) then
table.insert(out, ", " .. args.encyclopedia)
end
if safe(args["access-date"]) then
table.insert(out, " (pristupljeno " .. args["access-date"] .. ")")
end
table.insert(out, formatIDs(args))
return buildCitation(out)
end
-------------------------
-- OPĆI IZVOR
-------------------------
function p.izvor(frame)
local args = frame:getParent().args
local out = {}
table.insert(out, formatAuthors(args))
table.insert(out, formatDate(args))
table.insert(out, formatTitle(args))
table.insert(out, formatIDs(args))
return buildCitation(out)
end
return p