模組:沙盒/PexEric/1
外观
local p = {}
-- 检查模板是否存在(通过检查任意参数)
local function checkTemplateExistence(pageTitle, templates)
-- 将模板名称中的空格替换为下划线
local processedTemplates = {}
for _, t in ipairs(templates) do
table.insert(processedTemplates, t:gsub(" ", "_"))
end
local success, _ = pcall(function()
return require('Module:Template parameter value').getValue(pageTitle, processedTemplates, 'dummy', {})
end)
return success
end
-- 获取DYKEntry/archive模板的result参数值
local function getResultParameterValue(pageTitle, templates)
local processedTemplates = {}
for _, t in ipairs(templates) do
table.insert(processedTemplates, t:gsub(" ", "_"))
end
local success, result = pcall(function()
return require('Module:Template parameter value').getValue(pageTitle, processedTemplates, 'result', {})
end)
return success and result or nil
end
-- 检查Article history模板是否包含指定参数
local function checkArticleHistoryParams(pageTitle, templates, params)
local processedTemplates = {}
for _, t in ipairs(templates) do
table.insert(processedTemplates, t:gsub(" ", "_"))
end
for _, param in ipairs(params) do
local success, result = pcall(function()
return require('Module:Template parameter value').getValue(pageTitle, processedTemplates, param, {})
end)
if success and result ~= '' then
return true
end
end
return false
end
function p.checkDYKStatus(pageTitle)
-- 1. 检查候选状态(DYK_Invite模板)
local dykInviteTemplates = {
'DYK_Invite', 'DYK invite', 'Dyk invite', 'DYKInvite', 'DYKinvite', 'DYKC', 'DYKN'
}
if checkTemplateExistence(pageTitle, dykInviteTemplates) then
return 'candidate'
end
-- 2. 检查DYKEntry/archive模板
local dykEntryTemplates = {'DYKEntry/archive', 'NewDYKnomination/archive'}
local resultParam = getResultParameterValue(pageTitle, dykEntryTemplates)
if resultParam then
if resultParam == '-' or resultParam == '!' then
return 'no'
else
return 'yes'
end
end
-- 3. 检查Article history模板
local articleHistoryTemplates = {'Article history', 'ArticleHistory', 'Articlehistory'}
local dykParams = {'dyk1date', 'dykdate', 'dyk1entry', 'dykentry'}
-- 检查是否存在相关参数
if checkArticleHistoryParams(pageTitle, articleHistoryTemplates, dykParams) then
return 'yes'
end
-- 检查Article history模板是否存在(参数不存在时)
if checkTemplateExistence(pageTitle, articleHistoryTemplates) then
return 'no'
end
-- 默认返回空值
return nil
end
function p.main(frame)
local pageTitle = frame.args[1]
if not pageTitle then
return ''
end
local status = p.checkDYKStatus(pageTitle)
return status or ''
end
return p