Module:XfD old/AfD and MfD/sandbox

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 month = frame.args.month

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 ymd = require("Module:YMD to ISO")._main

local lang = mw.getContentLanguage()

-- Find the daily pages

local content = mw.title.new(rfd):getContent()

local dayPattern = "{{" .. logprefix .. "(.-)}}";

local total = 0

local lastTitle

for day in content:gmatch(dayPattern) do

local datestamp = ymd(day)

if datestamp >= threshold then

-- These discussions aren't seven days old yet

elseif month == "total" or month == lang:formatDate("F Y", datestamp) then

local dayTitle = logprefix .. day;

local dayContent = mw.title.new(dayTitle):getContent()

-- Match only title sections starting with lists or templates

local titlePattern = "==== ?([^\n]-) ?====%s+[%*#{]";

for title in dayContent:gmatch(titlePattern) do

total = total + 1

lastTitle = title

end

end

end

if month == "total" then

if total > 0 then

return "" .. total .. ""

else

return "0"

end

else

return total

end

end

return p