11 Appendix: Magic words

Redaktion (talk | contribs)
Created page with "<bookshelf src="Book:User manual" />"
 
No edit summary
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<bookshelf src="Book:User manual" />
<bookshelf src="Book:User manual" />
{{DISPLAYTITLE:Magic words}}
<section begin=training-intro />
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 dates, website statistics or page names.
Magic words are inserted directly in the source code. 
<section end=training-intro />
== Types of Magic words==
<section begin="training " />
There are basically four different types of Magic words:
*'''[[Manual:MagicWords#Behavior switch|Behavior switch]]''' (or "Double underscore"):  <code><nowiki>__TOC__</nowiki></code>
*'''[[Manual:MagicWords#Variable|Variable]]''':  <code><nowiki>{{FULLPAGENAME}}</nowiki></code>
*'''[[Manual:MagicWords#Tag|Tag]]''': <code><nowiki><gallery></nowiki></code>
*'''[[Manual:MagicWords#Parser function|Parser function]]''':  <code><nowiki>{{#ifeq:x|y|true|false}}</nowiki></code>
<section end="training" />
==Behavior switch==
Behaviour switchers allow you to control the appearance or behaviour of a page. It is also known as "double underscore".
It is used to specify desired omissions or insertions in the content. Behavioural switches can theoretically be entered anywhere in the wikicode, but this depends on the function. For example, the magic word that creates a table of contents is typically at the top of the article.
Most behavioural switches can be inserted via the Options () menu item in the visual editor.
{| class="wikitable" style="width:100%;"
! style="background-color:rgb(234, 236, 240);text-align:center;box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);width:200px;" class="" |Behaviour switch
! style="background-color:rgb(234, 236, 240);text-align:center;box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" class="" |Explanation
|-
| style="" |<nowiki>__FORCETOC__</nowiki>
| style="" |Forces a table of contents in the usual place at the top of the page (before the first heading)
|-
| style="" |<nowiki>__HIDETITLE__</nowiki>
| style="" |Hides the title area of a page. This is often used on portal pages.
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);width:200px;" |<nowiki>__NEWSECTIONLINK__</nowiki>
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |Inserts a link (usually "+") next to the "Edit" link, which can be used to create a new section (only on non-discussion pages)
|-
| style="" |__NODISCUSSION__
| style="" |Hides the discussion section at the bottom of the page.
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);width:200px;" |<nowiki>__NOEDITSECTION__</nowiki>
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |Hides the "Edit" link next to a heading.
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);width:200px;" |<nowiki>__NOTOC__</nowiki>
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |Hides the table of contents (TOC) on this page
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);width:200px;" |<nowiki>__TOC__</nowiki>
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |You can use this to move the table of contents to any position in the article. If a <nowiki>__NOTOC__</nowiki> exists, this will be "overwritten". However, only one table of contents can be inserted. If several are inserted, only the first (topmost) one is displayed.
|-
| style="" |__NOSTASH__
| style="" |Hides the section for file attachments at the bottom of the page
|}
== Variable ==
Variables contain (simple) dynamic data. If a template name conflicts with a variable, the variable is used. For example, you have the variable <code><nowiki>{{PAGENAME}}</nowiki></code>. In that case, you have to transclude the template with the same name as <code><nowiki>{{Template:PAGENAME}}</nowiki></code>.
{| class="wikitable" style="width:950px;"
! style="background-color:rgb(234, 236, 240);text-align:center;box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" class="" |Variable
! style="" |Output
! style="background-color:rgb(234, 236, 240);text-align:center;box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" class="" |Description
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |<nowiki>{{SITENAME}}</nowiki>
| style="" |{{SITENAME}}
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |Name of the wiki
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |<nowiki>{{CURRENTTIME}}</nowiki>
| style="" |{{CURRENTTIME}}
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |Time (24-hour HH:mm format)
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |<nowiki>{{CURRENTDAY}}</nowiki>
| style="" |{{CURRENTDAY}}
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |Current day (no preceding zero)
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |<nowiki>{{CURRENTMONTH}}</nowiki>
| style="" |{{CURRENTMONTH}}
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |Month (with preceding zero)
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |<nowiki>{{NUMBEROFARTICLES}}</nowiki>
| style="" |{{NUMBEROFARTICLES}}
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |Shows the number of all existing articles in the wiki (in the main namespace)
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |<nowiki>{{NAMESPACE}}</nowiki>
| style="" |{{NAMESPACE}}
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |Shows the namespace of the article
|-
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |<nowiki>{{PAGENAME}}</nowiki>
| style="" |{{PAGENAME}}
| style="box-sizing:inherit;padding:0.2em 0.4em;border:1px solid rgb(162, 169, 177);" |Shows the page name as it was created (cf. [[Reference:BlueSpiceHideTitle|changing article titles]])
|}
== Parser Function ==
=====Characteristics of a parser function=====
*'''Purpose:''' simple "programming language" for page content (mainly in templates)
*'''Syntax:''' <code>'''<nowiki>{{#if:</nowiki>'''<nowiki>{{{field|}}}</nowiki> | <nowiki>{{{field|}}}</nowiki> | N/A '''<nowiki>}}</nowiki>'''</code>
=====Description=====
Parser functions are similar to variables, but take one or more parameters.
Example:<syntaxhighlight lang="php">
{{#ifeq:{{{type}}}|warning
|This is a warning!
|
}}
</syntaxhighlight>They are used for simple logic only, since they are hard to read and to maintain on a larger scale. If complex logic is required, consider Lua scripts in  the "Module" namespace ([https://www.mediawiki.org/wiki/Extension:Scribunto mediawiki.org/wiki/Extension:Scribunto]) and invoke using <code><nowiki>{{#invoke:...}}</nowiki></code>
Parser functions can also be "tag-like", e.g. <code><nowiki>{{#ask:...}}</nowiki></code> from SemanticMediaWiki. For more information, refer to the MediaWiki help pages [https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions mediawiki.org/wiki/Help:Extension:ParserFunctions] and [https://www.mediawiki.org/wiki/Help:Magic_words#Parser_functions mediawiki.org/wiki/Help:Magic_words#Parser_functions].
== Tag ==
====Characteristics of a tag====
*'''Purpose:''' often used for custom development to process dynamic content
*'''Syntax''': <code><nowiki><smartlist /></nowiki></code>
====Description====
Tags are implemented in PHP as part of a MediaWiki extension. Tags with "bs:" prefix come from BlueSpice. All others come from MediaWiki or from third-party extensions, e.g. the extension [[Reference:SyntaxHighlight|SyntaxHighlight]].
{{Box Links-en
|Topic1=[https://www.mediawiki.org/wiki/Help:Magic_words mediawiki.org/wiki/Help:Magic_words]
|Topic2=[[Manual:Extension/BlueSpiceInsertMagic| Extension:BlueSpiceInsertMagic]]
}}
[[en:{{FULLPAGENAME}}]]
[[de:MagicWords]]
[[Category:Concept]]

Latest revision as of 11:38, 21 May 2025


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 dates, website statistics or page names.

Magic words are inserted directly in the source code.

Types of Magic words

There are basically four different types of Magic words:

Behavior switch

Behaviour switchers allow you to control the appearance or behaviour of a page. It is also known as "double underscore".

It is used to specify desired omissions or insertions in the content. Behavioural switches can theoretically be entered anywhere in the wikicode, but this depends on the function. For example, the magic word that creates a table of contents is typically at the top of the article.

Most behavioural switches can be inserted via the Options () menu item in the visual editor.

Behaviour switch Explanation
__FORCETOC__ Forces a table of contents in the usual place at the top of the page (before the first heading)
__HIDETITLE__ Hides the title area of a page. This is often used on portal pages.
__NEWSECTIONLINK__ Inserts a link (usually "+") next to the "Edit" link, which can be used to create a new section (only on non-discussion pages)
__NODISCUSSION__ Hides the discussion section at the bottom of the page.
__NOEDITSECTION__ Hides the "Edit" link next to a heading.
__NOTOC__ Hides the table of contents (TOC) on this page
__TOC__ You can use this to move the table of contents to any position in the article. If a __NOTOC__ exists, this will be "overwritten". However, only one table of contents can be inserted. If several are inserted, only the first (topmost) one is displayed.
__NOSTASH__ Hides the section for file attachments at the bottom of the page

Variable

Variables contain (simple) dynamic data. If a template name conflicts with a variable, the variable is used. For example, you have the variable {{PAGENAME}}. In that case, you have to transclude the template with the same name as {{Template:PAGENAME}}.

Variable Output Description
{{SITENAME}} BlueSpice Helpdesk Name of the wiki
{{CURRENTTIME}} 22:47 Time (24-hour HH:mm format)
{{CURRENTDAY}} 17 Current day (no preceding zero)
{{CURRENTMONTH}} 06 Month (with preceding zero)
{{NUMBEROFARTICLES}} 598 Shows the number of all existing articles in the wiki (in the main namespace)
{{NAMESPACE}} Manual Shows the namespace of the article
{{PAGENAME}} MagicWords Shows the page name as it was created (cf. changing article titles)

Parser Function

Characteristics of a parser function
  • Purpose: simple "programming language" for page content (mainly in templates)
  • Syntax: {{#if:{{{field|}}} | {{{field|}}} | N/A }}
Description

Parser functions are similar to variables, but take one or more parameters.

Example:

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

They are used for simple logic only, since they are hard to read and to maintain on a larger scale. If complex logic is required, consider Lua scripts in the "Module" namespace (mediawiki.org/wiki/Extension:Scribunto) and invoke using {{#invoke:...}}

Parser functions can also be "tag-like", e.g. {{#ask:...}} from SemanticMediaWiki. For more information, refer to the MediaWiki help pages mediawiki.org/wiki/Help:Extension:ParserFunctions and mediawiki.org/wiki/Help:Magic_words#Parser_functions.

Tag

Characteristics of a tag

  • Purpose: often used for custom development to process dynamic content
  • Syntax: <smartlist />

Description

Tags are implemented in PHP as part of a MediaWiki extension. Tags with "bs:" prefix come from BlueSpice. All others come from MediaWiki or from third-party extensions, e.g. the extension SyntaxHighlight.

Related info



PDF exclude - start

To submit feedback about this documentation, visit our community forum.

PDF exclude - end