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 23:43, 10 September 2016 (Undid revision 738769693 by Pppery (talk)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local function parse(frame, links)
	local output = ""
	links.size = nil
	for _, object in ipairs(links) do
		if object then
			local code = mw.title.new("Template:" .. object):getContent();
			if code then 
				local unsubstified = mw.ustring.match(code, "#invoke:Unsubst||");
			    local nmg = mw.ustring.match(code, "<noinclude>[^/]*{{Tfm")
			    local ndel = mw.ustring.match(code, "<noinclude>[^/]*{{Template for discussion") 
			    local disabled = mw.ustring.match(code,"type=disabled")
			    local safesubst = mw.ustring.match(code,"{{{|safesubst:}}}")
			    local hasmtag = mw.ustring.match(code,"{{Tfm")
			    local hasdtag = mw.ustring.match(code,"{{Template for discussion");
			    if not (hasmtag or hasdtag) or ((nmg or ndel or disabled) and (unsubstified or not safesubst)) then
				    output = output .. "\n* {{tfd links|" .. object .. "}}";
				end
			end
		end
	end
	return frame:preprocess(output);
end
local function parseDay(day, links)
	local daytext = mw.title.new(day):getContent();
	daytext = mw.ustring.gsub(daytext,"Please do not modify it","{{tfd links|this is closed}}");
	daytext = mw.ustring.gsub(daytext,"|type=merge","");
	local daymatcher = mw.ustring.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;
	links = parseDay(today, links);
	while true do
		local day = matcher();
		if not day then
			return parse(frame, links);
		end
		links = parseDay(day, links);
	end
end
return p