Modul:Citation/CS1: razlika između inačica
Prijeđi na navigaciju
Prijeđi na pretraživanje
Nema sažetka uređivanja |
mNema sažetka uređivanja |
||
| Redak 256: | Redak 256: | ||
table.insert(parts, sentence({ | table.insert(parts, sentence({ | ||
formatAuthors(args), | |||
args.year and '(' .. args.year .. ')' or nil, | |||
italic(args.title), | |||
args.language and ('[jezik: ' .. args.language .. ']') or nil | |||
})) | })) | ||
| Redak 266: | Redak 267: | ||
util.join({args.location, args.publisher}, ': '), | util.join({args.location, args.publisher}, ': '), | ||
args.language and ('Na jeziku: ' .. args.language) or nil, | args.language and ('Na jeziku: ' .. args.language) or nil, | ||
args.isbn and ('ISBN ' .. args.isbn) or nil, | |||
formatIds(args) | formatIds(args) | ||
})) | })) | ||
Inačica od 18. siječanj 2026. u 10:19
Dokumentacija modula
Ovaj modul i njegovi pod-moduli podržavaju CS1 i CS2 stil citiranja. Ovaj modul nije namijenjen za direktno pozivanje, već ga je potrebno pozvati iz predloška koji ga koristi.
<section end=module_components_table />
<section begin=module_components_table /> Pod-moduli navedeni niže osiguravaju funkcionalnost predložaka za for CS1/2 stil citiranja:
| Pod-modul | Opis | |
|---|---|---|
| Gold padlock | Modul:Citation/CS1 | Odgovoran za prikazivanje i druge podržane funkcije |
| Modul:Citation/CS1/Configuration | Tablice prijevoda; Rukovanje pogreškama i identifikatorima | |
| Modul:Citation/CS1/Whitelist | Popis aktivnih i zastarjelih parametara za citiranje | |
| Modul:Citation/CS1/Date validation | Rukovanje oblicima datuma i validacija njihove točnosti | |
| Modul:Citation/CS1/Identifiers | Funkcije za rukovanje imenovanim identifikatorima (ISBN, DOI, PMID, i sl.) | |
| Modul:Citation/CS1/Utilities | Često korištene tablice i funkcije | |
| Modul:Citation/CS1/COinS | Funkcije koje stvaraju meta-podatke o citiranom CS1/2 izvoru | |
| Modul:Citation/CS1/styles.css | CSS stilovi primijenjeni na predloške za citiranje | |
| Silver padlock | Modul:Citation/CS1/Suggestions | Popias koji mapira česte netočno navedene parametre i dodjeljuje im ispravna imena |
-- Modul:Citation/CS1
-- Hrvatska, stabilna i pojednostavljena verzija CS1 sustava
require('strict')
local p = {}
local cfg = require('Module:Citation/CS1/Configuration')
local util = require('Module:Citation/CS1/Utilities')
local ids = require('Module:Citation/CS1/Identifiers')
local whitelist = require('Module:Citation/CS1/Whitelist')
local dateval = require('Module:Citation/CS1/Date_validation')
--------------------------------------------------------------------------------
-- POMOĆNE FUNKCIJE
--------------------------------------------------------------------------------
local function getArgs(frame)
return require('Module:Arguments').getArgs(frame)
end
local function clean(s)
if not s then return nil end
return mw.text.trim(s):gsub('[%.,;:]+$', '')
end
local function italic(s)
if not util.is_set(s) then return nil end
return "''" .. clean(s) .. "''"
end
local function quoted(s)
if not util.is_set(s) then return nil end
return '„' .. clean(s) .. '“'
end
local function sentence(parts)
local line = util.join(parts, ' ')
if not line or line == '' then return nil end
if not line:match('[%.%!%?]$') then
line = line .. '.'
end
return line
end
local function normalizeClass(args, frame)
local cls = args.CitationClass or args.type
if cls then
cls = mw.text.trim(cls):lower()
else
local title = frame:getTitle() or (frame:getParent() and frame:getParent():getTitle()) or ''
title = mw.ustring.lower(title)
if title:find('cite web', 1, true) then cls = 'web'
elseif title:find('cite book', 1, true) then cls = 'book'
elseif title:find('cite journal', 1, true) then cls = 'journal'
elseif title:find('citiranje knjige', 1, true) then cls = 'book'
elseif title:find('citiranje weba', 1, true) then cls = 'web'
elseif title:find('citiranje casopisa', 1, true) then cls = 'journal'
elseif title:find('citiranje novina', 1, true) then cls = 'newspaper'
elseif title:find('citiranje enciklopedije', 1, true) then cls = 'encyclopedia'
elseif title:find('citiranje zakona', 1, true) then cls = 'law'
elseif title:find('citiranje arhive', 1, true) then cls = 'archive'
elseif title:find('citiranje intervjua', 1, true) then cls = 'interview'
else cls = 'web'
end
end
if cls ~= 'web' and cls ~= 'book' and cls ~= 'journal' then
cls = 'web'
end
return cls
end
--------------------------------------------------------------------------------
-- HRVATSKI ALIAS PARAMETRI (ASCII-SAFE)
--------------------------------------------------------------------------------
local hr_aliases = {
autor = "author",
autor1 = "author1",
autor2 = "author2",
autor3 = "author3",
naslov = "title",
izdavac = "publisher",
mjesto = "location",
place = "location",
godina = "year",
stranica = "pages",
stranice = "pages",
urednik = "editor",
izdanje = "edition",
novine = "newspaper",
enciklopedija = "encyclopedia",
zakon = "law",
arhiva = "archive",
intervju = "interview",
}
--------------------------------------------------------------------------------
-- PROŠIRENI getArgs() S MAPIRANJEM HR PARAMETARA
--------------------------------------------------------------------------------
local function getArgs(frame)
local args = require('Module:Arguments').getArgs(frame)
-- mapiranje hrvatskih parametara
for hr, en in pairs(hr_aliases) do
if args[hr] and not args[en] then
args[en] = args[hr]
end
end
-- fallback: page → pages
if args.page and not args.pages then
args.pages = args.page
end
return args
end
--------------------------------------------------------------------------------
-- VALIDACIJA PARAMETARA (CS1-like)
--------------------------------------------------------------------------------
local function validateParams(args, cls)
local errors = {}
-- Nepoznati parametri
for k, v in pairs(args) do
if type(k) == 'string' and not whitelist.params[k] then
table.insert(errors, "Nepoznat parametar: <code>" .. k .. "</code>")
end
end
-- Obavezni parametri po klasi
for _, req in ipairs(cfg.required_params[cls] or {}) do
if not util.is_set(args[req]) then
table.insert(errors, "Nedostaje obavezni parametar: <code>" .. req .. "</code>")
end
end
-- Parametri koji ne pripadaju klasi
local allowed = {}
for _, p in ipairs(cfg.class_params[cls] or {}) do
allowed[p] = true
end
for k, v in pairs(args) do
if type(k) == 'string' and whitelist.params[k] and not allowed[k] then
table.insert(errors, "Parametar <code>" .. k .. "</code> nije dopušten u klasi <code>" .. cls .. "</code>")
end
end
-- Bare URL
if util.is_set(args.url) and not util.is_set(args.title) then
table.insert(errors, "Bare URL: nedostaje parametar <code>title</code>")
end
-- Prazni parametri
for k, v in pairs(args) do
if type(k) == 'string' and type(v) == 'string' and mw.text.trim(v) == '' then
table.insert(errors, "Prazan parametar: <code>" .. k .. "</code>")
end
end
return errors
end
--------------------------------------------------------------------------------
-- FORMATIRANJE IDENTIFIKATORA
--------------------------------------------------------------------------------
local function formatIds(args)
local out = {}
for id, _ in pairs(cfg.id_handlers or {}) do
local val = args[id:lower()] or args[id]
if util.is_set(val) then
table.insert(out, ids.format(id, val))
end
end
return util.join(out, ' · ')
end
--------------------------------------------------------------------------------
-- FORMATIRANJE AUTORA
--------------------------------------------------------------------------------
local function formatAuthors(args)
local list = {}
if util.is_set(args.author) then
table.insert(list, args.author)
end
for i = 1, 9 do
local a = args['author' .. i]
if util.is_set(a) then
table.insert(list, a)
end
end
if #list == 0 then return nil end
if #list == 1 then return list[1] end
if #list == 2 then return list[1] .. ' i ' .. list[2] end
local last = table.remove(list)
return table.concat(list, ', ') .. ' i ' .. last
end
--------------------------------------------------------------------------------
-- CITATION: WEB
--------------------------------------------------------------------------------
local function citeWeb(args)
local parts = {}
table.insert(parts, sentence({
formatAuthors(args),
args.date and '(' .. args.date .. ')' or nil,
italic(args.title)
}))
table.insert(parts, sentence({
italic(args.work),
args.publisher,
args.language and ('Na jeziku: ' .. args.language) or nil,
formatIds(args)
}))
if util.is_set(args.url) then
local url = '[' .. args.url .. ' ' .. args.url .. ']'
if util.is_set(args['access-date']) then
url = url .. ' (pristupljeno ' .. args['access-date'] .. ')'
end
table.insert(parts, sentence({url}))
end
if util.is_set(args.quote) then
table.insert(parts, sentence({quoted(args.quote)}))
end
return util.join(parts, ' ')
end
--------------------------------------------------------------------------------
-- CITATION: BOOK
--------------------------------------------------------------------------------
local function citeBook(args)
local parts = {}
table.insert(parts, sentence({
formatAuthors(args),
args.year and '(' .. args.year .. ')' or nil,
italic(args.title),
args.language and ('[jezik: ' .. args.language .. ']') or nil
}))
table.insert(parts, sentence({
args.editor and ('Uredio: ' .. args.editor) or nil,
args.edition and (args.edition .. ' izd.') or nil,
util.join({args.location, args.publisher}, ': '),
args.language and ('Na jeziku: ' .. args.language) or nil,
args.isbn and ('ISBN ' .. args.isbn) or nil,
formatIds(args)
}))
if util.is_set(args.url) then
local url = '[' .. args.url .. ' ' .. args.url .. ']'
if util.is_set(args['access-date']) then
url = url .. ' (pristupljeno ' .. args['access-date'] .. ')'
end
table.insert(parts, sentence({url}))
end
if util.is_set(args.quote) then
table.insert(parts, sentence({quoted(args.quote)}))
end
return util.join(parts, ' ')
end
--------------------------------------------------------------------------------
-- CITATION: JOURNAL
--------------------------------------------------------------------------------
local function citeJournal(args)
local parts = {}
table.insert(parts, sentence({
formatAuthors(args),
args.year and '(' .. args.year .. ')' or nil,
quoted(args.title)
}))
table.insert(parts, sentence({
italic(args.journal),
util.join({args.volume, args.issue and '(' .. args.issue .. ')' or nil}, ' '),
args.pages and ('str. ' .. args.pages) or nil,
args.language and ('Na jeziku: ' .. args.language) or nil,
formatIds(args)
}))
if util.is_set(args.url) then
local url = '[' .. args.url .. ' ' .. args.url .. ']'
if util.is_set(args['access-date']) then
url = url .. ' (pristupljeno ' .. args['access-date'] .. ')'
end
table.insert(parts, sentence({url}))
end
if util.is_set(args.quote) then
table.insert(parts, sentence({quoted(args.quote)}))
end
return util.join(parts, ' ')
end
local function citeNewspaper(args)
local parts = {}
table.insert(parts, sentence({
formatAuthors(args),
args.date or args.year,
quoted(args.title)
}))
table.insert(parts, sentence({
italic(args.newspaper),
args.publisher,
util.join({args.location}, ', '),
args.pages and ('str. ' .. args.pages) or nil,
formatIds(args)
}))
if util.is_set(args.url) then
local url = '[' .. args.url .. ' ' .. args.url .. ']'
if util.is_set(args['access-date']) then
url = url .. ' (pristupljeno ' .. args['access-date'] .. ')'
end
table.insert(parts, sentence({url}))
end
return util.join(parts, ' ')
end
local function citeEncyclopedia(args)
local parts = {}
table.insert(parts, sentence({
formatAuthors(args),
italic(args.title)
}))
table.insert(parts, sentence({
italic(args.encyclopedia),
args.volume,
args.edition and (args.edition .. '. izd.') or nil,
util.join({args.location, args.publisher}, ': '),
args.year,
args.pages and ('str. ' .. args.pages) or nil,
formatIds(args)
}))
return util.join(parts, ' ')
end
local function citeLaw(args)
local parts = {}
table.insert(parts, sentence({
italic(args.title),
args.law,
args.jurisdiction,
args.year or args.date
}))
table.insert(parts, sentence({
args.article and ('čl. ' .. args.article) or nil,
args.section and ('§ ' .. args.section) or nil,
args.chapter and ('pog. ' .. args.chapter) or nil,
args.publisher
}))
if util.is_set(args.url) then
local url = '[' .. args.url .. ' ' .. args.url .. ']'
table.insert(parts, sentence({url}))
end
return util.join(parts, ' ')
end
local function citeArchive(args)
local parts = {}
table.insert(parts, sentence({
formatAuthors(args),
italic(args.title),
args.year or args.date
}))
table.insert(parts, sentence({
args.archive,
args.collection,
util.join({args.location}, ', '),
args.identifier,
args.pages and ('str. ' .. args.pages) or nil
}))
return util.join(parts, ' ')
end
local function citeInterview(args)
local parts = {}
table.insert(parts, sentence({
args.interviewer and ('Intervju: ' .. args.interviewer) or nil,
formatAuthors(args),
quoted(args.title)
}))
table.insert(parts, sentence({
italic(args.program),
args.publisher,
args.location,
args.date or args.year
}))
if util.is_set(args.url) then
local url = '[' .. args.url .. ' ' .. args.url .. ']'
table.insert(parts, sentence({url}))
end
return util.join(parts, ' ')
end
--------------------------------------------------------------------------------
-- GLAVNA FUNKCIJA
--------------------------------------------------------------------------------
function p.citation(frame)
local args = getArgs(frame)
local cls = normalizeClass(args, frame)
-- Validacija
local errors = validateParams(args, cls)
if #errors > 0 then
local out = '<div class="citation-errors" style="color:#b00; font-size:90%;">'
for _, e in ipairs(errors) do
out = out .. '• ' .. e .. '<br>'
end
out = out .. '</div>'
return out
end
if cls == 'book' then
return citeBook(args)
elseif cls == 'journal' then
return citeJournal(args)
elseif cls == 'newspaper' then
return citeNewspaper(args)
elseif cls == 'encyclopedia' then
return citeEncyclopedia(args)
elseif cls == 'law' then
return citeLaw(args)
elseif cls == 'archive' then
return citeArchive(args)
elseif cls == 'interview' then
return citeInterview(args)
else
return citeWeb(args)
end
end
-- Alias za #invoke: ... |main
p.main = p.citation
return p