Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Help:Magic words

Page semi-protected
From Wikipedia, the free encyclopedia

Special markup for MediaWiki
"WP:MAGIC" and "H:MW" redirect here. For WikiProject Magic, seeWikipedia:WikiProject Magic. For the MediaWiki Help namespace, seeHelp:MediaWiki namespace. For the MediaWiki software application, seeMediaWiki.
For a more comprehensive guide, seemw:Help:Magic words.
This help page is ahow-to guide.
It explains concepts or processes used by the Wikipedia community. It is not one ofWikipedia's policies or guidelines, and may reflect varying levels ofconsensus.
Are you new here? There is a simplified version of this page atHelp:Magic words for beginners.

Magic words (includingparser functions,variables, andbehavior switches) are features ofwiki markup that give instructions to Wikipedia's underlyingMediaWiki software. For example, certain magic words are used to suppress or position thetable of contents, disableindexing by external search engines, or produce output dynamically based on the current page or on user-definedconditional expressions. Some of these features are especially useful fortemplates.

This page is a quick reference for magic words. For more comprehensive information, refer to the main MediaWiki documentation:

General information

In general, there are three types of magic words:

  1. Behavior switches: often appear in double underscores, all uppercase, e.g.,__NOTOC__. They will change the behavior of a page, rather than return a value.
  2. Parser functions: all in lowercase. A parser function sometimes starts with a pound sign (#) and will always be followed by a colon (:) and pipe-separated (|) parameters, e.g.,{{#ifexpr:Y|Yes|No}}, wrapped in double braces. They will take a value and return a value.
  3. Variables: these are all uppercase, e.g.,{{PAGENAME}}. A variable will be wrapped in double braces and will return a value in its place.

The software generally interprets magic words in the following way:

  • Magic words arecase sensitive.
  • White space is generously allowed for readability. It is stripped from the start and end of their keywords and parameters (as is also done in template calls using named parameters).
  • They can betranscluded, even variables "about the current page". This is ensured by the parsing order.
  • Instead of magically transforming into HTML instructions,<nowiki> tags remove this magic so a magic word can itself be displayed (documented), e.g.<nowiki>{{#magic:}}</nowiki>or{{#magic:<nowiki/>}}.

Magic words compared to templates:

  • As with templates, magic words can betranscluded andsubstituted.
  • The names of magic words are purposely chosen to be unlike the names of templates, and vice versa. Many parser function names will begin with a#(pound or hash), but template names will not start with a#, and probably not end in a: (colon), or be all-uppercase.
  • The first parameter's syntax differs. In{{#magic: p1 | p2 | p3}}, the name is#magic and it is followed by an unspaced: and a required input parameter,p1. With a template,p1 is optional and it is preceded by a| (pipe) instead of a:, e.g.{{template|p1}}.

Most magic words can be used where needed on a page, but seeMOS:ORDER for guidance on placing some magic words that are behavior switches (such as{{DEFAULTSORT:}} and{{DISPLAYTITLE}}).

Behavior switches

Further information:mw:Help:Magic words § Behavior switches
SwitchDescription
Table of contents
__TOC__Places the page'stable of contents (TOC) at the word's position. This magic word does not work in skins that present the table of contents outside the article content e.g. the defaultVector 2022 skin.
__FORCETOC__Forces the TOC to appear in its default position, even when there are fewer than four headings. Can be used anywhere on a page. This magic word does not work in skins that present the table of contents outside the article content e.g. the default Vector 2022 skin.
__NOTOC__Suppresses the appearance of the page's TOC. Can be used anywhere on a page.Mobile version use an alternative navigation scheme, which is not affected by__NOTOC__.
Editing
__NOEDITSECTION__Hides the "edit" links normally besideall headings on the page. To hide the edit link beside aparticular heading, specify the heading using e.g. anHTML tag such as<h2>heading</h2> rather than with the usual wiki equals-signs syntax (e.g.==heading ==).
__ARCHIVEDTALK__Hides the"Reply" button
__NOTALK__Makes a page in a talk namespace not be treated like a talk page.
__NEWSECTIONLINK__On non-talk pages, adds a "New section" link as a means to add a new section to the page.
__NONEWSECTIONLINK__Removes the "New section" link (the add-new-section link) on talk pages.
Categories
__NOGALLERY__Replaces thumbnails on a category page with normal links.
__HIDDENCAT__Makes a categoryhidden when included on that category's page.
__EXPECTUNUSEDCATEGORY__Removes a category fromSpecial:UnusedCategories.
Other
__EXPECTUNUSEDTEMPLATE__
Used on a template page, removes the page fromSpecial:UnusedTemplates.

If this switch is not intended to be transcluded with the template's contents, it should be used inside<noinclude>...</noinclude> (or on a template documentation page inside ‎<noinclude>...</noinclude>), similarly to template categories.

If the switch is intended to remove from the report all pages that transclude a given template (for example, a notice that is transcluded on testcases or sandbox subpages), put the switch inside ‎<includeonly>...</includeonly> tags within the template page.
__INDEX__Instructssearch engines to index the page.
__NOINDEX__Instructs search engines not to index the page. SeeWikipedia:Controlling search engine indexing.
__STATICREDIRECT__Prevents the link on aredirection page from being updated automatically when the page to which it redirects is moved (and "Update any redirects that point to the original title" is selected).
__DISAMBIG__Marks a page as adisambiguation page, adds it toSpecial:DisambiguationPages and places inward links inSpecial:DisambiguationPageLinks. (Seemw:Extension:Disambiguator.)
__EXPECTED_UNCONNECTED_PAGE__Some pages do not fit the scope of Wikidata items, such as discussion archives, template subpages, etc. To prevent a page from being listed inSpecial:UnconnectedPages, use this magic word anywhere on the page. Pages that don't meetWikidata's notability criteria should not receive a Wikidata item (seemw:Extension:Wikibase).
{{DISPLAYTITLE:title}}Used to amend thedisplayed form of the page's title.
{{DEFAULTSORT:sortkey}}Sets the defaultkey (the index) under which the page is categorised. Functionality is documented atHelp:Category § Default sort key, and guidelines are atWikipedia:Categorization § Sort keys.
{{NOEXTERNALLANGLINKS}}(equivalent to{{NOEXTERNALLANGLINKS:*}}) Suppresses the automated inclusion ofWikidatainterlanguage links on the lefthand side of the page. To suppress specific language links rather than all languages use{{NOEXTERNALLANGLINKS:list}}, wherelist is apipe-delimited list ofISO 639‑1 language codes (e.g.{{NOEXTERNALLANGLINKS:fr|es|ja}} to suppress the French ("fr"), Spanish ("es") and Japanese ("ja") interlanguage links).

Variables

Shortcut
"WP:VAR" and "WP:PAGENAME" redirect here. For policies and guidelines with WP:*VAR shortcuts, mostly about style matters, seeWP:VARS. For the article naming policy, seeWikipedia:Article titles.
Further information:mw:Help:Magic words § Variables, andWikipedia:Page name § sub
Page name variableOutputDescription
{{FULLPAGENAME}}Help:Magic wordsCanonicalpage name.Title line. Title unless letter-case is altered with{{DISPLAYTITLE}}.[a]
{{PAGENAME}}Magic wordsTitle line excludingnamespace.
{{BASEPAGENAME}}Magic wordsTitle of parent page, excluding namespace.
{{ROOTPAGENAME}}Magic wordsTitle of topmost parent (before all subpages), excluding namespace.
{{SUBPAGENAME}}Magic wordsOn a subpage, rightmost portion ofcurrent title; higher subpagenames show asbacklinks.
{{ARTICLEPAGENAME}}Help:Magic wordsTitle of the subject page associated with the current page. These are useful on talk pages (but see note about Category talk pages).
{{SUBJECTPAGENAME}}Help:Magic words
{{TALKPAGENAME}}Help talk:Magic wordsTitle of the talk page associated with the current page. Useful on subject pages.
{{NAMESPACENUMBER}}12Number of the current page's namespace.
{{NAMESPACE}}HelpNamespace of the title.
{{ARTICLESPACE}}HelpOn a talk page, the namespace part of the title of the associated subject page.
{{SUBJECTSPACE}}Help
{{TALKSPACE}}Help talkNamespace of the talk page associated with the current page.
{{FULLPAGENAMEE}},
{{PAGENAMEE}},
 (etc.)
Help:Magic_words,
Magic_words,
(etc.)
Adding an E to the end of the above variables, renders the above encoded for use in MediaWikiURLs (i.e. with underscores replacing spaces).
{{SHORTDESC}}Only works on the English Wikipedia, where it displays a short description below the article title on mobile platforms.SeeWikipedia:Short description.

information Note: The magic words above can also take a parameter, in order to parse values on a page other than the current page. A colon (:) is used to pass the parameter, rather than a pipe (|) that is used in templates, like{{MAGICWORD:value}}. For example,{{TALKPAGENAME:Wikipedia:MOS}} returnsWikipedia talk:MOS on any page.

 Caution: Attempting to use (some) page name variables to create a wikilink to an image page, category page or interlanguage link will produce a different effect: this will respectively place the image on the page, add the page to the category, or create an interlanguage link at the edge of the page. To override this normal behavior,prefix the variable with a colon (:); for example[[:{{FULLPAGENAME}}]].

For more details on parser functions that relate to page names and namespaces, see:meta:Help:Page name § Variables and parser functions.

Site variableOutputDescription
{{SITENAME}}WikipediaSite name ($wgSitename).
{{SERVER}}//en.wikipedia.orgDomainURL ($wgServer).
{{SERVERNAME}}en.wikipedia.orgSubdomain and domain name.
{{ARTICLEPATH}}/wiki/$1Relative article path ($wgArticlePath).
{{SCRIPTPATH}}/wRelative script path ($wgScriptPath).
{{STYLEPATH}}/w/skinsRelative style path ($wgStylePath).
{{CURRENTVERSION}}1.45.0-wmf.24 (4a7b2ac)Returns current MediaWiki version.

Other variables by type

Current date and time
Universal timeLocal-website time
VariableOutputVariableOutput
{{CURRENTYEAR}}2025{{LOCALYEAR}}2025
{{CURRENTMONTH}}10{{LOCALMONTH}}10
{{CURRENTMONTHNAME}}October{{LOCALMONTHNAME}}October
{{CURRENTMONTHABBREV}}Oct{{LOCALMONTHABBREV}}Oct
{{CURRENTDAY}}[b]26{{LOCALDAY}}[b]26
{{CURRENTDAY2}}[b]26{{LOCALDAY2}}[b]26
{{CURRENTDOW}}0{{LOCALDOW}}0
{{CURRENTDAYNAME}}Sunday{{LOCALDAYNAME}}Sunday
{{CURRENTTIME}}18:02{{LOCALTIME}}18:02
{{CURRENTHOUR}}18{{LOCALHOUR}}18
{{CURRENTWEEK}}43{{LOCALWEEK}}43
{{CURRENTTIMESTAMP}}[c]20251026180221{{LOCALTIMESTAMP}}[c]20251026180221
Page revision data
VariableOutput
{{REVISIONDAY}}[b]5
{{REVISIONDAY2}}[b]05
{{REVISIONMONTH}}10
{{REVISIONYEAR}}2025
{{REVISIONTIMESTAMP}}[c]20251005161638
{{REVISIONUSER}}[d]Redrose64
Wiki statistics
{{NUMBEROFPAGES}}64,334,093
{{NUMBEROFARTICLES}}7,080,767
{{NUMBEROFFILES}}951,554
{{NUMBEROFEDITS}}1,314,141,557
{{NUMBEROFUSERS}}49,867,863
{{NUMBEROFADMINS}}828
{{NUMBEROFACTIVEUSERS}}114,046

Parser functions

Shortcuts
Further information:mw:Help:Magic words § Parser functions, andmw:Help:Extension:ParserFunctions

Metadata

FunctionDescription
{{PAGEID}}Unique page identifier number (for example, this page's ID is3235121).
{{PAGESIZE:fullpagename}}[e]Size of named page in bytes (for example, this page is40,142 bytes).
{{PROTECTIONLEVEL:action|fullpagename}}Protection level assigned toaction ("edit", "move", etc.) on named page (this page's protection level for "edit" isautoconfirmed).
{{PROTECTIONEXPIRY:action|fullpagename}}Protection expiry assigned toaction ("edit", "move", etc.) on named page (this page's protection expiry isinfinity).
{{PENDINGCHANGELEVEL:fullpagename}}Protection level forpending changes on the named page (this page, which doesn't have one, is).
{{PAGESINCATEGORY:categoryname}}Number of pages in the category namedcategoryname. Each subcategory is counted as one item.
{{NUMBERINGROUP:groupname}}Number of users in theuser group namedgroupname.

Page IDs can be associated with articles via wikilinks (i.e.Special:Redirect/page/3235121 goes to this page).To output numbers without commaseparators (for example, as "123456789" rather than "123,456,789"), append the parameter|R.

Formatting

Further information:mw:Help:Magic words § Formatting
FunctionDescription
{{lc:string}}Converts all characters instring to lower case.
{{lcfirst:string}}Converts first character ofstring to lower case.
{{uc:string}}Converts all characters instring to upper case.
{{ucfirst:string}}Converts first character ofstring to upper case.
{{formatnum:unformatted_number}}
{{formatnum:formatted_num |R}}
Adds comma separators to anunformatted_number (e.g. 123456789 becomes 123,456,789). To remove such formatting, use{{formatnum:formatted_number|R}} (i.e.{{formatnum:7,654,321|R}}, for example, produces 7654321).
{{#dateformat:date|format}}
{{#formatdate:date|format}}
Formats a date according to user preferences; a default can be given as an optional case-sensitive second parameter for users without date preference; can convert a date from an existing format to any ofdmy,mdy,ymd, orISO 8601 formats, with the user's preference overriding the specified format.
{{padleft:xyz|stringlength}}
{{padright:xyz|stringlength}}

{{padleft:xyz|length|padstr}}
{{padright:xyz|length|padstr}}
Pad with zeroes '0' to the right or left, to fill the given length; an alternative padding string can be given as a third parameter; the repeated padding string (padstr) will be truncated if its length does not evenly divide the required number of characters.
{{plural:N|singular|plural}}Outputssingular ifN is equal to 1, otherwise outputsplural. See thedocumentation at mediawiki.org for more details.
{{#time:format|object}}
{{#timel:format|object}}

{{#time:d F Y|date|langcode}}

{{#timef:object|format type|langcode}}
Used to format dates and times, for ISO format, dots or English month names.#timel and#timefl are based on local time as defined for each wiki; for English Wikipedia, this is identical to#time and#timef.
The optional 3rd parameter is the output language code (French, German, Swedish: fr, de, sv, etc.). Example Finnish:{{#time:d F Y|June 30, 2016|fi}} shows: 30 kesäkuu 2016 (June). ISO to German:{{#time:d. M Y|1987-10-31|de}} shows: 31. Okt. 1987.
For format codes, see:mw:Help:Extension:ParserFunctions##time. Use the format{{#time: H:i, j F Y (e)|...}} to match the format used by timestamps in signatures.
#timef formats a date using a standard format for the selected language, see:mw:Help:Extension:ParserFunctions##timef.
{{gender:user|m_out|f_out|u_out}}Outputsm_out,f_out oru_out according to whether the gender specified inuser's preferences is, respectively, male, female or unspecified. Other parameter permutations are available, seemw:Help:Magic words#gender andtranslatewiki:Gender.
{{#tag:tagname|content with magic}}Only way toevaluate magic wordsinside a tag, in order to generate<tagname>magic</tagname>. Also handles tag attributes. Details atmw:Help:Magic words#tag.

Paths

FunctionDescription
{{localurl:fullpagename |query}}Relativepath to page name. Thequery parameter is optional.
{{fullurl:fullpagename |query}}Absolute path, withoutprotocol prefix (i.e. without "http:" etc.), to page name. Thequery parameter is optional.
{{canonicalurl:fullpagename |query}}Absolute path, including protocol prefix, to page name. Thequery parameter is optional.
{{filepath:filename}}Absolute path to the media filefilename.
{{urlencode:string}}Encodesstring for use in URL query strings;{{urlencode:test string}}, for example, produces: test+string. To encodestring for use in URL paths or MediaWiki page names, append, respectively,|PATH or|WIKI (to produce "test%20string" or "test_string").
{{anchorencode:string}}Input encoded for use in MediaWiki URLsection anchors.
{{ns:n}}Returns the name of thenamespace whose index is the numbern. For MediaWiki URLs, use{{nse:}}.
{{#rel2abs:path}}Converts a relative file path to an absolute path.
{{#titleparts:fullpagename|number|first segment}}Splits the fullpagename (title) into that number of segments.

Conditional

Further information:Help:Conditional expressions
FunctionDescription
{{#expr:expression}}Evaluatesexpression (seemw:Manual:Expr parser function syntax).
{{#if:string |result1 |result2}}Outputsresult2 ifstring isempty, otherwise outputsresult1.
{{#ifeq:string1|string2 |result1 |result2}}Outputsresult1 ifstring1 andstring2 are equal (alphabetically or numerically), otherwise outputsresult2.
{{#iferror:test_string |result1 |result2}}Outputsresult1 iftest_string generates a parsing error, otherwise outputsresult2.
{{#ifexpr:expression |result1 |result2}}Outputsresult1 ifexpression is true, otherwise outputsresult2.
{{#ifexist:pagetitle |result1 |result2}}[e]Outputsresult1 if the page [[pagetitle]] exists, otherwise outputsresult2. Note that underscores are needed for spaces in namespaces.
{{#switch:string |c1=r1 |c2=r2 ... |default}}Outputsr1 ifstring isc1,r2 ifstring isc2, etc., otherwise outputsdefault (if provided).

If, in these conditional functions,empty unnamed parameters are to be parsed as empty rather than as text (i.e. as empty rather than as the text "{{{1}}}", "{{{2}}}", etc.), they will require trailing pipes (i.e.{{{1|}}},{{{2|}}}, etc., rather than{{{1}}},{{{2}}}, etc.).

Other

FunctionDescription
{{#babel:code1|code2|...}}Renderuserboxes telling your language skills. Improves upon{{Babel}} (an alternative).
{{#categorytree:category|...}}List pages in a category, recursively.
{{#coordinates:arg1|arg2|...}}Save theGeoData coordinates of the subject to the page's database. Used in{{coord}}.
{{#invoke:module|function|arg1|...}}UseScribunto to transclude alua template, e.g. functionreplace inmoduleString.
{{#language:code1|code2}}Print the name represented by the language code, e.g.enEnglish. Print in language 2 if given, e.g.{{#language:en|zh}} prints 英语
{{#lst:}}, {{#lsth:}}, {{#lstx:}}Three ways totransclude a section of a page.
{{#mentor:Username}}Display the currently assigned mentor for target Username, if set.
{{#property:arg1|arg2|...}}Include aproperty (Wikidata) from a named entity, instead of the default on the page.
{{#related:...}}Links to similar topics, to engage readers. (Beta feature.)
{{#section:}}, {{#section-h:}}, {{#section-x:}}Aliases for{{#lst:}}, {{#lsth}}, {{#lstx}} (above).
{{#statements:arg1|...}}Display the value of any statement (Wikidata) included in an item.
{{#target:fullpagename}}Send a message to a list of talk pages on the fullpagename, using theMassMessage function.
{{int:pagename}}Transclude aninterface message, i.e. apagename in MediaWiki namespace
{{!}}Used to include a pipe character as part of a template argument or table cell contents. Before this was added as a magic word, many wikis implemented this by creatingTemplate:! with| as the content.
{{=}}Used to include an equal sign as part of a template argument or table cell contents. Before this was added as a magic word, many wikis implemented this by creatingTemplate:= with= as the content.

Substituting and nesting

Magic words can sometimes behave weirdly whensubstituted or nested. It's possible to subst some magic words (so that the page stops being updated if the value of the word changes). Here are some examples of how this works:

Blue question mark?CodeOutput
Red X symbolN{{PAGESIZE}}0
Green checkmarkY{{PAGESIZE:Help:Magic words}}40,142
Green checkmarkY{{subst:PAGESIZE:Help:Magic words}}40,142
Green checkmarkY{{PAGESIZE:{{FULLPAGENAME}}}}40,142
Red X symbolN{{subst:PAGESIZE:{{FULLPAGENAME}}}}0
Green checkmarkY{{PAGESIZE:{{subst:FULLPAGENAME}}}}40,142
Green checkmarkY{{subst:PAGESIZE:{{subst:FULLPAGENAME}}}}40,142

See also

Notes

  1. ^If{{FULLPAGENAME}} is used in a page that istranscluded from another page, it will return the name of the target. {{#invoke:TEMPLATENAME|main}} can be used to determine the name of the template itself.
  2. ^abcdef{{CURRENTDAY}},{{LOCALDAY}} and{{REVISIONDAY}} return the day (e.g. "6"), whilst{{CURRENTDAY2}},{{LOCALDAY2}} and{{REVISIONDAY2}} return the day with zero-padding (e.g. "06"). For all two-digit days (i.e. 10 to 31), these are the same.
  3. ^abcThese timestamp outputs can be formatted with{{Format revisiontimestamp}} (aka{{FRTS}}). For example, {{FRTS|{{REVISIONTIMESTAMP}}}} turns "20251005161638" into "2025-10-05 16:16:38".
  4. ^This shows the last user to edit the page. There is no way to show the user viewing the page with magic words due to technical restrictions.
  5. ^abThis function is anexpensive parser function.
General
technical help
Special
page
-related
Wikitext
Links anddiffs
Media files: images,
videos and sounds
Other graphics
Templates and
Lua modules
Data structure
HTML andCSS
Customisation
and tools
Automated editing
Retrieved from "https://en.wikipedia.org/w/index.php?title=Help:Magic_words&oldid=1315241943"
Categories:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp