Broken/Footnotes: razlika između inačica

Izvor: Hrvatska internetska enciklopedija
Prijeđi na navigaciju Prijeđi na pretraživanje
Bot: Automatski unos stranica
 
Nema sažetka uređivanja
Redak 1: Redak 1:
<!--'''Modul:Footnotes'''-->f = {
-- Modul:Harvard
args_default = {
-- Hrvatska verzija harvardskih citata (sfn, harvard, itd.)
bracket_left = "",
-- s osnovnom validacijom i tracking kategorijama
bracket_right = "",
bracket_year_left = "",
bracket_year_right = "",
postscript = "",
page = "",
pages = "",
location = "",
page_sep = ", str.&nbsp;",
pages_sep = ", str.&nbsp;",
ref = "",
P1 = "",
P2 = "",
P3 = "",
P4 = "",
P5 = ""
}
};


function trim( str )
require('strict')
if str == nil then
return nil;
end
str = str:match( "^%s*(.-)%s*$");
return str:gsub("%.$", "")
end   


function core( args )
local mHarv = {}
local result;


if args.P5 ~= "" then
-------------------------------------------------------------------------------
result = args.P1 .. ' et al. ' .. args.bracket_year_left .. args.P5 ..
-- KONFIGURACIJA
args.bracket_year_right;
-------------------------------------------------------------------------------
elseif args.P4 ~= "" then
result = args.P1 .. ', ' .. args.P2 .. ' i ' .. args.P3 .. ' ' ..
args.bracket_year_left .. args.P4 .. args.bracket_year_right;
elseif args.P3 ~= "" then
result = args.P1 .. ' i ' .. args.P2 .. ' ' .. args.bracket_year_left ..
args.P3 .. args.bracket_year_right;
else
result = trim( args.P1 .. ' ' .. args.bracket_year_left .. args.P2 ..
args.bracket_year_right )
end


if args.ref ~= 'none' then
local cfg = {
if args.ref ~= "" then
    -- skrivena kategorija za probleme
result = "[[#" .. mw.uri.anchorEncode(args.ref) .. "|" .. result .. "]]";
    cat_error = '[[Kategorija:Stranice s greškama u harvardskim citatima]]',
else
result = "[[#CITEREF" .. mw.uri.anchorEncode(args.P1 .. args.P2 .. args.P3 .. args.P4 .. args.P5) .. "|" .. result .. "]]";
end
end


if args.page ~= "" then
    -- maksimalan broj pozicijskih parametara (autori + godina)
result = result .. args.page_sep .. args.page;
    max_params = 5,
elseif args.pages ~= "" then
result = result .. args.pages_sep .. args.pages;
end     


if args.location ~= "" then
    -- minimalno: autor + godina
result = result .. ", " .. args.location;
    min_positional = 2,
end
}


result = args.bracket_left .. result .. args.bracket_right .. args.postscript;
-------------------------------------------------------------------------------
return result;
-- POMOĆNE FUNKCIJE
-------------------------------------------------------------------------------
 
local function trim(str)
    if not str then return '' end
    str = mw.text.trim(str)
    -- makni završnu točku da ne dupliramo
    return str:gsub('%.$', '')
end
 
local function is_set(v)
    return v ~= nil and trim(v) ~= ''
end
 
local function error_tag(msg)
    return string.format(
        '<span class="citation-error" style="color:#b00;">%s</span>',
        msg
    )
end
 
local function add_tracking()
    return cfg.cat_error
end
 
local function build_citeref_key(args)
    -- ENWIKI koristi sofisticiraniji algoritam; ovdje pojednostavljena verzija:
    -- spajamo autore i godinu bez razmaka
    local parts = {}
 
    if is_set(args.P1) then table.insert(parts, args.P1) end
    if is_set(args.P2) then table.insert(parts, args.P2) end
    if is_set(args.P3) then table.insert(parts, args.P3) end
    if is_set(args.P4) then table.insert(parts, args.P4) end
    if is_set(args.P5) then table.insert(parts, args.P5) end
 
    return table.concat(parts, '')
