模組:DYK status
外观
-- 本模块用来检查条目的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