Open main menu
Lua
CodeDiscussionEditHistoryLinksLink countNo test API Subpages:DocumentationTestsResultsSandboxLive code All modules

Module:Archive (talk · edit · hist · links · doc · subpages · tests / results · sandbox · all modules)
This module outputs a list of archived subpages by year and month: see how it's used in Commons:Photography critiques.

Code

local p = {}

function p.pages(frame)
    local title = mw.title.getCurrentTitle().fullText
    if frame.args.page ~= nil then title = frame.args.page end
    local lang = mw.language.new('en')
    local from_month = 1
    if frame.args.from_month ~= nil then from_month = tonumber(frame.args.from_month) end
    local from_year = 2006
    if frame.args.from_year ~= nil then from_year = tonumber(frame.args.from_year) end
    local d = os.date('*t')
    local to_month = d.month
    local to_year = d.year
    local str = {}
    local ts
    for year = from_year, to_year do
        table.insert( str, "*'''"..year..":''' " )
        for month = 1, 12 do
            if year~=from_year or month>=from_month then
                ts = table.concat( { year, month }, '-' )
                mmsg = lang:formatDate( 'F', ts )
                if mw.message.new( mmsg..' long' ):exists() then mmsg = mmsg..' long' end
                str[#str] = str[#str]..'[['..title..'/'..lang:formatDate( 'F Y', ts )..'|{{int:'..mmsg..'}}]]'
                if year==to_year and month==to_month then break end
                if month<12 then str[#str] = str[#str]..', ' end
            end
        end
    end
    return frame:preprocess( table.concat( str, '\n' ) )
end

return p