Module:Noinclude tfd
Appearance
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