Help:Magic words: Difference between revisions

Content deleted Content added
Other variables by type: add id for direct link
Behavior switches: Add missing nowiki
 
(22 intermediate revisions by 9 users not shown)
Line 1:
{{pp-vandalism|small=yes}}
{{Shortshort description|Special markup for MediaWiki}}
{{redirect|WP:MAGIC|WikiProject Magic|Wikipedia:WikiProject Magic}}
{{redirect|H:MW|the MediaWiki Help namespace|Help:MediaWiki namespace|information about the entire MediaWiki software application|MediaWiki}}
{{for|an introduction|Help:Magic words for beginners}}{{for|a more comprehensive guide|mw:Help:Magic words}}{{Wikipedia how-to|H:MW|WP:MAGIC|WP:MAGICWORDS}}
{{Wikipedia how-to|H:MW|WP:MAGIC|WP:MAGICWORD|WP:MAGICWORDS}}
 
'''Magic words''' (including '''parser functions''', '''variables''', and '''behavior switches''') are features of [[Help:Wiki markup|wiki markup]] that give instructions to Wikipedia's underlying [[MediaWiki]] software. For example, certain magic words canare used to suppress or position the [[Wikipedia:Table of contents|table of contents]], disable [[Wikipedia:INDEXING|indexing]] by external search engines, andor produce output dynamically based on the current page or on user-defined [[Help:Conditional expressions|conditional logicexpressions]]. Some of these features are especially useful for [[WP:Templates|templates]].
 
This page is a quick reference for magic words. For more comprehensive information, refer to the main MediaWiki documentation:
* [[mw:Help:Magic words]]: All standard magic words, including the "standard" parser functions.
* [[mw:Help:Extension:ParserFunctions]]: Additional parser functions, including conditional expressions, included in English Wikipedia.
 
