Modul:Bad title suggestion

Vikipediya, azad ensiklopediya
Naviqasiyaya keç Axtarışa keç

Bu modul MediaWiki:Title-invalid-characters-də "Bad title" interfeys mesajı üçün başlıq təklifləri verir. İstifadəçi etibarsız simvolları olan səhifəni açdıqda, bu modul ilk etibarsız simvola qədər verilmiş başlığı olan səhifəni yoxlayır. Əgər mövcuddursa, {{Did you mean box}} göstərilir.

İstifadəsi

{{#invoke:Bad title suggestion|main|invalid_char|bad_title_encoded}}

MediaWiki:Title-invalid-characters üçün:

{{#invoke:Bad title suggestion|main|$1|$2}}

Nümunələr

  • Test>: {{#invoke:Bad title suggestion|main|>|Test>}}

(heç nə göstərilmədi)

  • <Test>: {{#invoke:Bad title suggestion|main|<|#60;Test#62;}}

(heç nə göstərilmədi)


local getArgs = require("Module:Arguments").getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	-- The invalid character, e.g. ">" or "}"
	local chr = args[1]
	-- The escaped bad title, e.g. "Foobar&#62;" or "Foobar&#124;text"
	local title = args[2]
	-- 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 = args[3]
	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)
	if index == nil then
		return ""
	end
	local page = mw.title.new(mw.ustring.sub(title, 1, index - 1))
	if page == nil or not page.exists then
		return ""
	end
	
	return '<div class="mw-parser-output">' .. frame:expandTemplate{
		title = "Did you mean box",
		args = { page.fullText }
	} .. '</div>'
end

return p