Module:Sandbox/MSGJ
Appearance
require('strict')
local p = {}
p.main = function(frame)
local banner_name = mw.text.trim(frame.args[1]) -- name of template to look for, e.g. WikiProject Finland
local WPBSredirects = mw.loadData('Module:WikiProject banner/config').banner_shell.redirects -- load the current set of redirects to Template:WikiProjct banner shell
local page_content = mw.title.getCurrentTitle():getContent() -- get content of current page
local content_without_shell
for capture in mw.ustring.gmatch(page_content, '%b{}') do -- look for possible templates on page
for _, redirect in ipairs(WPBSredirects) do
if mw.ustring.find(capture, '^{{%s*' .. redirect .. '%s*[|}].*}}$') then -- found a banner shell
content_without_shell = mw.ustring.gsub(page_content, capture, '') -- remove banner shell content from page content
break -- ideally want to break out from both for loops now
end
end
end
local template_outside_shell
if content_without_shell then -- banner shell was found
if mw.ustring.find(content_without_shell, '{{%s*' .. banner_name .. '%s*[%|}]') then -- found banner template outside of the shell
template_outside_shell = true
else -- banner template must be inside the shell
template_outside_shell = false
end
else -- no banner shell on page
template_outside_shell = true
end
return template_outside_shell
end
return p