Permanently protected module
From Wikipedia, the free encyclopedia


require("strict")

local getArgs = require("Module:Arguments").getArgs

local p = {}

local function dedab(title) 

	return title:gsub(" ?%(.-%)","")

end



function p.main(frame)

	local args = getArgs(frame)

	-- The invalid character, e.g. ">" or "}"

	local chr = args1

	-- The escaped bad title, e.g. "Foobar>" or "Foobar|text"

	local title = args2

	-- A pipe (|) as the invalid character is a special case; it is not

	-- escaped, so instead the module thinks it got two empty arguments

	-- and the title as the third argument.

	if chr == nil and title == nil then

		chr = "|"

		title = args3

	end

	if chr == nil or title == nil then

		return ""

	end

	-- Determine the suggested title by taking a prefix of the bad title

	-- up to the first invalid character. Only display the suggestion box

	-- if the page exists.

	local index = mw.ustring.find(title, mw.text.nowiki(chr), 1, true)

	local truncate = ""

	if index then

		local page = mw.title.new(mw.ustring.sub(title, 1, index - 1))

		if page and page.exists then

			truncate = '<div class="mw-parser-output">' .. frame:expandTemplate{

				title = "Did you mean box",

				args = { page.fullText }

			} .. '</div>'

		end

	end

	return p._substitute(frame, title, chr)..truncate

end

function p._substitute(frame, title, chr)

	-- Since the overrides page has a lower protection level than this one don't crash if it's invalid

	local success, overrides = pcall(function() return mw.loadJsonData("Module:Bad title suggestion/override.json") end)

	local spage

	local substitute = ""

	title = mw.text.decode(title):gsub("_", " ")

	if success and overridestitle then

		spage = mw.title.new(overridestitle])

	elseif success and overridestitle:lower()] then

		spage = mw.title.new(overridestitle:lower()])

	elseif success and overridesdedab(title)] then

		spage = mw.title.new(overridesdedab(title)])

	elseif not chr or chr == "[" or chr == "]" then

		local replaced = title:gsub("%[","("):gsub("%]",")")

		if replaced ~= title then

			spage = mw.title.new(replaced)

		end

	end

	if spage and spage.exists then

		substitute = '<div class="mw-parser-output">' .. frame:expandTemplate{

				title = "Did you mean box",

				args = { spage.fullText }

		} .. '</div>'

	end

	return substitute

end

function p.substitute(frame)

	return p._substitute(frame, frame.args1], nil)

end

return p
Permanently protected module
From Wikipedia, the free encyclopedia


require("strict")

local getArgs = require("Module:Arguments").getArgs

local p = {}

local function dedab(title) 

	return title:gsub(" ?%(.-%)","")

end



function p.main(frame)

	local args = getArgs(frame)

	-- The invalid character, e.g. ">" or "}"

	local chr = args1

	-- The escaped bad title, e.g. "Foobar&#62;" or "Foobar&#124;text"

	local title = args2

	-- A pipe (|) as the invalid character is a special case; it is not

	-- escaped, so instead the module thinks it got two empty arguments

	-- and the title as the third argument.

	if chr == nil and title == nil then

		chr = "|"

		title = args3

	end

	if chr == nil or title == nil then

		return ""

	end

	-- Determine the suggested title by taking a prefix of the bad title

	-- up to the first invalid character. Only display the suggestion box

	-- if the page exists.

	local index = mw.ustring.find(title, mw.text.nowiki(chr), 1, true)

	local truncate = ""

	if index then

		local page = mw.title.new(mw.ustring.sub(title, 1, index - 1))

		if page and page.exists then

			truncate = '<div class="mw-parser-output">' .. frame:expandTemplate{

				title = "Did you mean box",

				args = { page.fullText }

			} .. '</div>'

		end

	end

	return p._substitute(frame, title, chr)..truncate

end

function p._substitute(frame, title, chr)

	-- Since the overrides page has a lower protection level than this one don't crash if it's invalid

	local success, overrides = pcall(function() return mw.loadJsonData("Module:Bad title suggestion/override.json") end)

	local spage

	local substitute = ""

	title = mw.text.decode(title):gsub("_", " ")

	if success and overridestitle then

		spage = mw.title.new(overridestitle])

	elseif success and overridestitle:lower()] then

		spage = mw.title.new(overridestitle:lower()])

	elseif success and overridesdedab(title)] then

		spage = mw.title.new(overridesdedab(title)])

	elseif not chr or chr == "[" or chr == "]" then

		local replaced = title:gsub("%[","("):gsub("%]",")")

		if replaced ~= title then

			spage = mw.title.new(replaced)

		end

	end

	if spage and spage.exists then

		substitute = '<div class="mw-parser-output">' .. frame:expandTemplate{

				title = "Did you mean box",

				args = { spage.fullText }

		} .. '</div>'

	end

	return substitute

end

function p.substitute(frame)

	return p._substitute(frame, frame.args1], nil)

end

return p

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook