跳转到内容

模組:DYK status

维基百科,自由的百科全书

这是本页的一个历史版本,由PexEric留言 | 贡献2025年4月4日 (五) 10:16 建立内容为“-- 本模块用来检查条目的DYK状态 -- 以下模板的重定向检索于2025-04-04 local p = {} local function normalize(str) return mw.text.trim(str):gsub("_", " "):lower() end local function checkTemplates(content, templates) for _, tpl in ipairs(templates) do if content:lower():find("{{%s*" .. tpl:lower() .. "%s*[|}]") then return true end end return false end local function getParam(temp…”的新页面)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
-- 本模块用来检查条目的DYK状态
-- 以下模板的重定向检索于2025-04-04
local p = {}

local function normalize(str)
    return mw.text.trim(str):gsub("_", " "):lower()
end

local function checkTemplates(content, templates)
    for _, tpl in ipairs(templates) do
        if content:lower():find("{{%s*" .. tpl:lower() .. "%s*[|}]") then
            return true
        end
    end
    return false
end

local function getParam(templateContent, param)
    param = param:lower()
    for part in mw.text.gsplit(templateContent, "|") do
        local key, value = part:match("^%s*(.-)%s*=.*")
        if key and normalize(key) == param then
            return mw.text.trim(value or "")
        end
    end
    return nil
end

function p.checkDYKStatus(frame)
    local pageTitle = frame.args[1]
    if not pageTitle then return end

    local talkTitle = mw.title.makeTitle("Talk", pageTitle)
    if not talkTitle or not talkTitle.exists then return end
    local content = talkTitle:getContent()

    -- 检查候选模板
    if checkTemplates(content, {"DYK_Invite", "DYK invite", "Dyk invite", 
                                "DYKInvite", "DYKinvite", "DYKC", "DYKN"}) then
        return "candidate"
    end

    -- 检查DYKEntry/archive
    if checkTemplates(content, {"DYKEntry/archive", "NewDYKnomination/archive"}) then
        local dykEntry = content:match("%b{}", content:find("{{%s*DYKEntry/archive"))
                     or content:match("%b{}", content:find("{{%s*NewDYKnomination/archive"))
        if dykEntry then
            local result = getParam(dykEntry, "result"):gsub("%s", "")
            if result == "-" or result == "!" then
                return "no"
            else
                return "yes"
            end
        end
    end

    -- 检查Article history
    if checkTemplates(content, {"Article history", "ArticleHistory"}) then
        local ahTemplate = content:match("%b{}", content:find("{{%s*Article history"))
                      or content:match("%b{}", content:find("{{%s*ArticleHistory"))
        if ahTemplate then
            for part in mw.text.gsplit(ahTemplate, "|") do
                local key = part:match("^%s*([^=]+)%s*=") or ""
                key = normalize(key)
                if key:match("^dyk%d*date$") or key:match("^dyk%d*entry$") then
                    return "yes"
                end
            end
        end
    end

    return nil
end

return p