Help:Magic words: Difference between revisions
PinkYoshiFan (talk | contribs) (Apparently we don't have the disambig extension installed, not sure if anyone else cares about it. I ended up pretty much merging variables and parser functions here due to being fairly similar in invocation.) |
mNo edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{help}} | {{help}} | ||
'''Magic words''' are functions in MediaWiki that either modify the page and are called with double underscores on each side (officially referred to as "behavior switches") and things that return information and are called similarly to templates (officially referred to as "variables", ones that can take parameters can also be called "parser functions"). This is a list of helpful magic words and descriptions. Functions marked as {{color|expensive|red}} use more server resources and should not be used unless neccesary. | '''Magic words''' are functions in MediaWiki that either modify the page and are called with double underscores on each side (officially referred to as "behavior switches") and things that return information and are called similarly to templates (officially referred to as "variables", ones that can take parameters can also be called "parser functions"). This is a list of helpful magic words and descriptions. Functions marked as {{color|expensive|red}} use more server resources and should not be used unless neccesary. Behavior switches are typically used directly on pages (although can be used on templates, such as <code><nowiki>__EXPECTUNUSEDCATEGORY__</nowiki></code> on {{t|Not unused}}, and variables and parser functions are typically used on templates. Variables and parser functions can also be substituted by putting <code>subst:</code> before the name of it but after the opening braces. This is also not a comprehensive list, and only includes the ones that are simpler and/or more likely to be used here. For a full list and more in-depth explanations, see [[mw:Magic words|the mediawiki.org documentation]]. | ||
==Behavior switches== | ==Behavior switches== | ||
{|class="wikitable" | {|class="wikitable mw-collapsible" | ||
!Name | !Name | ||
!Effect | !Effect | ||
Line 19: | Line 20: | ||
|- | |- | ||
|<code><nowiki>__NOGALLERY__</nowiki></code> | |<code><nowiki>__NOGALLERY__</nowiki></code> | ||
|Makes files appear as normal links in [[ | |Makes files appear as normal links in [[Help:Category|categories]] | ||
|- | |- | ||
|<code><nowiki>__HIDDENCAT__</nowiki></code> | |<code><nowiki>__HIDDENCAT__</nowiki></code> | ||
Line 30: | Line 31: | ||
|Hides the page from search engine results | |Hides the page from search engine results | ||
|} | |} | ||
==Variables | ==Variables== | ||
All time-related variables use UTC and may not be fully accurate due to server-side caching. | |||
All time-related variables use UTC. | {|class="wikitable mw-collapsible" | ||
{|class="wikitable" | |||
!colspan="2"|Base MediaWiki variables and parser functions | !colspan="2"|Base MediaWiki variables and parser functions | ||
|- | |- | ||
Line 92: | Line 92: | ||
|<code><nowiki>{{!}}</nowiki></code> | |<code><nowiki>{{!}}</nowiki></code> | ||
|The pipe character <nowiki>|</nowiki>, for table markup within templates. | |The pipe character <nowiki>|</nowiki>, for table markup within templates. | ||
|- | |||
|} | |||
==Parser functions== | |||
{|class="wikitable mw-collapsible" | |||
!colspan="2"|Base MediaWiki parser functions | |||
|- | |||
!Name | |||
!Effect | |||
|- | |- | ||
|<code><nowiki>{{PAGESINCATEGORY:name|modifier}}</nowiki></code> | |<code><nowiki>{{PAGESINCATEGORY:name|modifier}}</nowiki></code> | ||
Line 103: | Line 111: | ||
|- | |- | ||
|<code><nowiki>{{ns:name/id}}</nowiki></code> | |<code><nowiki>{{ns:name/id}}</nowiki></code> | ||
|The name of the [[ | |The name of the [[Help:Namespace|namespace]] specified in <code>name/id</code> | ||
|- | |- | ||
|<code><nowiki>{{lc:text}}</nowiki></code> | |<code><nowiki>{{lc:text}}</nowiki></code> | ||
Line 111: | Line 119: | ||
|<code>text</code> in all uppercase | |<code>text</code> in all uppercase | ||
|} | |} | ||
== | {|class="wikitable mw-collapsible" | ||
!colspan="2"|Extension parser functions | |||
|- | |||
!Name | |||
!Effect | |||
|- | |||
|<code><nowiki>{{#expr:math}}</nowiki></code> | |||
|Does whatever mathematical formula is input. Also supports [[wikipedia:Boolean algebra|boolean]] inputs. | |||
|- | |||
|<code><nowiki>{{#if:test|not empty|empty}}</nowiki></code> | |||
|Returns <code>empty</code> if <code>test</code> is empty or whitespace and <code>not empty</code> if not. | |||
|- | |||
|<code><nowiki>{{#ifeq:test1|test2|same|different}}</nowiki></code> | |||
|Returns <code>same</code> if <code>test1</code> and <code>test2</code> match and <code>different</code> otherwise | |||
|- | |||
|<code><nowiki>{{#switch:test|1=one|2|1+1=two|#default=three}}</nowiki></code> | |||
|Returns <code>one</code> if <code>test</code> is <code>1</code> and <code>two</code> if <code>test</code> is <code>2</code> or <code>1+1</code>, and <code>three</code> if it is none of them. The values to check for can be repeated indefinitely (in theory). | |||
|} | |||
{{Policies}} | {{Policies}} |
Latest revision as of 00:09, 28 January 2024
|
Magic words are functions in MediaWiki that either modify the page and are called with double underscores on each side (officially referred to as "behavior switches") and things that return information and are called similarly to templates (officially referred to as "variables", ones that can take parameters can also be called "parser functions"). This is a list of helpful magic words and descriptions. Functions marked as expensive use more server resources and should not be used unless neccesary. Behavior switches are typically used directly on pages (although can be used on templates, such as __EXPECTUNUSEDCATEGORY__
on {{Not unused}}, and variables and parser functions are typically used on templates. Variables and parser functions can also be substituted by putting subst:
before the name of it but after the opening braces. This is also not a comprehensive list, and only includes the ones that are simpler and/or more likely to be used here. For a full list and more in-depth explanations, see the mediawiki.org documentation.
Behavior switches
Name | Effect |
---|---|
__NOTOC__
|
Makes the table of contents disappear |
__FORCETOC__
|
Overrides and undoes __NOTOC__
|
__TOC__
|
Makes the table of contents appear in a different location |
__NOEDITSECTION__
|
Makes a page section not be editable without editing the whole page |
__NOGALLERY__
|
Makes files appear as normal links in categories |
__HIDDENCAT__
|
Makes a category hidden and not appear to users unless they change a setting in their user preferences |
__EXPECTUNUSEDCATEGORY__
|
Makes a category not appear unused. Should only be used on maintenance categories. |
__NOINDEX__
|
Hides the page from search engine results |
Variables
All time-related variables use UTC and may not be fully accurate due to server-side caching.
Base MediaWiki variables and parser functions | |
---|---|
Name | Returns |
{{CURRENTYEAR}}
|
Year as numerals |
{{CURRENTMONTH}}
|
Month as numerals with leading zeroes added (adding 1 to the end removes the leading zeroes, adding NAME to the end makes it the name, adding ABBREV makes it the name abbreviation) |
{{CURRENTDAY}}
|
Day of the month (adding 2 to the end adds leading zeroes) |
{{CURRENTDOW}}/{{CURRENTDAYNAME}}
|
Number/name of the day of the week |
{{CURRENTTIME}}
|
24-hour time as HH:mm |
{{CURRENTHOUR}}
|
Hour with leading zeroes |
{{CURRENTWEEK}}
|
Current week of the year |
{{CURRENTTIMESTAMP}}
|
Timestamp as YYYYMMDDHHmmss |
{{SITENAME}}
|
Name of the wiki |
{{NUMBEROFx}}
|
Number of x on the wiki:
|
{{xPAGENAME}}
|
Returns the name of the current page, containing the parts x
This is not affected by DISPLAYTITLE |
{{NAMESPACE}}
|
The namespace of the page. Adding NUMBER to the end makes it the id. |
{{!}}
|
The pipe character |, for table markup within templates. |
Parser functions
Base MediaWiki parser functions | |
---|---|
Name | Effect |
{{PAGESINCATEGORY:name|modifier}}
|
EXPENSIVE. Returns the number of pages in the category name . modifier can be set to all, pages, subcats (subcategories), or files.
|
{{DISPLAYTITLE:name}}
|
Makes the page title display as something different than the page URL. |
{{localurl:name|query}}
|
Returns the url path (not including domain name, replace local with full for domain name and interwiki support and replace it with canonical to include https:) of a page on the wiki. query can be set to a query that can be performed in the url (such as action=edit
|
{{ns:name/id}}
|
The name of the namespace specified in name/id
|
{{lc:text}}
|
text in all lowercase
|
{{uc:text}}
|
text in all uppercase
|
Extension parser functions | |
---|---|
Name | Effect |
{{#expr:math}}
|
Does whatever mathematical formula is input. Also supports boolean inputs. |
{{#if:test|not empty|empty}}
|
Returns empty if test is empty or whitespace and not empty if not.
|
{{#ifeq:test1|test2|same|different}}
|
Returns same if test1 and test2 match and different otherwise
|
{{#switch:test|1=one|2|1+1=two|#default=three}}
|
Returns one if test is 1 and two if test is 2 or 1+1 , and three if it is none of them. The values to check for can be repeated indefinitely (in theory).
|