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 {{for-multi|
{{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
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
* 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>{{
Most magic words can be used
== Behavior switches ==
Line 37 ⟶ 40:
! scope="col" | Description
|-
| colspan=2 align=center style="background-color:#f1f4fd" | '''[[Wikipedia:Table of contents|Table of contents]]'''
| 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="
▲| 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" | <
| 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'''
| 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="
▲| 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=<
|-
! 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="
| 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" | <
| 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" | <
| Replaces thumbnails on a category page with normal links.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="HIDDENCAT" | <
| Makes a category [[WP:HIDDENCAT|hidden]] when included on that category's page.
|-
! scope="row" style="background-color:var(--background-color-neutral-subtle);" id="
| 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" | <
| 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" | <
| 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" | <
| 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" | <
| 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" | <
| 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" | <
|| (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.
|}
== Variables ==
{{Shortcut|WP:VAR}}
{{
{{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}}
{| 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>
| Outputs ''r1'' if ''string'' is ''c1'', ''r2'' if ''string'' is ''c2'', etc., otherwise outputs ''default'' (if provided).
|}
|