Modul:Harvard: razlika između inačica
Prijeđi na navigaciju
Prijeđi na pretraživanje
mNema sažetka uređivanja |
mNema sažetka uređivanja |
||
| Nisu prikazane 3 međuinačice | |||
| Redak 1: | Redak 1: | ||
-- Modul:Harvard | -- Modul:Harvard | ||
local util = require('Module:Citation/CS1/Utilities') | local util = require('Module:Citation/CS1/Utilities') | ||
local m = {} | local m = {} | ||
| Redak 15: | Redak 10: | ||
local function trim(s) | local function trim(s) | ||
return | if not s then return '' end | ||
return mw.text.trim(s):gsub('%.$','') | |||
end | end | ||
local function is_set(v) | local function is_set(v) | ||
return v ~= nil and | return v ~= nil and v ~= '' | ||
end | end | ||
| Redak 28: | Redak 24: | ||
local function validate(args) | local function validate(args) | ||
local errors = {} | local errors = {} | ||
local count = 0 | local count = 0 | ||
for i = 1, cfg.max_params do | for i = 1, cfg.max_params do | ||
if is_set(args['P'..i]) then count = count + 1 end | if is_set(args['P'..i]) then count = count + 1 end | ||
end | end | ||
if count < cfg.min_positional then | if count < cfg.min_positional then | ||
table.insert(errors, 'Premalo parametara: potrebno je barem ime autora i godina.') | table.insert(errors, 'Premalo parametara: potrebno je barem ime autora i godina.') | ||
end | end | ||
return errors | return errors | ||
end | end | ||
| Redak 43: | Redak 36: | ||
local function format_errors(errors) | local function format_errors(errors) | ||
if #errors == 0 then return '' end | if #errors == 0 then return '' end | ||
return error_tag(table.concat(errors, ' • ')) .. cfg.cat_error | |||
end -- Ovdje je nedostajao ovaj 'end' | |||
return error_tag(table.concat( | |||
end | |||
local function core(args) | local function core(args) | ||
-- 1) AUTORI I GODINA | -- 1) AUTORI I GODINA | ||
local authors = {} | 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 | local year = nil | ||
| Redak 61: | Redak 53: | ||
if tonumber(args['P'..i]) then | if tonumber(args['P'..i]) then | ||
year = args['P'..i] | year = args['P'..i] | ||
break | |||
end | end | ||
end | end | ||
local author_text = util.format_authors(authors) | 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 '' | local result = author_text or '' | ||
if year then | if year then | ||
result = result .. ' ' .. args.bracket_year_left .. year .. args.bracket_year_right | result = result .. ' ' .. (args.bracket_year_left or '') .. year .. (args.bracket_year_right or '') | ||
end | end | ||
-- 2) CITEREF logika | -- 2) CITEREF logika | ||
if args.ref ~= 'none' then | if args.ref ~= 'none' then | ||
local | local anchor = "" | ||
if is_set(args.ref) then | if is_set(args.ref) then | ||
anchor = mw.uri.anchorEncode(args.ref) | |||
result = '[[' .. '#' .. anchor .. '|' .. result .. ']]' | |||
result = | elseif #authors > 0 and year then | ||
elseif | local key = "" | ||
if util.citeref_key then | |||
key = util.citeref_key(authors, year) | |||
else | |||
result = | key = table.concat(authors) .. year | ||
end | |||
anchor = mw.uri.anchorEncode(key) | |||
result = '[[' .. '#CITEREF' .. anchor .. '|' .. result .. ']]' | |||
end | end | ||
end | end | ||
-- 3) | -- 3) Stranice i lokacija | ||
if is_set(args.page) then | if is_set(args.page) then | ||
result = result .. args.page_sep .. args.page | result = result .. (args.page_sep or ', str. ') .. args.page | ||
elseif is_set(args.pages) then | elseif is_set(args.pages) then | ||
result = result .. args.pages_sep .. args.pages | result = result .. (args.pages_sep or ', str. ') .. args.pages | ||
end | end | ||
if is_set(args.location) then | if is_set(args.location) then | ||
result = result .. ', ' .. args.location | result = result .. ', ' .. args.location | ||
end | end | ||
return args.bracket_left .. result .. args.bracket_right .. (args.postscript or '') | return (args.bracket_left or '') .. result .. (args.bracket_right or '') .. (args.postscript or '') | ||
end | 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 | local content = core(args) | ||
return { | |||
-- Najjednostavniji mogući ref tag bez kompliciranja s imenima | |||
return frame:extensionTag{ | |||
name = 'ref', | |||
content = content | |||
} | } | ||
end | end | ||
-- Funkcija za harvardsko citiranje (bez fusnote) | |||
function m.harvard_citation(frame) | function m.harvard_citation(frame) | ||
local pframe = frame:getParent() | local pframe = frame:getParent() | ||
local args = | 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) | |||
return format_errors( | |||
end | end | ||
function m.main(frame) | function m.main(frame) | ||
return m.sfn(frame) | return m.sfn(frame) | ||
end | |||
function m.nonexistent(frame) | |||
return "" | |||
end | end | ||
return m | return m | ||
Posljednja izmjena od 7. travanj 2026. u 12:10
-- 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