This is an old revision of this page, as edited by Pppery(talk | contribs) at 17:26, 11 June 2024(Sync from main: add some more replacement patterns). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 17:26, 11 June 2024 by Pppery(talk | contribs)(Sync from main: add some more replacement patterns)
This Lua module is used in system messages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them.
This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
This module implements title suggestions for the "Bad title" interface message at MediaWiki:Title-invalid-characters. When the user asks for a page with invalid characters, this module checks for a page with the given title up to the first invalid character. If it exists, {{Did you mean box}} is displayed.
Usage
{{#invoke:Bad title suggestion|main|invalid_char|bad_title_encoded}}
localgetArgs=require("Module:Arguments").getArgslocalp={}functionp.main(frame)localargs=getArgs(frame)-- The invalid character, e.g. ">" or "}"localchr=args[1]-- The escaped bad title, e.g. "Foobar>" or "Foobar|text"localtitle=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.ifchr==nilandtitle==nilthenchr="|"title=args[3]endifchr==nilortitle==nilthenreturn""endreturnp._main(chr,title)endfunctionp._main(chr,title)localframe=mw.getCurrentFrame()-- 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.localindex=mw.ustring.find(title,mw.text.nowiki(chr),1,true)localtruncate=""ifindexthenlocalpage=mw.title.new(mw.ustring.sub(title,1,index-1))ifpageandpage.existsthentruncate='<div class="mw-parser-output">'..frame:expandTemplate{title="Did you mean box",args={page.fullText}}..'</div>'endendlocalsubstitute=""localsuccess,overrides=pcall(function()returnmw.loadJsonData("Module:Bad title suggestion/override.json")end)localspagetitle=mw.text.decode(title)ifsuccessandoverrides[title]thenspage=mw.title.new(overrides[title])elseifchr=="["orchr=="]"thenlocalreplaced=title:gsub("%[","("):gsub("%]",")")spage=mw.title.new(replaced)endifspageandspage.existsthensubstitute='<div class="mw-parser-output">'..frame:expandTemplate{title="Did you mean box",args={spage.fullText}}..'</div>'endreturnsubstitute..truncateendreturnp