end
end


function f.harvard_core( frame )
-------------------------------------------------------------------------------
local args = {};
-- VALIDACIJA
local pframe = frame:getParent();
-------------------------------------------------------------------------------
 
local function validate_args(args)
    local errors = {}
 
    -- broj pozicijskih parametara
    local count = 0
    for i = 1, cfg.max_params do
        if is_set(args['P' .. i]) then
            count = count + 1
        end
    end


args.bracket_left = pframe.args.BracketLeft or "";
    if count < cfg.min_positional then
args.bracket_right = pframe.args.BracketRight or "";
        table.insert(errors, 'Premalo parametara: potrebno je barem ime autora i godina.')
args.bracket_year_left = pframe.args.BracketYearLeft or "";
    end
args.bracket_year_right = pframe.args.BracketYearRight or "";
args.postscript = pframe.args.Postscript or "";
if 'none' == args.postscript then
args.postscript = '';
end


args.page = pframe.args.Page or "";
    -- očekivanje da je jedan od parametara godina (P2 ili P3 ili P4 ili P5)
args.pages = pframe.args.Pages or "";
    -- (ne strogo, samo upozorenje ako su svi očito imena)
args.location = pframe.args.Location or "";
    -- ovo ostavljamo mekano – radije manje lažnih pozitivnih
args.page_sep = pframe.args.PageSep or "";
args.pages_sep = pframe.args.PagesSep or "";
args.ref = pframe.args.REF or "{{{REF}}}";
args.P1 = trim( pframe.args.P1 ) or "";
args.P2 = trim( pframe.args.P2 ) or "";
args.P3 = trim( pframe.args.P3 ) or "";
args.P4 = trim( pframe.args.P4 ) or "";
args.P5 = trim( pframe.args.P5 ) or "";


return core( args );
    return errors
end
end


function f.harvard_citation( frame )
local function format_errors(errors)
local args = f.args_default;
    if #errors == 0 then
pframe = frame:getParent();
        return ''
    end


args.bracket_left = "(";
    local out = {}
args.bracket_right = ")";
    for _, e in ipairs(errors) do
args.page = pframe.args.p or pframe.args.page or "";
        table.insert(out, '• ' .. e)
args.pages = pframe.args.pp or pframe.args.pages or "";
    end
args.location = pframe.args.loc or "";
args.ref = pframe.args.ref or pframe.args.Ref or "";
args.P1 = trim( pframe.args[1] ) or "";
args.P2 = trim( pframe.args[2] ) or "";
args.P3 = trim( pframe.args[3] ) or "";
args.P4 = trim( pframe.args[4] ) or "";
args.P5 = trim( pframe.args[5] ) or "";


return core( args );
    return error_tag(table.concat(out, '<br>')) .. add_tracking()
end
end


function f.harvard_citation_no_bracket( frame )
-------------------------------------------------------------------------------
local args = f.args_default;
-- JEZGRA FORMATIRANJA
pframe = frame:getParent();
-------------------------------------------------------------------------------
 
local function core(args)
    local result
 
    -- osnovni obrazac: autori + godina
    if is_set(args.P5) then
        -- P1 + " et al." + P5 (godina)
        result = args.P1 .. ' et al. ' ..
            args.bracket_year_left .. args.P5 .. args.bracket_year_right
    elseif is_set(args.P4) then
        -- P1, P2 i P3 + P4 (godina)
        result = args.P1 .. ', ' .. args.P2 .. ' i ' .. args.P3 .. ' ' ..
            args.bracket_year_left .. args.P4 .. args.bracket_year_right
    elseif is_set(args.P3) then
        -- P1 i P2 + P3 (godina)
        result = args.P1 .. ' i ' .. args.P2 .. ' ' ..
            args.bracket_year_left .. args.P3 .. args.bracket_year_right
    else
        -- P1 + P2
        result = trim(args.P1 .. ' ' .. args.bracket_year_left .. args.P2 .. args.bracket_year_right)
    end
 
    -- REF / CITEREF logika
    if args.ref ~= 'none' then
        if is_set(args.ref) then
            result = string.format('[[#%s|%s]]', mw.uri.anchorEncode(args.ref), result)
        else
            local key = build_citeref_key(args)
            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
 
    result = args.bracket_left .. result .. args.bracket_right .. (args.postscript or '')
 
    return result
