Module:版本列表

来自缺氧 Wiki
跳转到导航 跳转到搜索

可在Module:版本列表/doc创建此模块的帮助文档

-- Module:版本列表
local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string
local tableBuilder = require([[Module:Tablebuilder]])
local vData = mw.loadData([[Module:Data/版本]])
local vInfo = mw.loadData([[Module:Data/版本信息]])
local getArgs = require('Dev:Arguments').getArgs

function wikiLink(s)
    local link = s
    if mw.ustring.sub(s, 1, 1) then link = ':' .. s end
    return fstr("[[%s|%s]]", link, s)
end

-- test by: = p.show_table(require("Module:debug").frame({class = "sortable", style=""},{}))
function p.show_table(frame)
    local tData = {
        {
            "版本号", "页面", "前缀", "版本名称", "发布时间",
            "类型", "影响页面"
        }
    }
    -- reverse order
    local ks = {}
    for k in pairs(vData) do table.insert(ks, k) end
    table.sort(ks, function(x, y) return x > y end)
    for _, k in ipairs(ks) do
        local pages = {}
        local ap = vData[k]["affected_pages"]
        if type(ap) == "table" and (#ap ~= 0) then
            for _, p in ipairs(ap) do
                table.insert(pages, wikiLink(p))
            end
        end
        pages = table.concat(pages, ' • ')

        table.insert(tData, {
            k, -- 版本号
            fstr("[[%s]]", vData[k]["page"]), -- 页面
            vData[k]["prefix"] or "", -- 前缀
            vData[k]["zhName"] or "", -- 版本名称
            (vData[k]["release_date"]):gsub("(%d%d)/(%d%d)/(%d%d)", "20%3-%1-%2"), -- 发布时间
            vInfo.releaseVarients[vData[k]["type"] or ""], -- 类型
            pages -- 影响页面
        })
    end

    local t = tableBuilder.new(tData, "版本列表", frame.args["style"], {
        "wikitable", "th-nowrap", "versions-table", getArgs(frame)["class"]
    })
    return t:getTable()
end
return p