Module:Noinclude tfd
Appearance
local redr = require("Module:Redirect")
local function parse(frame, links)
local output = ""
links.size = nil
for _, object in ipairs(links) do
if object then
local title = "Template:" .. object;
title = redr.getTarget(title) or title;
local code = mw.title.new(title):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:}}}") or mw.ustring.match(code, "<includeonly>safesubst:</includeonly>");
local oldstylesubst = mw.ustring.match(code, "{{{subst|}}}");
local hasmtag = mw.ustring.match(code,"{{Tfm")
or mw.ustring.match(code,"{{Template for merging");
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 or oldstylesubst))) 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}}");
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