end


args.page = pframe.args.p or pframe.args.page or "";
-------------------------------------------------------------------------------
args.pages = pframe.args.pp or pframe.args.pages or "";
-- DEFAULT ARGUMENTI
args.location = pframe.args.loc or "";
-------------------------------------------------------------------------------
args.ref = pframe.args.ref or pframe.args.Ref or "";
args.P1 = trim( pframe.args[1] ) or "";
args.P2 = trim( pframe.args[2] ) or "";
args.P3 = trim( pframe.args[3] ) or "";
args.P4 = trim( pframe.args[4] ) or "";
args.P5 = trim( pframe.args[5] ) or "";


return core( args );
local function default_args()
    return {
        bracket_left = '',
        bracket_right = '',
        bracket_year_left = '',
        bracket_year_right = '',
        postscript = '',
        page = '',
        pages = '',
        location = '',
        page_sep = ', str.&nbsp;',
        pages_sep = ', str.&nbsp;',
        ref = '',
        P1 = '',
        P2 = '',
        P3 = '',
        P4 = '',
        P5 = '',
    }
end
end


function f.sfn( frame )
-------------------------------------------------------------------------------
local args = f.args_default;
-- JAVNE FUNKCIJE
for k, v in pairs( frame.args ) do -- for {{sfnp}}, override default with values provided in the #invoke:
-------------------------------------------------------------------------------
args[k] = v;  
 
end
function mHarv.harvard_core(frame)
    local pframe = frame:getParent()
pframe = frame:getParent();
    local args = default_args()


args.postscript = pframe.args.postscript or pframe.args.ps or ".";
    args.bracket_left = pframe.args.BracketLeft or ''
if 'none' == args.postscript then
    args.bracket_right = pframe.args.BracketRight or ''
args.postscript = '';
    args.bracket_year_left = pframe.args.BracketYearLeft or ''
end
    args.bracket_year_right = pframe.args.BracketYearRight or ''
args.page = pframe.args.p or pframe.args.page or "";
    args.postscript = pframe.args.Postscript or ''
args.pages = pframe.args.pp or pframe.args.pages or "";
    if args.postscript == 'none' then
args.location = pframe.args.loc or "";
        args.postscript = ''
args.ref = pframe.args.ref or pframe.args.Ref or "";
    end
args.P1 = trim( pframe.args[1] ) or "";
args.P2 = trim( pframe.args[2] ) or "";
args.P3 = trim( pframe.args[3] ) or "";
args.P4 = trim( pframe.args[4] ) or "";
args.P5 = trim( pframe.args[5] ) or "";


local result = core( args );
    args.page = pframe.args.Page or ''
local name = "FOOTNOTE" .. args.P1 .. args.P2 ..  
    args.pages = pframe.args.Pages or ''
args.P3 .. args.P4 .. args.P5 .. args.page .. args.pages .. args.location;
    args.location = pframe.args.Location or ''
    args.page_sep = pframe.args.PageSep or args.page_sep
    args.pages_sep = pframe.args.PagesSep or args.pages_sep
    args.ref = pframe.args.REF or ''


result = frame:extensionTag{ name = "ref", args = {name=name}, content=result };
    args.P1 = trim(pframe.args.P1)
    args.P2 = trim(pframe.args.P2)
    args.P3 = trim(pframe.args.P3)
    args.P4 = trim(pframe.args.P4)
    args.P5 = trim(pframe.args.P5)


return result;
    local errors = validate_args(args)
    local base = core(args)
 
    return format_errors(errors) .. base
