Help:Magic words
Magic words are strings of text that MediaWiki associates with a return value or function, such as time, site details, or page names.
For full details, see mw:Help:Magic words.
Examples
- __NOTOC__ - Hides the table of contents (short for "NO Table Of Contents").
- __NOINDEX__ - Tell search engines not to index the page
- {{CURRENTYEAR}} - Current year: 2024
- {{NUMBEROFARTICLES}} - Number of pages in content namespaces: 689
- {{FULLPAGENAME}} - Namespace and page title: Help:Magic words
- {{PAGENAME}} - Page title: Magic words
There are many, many more, for a wide range of date and time, site statistics and page name data.
Parser functions
This page describes the parser functions that can be entered in Wikicode to process more complex functions and calculations to be performed. They are especially useful in creating templates.
Some are provided by the MediaWiki ParserFunctions extension and have syntax:
{{#functionname: argument 1 | argument 2 | argument 3 ...}}
Others are basic MediaWiki functions and generally have syntax:
{{Functionname: argument 1 | argument 2 | argument 3 ...}}
Extra parser functions
The Parser Functions extension is enabled on WikiMSK, giving another 11 functions, including if and switch functions, to perform certain logical operations. Examples include:
- #expr evaluates an expression as true (1) or false (0). For logical inputs, any non-zero number is true, and 0 is false
- {{#expr: 1.5*2=3 }} โ 1
- {{#expr: 1.5*2=400 }} โ 0
- {{#expr: 1 and 0 }} โ 0
- {{#expr: 1 or 0 }} โ 1
- #if is a little counterintuitive. It returns a true value if the first parameter is 'non-empty'. If it is empty or only whitespace, it evaluates to false. A mathematical expression is treated as a string and evaluates to true even if the expression itself is false. The second parameter is the 'true' output, and the third and final parameter is the 'false' output:
- {{#if: blah | rhino | unicorn }} โ rhino
- {{#if: | rhino | unicorn }} โ unicorn
- {{#if: 0 | yes | no }} โ yes
- #ifexpr evaluates a mathematical expression and returns the second parameter string if true, and the third (and last) parameter string if false. E.g.:
- {{#ifexpr: 1 < 0 | true | false}} โ false
- {{#ifexpr: 1+1=2 | blue | red}} โ blue
- switch displays the value of one of its parameters, e.g. {{#switch: baz | foo = Foo | baz = Baz | Bar }}
- fullurl outputs a page's URL, e.g. {{Fullurl:page name}} {{Fullurl:passive solar}} โ https://wikimsk.org/wiki/Passive_solar
For full details, see mw:Help:Magic words #Parser functions. For more detailed information, visit wiki/Help:Parser_function
Recommendations
- Use in templates, not directly in pages.
- If you're experimenting with parser function code, especially complex code, use your userspace. E.g. put the template at [[User:Yourname/templatename]], and insert the template using {{User:Yourname/templatename}}. If it proves useful, it can be moved to template space later.
- If your documentation explains how your template works, this helps future editors of the template.
Further reading
You can check a full list on mw:Help:Magic words
References
Part or all of this article or section is derived from Help:Magic words by Appropedia, used under CC-BY-SA