Jump to content
Wikipedia The Free Encyclopedia

Module:Disambiguation

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
This module is rated as ready 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 on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
[画像:Warning] This Lua module is used in system messages, and on approximately 276,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 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 depends on the following other modules:

This module detects if a given page is a disambiguation page.

Usage

{{#invoke:Disambiguation|isDisambiguationPage|Page title}}
returns yes if the page is a disambiguation page, or nothing if the page is not a disambiguation page

Examples:

  • {{#invoke:Disambiguation|isDisambiguationPage|Paris}}
  • {{#invoke:Disambiguation|isDisambiguationPage|New}} → yes
  • {{#invoke:Disambiguation|isDisambiguationPage|Black swan (disambiguation)}} → yes

You can also use magic words like {{SUBJECTPAGENAME }}:

  • {{#invoke:Disambiguation|isDisambiguationPage|{{SUBJECTPAGENAME}}}} → yes

Usage within Lua modules

Import this module, e.g with

localmDisambiguation=require('Module:Disambiguation')

Then you can use the functions isDisambiguation and _isDisambiguationPage.

If you have already have a Title object for the page to check, get the content using the title object's getContent() method, and pass that into isDisambiguation:

localisDab=mDisambiguation.isDisambiguation(content)-- returns true or false
(where 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
(where pageName is a string, the name of page to check)

Internal operations

  • Although set index articles are treated by some templates as disambiguation pages, they are actually considered a special type of list and are not treated as disambiguation pages by this module
  • As this module relies on detecting templates with names like "disambiguation" in the article text, it is subject to false positives by templates such as {{italic disambiguation }}. These templates should be added to the falsePositives list in the code to exclude them.
  • The list of disambiguation templates is maintained at Module:Disambiguation/templates.
The above documentation is transcluded from Module:Disambiguation/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Subpages of this module.

 localp={}
 localmRedirect=require('Module:Redirect')
 localdisambiguationTemplates=mw.loadData('Module:Disambiguation/templates')
 localPrepareText=require('Module:Wikitext Parsing').PrepareText

 localfunctioncapitalize(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)
 end

 localfunctionisDisambiguationTemplate(template)
 returndisambiguationTemplates[capitalize(template)]orfalse
 end

 p.isDisambiguation=function(content)
 -- false if there is no content
 ifcontent==nilthen
 returnfalse
 end

 -- redirects are not disambiguation pages
 ifmRedirect.getTargetFromText(content)~=nilthen
 returnfalse
 end

 -- check for disambiguation templates in the content
 localtemplateNames={}
 -- remove nowiki content and html comments for this check
 localactivecontent=PrepareText(content)
 fortemplateinstring.gmatch(activecontent,"{{%s*([^|}]-)%s*[|}]")do
 ifisDisambiguationTemplate(template)then
 returntrue
 end
 end

 -- check for magic word
 ifstring.find(content,"__DISAMBIG__",1,true)~=nilthen
 returntrue
 end

 returnfalse
 end

 p._isDisambiguationPage=function(page)
 -- Look "(disambiguation)" in the title
 ifstring.find(page,"(disambiguation)",0,true)~=nilthen
 returntrue;
 end
 -- Look for disamiguation template in page content
 localtitle=mw.title.new(page)
 ifnottitlethenreturnfalseend
 localcontent=title:getContent()
 returnp.isDisambiguation(content)
 end

 -- Entry points for templates
 p.isDisambiguationPage=function(frame)
 localtitle=frame.args[1]
 returnp._isDisambiguationPage(title)and"yes"or""
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /