Module:XfD old/AfD and MfD

MyWikiBiz, Author Your Legacy — Thursday March 28, 2024
< Module:XfD old
Revision as of 08:01, 16 July 2021 by Zoran (talk | contribs) (Pywikibot 6.4.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Documentation for this module may be created at Module:XfD old/AfD and MfD/doc

-- Various hacky solutions to allow AfD and MfD to show up on [[Template:XFD Backlog]]
-- AfD is easy, as [[User:Mathbot]] already summarizes the total on each day
local p = {}
local lang = mw.getContentLanguage()
function p.afd(frame) 
	local month = frame.args.month
	local pat
	if month == "total" then
		pat = "%(([0-9]+) open"
	else
		month = lang:formatDate("Y F", month)
		pat = "%[%[Wikipedia:Articles for deletion/Log/" .. month .. "[^%]]*%]%] %(([0-9]+) open /"
	end
	local content = mw.title.new("Wikipedia:Articles for deletion/Old"):getContent()
	local count = 0
	for daycount in content:gmatch(pat) do
		count = count + daycount
	end
	return count
end
-- MfD is much harder, because the only list of all active MfDs is the main
-- [[Wikipedia:Miscellany for deletion]] page itself
function p.mfd(frame)
	local month = frame.args.month
	local content = mw.title.new("Wikipedia:Miscellany for deletion"):getContent()
	local rightmonth = true
	local pat;
	if month ~= "total" then
		pat = lang:formatDate("^=== ?F [0-9]*, Y ?===$", month)
		rightmonth = false
	end
	local _, endindex = content:find("==Old business==")
	local count = 0
	for line in mw.text.gsplit(content:sub(endindex,#content), "\n") do
		if line:find("{{Wikipedia:Miscellany for deletion/") and rightmonth then
			count = count + 1
		elseif month == "total" then
			-- don't worry about month section headers
		elseif line:find(pat) then
			rightmonth = true
		elseif line:find("=== ?.* ?===") then
			-- A section header for the wrong month
			if rightmonth then
				-- We're now looking at MfDs before the month in question
				break
			end
			-- We still haven't reached the month in question yet
		end
	end
	return count
end
return p