== General information ==
In general, there are three types of magic words.:
# '''[[#Behavior switches|Behavior switches]]''': often appear in double underscores, all uppercase, e.g., <code>__NOTOC<nowiki/>__</code>. They will change the behavior of a page, rather than return a value.
# '''[[#Parser functions|Parser functions]]''': all in lowercase. A parser function sometimes starts with a pound sign (<code>#</code>) and will always be followed by a colon (<code>:</code>) and pipe-separated (<code>|</code>) parameters, e.g., <code><nowiki>{{#ifexpr:Y|Yes|No}}</nowiki></code>, wrapped in double braces. They will take a value and return a value.
# '''[[#Variables|Variables]]''': these are all uppercase, e.g., {{tld|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 are [[case sensitive]].
* [[Whitespace character|White space]] is generously allowed for readability. It will beis stripped from the start and end of their keywords and parameters (as is also done in template calls using named parameters).
* They can be [[WP:Transclusion|transcluded]], even variables "about the current page". This is ensured by the parsing order.
* Instead of magically transforming into HTML instructions, {{tag|[[help:wikitext#Nowiki|nowiki]]|o}} tags remove this magic so a magic word can itself be displayed (documented), e.g. <code><nowiki><nowiki>{{#magic:}}</nowiki></nowiki></code>or <code><nowiki>{{#magic:<nowiki/>}}</nowiki></code>.
Line 26 ⟶ 25:
Magic words compared to templates:
* As with templates, magic words can be [[help:transclusion|transcluded]] and [[Help:substitution|substituted]].
* 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 <code>#</code>([[Hash (character)|pound or hash]]), but template names [[wp:NCHASHTAG | will not start with a <code>#</code>]], and probably not end in a <code>:</code> (colon), or be all-uppercase.
* The first parameter's syntax differs. In <code>{{#magic: <nowiki/>p1 | p2 | p3}}</code>, the name is <code>#magic</code> and it is followed by an unspaced <code>:</code> and a required input parameter, <code>p1</code>. With a template, <code>p1</code> is optional and it is preceded by a <code>|</code> (pipe) instead of a <code>:</code>, e.g. <code><nowiki>{{templatetemp</nowiki><nowiki/><nowiki>late|p1}}</nowiki></code>.
 
Most magic words can be used in anywhere needed locations on a page;, but see [[MOS:ORDER]] for guidance on where toplacing placesome magic words that are behavior switches (such as <code><nowiki>{{DEFAULTSORT:}}</nowiki></code> and <code><nowiki>{{DISPLAYTITLE}}</nowiki></code>).
 
== Behavior switches ==
Line 37 ⟶ 36:
! scope="col" | Description
|-
| colspan=2 align=center style="background-color:#f1f4fd" | '''[[Wikipedia:Table of contents|Table of contents]]'''
! scope="row" id="TOC" | <kbd><nowiki>__TOC__</nowiki></kbd>
| Places the page's [[Help:Table of contents|table 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 default Vector 2022 skin.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="FORCETOCTOC" | <kbdcode><nowiki>__FORCETOC____TOC__</nowiki></kbdcode>
| Places the page's [[Help:Table of contents|table 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 default [[Wikipedia:Vector 2022|Vector 2022]] skin.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="FORCETOC" | <code><nowiki>__FORCETOC__</nowiki></code>
| 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.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="NOTOC" | <kbdcode><nowiki>__NOTOC__</nowiki></kbdcode>
| Suppresses the appearance of the page's TOC. Can be used anywhere on a page. [[Help:Mobile access|Mobile version]] use an alternative navigation scheme, which is not affected by <code><nowiki>__NOTOC__</nowiki></code>.
|-
| colspan=2 align=center style="background-color:#f1f4fd" | '''Editing'''
! scope="row" id="NOEDITSECTION" | <kbd><nowiki>__NOEDITSECTION__</nowiki></kbd>
| Hides the "edit" links normally beside ''all'' headings on the page. To hide the edit link beside a ''particular'' heading, specify the heading using e.g. an [[HTML element|HTML tag]] such as {{tag|h2|content=''heading''}} rather than with the usual wiki equals-signs syntax (e.g. {{nowrap|1=<kbd>== ''heading'' ==</kbd>}}{{thinsp}}).
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="ARCHIVEDTALKNOEDITSECTION" | <kbdcode><nowiki>__ARCHIVEDTALK____NOEDITSECTION__</nowiki></kbdcode>
| Hides the "edit" links normally beside ''all'' headings on the page. To hide the edit link beside a ''particular'' heading, specify the heading using e.g. an [[HTML element|HTML tag]] such as {{tag|h2|content=''heading''}} rather than with the usual wiki equals-signs syntax (e.g. {{nowrap|1=<kbdcode>== ''heading'' ==</kbdcode>}}{{thinsp}}).
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="ARCHIVEDTALK" | <code><nowiki>__ARCHIVEDTALK__</nowiki></code>
| Hides the [[:mw:Talk_pages_project/Replying|"Reply" button]]
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="NEWSECTIONLINKNOTALK" | <kbdcode><nowiki>__NEWSECTIONLINK____NOTALK__</nowiki></kbdcode>
| Makes a page in a talk namespace not be treated like a talk page.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="NEWSECTIONLINK" | <code><nowiki>__NEWSECTIONLINK__</nowiki></code>
| On non-talk pages, adds a "{{int:vector-action-addsection}}" link as a means to add a new section to the page.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="NONEWSECTIONLINK" | <kbdcode><nowiki>__NONEWSECTIONLINK__</nowiki></kbdcode>
| Removes the "{{int:vector-action-addsection}}" link (the add-new-section link) on talk pages.
|-
| colspan=2 align=center style="background-color:#f1f4fd" | '''Categories'''
! scope="row" id="NOGALLERY" | <kbd><nowiki>__NOGALLERY__</nowiki></kbd>
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="NOGALLERY" | <kbdcode><nowiki>__NOGALLERY__</nowiki></kbdcode>
| Replaces thumbnails on a category page with normal links.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="HIDDENCAT" | <kbdcode><nowiki>__HIDDENCAT__</nowiki></kbdcode>
| Makes a category [[WP:HIDDENCAT|hidden]] when included on that category's page.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="INDEXEXPECTUNUSEDCATEGORY" | <kbdcode><nowiki>__INDEX____EXPECTUNUSEDCATEGORY__</nowiki></kbdcode>
| Removes a category from [[Special:UnusedCategories]].
|-
| colspan=2 align=center style="background-color:#f1f4fd" | '''Other'''
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="EXPECTUNUSEDTEMPLATE" | <code><nowiki>__EXPECTUNUSEDTEMPLATE__</nowiki></code>
| <div>Used on a template page, removes the page from [[Special:UnusedTemplates]].
 
If this switch is not intended to be transcluded with the template's contents, it should be used inside {{tag|noinclude}} (or on a template documentation page inside ‎{{tag|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 ‎{{tag|includeonly}} tags within the template page.</div>
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="INDEX" | <code><nowiki>__INDEX__</nowiki></code>
| Instructs [[Web search engine|search engine]]s to index the page.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="NOINDEX" | <kbdcode><nowiki>__NOINDEX__</nowiki></kbdcode>
| Instructs search engines not to index the page. See [[Wikipedia:Controlling search engine indexing]].
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="STATICREDIRECT" | <kbdcode><nowiki>__STATICREDIRECT__</nowiki></kbdcode>
| Prevents the link on a [[Help:Redirect|redirection]] 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).
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="DISAMBIG" | <kbdcode><nowiki>__DISAMBIG__</nowiki></kbdcode>
| Marks a page as a [[WP:DAB|disambiguation page]], adds it to [[Special:DisambiguationPages]] and places inward links in [[Special:DisambiguationPageLinks]]. (See [[mw:Extension:Disambiguator]].)
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="DISPLAYTITLE" | <kbdcode>{<nowiki/>{DISPLAYTITLE:''title''}}</kbdcode>
| Used to amend the [[WP:DISPLAYTITLE|displayed form]] of the page's title.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="DEFAULTSORT" | <kbdcode>{<nowiki/>{DEFAULTSORT:''sortkey''}}</kbdcode>
| Sets the default [[Help:Category#Sorting category pages|key]] (the index) under which the page is categorised. Functionality is documented at {{section link|Help:Category#Default sort key}}, and guidelines are at {{section link|Wikipedia:Categorization#Sort keys}}.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="NOEXTERNALLANGLINKS" | <kbdcode>[[mw:Wikibase/Installation/Advanced configuration#noexternallanglinks|{<nowiki/>{NOEXTERNALLANGLINKS}}]]</kbdcode>
|| (equivalent to <code>{<nowiki/>{NOEXTERNALLANGLINKS:*}}</code>{{thinsp}}) Suppresses the automated inclusion of [[Wikidata:Help:Linking Wikipedia pages|Wikidata]] [[Help:Interlanguage links|interlanguage links]] on the lefthand side of the page. LinksTo tosuppress particularspecific language links rather than all languages may be suppressed by usinguse <code>{<nowiki/>{NOEXTERNALLANGLINKS:''list''}}</code>, where ''list'' is a [[Vertical bar|pipe]]-[[Delimiter|delimited]] list of [[languageISO code639‑1]]s language codes (e.g. <code>{<nowiki/>{NOEXTERNALLANGLINKS:fr{{pipe}}es{{pipe}}ja}}</code> to suppress the French ("fr"), Spanish ("es") and Japanese ("ja") interlanguage links).
|}
 
Line 156 ⟶ 176:
|}
 
''Note:''{{a 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 (<kbd>:</kbd>) is used to pass the parameter, rather than a pipe (<kbd>{{!}}</kbd>) that is used in templates, like <kbd><nowiki>{{MAGICWORD:value}}</nowiki></kbd>. For example, <kbd><nowiki>{{TALKPAGENAME:Wikipedia:MOS}}</nowiki></kbd> returns <samp><nowiki>Wikipedia talk:MOS</nowiki></samp> on any page.
 
{{respond|orangeexclamation|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, [[Help:Link|prefix the variable with a colon]] (<code>:</code>); for example <kbd><nowiki>[[:{{FULLPAGENAME}}]]</nowiki></kbd>.
''Note:'' In the "Category" and "Category talk" namespaces, to wikilink (some) page name variables may require [[help:link|prefixing a colon]] to avoid unwanted categorization.
 
{{crossref|printworthy=y|For more details on parser functions that relate to page names and namespaces, see: {{section link|meta:Help:Page name#Variables and parser functions}}.}}
Line 196 ⟶ 216:
 
=== Other variables by type ===
{| class="wikitable plainrowheaders" id="Current_date_and_time"
|+ Current date and time
! scope="col" colspan="2" | Universal time
Line 351 ⟶ 371:
| Number of users in the [[Wikipedia:User access levels|user group]] named ''groupname''.
|}
Page IDs can be associated with articles via wikilinks (i.e. <code>[[Special:Redirect/page/3235121]]</code> goes to this page).
To output numbers without comma [[Delimiter|separator]]s (for example, as "123456789" rather than "123,456,789"), append the parameter <kbd>|R</kbd>.
 
Line 384 ⟶ 404:
| Outputs ''singular'' if ''N'' is equal to 1, otherwise outputs ''plural''. See the [[mw:Help:Magic words#Localization|documentation at mediawiki.org]] for more details.
|-
! scope="row" id="mwtime" | <kbd>{<nowiki/>{#time:''format''{{pipe}}''object''}}</kbd><br /><kbd>{<nowiki/>{#timel:''format''{{pipe}}''object''}}<br /><br />{<nowiki/>{#time:d F Y{{pipe}}''date''{{pipe}}''langcode''}}<br /><br />{<nowiki/>{#timef:object{{pipe}}''format type''{{pipe}}''langcode''}}</kbd>
| Used to format dates and times, for ISO format, dots or English month names. <kbd>#timel</kbd> isand <kbd>#timefl</kbd> are based on local time as defined for each wiki; for English Wikipedia, this is identical to <kbd>#time</kbd> and <kbd>#timef</kbd>.<br />The optional 3rd parameter is the output language code (French, German, Swedish: fr, de, sv, etc.). Example Finnish: <kbd><nowiki>{{#time:d F Y|June 30, 2016|fi}}</nowiki></kbd> shows: {{#time:d F Y|June 30, 2016|fi}} (June). ISO to German: <kbd><nowiki>{{#time:d. M Y|1987-10-31|de}}</nowiki></kbd> shows: {{#time:d. M Y|1987-10-31|de}}.<br />For format codes, see: [[mw:Help:Extension:ParserFunctions##time]]. Use the format <kbd><nowiki>{{#time: H:i, j F Y (e)|...}}</nowiki></kbd> to match the format used by timestamps in signatures.<br /><kbd>#timef</kbd> formats a date using a standard format for the selected language, see: [[mw:Help:Extension:ParserFunctions##timef]].
|-
! scope="row" id="gender" | <kbd>{<nowiki/>{gender:''user''{{pipe}}''m_out''{{pipe}}''f_out''{{pipe}}''u_out''}}</kbd>
Line 435 ⟶ 455:
|-
! scope="row" id="expr" |<kbd>[[mw:Help:Extension:Parser functions##expr|{<nowiki/>{#expr:''expression''}}]] </kbd>
| Evaluates ''expression'' (see [[mmw:HelpManual:CalculationExpr parser function syntax]]).
|-
! scope="row" id="if" | <kbd>[[mw:Help:Extension:Parser functions##if|{<nowiki/>{#if:''string'' {{pipe}}''result1'' {{pipe}}''result2''}}]] </kbd>
Line 452 ⟶ 472:
| Outputs ''result1'' if the page [<nowiki/>[''pagetitle'']] exists, otherwise outputs ''result2''. Note that underscores are needed for spaces in namespaces.
|-
! scope="row" style="white-space: nowrap;" | <kbd>[[mw:Help:Extension:Parser functions##switch|{<nowiki/>{[[Help:Switch parser function|#switch]]:''string'' {{pipe}}''c1''=''r1'' {{pipe}}''c2''=''r2'' ... {{pipe}}''<nowiki>default''}}]] </nowiki>''</kbd>
| Outputs ''r1'' if ''string'' is ''c1'', ''r2'' if ''string'' is ''c2'', etc., otherwise outputs ''default'' (if provided).
|}