| Thismodule is rated asready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned onhelp pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed throughsandbox testing rather than repeated trial-and-error editing. |
| This module is currentlyprotected from editing. See theprotection policy andprotection log for more details. Please discuss any changes on thetalk page; you maysubmit an edit request to ask anadministrator to make an edit if it isuncontroversial or supported byconsensus. You may alsorequest that this page be unprotected. |
| This Lua module is used in system messages, and onapproximately 303,000 pages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption and server load, any changes should be tested in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on thetalk page before implementing them. |
| This module depends on the following other modules: |
This module detects if a given page is a disambiguation page.
{{#invoke:Disambiguation|isDisambiguationPage|Page title}}yes if the page is a disambiguation page, or nothing if the page is not a disambiguation pageExamples:
{{#invoke:Disambiguation|isDisambiguationPage|Paris}} →{{#invoke:Disambiguation|isDisambiguationPage|New}} → yes{{#invoke:Disambiguation|isDisambiguationPage|Black swan (disambiguation)}} → yesYou can also use magic words like{{SUBJECTPAGENAME}}:
{{#invoke:Disambiguation|isDisambiguationPage|{{SUBJECTPAGENAME}}}} → yesImport this module, e.g with
localmDisambiguation=require('Module:Disambiguation')
Then you can use the functionsisDisambiguation and_isDisambiguationPage.
If you have already have aTitle object for the page to check, get the content using the title object's getContent() method, and pass that intoisDisambiguation:
localisDab=mDisambiguation.isDisambiguation(content)-- returns true or false
content is a string, the wikitext content of page to check)If you don't otherwise need the title, you can pass in the page name to_isDisambiguationPage:
localisDab=mDisambiguation._isDisambiguationPage(pageName)-- returns true or false
pageName is a string, the name of page to check)localp={}localmRedirect=require('Module:Redirect')localdisambiguationTemplates=mw.loadData('Module:Disambiguation/templates')localPrepareText=require('Module:Wikitext Parsing').PrepareTextlocalfunctioncapitalize(s)-- This function only works on ASCII strings. If your wiki has-- disambiguation templates that use Unicode strings, use the commented-out-- line instead. Enwiki uses ASCII string manipulation only here to improve-- performance.returns:sub(1,1):upper()..s:sub(2,-1)-- return mw.ustring.upper(mw.ustring.sub(1, 1)) .. mw.ustring.sub(2, -1)endlocalfunctionisDisambiguationTemplate(template)returndisambiguationTemplates[capitalize(template)]orfalseendp.isDisambiguation=function(content)-- false if there is no contentifcontent==nilthenreturnfalseend-- redirects are not disambiguation pagesifmRedirect.getTargetFromText(content)~=nilthenreturnfalseend-- check for disambiguation templates in the contentlocaltemplateNames={}-- remove nowiki content and html comments for this checklocalactivecontent=PrepareText(content)fortemplateinstring.gmatch(activecontent,"{{%s*([^|}]-)%s*[|}]")doifisDisambiguationTemplate(template)thenreturntrueendend-- check for magic wordifstring.find(content,"__DISAMBIG__",1,true)~=nilthenreturntrueendreturnfalseendp._isDisambiguationPage=function(page)-- Look "(disambiguation)" in the titleifstring.find(page,"(disambiguation)",0,true)~=nilthenreturntrue;end-- Look for disamiguation template in page contentlocaltitle=mw.title.new(page)ifnottitlethenreturnfalseendlocalcontent=title:getContent()returnp.isDisambiguation(content)end-- Entry points for templatesp.isDisambiguationPage=function(frame)localtitle=frame.args[1]returnp._isDisambiguationPage(title)and"yes"or""endreturnp