WikiSysop (talk | contribs)
No edit summary
WikiSysop (talk | contribs)
No edit summary
Line 3: Line 3:
== Types of magic words==
== Types of magic words==
MediaWiki provides four types of magic words:
MediaWiki provides four types of magic words:
*'''[[MagicWords#Behavior switch|Behavior switch]]''' (also known as double underscore): <code><nowiki>__TOC__</nowiki></code>
*'''[[Magic Words#Behavior switch|Behavior switch]]''' (also known as double underscore): <code><nowiki>__TOC__</nowiki></code>
*'''[[MagicWords#Variable|Variable]]''': <code><nowiki>{{FULLPAGENAME}}</nowiki></code>
*'''[[Magic Words#Variable|Variable]]''': <code><nowiki>{{FULLPAGENAME}}</nowiki></code>
*'''[[MagicWords#Parser function|Parser function]]''': <code><nowiki>{{#ifeq:x|y|true|false}}</nowiki></code>
*'''[[Magic Words#Parser function|Parser function]]''': <code><nowiki>{{#ifeq:x|y|true|false}}</nowiki></code>
*'''[[MagicWords#Tag|Tag]]''': <code><nowiki><gallery></nowiki></code>
*'''[[Magic Words#Tag|Tag]]''': <code><nowiki><gallery></nowiki></code>
==Behavior switch==
==Behavior switch==
A behavior switch controls the appearance or behavior of a page. Because it starts and ends with two underscores, it is also known as a double underscore.
A behavior switch controls the appearance or behavior of a page. Because it starts and ends with two underscores, it is also known as a double underscore.

Revision as of 09:41, 3 November 2026

A magic word is a string of text that is recognized by the MediaWiki software. It triggers the software to return the value of a function, such as a date, a website statistic, or a page name. Magic words are inserted directly in the source code of a page.

Types of magic words

MediaWiki provides four types of magic words:

Behavior switch

A behavior switch controls the appearance or behavior of a page. Because it starts and ends with two underscores, it is also known as a double underscore.

  • Purpose: Adds or hides elements on a page.
  • Syntax: __TOC__

Behavior switches can be placed anywhere in the wikitext, but the position matters for some switches. For example, the switch for the table of contents is usually placed at the top of the page.

Most behavior switches can be inserted with the Options menu in the Visual Editor.

Behavior switch Description
__FORCETOC__ Displays a table of contents in its default position at the top of the page, before the first heading.
__HIDETITLE__ Hides the title area of the page. This switch is often used on portal pages.
__NEWSECTIONLINK__ Adds a link, usually "+", next to the Edit link. This link creates a new section. The link is only available on pages that are not discussion pages.
__NOEDITSECTION__ Hides the Edit link next to headings.
__NOSTASH__ Hides the file attachments section at the bottom of the page.
__NOTOC__ Hides the table of contents.
__TOC__ Places the table of contents at the position of the switch. Overrides __NOTOC__. Only one table of contents can be displayed on a page. If the switch is inserted several times, only the first one is used.

Variable

A variable is a magic word without parameters. It returns simple dynamic data.

  • Purpose: Displays dynamic data, such as dates, statistics, or page names.
  • Syntax: {{PAGENAME}}

If a template has the same name as a variable, the variable is used. To transclude the template, the namespace must be added. For example, a template named PAGENAME is transcluded with {{Template:PAGENAME}}.

Variable Output Description
{{SITENAME}} BlueSpice Helpdesk Shows the name of the wiki.
{{CURRENTTIME}} 20:59 Shows the current time in 24-hour format (HH:mm).
{{CURRENTDAY}} 23 Shows the current day of the month without a leading zero.
{{CURRENTMONTH}} 11 Shows the current month with a leading zero.
{{NUMBEROFARTICLES}} 71 Shows the number of pages in the main namespace of the wiki.
{{NAMESPACE}} Shows the namespace of the current page.
{{PAGENAME}} Magic Words Shows the page name as it was created. For more information, refer to changing page titles.

Parser function

A parser function is similar to a variable, but it takes one or more parameters.

  • Purpose: Adds simple logic to page content, mainly in templates.
  • Syntax: {{#if:{{{field|}}} | {{{field|}}} | N/A }}


Example:

{{#ifeq:{{{type}}}|warning
|This is a warning!
|
}}

Parser functions are only suitable for simple logic, because larger parser functions are difficult to read and maintain. For complex logic, Lua scripts in the Module namespace can be used and called with {{#invoke:...}}. For more information, refer to Extension:Scribunto on mediawiki.org.
Some parser functions work like tags, for example, {{#ask:...}} from Semantic MediaWiki. For more information, refer to the MediaWiki help pages Help:Extension:ParserFunctions and Help:Magic words – Parser functions.

Tag

A tag is a feature of a MediaWiki extension. Tags are implemented in PHP.

  • Purpose: Processes dynamic content, often as part of custom development.
  • Syntax: <smartlist />

Tags with the bs: prefix are provided by BlueSpice. All other tags are provided by MediaWiki or by third-party extensions, such as SyntaxHighlight.