模組:AIC status
外观
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.main(frame)
local args = getArgs(frame, {
trim = true,
removeBlanks = false
})
return p._main(args)
end
function p.parseCase(status)
local frame = mw.getCurrentFrame()
if status == "r" or status == "requested" or status == "t" or status == "td" or status == "to do" or status == "todo" then
return { isOpen = true, level = 1 }
elseif status == "o" or status == "ongoing" then
return { isOpen = true, level = 2 }
elseif status == "c" or status == "completed" then
return { isOpen = false, level = 3 }
elseif status == "u" or status == "unneeded" or status == "unnecessary" then
return { isOpen = false, level = 4 }
elseif status == "tg" or status == "tagged" or status == "tag" then
return { isOpen = false, level = 5 }
else
return { isOpen = true, level = 1 } -- Defaults to "to do"
end
end
function p.listCases(args)
local frame = mw.getCurrentFrame()
local headers = { frame:expandTemplate{ title = 'bang' } .. "'''积压'''",
frame:expandTemplate{ title = 'cloc' } .. " '''未已'''",
frame:expandTemplate{ title = 'yeac' } .. " '''完毕'''",
frame:expandTemplate{ title = 'nayc' } .. " '''无庸'''" ,
frame:expandTemplate{ title = 'yeag' } .. " '''标记'''" }
local caseList = { "", "", "", "", "" }
local totalCases = 0
local openCases = 0
for i = 1, 10 do
if args["article" .. tostring(i)] then
local caseStatus = p.parseCase(args["status" .. tostring(i)])
local link = "* [[" .. args["article" .. tostring(i)] .. "]]"
caseList[caseStatus.level] = caseList[caseStatus.level] .. link .. "\n\n"
totalCases = totalCases + 1
if caseStatus.isOpen then
openCases = openCases + 1
end
end
end
for i = 1, 5 do
if #caseList[i] > 0 then
caseList[i] = headers[i] .. "\n\n" .. caseList[i]
end
end
return {list = caseList[1] .. caseList[2] .. caseList[3] .. caseList[4] .. caseList[5], totalCases = totalCases, openCases = openCases}
end
function p._main(args)
local frame = mw.getCurrentFrame()
local status = args.status or args.cleanup_status or args[1] or "error"
local subpageArg = args.subpage or args.tracking_subpage or args[2] or ""
local hatnoteIcon = ""
local hatnote = ""
local hatnoteanchor = ""
local currentTitle = ""
local subpage = ""
local subpageLink = ""
local subpageExists = false
local count = 0
local displayError = false
local caseList = p.listCases(args)
-- Status aliases
if status == "requested" or status == "ongoing" or status == "no" or status == "unnecessary" or status == "completed" then
status = string.sub( status, 1, 1 )
end
if status == "n" then status = "u" end
-- Compute the number of open cases
if caseList.totalCases > 0 then
count = caseList.openCases
else
count = tonumber(args.count or args.pages_left_to_review or args[3] or "0")
end
if #subpageArg > 0 then
currentTitle = mw.title.getCurrentTitle()
hatnoteanchor = "<span class=\"anchor\" id=\"" .. subpageArg .. "\"></span>"
subpage = mw.title.new( "Wikipedia:人工智能布告板/追踪" .. "/" .. subpageArg )
subpageLink = "[[" .. subpage.fullText .. "|-{「}-" .. subpageArg .. "-{」}-]]"
if (status == "r" or status == "o") then -- Minimizes expensive calls
subpageExists = subpage.exists
if subpageExists then
local subpageContent = subpage.content
if select(2, mw.ustring.gsub(subpageContent, "{{%s*AIC article list", "")) > 0 then
count = select(2, mw.ustring.gsub(subpageContent, "{{%s*AIC article row%s*|[^|}]-|%s*[未待存otr|]", "")) + select(2, mw.ustring.gsub(subpageContent, "{{%s*AIC article row%s*|[^|}]-|%s*su", "")) + select(2, mw.ustring.gsub(subpageContent, "{{%s*AIC article row%s*|[^|}]-|%s*status%s*=%s*[未待存otrs|]", ""))
-- substract "tg"/"tagged"/"tag" rows
count = count - select(2, mw.ustring.gsub(subpageContent, "{{%s*AIC article row%s*|[^|}]-|%s*t[ag]", "")) - select(2, mw.ustring.gsub(subpageContent, "{{%s*AIC article row%s*|[^|}]-|%s*status%s*=%s*t[ag]", ""))
end
end
end
end
-- Building the hatnote
if status == "r" then
hatnoteIcon = frame:expandTemplate{ title = 'bang' }
if #subpageArg > 0 then
if subpageExists then
hatnote = "请求清理,进度记录于" .. subpageLink
else
hatnote = "请求清理,可建".. subpageLink .. "以记录进度"
end
else
hatnote = "请求清理"
end
elseif status == "o" then
hatnoteIcon = frame:expandTemplate{ title = 'icon2', args = { "Edit-clear.svg" , "16px", tooltip = "清理工作" } }
if #subpageArg > 0 then
if subpageExists then
hatnote = " 清理中,进度记录于" .. subpageLink
else
hatnote = " 清理中,可建".. subpageLink .. "以记录进度"
end
else
hatnote = " 清理中"
end
elseif status == "u" then
hatnoteIcon = frame:expandTemplate{ title = 'nayc' }
hatnote = " 无需清理"
elseif status == "c" then
hatnoteIcon = frame:expandTemplate{ title = 'yeac' }
hatnote = " 清理完毕"
else
hatnote = frame:expandTemplate{ title = 'error', args = {"请使用<code>{{{status}}}</code>指明清理状态" } }
displayError = true
end
if status == "r" or status == "o" then
if subpageExists or caseList.totalCases > 0 or args.count or args.pages_left_to_review or args[3] then
hatnote = hatnote .. "," .. count .. "个页面尚待处理"
end
end
if status == "u" or status == "c" then
if #subpageArg > 0 then
hatnote = hatnote .. ",可参见" .. subpageLink .. ""
end
end
-- Building the hatnote. Note that {{terminate sentence}} does not work for a terminated sentence wrapped in another element
if displayError then
return frame:expandTemplate{ title = 'hatnote', args = { hatnoteIcon .. hatnote , extraclasses = "aic-status-hatnote" } }
else
hatnote = frame:expandTemplate{ title = 'hatnote', args = { hatnoteIcon .. frame:expandTemplate{ title = 'terminate sentence', args = { hatnote } } , extraclasses = "aic-status-hatnote" } }
end
if caseList.totalCases > 0 then
hatnote = '<div class="mw-collapsible mw-collapsed">' .. hatnote .. '<div class="mw-collapsible-content">' .. caseList.list .. '</div></div>'
end
hatnote = hatnoteanchor .. hatnote
return hatnote
end
return p