Module:Bad title suggestion: Difference between revisions
From Thetacola Wiki
Jump to navigationJump to search
en>The Earwig m (Protected "Module:Bad title suggestion": Highly visible template: used in system interface messages ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite))) |
m (1 revision imported) |
(No difference)
|
Latest revision as of 00:22, 15 August 2022
File:Ambox important.svg | 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. |
File:Full-protection-shackle.svg | 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[edit source]
{{#invoke:Bad title suggestion|main|invalid_char|bad_title_encoded}}
In the case of MediaWiki:Title-invalid-characters, this is:
{{#invoke:Bad title suggestion|main|$1|$2}}
Examples[edit source]
- Foobar>:
{{#invoke:Bad title suggestion|main|>|Foobar>}}
- Wikipedia:Village pump}}:
{{#invoke:Bad title suggestion|main|}|Wikipedia:Village pump}}}}
- Main Page|title text!:
{{#invoke:Bad title suggestion|main|||Main Page|title text!}}
File:Dialog-information on.svg | Did you mean: Main Page? |
- This page absolutely does not exist>:
{{#invoke:Bad title suggestion|main|>|This page absolutely does not exist>}}
(nothing displayed)
- Category:Contents>:
{{#invoke:Bad title suggestion|main|>|Category:Contents>}}
- <Foobar>:
{{#invoke:Bad title suggestion|main|<|#60;Foobar#62;}}
(nothing displayed)
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>" 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) 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 frame:expandTemplate{ title = "Did you mean box", args = { page.fullText } } end return p