Jump to content

Module:Noinclude tfd

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pppery (talk | contribs) at 17:12, 4 September 2016 (Created page with 'local function parse(frame, links) local output = ""; links.size = nil; for _, object in ipairs(links) do if object then local code = frame:preprocess("{...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local function parse(frame, links)
	local output = "";
	links.size = nil;
	for _, object in ipairs(links) do
		if object then
			local code = frame:preprocess("{{" .. object .. "}}");
			if not (string.match(code, "id=\"tfd\"")) then
				output = output .. "\n" .. object;
			end
		end
	end
	return output;
end
local function preempt(value, iterator)
	local preempted = false;
	function result()
		if preempted then
			return iterator();
		else
			preempted = true;
			return value;
		end
	end
	return result;
end
local function parseDay(day, links)
	local daytext = mw.title.new(day):getContent();
	daytext = string.gsub(daytext,"Please do not modify it","{{tfd links|this is closed}}");
	daytext = string.gsub(daytext,"|type=merge","");
	local daymatcher = string.gmatch(daytext, "{{[tT]fd links|([^}]+)}}")
	local closed = false
	while true do
		local link = daymatcher();
		if not link then
			return links;
		end
		if link == "this is closed" then
			closed = not closed
		elseif not closed then
			links[links.size] = link;
			links.size = links.size + 1;
		end
	end
end
local p = {}
function p.main(frame)
	local links = {};
	links.size = 0;
	local tfdtext = mw.title.new("Wikipedia:Templates for discussion"):getContent();
	local matcher = string.gmatch(tfdtext, "{{(Wikipedia:Templates for discussion/Log/201%d [^%d]* %d%d?)}}");
	local today = frame:preprocess("{{CURRENTYEAR}} {{CURRENTMONTHNAME}} {{CURRENTDAY}}")
	today = "Wikipedia:Templates for discussion/Log/" .. today;
	matcher = preempt(today, matcher);
	while true do
		local day = matcher();
		mw.log(day);
		if not day then
			return parse(frame, links);
		end
		links = parseDay(day, links);
	end
end
return p