Module:XfD old/AfD and MfD/sandbox
Appearance
![]() | This is the module sandbox page for Module:XfD old/AfD and MfD (diff). |
local p = {}
-- RfD is even worse, since we have to manually parse all log pages
-- and "Old" discussions aren't displayed separately from "Current" ones
function p.rfd(frame)
local rfd = "Wikipedia:Redirects for discussion"
local logprefix = "Wikipedia:Redirects for discussion/Log/"
-- threshold is 7 days ago
local threshold = os.date("%F",os.time() - (86400*7))
local month = frame.args.month
local ymdtoiso = require("Module:YMD to ISO")._main
local lang = mw.getContentLanguage()
-- Find the daily pages
local content = mw.title.new(rfd):getContent()
local total = 0
local lastOpenTitle
for ymd in content:gmatch("{{" .. logprefix .. "(.-)}}") do
local iso = ymdtoiso(ymd)
if iso < threshold then
if month == "total" or month == lang:formatDate("F Y", iso) then
local dayContent = mw.title.new(logprefix .. ymd):getContent()
-- Match only title sections starting with lists or templates
for openTitle in dayContent:gmatch("==== ?([^\n]-) ?====%s+[%*%#%{]", "") do
total = total + 1
lastOpenTitle = openTitle
end
end
end
end
if total > 0 then
return "[[" .. rfd .. "#" .. lastOpenTitle .. "|" .. total .. "]]"
else
return "[[" .. rfd .. "|0]]"
end
end
return p