Module:Archive

提供: VANGUARD FLIGHT wiki
移動先: 案内検索
Module:Archive (talk<dot-separator>edit<dot-separator>hist<dot-separator>links<dot-separator>doc<dot-separator>subpages<dot-separator>tests / results<dot-separator>sandbox<dot-separator>all modules)


This module outputs a list of archived subpages by year and month: see how it's used in Commons:Photography critiques.


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