Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Humanipedia
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:Bad title suggestion
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
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 = args[1] -- The escaped bad title, e.g. "Foobar>" or "Foobar|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) 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 overrides[title] then spage = mw.title.new(overrides[title]) elseif success and overrides[title:lower()] then spage = mw.title.new(overrides[title:lower()]) elseif success and overrides[dedab(title)] then spage = mw.title.new(overrides[dedab(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.args[1], nil) end return p
Summary:
Please note that all contributions to Humanipedia may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Humanipedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Did you mean box
(
edit
)
Template:Documentation subpage
(
edit
)
Template:Error
(
edit
)
Template:Mbox
(
edit
)
Template:Module other
(
edit
)
Template:Module rating
(
edit
)
Template:Ombox
(
edit
)
Template:Pp
(
edit
)
Template:Protection padlock
(
edit
)
Template:Template link
(
edit
)
Template:Tl
(
edit
)
Template:Used in system
(
edit
)
Module:Arguments
(
edit
)
Module:Bad title suggestion
(
edit
)
Module:Bad title suggestion/doc
(
edit
)
Module:Bad title suggestion/override.json
(
edit
)
Module:Error
(
edit
)
Module:File link
(
edit
)
Module:Message box
(
edit
)
Module:Protection banner
(
edit
)