Modul:Citiranje: razlika između inačica

Izvor: Hrvatska internetska enciklopedija
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 == nil or v == "" then return nil end
     if not v or v == "" then return nil end
     return mw.text.trim(v)
     return mw.text.trim(v)
end
end


function p.knjiga(frame)
local function join(list)
     local args = frame:getParent().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


     local last = safe(args.last)
     -- Ako postoji authorlink
     local first = safe(args.first)
     if safe(args.authorlink) and authors[1] then
    local author = safe(args.author)
        authors[1] = string.format("[[%s|%s]]", args.authorlink, authors[1])
     local authorlink = safe(args.authorlink)
     end


     local year = safe(args.year)
     if #authors == 0 then return nil end
    local month = safe(args.month)
    local date = safe(args.date)


     local title = safe(args.title or args.Title)
     return table.concat(authors, "; ")
    local url = safe(args.url)
end


    local location = safe(args.location)
--------------------------------------------------------------------
    local publisher = safe(args.publisher)
-- Identifikatori (DOI, ISSN, OCLC, PMID)
    local pages = safe(args.pages)
--------------------------------------------------------------------
    local edition = safe(args.edition)
    local isbn = safe(args.isbn)
    local id = safe(args.id)
    local chapter = safe(args.chapter)
    local editor = safe(args.editor)
    local coauthors = safe(args.coauthors)


local function formatIDs(args)
     local out = {}
     local out = {}


     -- Autor
     if safe(args.doi) then
     if author then
        table.insert(out, " DOI: " .. args.doi)
         table.insert(out, author)
    end
     elseif last then
     if safe(args.issn) then
         if authorlink then
         table.insert(out, " ISSN " .. args.issn)
            table.insert(out, string.format("[[%s|%s]]", authorlink, last))
     end
        else
    if safe(args.oclc) then
            table.insert(out, last)
         table.insert(out, " OCLC " .. args.oclc)
         end
    end
         if first then
    if safe(args.pmid) then
             out[#out] = out[#out] .. ", " .. first
        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


     -- Koautori
     return ". ''" .. title .. "''"
     if coauthors then
end
        table.insert(out, ", " .. coauthors)
 
--------------------------------------------------------------------
-- 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


     -- Datum
     table.insert(out, ".") -- završna točka
     if date then
 
         table.insert(out, " (" .. date .. ")")
    return '<cite class="citation" style="font-style:normal">' ..
     elseif year then
        table.concat(out, "") ..
         if month then
        "</cite>"
             table.insert(out, " (" .. month .. " " .. year .. ")")
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, " (" .. year .. ")")
             table.insert(out, ", " .. args.publisher)
         end
         end
     end
     end


     -- Poglavlje
     if safe(args.pages) then
     if chapter then
        table.insert(out, ", str. " .. args.pages)
         table.insert(out, '. "' .. chapter .. '"')
    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


     -- Urednik
     if safe(args["access-date"]) then
    if editor then
         table.insert(out, " (pristupljeno " .. args["access-date"] .. ")")
         table.insert(out, ". Uredio " .. editor)
     end
     end


     -- Naslov
     table.insert(out, formatIDs(args))
     if title then
 
         if url then
    return buildCitation(out)
            table.insert(out, ". ''[" .. url .. " " .. title .. "]''")
end
         else
 
            table.insert(out, ". ''" .. title .. "''")
-------------------------
        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


    -- Izdanje
     if safe(args.issue) then
     if edition then
         table.insert(out, "(" .. args.issue .. ")")
         table.insert(out, ", " .. edition .. ". izd.")
     end
     end


    -- Lokacija + izdavač
     if safe(args.pages) then
     if publisher then
         table.insert(out, ", " .. args.pages)
        if location then
            table.insert(out, ", " .. location .. ": " .. publisher)
         else
            table.insert(out, ", " .. publisher)
        end
     end
     end


     -- Stranice
     table.insert(out, formatIDs(args))
     if pages then
 
         table.insert(out, ", str. " .. pages)
    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


     -- ISBN
     table.insert(out, formatIDs(args))
     if isbn then
 
         table.insert(out, ", ISBN " .. isbn)
    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


     -- ID
     if safe(args["access-date"]) then
    if id then
         table.insert(out, " (pristupljeno " .. args["access-date"] .. ")")
         table.insert(out, ". " .. id)
     end
     end


    -- Završna točka
     table.insert(out, formatIDs(args))
     table.insert(out, ".")
 
    return buildCitation(out)
end


     return '<cite class="citation-book" style="font-style:normal">' ..
-------------------------
        table.concat(out, "") ..
-- OPĆI IZVOR
        "</cite>"
-------------------------
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