Jump to content

Module:Sandbox/MSGJ

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MSGJ (talk | contribs) at 08:51, 19 September 2024 (content_without_shell = page_content in case no shell). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
require('strict')
local p = {}

p.main = function(frame)
	local banner_name = frame.args[1]
	local WPBSredirects = mw.loadData('Module:WikiProject banner/config').banner_shell.redirects
	local page_content = mw.title.getCurrentTitle():getContent()
	local content_without_shell = page_content
	for capture in mw.ustring.gmatch(page_content, '%b{}') do
		for _, redirect in ipairs(WPBSredirects) do
			if mw.ustring.find(capture, '^{{%s*' .. redirect .. '.*}}$') then -- found a banner shell
				content_without_shell = mw.ustring.gsub(page_content, capture, '') -- remove banner shell content from page content
			end
		end
	end
	local template_outside_shell = false
	if content_without_shell then -- banner shell was found
		if mw.ustring.find(content_without_shell, '{{%s*' .. banner_name .. '%s*[%|}]') then
			template_outside_shell = true
		end
	end
	return template_outside_shell
end

return p