Module:Item timeline by year

From Team Fortress Wiki
Revision as of 18:41, 19 April 2024 by Tark (talk | contribs) (Tark moved page Module:Item timeline list to Module:Item timeline by year without leaving a redirect)
Jump to: navigation, search

Usage

  • {{#invoke:Item timeline by year|list}} produces:
  • {{#invoke:Item timeline by year|list|12}} produces:
  • {{#invoke:Item timeline by year|list|1}} produces:
  • {{#invoke:Item timeline by year|list|9999}} produces:

local p = {}

-- Function to check if an article exists
function article_exists(article)
    local exists = mw.title.new(article)

    if exists and exists.exists then
        return true
    else
        return false
    end
end

-- Function to generate a fancy list :3
function p.generate(f)
    local startYear = 2007 -- Game release
    local currentYear = tonumber(os.date("%Y"))

    local output = {}
    local if_lang = f:expandTemplate{title='If lang'}
    
    -- Determine the number of years grouped together in each "section" of the timeline
    -- Defaults to 6 because I like it
    local split = tonumber(f.args[1]) or 6

    for year = startYear, currentYear, split do
        table.insert(output, '<div style="display:inline-table">')

        for y = year, math.min(year + split - 1, currentYear) do
            local title = string.format("Item timeline in %d", y)

            if article_exists(title) then
                table.insert(output, string.format(':*  [[%s%s|%d]]', title, if_lang, y))
            end
        end

        table.insert(output, '</div>')
    end

    return table.concat(output, "\n")
end

return p