Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Module:Disambiguation

Permanently protected module
From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
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.
Page protectedThis 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.
WarningThis 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.

Usage

{{#invoke:Disambiguation|isDisambiguationPage|Page title}}
returnsyes 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 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
(wherecontent 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
(wherepageName is a string, the name of page to check)

Internal operations

  • Althoughset 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 atModule:Disambiguation/templates.
The abovedocumentation istranscluded fromModule:Disambiguation/doc.(edit |history)
Editors can experiment in this module'ssandbox(edit |diff) andtestcases(edit |run) pages.
Subpages of this module.

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
Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Disambiguation&oldid=1273853830"
Categories:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp