模組:DYK status/sandbox
外观
![]() | 这是Module:DYK status(差异)的沙盒。 |
-- 本模块用来检查条目的DYK状态
-- 以下模板的重定向检索于2025-04-04
local p = {}
-- 模板名称正则模式(处理空格/下划线)
local invitePattern = "{{[sS]*(DYK[_ ]Invite|Dyk[_ ]invite|DYKInvite|DYKinvite|DYKC|DYKN)[sS]*}}"
local archivePattern = "{{[sS]*(DYKEntry/archive|NewDYKnomination/archive)[sS]*}}"
local historyPattern = "{{[sS]*(Article[_ ]history|ArticleHistory)[sS]*}}"
-- 提取模板参数的正则
local paramPattern = "|([^=|]+)[sS]*=([^|}]+)"
-- 主函数
function p.main(frame)
local pageTitleStr = frame.args[1]
if not pageTitleStr or pageTitleStr == '' then
return nil
end
-- 获取讨论页内容
local titleObj = mw.title.new(pageTitleStr)
if not titleObj then
return nil
end
local talkTitleObj = titleObj.talkPageTitle
if not talkTitleObj then
return nil
end
local talkPageContent = mw.title.new(talkTitleObj.prefixedText):getContent()
if not talkPageContent then
return nil
end
-- 1. 检查候选状态
if string.find(talkPageContent, invitePattern) then
return "candidate"
end
-- 2. 检查DYKEntry/archive模板
local archiveMatch = string.match(talkPageContent, archivePattern)
if archiveMatch then
-- 提取result参数
for param, value in string.gmatch(archiveMatch, paramPattern) do
if string.lower(string.match(param, "%S+")) == "result" then
if value == '-' or value == '!' then
return "no"
else
return "yes"
end
end
end
return "yes" -- 有模板但无result参数默认为通过
end
-- 3. 检查Article history模板
local historyMatch = string.match(talkPageContent, historyPattern)
if historyMatch then
-- 检查dyk相关参数
for param, _ in string.gmatch(historyMatch, paramPattern) do
local cleanParam = string.lower(string.match(param, "%S+"))
if cleanParam:match("^dyk%d*date$") or cleanParam:match("^dyk%d*entry$") then
return "yes"
end
end
end
-- 默认状态
return nil
end
return p