end
end


return f;
function mHarv.harvard_citation(frame)
    local pframe = frame:getParent()
    local args = default_args()
 
    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 ''
 
    args.P1 = trim(pframe.args[1])
    args.P2 = trim(pframe.args[2])
    args.P3 = trim(pframe.args[3])
    args.P4 = trim(pframe.args[4])
    args.P5 = trim(pframe.args[5])
 
    local errors = validate_args(args)
    local base = core(args)
 
    return format_errors(errors) .. base
end
 
function mHarv.harvard_citation_no_bracket(frame)
    local pframe = frame:getParent()
    local args = default_args()
 
    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 ''
 
    args.P1 = trim(pframe.args[1])
    args.P2 = trim(pframe.args[2])
    args.P3 = trim(pframe.args[3])
    args.P4 = trim(pframe.args[4])
    args.P5 = trim(pframe.args[5])
 
    local errors = validate_args(args)
    local base = core(args)
 
    return format_errors(errors) .. base
end
 
function mHarv.sfn(frame)
    local pframe = frame:getParent()
    local args = default_args()
 
    -- override s #invoke args
    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 ''
 
    args.P1 = trim(pframe.args[1])
    args.P2 = trim(pframe.args[2])
    args.P3 = trim(pframe.args[3])
    args.P4 = trim(pframe.args[4])
    args.P5 = trim(pframe.args[5])
 
    local errors = validate_args(args)
    local base = core(args)
 
    local name = 'FOOTNOTE' ..
        args.P1 .. args.P2 .. args.P3 .. args.P4 .. args.P5 ..
        args.page .. args.pages .. args.location
 
    local ref = frame:extensionTag{
        name = 'ref',
        args = { name = name },
        content = base
    }
 
    return format_errors(errors) .. ref
end
 
-- alias za main (ako netko pozove |main)
mHarv.main = mHarv.sfn
 
return mHarv

Inačica od 12. siječanj 2026. u 10:06

-- 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 = ,
   -- maksimalan broj pozicijskih parametara (autori + godina)
   max_params = 5,
   -- minimalno: autor + godina
   min_positional = 2,

}


-- POMOĆNE FUNKCIJE


local function trim(str)

   if not str then return  end
   str = mw.text.trim(str)
   -- makni završnu točku da ne dupliramo
   return str:gsub('%.$', )

end

local function is_set(v)

   return v ~= nil and trim(v) ~= 

end

local function error_tag(msg)

   return string.format(
       '%s',
       msg
   )

end

local function add_tracking()

   return cfg.cat_error

end

local function build_citeref_key(args)

   -- ENWIKI koristi sofisticiraniji algoritam; ovdje pojednostavljena verzija:
   -- spajamo autore i godinu bez razmaka
   local parts = {}
   if is_set(args.P1) then table.insert(parts, args.P1) end
   if is_set(args.P2) then table.insert(parts, args.P2) end
   if is_set(args.P3) then table.insert(parts, args.P3) end
   if is_set(args.P4) then table.insert(parts, args.P4) end
   if is_set(args.P5) then table.insert(parts, args.P5) end
   return table.concat(parts, )

end


-- VALIDACIJA


local function validate_args(args)

   local errors = {}
   -- broj pozicijskih parametara
   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
   -- očekivanje da je jedan od parametara godina (P2 ili P3 ili P4 ili P5)
   -- (ne strogo, samo upozorenje ako su svi očito imena)
   -- ovo ostavljamo mekano – radije manje lažnih pozitivnih
   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, '
')) .. add_tracking()

end


-- JEZGRA FORMATIRANJA


