Jump to content

Module:XfD old

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pppery (talk | contribs) at 04:36, 2 March 2019 (Pppery moved page Module:XfD summary to Module:XfD old without leaving a redirect: I'm terrible at naming things). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local tableTools = require("Module:TableTools")
local ymd = require("Module:YMD to ISO")._main
local lang = mw.getContentLanguage()
local function getlog(name) 
	 return mw.ustring.match(name, "Log/(.*)")
end
function sortkey(name1, name2)
	local key1 = ymd(getlog(name1))
	local key2 = ymd(getlog(name2))
	return key1 > key2
end
function p._main(frame, makeoutput)
	local t = frame.args.title or frame:getParent():getTitle()
	local content = mw.title.new(t .. "/Old unclosed discussions"):getContent();
	local m = mw.ustring.gmatch(content, "* %[%[(" .. t .. "/Log/[^#]*)#%{%{anchorencode:([^}]*)")
	local seen = {}
	while true do
		local logpage, header = m()
		if not logpage then
			break
		end
		if seen[logpage] == nil then
			seen[logpage] = {}
		end
		seen[logpage][#seen[logpage]+1] = header
	end
	mw.logObject(seen)
	local out = ""
	for k, v in tableTools.sortedPairs(seen, sortkey) do
		out = out .. makeoutput(k, v)
	end
	return mw.text.trim(out)
end
function p.list(frame) 
	local function listoutput(k, v)  
		return "* [[" .. k .. "]] (" .. tostring(#v) .. " open) \n"
	end
	return p._main(frame, listoutput)
end
function p.transclude(frame) 
	local function transoutput(k, v)
		local out = ""
		out = out .. "=== [[" .. k .. "|" .. getlog(k):sub(5) .. "]] ===\n"
		for _, discussion in pairs(v) do
			out = out .. "==== " .. discussion .. " ====\n"
			out = out .. frame:callParserFunction("#section-h", k, discussion)
			out = out .. "\n"
		end
		return out
	end
	return p._main(frame, transoutput)
end
return p