Modul:On this day

Iz Wikipedije, proste enciklopedije
Documentation icon Dokumentacija modula[predogled] [uredi] [zgodovina] [osveži]

Implements {{On this day}}

local p = {}

function p.countDates( frame )
    local args = frame:getParent().args
    local i = 1
    while true do
        local oldid = args['oldid' .. i] or ''
        if oldid == '' then
            return i - 1
        end
        i = i + 1
    end
end

function p.showDates( frame )
    local args = frame:getParent().args
    local i = 1
    local ret = {}
    local page = mw.title.getCurrentTitle().text
    local fmt = '[//sl.wikipedia.org/wiki/Wikipedija:Izbrane_obletnice/%s?oldid=%s %s]'
    if not args.demo then
        fmt = fmt .. '[[Kategorija:Izbrane obletnice (%s)|%s]]'
    end
    local lang = mw.getContentLanguage()

    while true do
        local date = args['date' .. i] or ''
        local oldid = args['oldid' .. i] or ''
        if oldid == '' then
            break
        end
        ret[i] = string.format( fmt,
            lang:formatDate('j._xg_Y', date ),
            oldid,
            lang:formatDate('\tj. xg Y', date ),
            lang:formatDate('F Y', date ),
            page
        )
        i = i + 1
    end

    i = #ret
    if i > 1 then
        ret[i] = ' in ' .. ret[i]
    end
    m = table.concat( ret, i > 2 and ', ' or ' ' )
    n = table.concat (ret, ', ', 1, i-1)
    if #ret > 2 then return n..ret[i] 
    elseif #ret < 3 then return m
   end
end

return p