Module:Noinclude tfd
Appearance
local redr = require("Module:Redirect")
local function stringCount(string, pattern)
local _dump, cnt = mw.ustring.gsub(string, pattern, "")
return cnt
end
local function parse(frame, links)
local output = ""
links.size = nil
for _, object in ipairs(links) do
if object then
local title = "Template:" .. object;
local rtarget;
if #output > 0 then
errorvalue, rtarget = pcall(redr.getTarget, title);
if not errorvalue then
-- the most likely error here is too many expensive parser function calls
return frame:preprocess(output .. "\n* (too many expensive parser functions to continue)");
end
else
-- no output, so we might as well let any error propogate
rtarget = redr.getTarget(title)
end
title = rtarget or title;
local code = mw.title.new(title):getContent();
if code then
local unsubstified = mw.ustring.match(code, "#invoke:Unsubst||");
local nmg = stringCount(code, "<noinclude>[^/]*{{Tfm")
local ndel = stringCount(code, "<noinclude>[^/]*{{Template for discussion")
local disabled = stringCount(code,"type=disabled")
local safesubst = mw.ustring.match(code,"{{{|safesubst:}}}") or mw.ustring.match(code, "<includeonly>safesubst:</includeonly>");
safesubst = safesubst or mw.ustring.match(code,"SAFESUBST:%s*<noinclude%s*/>");
local oldstylesubst = mw.ustring.match(code, "{{{subst|}}}") or mw.ustring.match(code, "<includeonly>[Ss]ubst:</includeonly>");
local tagCnt = stringCount(code,"{{Tfm") + stringCount(code,"{{Template for merging")
tagCnt = tagCnt + stringCount(code,"{{Template for discussion");
if not tagCnt or ((nmg + ndel + disabled >= tagCnt) 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}}");
daytext = mw.ustring.gsub(daytext,"{{[tT]fd links|([^}|]+)[^}]-|module=Module:[^}]-}}", "");
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