Modul:Harvard
Prijeđi na navigaciju
Prijeđi na pretraživanje
-- Modul:Harvard
local util = require('Module:Citation/CS1/Utilities')
local m = {}
local cfg = {
cat_error = '[[Kategorija:Grješke u citiranju]]',
max_params = 5,
min_positional = 2,
}
local function trim(s)
if not s then return '' end
return mw.text.trim(s):gsub('%.$','')
end
local function is_set(v)
return v ~= nil and v ~= ''
end
local function error_tag(msg)
return '<span class="citation-error" style="color:#b00;">' .. msg .. '</span>'
end
local function validate(args)
local errors = {}
local count = 0
for i = 1, cfg.max_params do
if is_set(args['P'..i]) then count = count + 1 end
end
if count < cfg.min_positional then
table.insert(errors, 'Premalo parametara: potrebno je barem ime autora i godina.')
end
return errors
end
local function format_errors(errors)
if #errors == 0 then return '' end
return error_tag(table.concat(errors, ' • ')) .. cfg.cat_error
end -- Ovdje je nedostajao ovaj 'end'
local function core(args)
-- 1) AUTORI I GODINA
local authors = {}
for i = 1, 5 do
local val = args['P'..i]
if is_set(val) and not tonumber(val) then
table.insert(authors, val)
end
end
local year = nil
for i = 1, 5 do
if tonumber(args['P'..i]) then
year = args['P'..i]
break
end
end
local author_text = ""
if util.format_authors then
author_text = util.format_authors(authors)
else
author_text = table.concat(authors, ', ')
end
local result = author_text or ''
if year then
result = result .. ' ' .. (args.bracket_year_left or '') .. year .. (args.bracket_year_right or '')
end
-- 2) CITEREF logika
if args.ref ~= 'none' then
local anchor = ""
if is_set(args.ref) then
anchor = mw.uri.anchorEncode(args.ref)
result = '[[' .. '#' .. anchor .. '|' .. result .. ']]'
elseif #authors > 0 and year then
local key = ""
if util.citeref_key then
key = util.citeref_key(authors, year)
else
key = table.concat(authors) .. year
end
anchor = mw.uri.anchorEncode(key)
result = '[[' .. '#CITEREF' .. anchor .. '|' .. result .. ']]'
end
end
-- 3) Stranice i lokacija
if is_set(args.page) then
result = result .. (args.page_sep or ', str. ') .. args.page
elseif is_set(args.pages) then
result = result .. (args.pages_sep or ', str. ') .. args.pages
end
if is_set(args.location) then
result = result .. ', ' .. args.location
end
return (args.bracket_left or '') .. result .. (args.bracket_right or '') .. (args.postscript or '')
end
function m.sfn(frame)
local pframe = frame:getParent()
local args = {
P1 = trim(pframe.args[1]),
P2 = trim(pframe.args[2]),
P3 = trim(pframe.args[3]),
P4 = trim(pframe.args[4]),
P5 = trim(pframe.args[5]),
page = pframe.args.p or pframe.args.page or '',
pages = pframe.args.pp or pframe.args.pages or '',
location = pframe.args.loc or '',
ref = pframe.args.ref or pframe.args.Ref or '',
postscript = pframe.args.postscript or pframe.args.ps or '.'
}
if args.postscript == 'none' then args.postscript = '' end
local content = core(args)
-- Najjednostavniji mogući ref tag bez kompliciranja s imenima
return frame:extensionTag{
name = 'ref',
content = content
}
end
-- Funkcija za harvardsko citiranje (bez fusnote)
function m.harvard_citation(frame)
local pframe = frame:getParent()
local args = {
bracket_left = '(',
bracket_right = ')',
page_sep = ', str. ',
pages_sep = ', str. ',
P1 = trim(pframe.args[1]),
P2 = trim(pframe.args[2]),
P3 = trim(pframe.args[3]),
P4 = trim(pframe.args[4]),
P5 = trim(pframe.args[5]),
page = pframe.args.p or pframe.args.page or '',
pages = pframe.args.pp or pframe.args.pages or '',
location = pframe.args.loc or '',
ref = pframe.args.ref or pframe.args.Ref or ''
}
return format_errors(validate(args)) .. core(args)
end
function m.main(frame)
return m.sfn(frame)
end
function m.nonexistent(frame)
return ""
end
return m