Jump to content

Module:XfD old/AfD and MfD/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by RAN1 (talk | contribs) at 22:15, 11 November 2022 (No need to interpolate a constant). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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