Module:Major events

From Soyjak Wiki, the free ensoyclopedia
Jump to navigationJump to search

This module displays a limited number of recent events from a specified source page (Main Page/Major Events/data). Events must be listed newest first, with each event occupying one source line only.

Usage

{{#invoke:Major events|main
|source=
|limit=
}}

Parameters

  • source - Page containing the event list. Required.
  • limit - Maximum number of events to display. Default is 5.

Formatting

Events must follow the following format:

* '''September 1, 2026''' - Event text

Only top-level list items beginning with a bolded month, day, and four-digit year are recognized. Events must be ordered newest first.



local p = {}
local function makeError(message)
    return '<strong class="error">Major events error: ' .. message .. '</strong>'
end

function p.main(frame)
    local source = mw.text.trim(frame.args.source or '')
    local limit = tonumber(frame.args.limit) or 5

    if source == '' then return makeError('no source page specified') end

    limit = math.floor(limit)
    if limit < 1 then return '' end

    local title = mw.title.new(source)
    if not title then return makeError('invalid source page') end

    local content = title:getContent()
    if not content then return makeError('source page does not exist') end

    local events = {}
    for line in mw.text.gsplit(content, '\n', true) do
        if line:match("^%s*%*%s*'''[A-Z][a-z]+%s+%d%d?,%s+%d%d%d%d'''%s*%-") then
            events[#events + 1] = line
            if #events >= limit then break end
        end
    end
    if #events == 0 then return makeError('no events found') end
    return frame:preprocess(table.concat(events, '\n'))
end

return p