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 =...«.
 
Nema sažetka uređivanja
 
Nije prikazana jedna međuinačica
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
 
    -- 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
 
--------------------------------------------------------------------
-- Automatsko generiranje ID-a
--------------------------------------------------------------------
 
local function slugify(text)
    if not text then return nil end
    text = mw.ustring.lower(text)
 
    -- uklanjanje dijakritike
    text = mw.ustring.gsub(text, "č", "c")
    text = mw.ustring.gsub(text, "ć", "c")
    text = mw.ustring.gsub(text, "š", "s")
    text = mw.ustring.gsub(text, "ž", "z")
    text = mw.ustring.gsub(text, "đ", "dj")
 
    -- zamjena razmaka i nedozvoljenih znakova
    text = mw.ustring.gsub(text, "[^a-z0-9]+", "_")
 
    -- uklanjanje viška podvlaka
    text = mw.ustring.gsub(text, "_+", "_")
    text = mw.ustring.gsub(text, "^_", "")
    text = mw.ustring.gsub(text, "_$", "")
 
    return text
end


     local last = safe(args.last)
local function autoID(args)
    local first = safe(args.first)
    -- ako korisnik već ima ID → koristi njega
    local author = safe(args.author)
     if safe(args.id) or safe(args.doi) or safe(args.issn)
    local authorlink = safe(args.authorlink)
        or safe(args.oclc) or safe(args.pmid) then
        return nil
    end


    local last = safe(args.last) or safe(args.author)
     local year = safe(args.year)
     local year = safe(args.year)
     local month = safe(args.month)
     local title = safe(args.title) or safe(args.Title)
     local date = safe(args.date)
 
    if not last and not title then return nil end
 
    local parts = {}
 
    if last then table.insert(parts, slugify(last)) end
    if year then table.insert(parts, year) end
    if title then table.insert(parts, slugify(title)) end
 
    if #parts == 0 then return nil end
 
    return " ID: " .. table.concat(parts, "-")
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


     local title = safe(args.title or args.Title)
     return '<cite class="citation" style="font-style:normal">' ..
    local url = safe(args.url)
        table.concat(out, "") ..
        "</cite>"
end


    local location = safe(args.location)
--------------------------------------------------------------------
    local publisher = safe(args.publisher)
-- FUNKCIJE ZA POJEDINE VRSTE IZVORA
    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)


-------------------------
-- KNJIGA
-------------------------
function p.knjiga(frame)
    local args = frame:getParent().args
     local out = {}
     local out = {}


     -- Autor
     table.insert(out, formatAuthors(args))
     if author then
    table.insert(out, formatDate(args))
         table.insert(out, author)
    table.insert(out, formatTitle(args))
     elseif last then
 
         if authorlink then
     if safe(args.edition) then
             table.insert(out, string.format("[[%s|%s]]", authorlink, last))
         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, last)
             table.insert(out, ", " .. args.publisher)
        end
        if first then
            out[#out] = out[#out] .. ", " .. first
         end
         end
     end
     end


    -- Koautori
     if safe(args.pages) then
     if coauthors then
         table.insert(out, ", str. " .. args.pages)
         table.insert(out, ", " .. coauthors)
     end
     end


     -- Datum
     table.insert(out, formatIDs(args))
     if date then
     table.insert(out, autoID(args))
        table.insert(out, " (" .. date .. ")")
 
     elseif year then
 
        if month then
    return buildCitation(out)
            table.insert(out, " (" .. month .. " " .. year .. ")")
end
         else
 
            table.insert(out, " (" .. year .. ")")
-------------------------
        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


     -- Poglavlje
     if safe(args["access-date"]) then
    if chapter then
         table.insert(out, " (pristupljeno " .. args["access-date"] .. ")")
         table.insert(out, '. "' .. chapter .. '"')
     end
     end


     -- Urednik
     table.insert(out, formatIDs(args))
     if editor then
    table.insert(out, autoID(args))
         table.insert(out, ". Uredio " .. editor)
 
 
    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
     end


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


     return '<cite class="citation-book" style="font-style:normal">' ..
 
        table.concat(out, "") ..
     return buildCitation(out)
        "</cite>"
end
end


return p
return p

Posljednja izmjena od 12. siječanj 2026. u 12:21

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

--------------------------------------------------------------------
-- Automatsko generiranje ID-a
--------------------------------------------------------------------

local function slugify(text)
    if not text then return nil end
    text = mw.ustring.lower(text)

    -- uklanjanje dijakritike
    text = mw.ustring.gsub(text, "č", "c")
    text = mw.ustring.gsub(text, "ć", "c")
    text = mw.ustring.gsub(text, "š", "s")
    text = mw.ustring.gsub(text, "ž", "z")
    text = mw.ustring.gsub(text, "đ", "dj")

    -- zamjena razmaka i nedozvoljenih znakova
    text = mw.ustring.gsub(text, "[^a-z0-9]+", "_")

    -- uklanjanje viška podvlaka
    text = mw.ustring.gsub(text, "_+", "_")
    text = mw.ustring.gsub(text, "^_", "")
    text = mw.ustring.gsub(text, "_$", "")

    return text
end

local function autoID(args)
    -- ako korisnik već ima ID → koristi njega
    if safe(args.id) or safe(args.doi) or safe(args.issn)
        or safe(args.oclc) or safe(args.pmid) then
        return nil
    end

    local last = safe(args.last) or safe(args.author)
    local year = safe(args.year)
    local title = safe(args.title) or safe(args.Title)

    if not last and not title then return nil end

    local parts = {}

    if last then table.insert(parts, slugify(last)) end
    if year then table.insert(parts, year) end
    if title then table.insert(parts, slugify(title)) end

    if #parts == 0 then return nil end

    return " ID: " .. table.concat(parts, "-")
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))
    table.insert(out, autoID(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))
    table.insert(out, autoID(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))
    table.insert(out, autoID(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))
    table.insert(out, autoID(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))
    table.insert(out, autoID(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))
    table.insert(out, autoID(args))


    return buildCitation(out)
end

return p