Help:Magic words: Difference between revisions

Content deleted Content added
the switches are not "___location-dependent", but MOS:ORDER describes preferences for where to put them for convenience of the editors, like DISPLAYTITLE goes near the top and DEFAULTSORT goes together with the categories — Undid revision 1287352321 by Jonesey95 (talk)
m fix
 
(12 intermediate revisions by 6 users not shown)
Line 1:
{{pp-vandalism|small=yes}}
{{short description|Special markup for MediaWiki}}
{{redirect-multi|2
|WP:MAGIC|H:MW
|WikiProject Magic|Wikipedia:WikiProject Magic}}
{{redirect|H:MW|the MediaWiki Help namespace|Help:MediaWiki namespace|information about the entire MediaWiki software application|MediaWiki}}
{{for-multi|ana introductionmore comprehensive guide|mw:Help:Magic words for beginners}}
{{Wikipedia how-to|H:MW|WP:MAGIC|WP:MAGICWORDS}}
{{Simple|Help:Magic words for beginners}}
 
'''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 ⟶ 29:
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 ⟶ 40:
! 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).
|}
 
== Variables ==
{{Shortcut|WP:VAR}}
{{Redirectredirect-multi|2|WP:VAR|WP:PAGENAME|policies and guidelines with WP:*VAR shortcuts, mostly about style matters|WP:VARS|the article naming policy|Wikipedia:Article titles}}
{{Further|mw:Help:Magic words#Variables|Wikipedia:Page name#sub}}
{{Redirect|WP:VAR|policies and guidelines with WP:*VAR shortcuts, mostly about style matters|WP:VARS}}
{{Redirect|WP:PAGENAME|the article naming policy|Wikipedia:Article titles}}
 
{| class="wikitable plainrowheaders"
! scope="col" | Page name variable
Line 351 ⟶ 373:
| 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 452 ⟶ 474:
| 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).
|}