local function core(args)

   local result
   -- osnovni obrazac: autori + godina
   if is_set(args.P5) then
       -- P1 + " et al." + P5 (godina)
       result = args.P1 .. ' et al. ' ..
           args.bracket_year_left .. args.P5 .. args.bracket_year_right
   elseif is_set(args.P4) then
       -- P1, P2 i P3 + P4 (godina)
       result = args.P1 .. ', ' .. args.P2 .. ' i ' .. args.P3 .. ' ' ..
           args.bracket_year_left .. args.P4 .. args.bracket_year_right
   elseif is_set(args.P3) then
       -- P1 i P2 + P3 (godina)
       result = args.P1 .. ' i ' .. args.P2 .. ' ' ..
           args.bracket_year_left .. args.P3 .. args.bracket_year_right
   else
       -- P1 + P2
       result = trim(args.P1 .. ' ' .. args.bracket_year_left .. args.P2 .. args.bracket_year_right)
   end
   -- REF / CITEREF logika
   if args.ref ~= 'none' then
       if is_set(args.ref) then
           result = string.format('%s', mw.uri.anchorEncode(args.ref), result)
       else
           local key = build_citeref_key(args)
           result = string.format('%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
   result = args.bracket_left .. result .. args.bracket_right .. (args.postscript or )
   return result

end


-- DEFAULT ARGUMENTI


local function default_args()

   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


-- JAVNE FUNKCIJE


function mHarv.harvard_core(frame)

   local pframe = frame:getParent()
   local args = default_args()
   args.bracket_left = pframe.args.BracketLeft or 
   args.bracket_right = pframe.args.BracketRight or 
   args.bracket_year_left = pframe.args.BracketYearLeft or 
   args.bracket_year_right = pframe.args.BracketYearRight or 
   args.postscript = pframe.args.Postscript or 
   if args.postscript == 'none' then
       args.postscript = 
   end
   args.page = pframe.args.Page or 
   args.pages = pframe.args.Pages or 
   args.location = pframe.args.Location or 
   args.page_sep = pframe.args.PageSep or args.page_sep
   args.pages_sep = pframe.args.PagesSep or args.pages_sep
   args.ref = pframe.args.REF or 
   args.P1 = trim(pframe.args.P1)
   args.P2 = trim(pframe.args.P2)
   args.P3 = trim(pframe.args.P3)
   args.P4 = trim(pframe.args.P4)
   args.P5 = trim(pframe.args.P5)
   local errors = validate_args(args)
   local base = core(args)
   return format_errors(errors) .. base

end

function mHarv.harvard_citation(frame)

   local pframe = frame:getParent()
   local args = default_args()
   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 
   args.P1 = trim(pframe.args[1])
   args.P2 = trim(pframe.args[2])
   args.P3 = trim(pframe.args[3])
   args.P4 = trim(pframe.args[4])
   args.P5 = trim(pframe.args[5])
   local errors = validate_args(args)
   local base = core(args)
   return format_errors(errors) .. base

end

function mHarv.harvard_citation_no_bracket(frame)

   local pframe = frame:getParent()
   local args = default_args()
   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 
   args.P1 = trim(pframe.args[1])
   args.P2 = trim(pframe.args[2])
   args.P3 = trim(pframe.args[3])
   args.P4 = trim(pframe.args[4])
   args.P5 = trim(pframe.args[5])
   local errors = validate_args(args)
   local base = core(args)
   return format_errors(errors) .. base

end

function mHarv.sfn(frame)

   local pframe = frame:getParent()
   local args = default_args()
   -- override s #invoke args
   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 
   args.P1 = trim(pframe.args[1])
   args.P2 = trim(pframe.args[2])
   args.P3 = trim(pframe.args[3])
   args.P4 = trim(pframe.args[4])
   args.P5 = trim(pframe.args[5])
   local errors = validate_args(args)
   local base = core(args)
   local name = 'FOOTNOTE' ..
       args.P1 .. args.P2 .. args.P3 .. args.P4 .. args.P5 ..
       args.page .. args.pages .. args.location
   local ref = frame:extensionTag{
       name = 'ref',
       args = { name = name },
       content = base
   }
   return format_errors(errors) .. ref

end

-- alias za main (ako netko pozove |main) mHarv.main = mHarv.sfn

return mHarv