Modul:Harvard: razlika između inačica
Prijeđi na navigaciju
Prijeđi na pretraživanje
Stvorena nova stranica sa sadržajem: »-- Modul:Harvard -- Hrvatska verzija harvardskih citata (sfn, harvard, itd.) -- s osnovnom validacijom i tracking kategorijama require('strict') local mHarv = {} ------------------------------------------------------------------------------- -- KONFIGURACIJA ------------------------------------------------------------------------------- local cfg = { -- skrivena kategorija za probleme cat_error = '[[Kategorija:Stranice s greškama u har...«. |
Nema sažetka uređivanja |
||
| Redak 1: | Redak 1: | ||
-- Modul:Harvard | -- Modul:Harvard | ||
-- | -- Ujednačen stil s CS1 modulom (autori, godine, stranice, CITEREF) | ||
require('strict') | require('strict') | ||
local | local util = require('Module:Citation/CS1/Utilities') | ||
local m = {} | |||
local cfg = { | local cfg = { | ||
cat_error = '[[Kategorija:Greške u citiranju]]', | |||
cat_error = '[[Kategorija: | |||
max_params = 5, | max_params = 5, | ||
min_positional = 2, | min_positional = 2, | ||
} | } | ||
local function trim(s) | |||
return util.trim and util.trim(s) or (mw.text.trim(s or ''):gsub('%.$','')) | |||
local function trim( | |||
end | end | ||
| Redak 38: | Redak 23: | ||
local function error_tag(msg) | local function error_tag(msg) | ||
return | return '<span class="citation-error" style="color:#b00;">' .. msg .. '</span>' | ||
end | end | ||
local function | 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 | if is_set(args['P'..i]) then count = count + 1 end | ||
end | end | ||
| Redak 80: | Redak 37: | ||
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 | ||
| Redak 89: | Redak 42: | ||
local function format_errors(errors) | local function format_errors(errors) | ||
if #errors == 0 then | if #errors == 0 then return '' end | ||
local out = {} | local out = {} | ||
for _, e in ipairs(errors) do | for _, e in ipairs(errors) do | ||
table.insert(out, '• ' .. e) | table.insert(out, '• ' .. e) | ||
end | end | ||
return error_tag(table.concat(out, '<br>')) .. cfg.cat_error | |||
return error_tag(table.concat(out, '<br>')) .. | |||
end | end | ||
local function core(args) | |||
local authors = {} | |||
if is_set(args.P1) then table.insert(authors, args.P1) end | |||
if is_set(args.P2) and not tonumber(args.P2) then table.insert(authors, args.P2) end | |||
if is_set(args.P3) and not tonumber(args.P3) then table.insert(authors, args.P3) end | |||
local | local year = nil | ||
local result | for i = 1, 5 do | ||
if tonumber(args['P'..i]) then | |||
year = args['P'..i] | |||
end | |||
end | |||
local author_text = util.format_authors(authors) | |||
local result = author_text | |||
if year then | |||
if | result = result .. ' ' .. args.bracket_year_left .. year .. args.bracket_year_right | ||
result = | |||
end | end | ||
-- | -- CITEREF | ||
if args.ref ~= 'none' then | if args.ref ~= 'none' then | ||
local key = util.citeref_key(authors, year) | |||
if is_set(args.ref) then | if is_set(args.ref) then | ||
result = string.format('[[#%s|%s]]', mw.uri.anchorEncode(args.ref), result) | result = string.format('[[#%s|%s]]', mw.uri.anchorEncode(args.ref), result) | ||
else | else | ||
result = string.format('[[#CITEREF%s|%s]]', mw.uri.anchorEncode(key), result) | result = string.format('[[#CITEREF%s|%s]]', mw.uri.anchorEncode(key), result) | ||
end | end | ||
| Redak 148: | Redak 92: | ||
end | end | ||
return args.bracket_left .. result .. args.bracket_right .. (args.postscript or '') | |||
end | end | ||
local function defaults() | |||
local function | |||
return { | return { | ||
bracket_left = '', | bracket_left = '', | ||
| Redak 178: | Redak 116: | ||
end | end | ||
function m.harvard_citation(frame) | |||
function | |||
local pframe = frame:getParent() | local pframe = frame:getParent() | ||
local args = | local args = defaults() | ||
args.bracket_left = '(' | args.bracket_left = '(' | ||
| Redak 226: | Redak 128: | ||
args.ref = pframe.args.ref or pframe.args.Ref or '' | args.ref = pframe.args.ref or pframe.args.Ref or '' | ||
for i = 1, 5 do | |||
args['P'..i] = trim(pframe.args[i]) | |||
end | |||
return format_errors(errors) .. | local errors = validate(args) | ||
return format_errors(errors) .. core(args) | |||
end | end | ||
function | function m.harvard_citation_no_bracket(frame) | ||
local pframe = frame:getParent() | local pframe = frame:getParent() | ||
local args = | local args = defaults() | ||
args.page = pframe.args.p or pframe.args.page or '' | args.page = pframe.args.p or pframe.args.page or '' | ||
| Redak 247: | Redak 145: | ||
args.ref = pframe.args.ref or pframe.args.Ref or '' | args.ref = pframe.args.ref or pframe.args.Ref or '' | ||
for i = 1, 5 do | |||
args['P'..i] = trim(pframe.args[i]) | |||
end | |||
local errors = | local errors = validate(args) | ||
return format_errors(errors) .. core(args) | |||
return format_errors(errors) .. | |||
end | end | ||
function | function m.sfn(frame) | ||
local pframe = frame:getParent() | local pframe = frame:getParent() | ||
local args = | local args = defaults() | ||
for k, v in pairs(frame.args) do | for k, v in pairs(frame.args) do | ||
args[k] = v | args[k] = v | ||
| Redak 269: | Redak 162: | ||
args.postscript = pframe.args.postscript or pframe.args.ps or '.' | args.postscript = pframe.args.postscript or pframe.args.ps or '.' | ||
if args.postscript == 'none' then | if args.postscript == 'none' then args.postscript = '' end | ||
args.page = pframe.args.p or pframe.args.page or '' | args.page = pframe.args.p or pframe.args.page or '' | ||
| Redak 278: | Redak 169: | ||
args.ref = pframe.args.ref or pframe.args.Ref or '' | args.ref = pframe.args.ref or pframe.args.Ref or '' | ||
for i = 1, 5 do | |||
args['P'..i] = trim(pframe.args[i]) | |||
end | |||
local errors = | local errors = validate(args) | ||
local base = core(args) | local base = core(args) | ||
local | local authors = {} | ||
if is_set(args.P1) then table.insert(authors, args.P1) end | |||
args | if is_set(args.P2) and not tonumber(args.P2) then table.insert(authors, args.P2) end | ||
if is_set(args.P3) and not tonumber(args.P3) then table.insert(authors, args.P3) end | |||
local year = nil | |||
for i = 1, 5 do | |||
if tonumber(args['P'..i]) then year = args['P'..i] end | |||
end | |||
local key = util.citeref_key(authors, year) | |||
local ref = frame:extensionTag{ | local ref = frame:extensionTag{ | ||
name = 'ref', | name = 'ref', | ||
args = { name = | args = { name = 'FOOTNOTE' .. key .. args.page .. args.pages .. args.location }, | ||
content = base | content = base | ||
} | } | ||
| Redak 300: | Redak 197: | ||
end | end | ||
m.main = m.sfn | |||
return | return m | ||
Inačica od 12. siječanj 2026. u 10:12
Script error: The function "nonexistent" does not exist.
-- Modul:Harvard
-- Ujednačen stil s CS1 modulom (autori, godine, stranice, CITEREF)
require('strict')
local util = require('Module:Citation/CS1/Utilities')
local m = {}
local cfg = {
cat_error = '[[Kategorija:Greške u citiranju]]',
max_params = 5,
min_positional = 2,
}
local function trim(s)
return util.trim and util.trim(s) or (mw.text.trim(s or ''):gsub('%.$',''))
end
local function is_set(v)
return v ~= nil and trim(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
local out = {}
for _, e in ipairs(errors) do
table.insert(out, '• ' .. e)
end
return error_tag(table.concat(out, '<br>')) .. cfg.cat_error
end
local function core(args)
local authors = {}
if is_set(args.P1) then table.insert(authors, args.P1) end
if is_set(args.P2) and not tonumber(args.P2) then table.insert(authors, args.P2) end
if is_set(args.P3) and not tonumber(args.P3) then table.insert(authors, args.P3) end
local year = nil
for i = 1, 5 do
if tonumber(args['P'..i]) then
year = args['P'..i]
end
end
local author_text = util.format_authors(authors)
local result = author_text
if year then
result = result .. ' ' .. args.bracket_year_left .. year .. args.bracket_year_right
end
-- CITEREF
if args.ref ~= 'none' then
local key = util.citeref_key(authors, year)
if is_set(args.ref) then
result = string.format('[[#%s|%s]]', mw.uri.anchorEncode(args.ref), result)
else
result = string.format('[[#CITEREF%s|%s]]', mw.uri.anchorEncode(key), result)
end
end
-- stranice
if is_set(args.page) then
result = result .. args.page_sep .. args.page
elseif is_set(args.pages) then
result = result .. args.pages_sep .. args.pages
end
-- lokacija
if is_set(args.location) then
result = result .. ', ' .. args.location
end
return args.bracket_left .. result .. args.bracket_right .. (args.postscript or '')
end
local function defaults()
return {
bracket_left = '',
bracket_right = '',
bracket_year_left = '',
bracket_year_right = '',
postscript = '',
page = '',
pages = '',
location = '',
page_sep = ', str. ',
pages_sep = ', str. ',
ref = '',
P1 = '',
P2 = '',
P3 = '',
P4 = '',
P5 = '',
}
end
function m.harvard_citation(frame)
local pframe = frame:getParent()
local args = defaults()
args.bracket_left = '('
args.bracket_right = ')'
args.page = pframe.args.p or pframe.args.page or ''
args.pages = pframe.args.pp or pframe.args.pages or ''
args.location = pframe.args.loc or ''
args.ref = pframe.args.ref or pframe.args.Ref or ''
for i = 1, 5 do
args['P'..i] = trim(pframe.args[i])
end
local errors = validate(args)
return format_errors(errors) .. core(args)
end
function m.harvard_citation_no_bracket(frame)
local pframe = frame:getParent()
local args = defaults()
args.page = pframe.args.p or pframe.args.page or ''
args.pages = pframe.args.pp or pframe.args.pages or ''
args.location = pframe.args.loc or ''
args.ref = pframe.args.ref or pframe.args.Ref or ''
for i = 1, 5 do
args['P'..i] = trim(pframe.args[i])
end
local errors = validate(args)
return format_errors(errors) .. core(args)
end
function m.sfn(frame)
local pframe = frame:getParent()
local args = defaults()
for k, v in pairs(frame.args) do
args[k] = v
end
args.postscript = pframe.args.postscript or pframe.args.ps or '.'
if args.postscript == 'none' then args.postscript = '' end
args.page = pframe.args.p or pframe.args.page or ''
args.pages = pframe.args.pp or pframe.args.pages or ''
args.location = pframe.args.loc or ''
args.ref = pframe.args.ref or pframe.args.Ref or ''
for i = 1, 5 do
args['P'..i] = trim(pframe.args[i])
end
local errors = validate(args)
local base = core(args)
local authors = {}
if is_set(args.P1) then table.insert(authors, args.P1) end
if is_set(args.P2) and not tonumber(args.P2) then table.insert(authors, args.P2) end
if is_set(args.P3) and not tonumber(args.P3) then table.insert(authors, args.P3) end
local year = nil
for i = 1, 5 do
if tonumber(args['P'..i]) then year = args['P'..i] end
end
local key = util.citeref_key(authors, year)
local ref = frame:extensionTag{
name = 'ref',
args = { name = 'FOOTNOTE' .. key .. args.page .. args.pages .. args.location },
content = base
}
return format_errors(errors) .. ref
end
m.main = m.sfn
return m