Difference between revisions of "Manual:MagicWords"

[quality revision][quality revision]
(Changed categories.)
m
(Tag: 2017 source edit)
 

What are magic words (or MagicWords)?[edit | edit source]

A "magic word", also known as MagicWord, is a symbol recognized by the MediaWiki software. It triggers the software to do something other than display that symbol or transclude a page with that name, but instead to use the symbol directly.

There are different types of MagicWords:

  • Behavior switch (or "Double underscore"): __TOC__
  • Variable: {{FULLPAGENAME}}
  • Tag: <gallery>
  • Parser function: {{#ifeq:x|y|true|false}}

The 4 types of MagicWords[edit | edit source]

Behavior switch[edit | edit source]

Characteristics of a behavior switch[edit | edit source]

  • Purpose: controls the layout or behavior of the page
  • Syntax: __NOTOC__

Description[edit | edit source]

A behavior switch includes or omits certain elements of the page. It is also known as "double underscore". Behavior switches can be put anywhere in the source code of the designated page (usually at the end of the page). The behavior switch __TOC__ produces as output the table of contents exactly where it was inserted on the page.====

Variable[edit | edit source]

Characteristics of a variable[edit | edit source]

  • Purpose: returns information about the page, wiki, or date
  • Syntax: {{PAGENAME}}

Description[edit | edit source]

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}}.

Parser Function[edit | edit source]

Characteristics of a parser function[edit | edit source]
  • Purpose: simple "programming language" for page content (mainly in templates)
  • Syntax: {{#if:{{{field|}}} | {{{field|}}} | N/A }}
Description[edit | edit source]
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[edit | edit source]

Characteristics of a tag[edit | edit source]

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

Description[edit | edit source]

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

How to add a magic word[edit | edit source]

Magic words are inserted directly in the source code. Some frequently used magic words can also be added directly with the VisualEditor Insert > Magic word menu item:

Manual:VE-insert-magicword.png


Related info

{{DISPLAYTITLE:Magic words}}
        __NOTOC__
            
==What are magic words (or MagicWords)?==
        
        A "magic word", also known as MagicWord, is a symbol recognized by the MediaWiki software. It triggers the software to do something other than display that symbol or transclude a page with that name, but instead to use the symbol directly. 
        

        There are different types of MagicWords:
        <section begin="magicwordsTraining" />
        
            *'''Behavior switch''' (or "Double underscore"):  <code><nowiki>__TOC__</nowiki></code>
        
        *'''Variable''':  <code><nowiki>{{FULLPAGENAME}}</nowiki></code>
        
        *'''Tag''': <code><nowiki><gallery></nowiki></code>
        
        *'''Parser function''':  <code><nowiki>{{#ifeq:x|y|true|false}}</nowiki></code>
        <section end="magicwordsTraining" />
        
        ==The 4 types of MagicWords==
        

        ===Behavior switch===
        

        ====Characteristics of a behavior switch====
        

        *'''Purpose:''' controls the layout or behavior of the page
        
        *'''Syntax:''' <code><nowiki>__NOTOC__</nowiki></code>
        

        ====Description====
        

        A behavior switch includes or omits certain elements of the page. It is also known as "double underscore". Behavior switches can be put anywhere in the source code of the designated page (usually at the end of  the page). The behavior switch  <code><nowiki>__TOC__</nowiki></code> produces as output the table of contents exactly where it was inserted on the page.====
        

        ===Variable===
        

        ====Characteristics of a variable====
        

        *'''Purpose:''' returns information about the page, wiki, or date
        
        *'''Syntax:''' <code><nowiki>{{PAGENAME}}</nowiki></code>
        

        ====Description====
        
        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>.
        

        ===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 ([[mediawikiwiki:Extension:Scribunto|Extension:Scribunto]]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 [[mediawikiwiki:Help:Extension:ParserFunctions|Help:Extension:ParserFunctions]] and [[mediawikiwiki: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 (see [[Reference:BlueSpiceTagSearch]]). All others come from MediaWiki or from third-party extensions, e.g. the extension [[Reference:SyntaxHighlight|SyntaxHighlight]].
        

        ==How to add a magic word==
        
        Magic words are inserted directly in the source code. Some frequently used magic words can also be added directly with the VisualEditor ''Insert > Magic word'' menu item:
        

        [[File:Manual:VE-insert-magicword.png|300x300px]]
        

        {{Box Links-en
        
        |Topic1=[[mediawikiwiki:Help:Magic_words|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:Content]]
        
        [[Category:Editing]]
Line 1: Line 1:
 
{{DISPLAYTITLE:Magic words}}
 
{{DISPLAYTITLE:Magic words}}
__NOTOC__
 
 
 
==What are magic words (or MagicWords)?==
 
==What are magic words (or MagicWords)?==
 
A "magic word", also known as MagicWord, is a symbol recognized by the MediaWiki software. It triggers the software to do something other than display that symbol or transclude a page with that name, but instead to use the symbol directly.  
 
A "magic word", also known as MagicWord, is a symbol recognized by the MediaWiki software. It triggers the software to do something other than display that symbol or transclude a page with that name, but instead to use the symbol directly.  
Line 7: Line 5:
 
There are different types of MagicWords:
 
There are different types of MagicWords:
 
<section begin="magicwordsTraining" />
 
<section begin="magicwordsTraining" />
 +
 
*'''Behavior switch''' (or "Double underscore"):  <code><nowiki>__TOC__</nowiki></code>
 
*'''Behavior switch''' (or "Double underscore"):  <code><nowiki>__TOC__</nowiki></code>
 
*'''Variable''':  <code><nowiki>{{FULLPAGENAME}}</nowiki></code>
 
*'''Variable''':  <code><nowiki>{{FULLPAGENAME}}</nowiki></code>
Line 48: Line 47:
 
|
 
|
 
}}
 
}}
</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 ([[mediawikiwiki:Extension:Scribunto|Extension:Scribunto]]) and invoke using <code><nowiki>{{#invoke:...}}</nowiki></code>
+
</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 [[mediawikiwiki:Help:Extension:ParserFunctions|Help:Extension:ParserFunctions]] and [[mediawikiwiki:Help:Magic_words#Parser_functions|Help:Magic_words#Parser_functions]].
+
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===
 
===Tag===
Line 68: Line 67:
  
 
{{Box Links-en
 
{{Box Links-en
|Topic1=[[mediawikiwiki:Help:Magic_words|https://www.mediawiki.org/wiki/Help:Magic_words]]
+
|Topic1=[https://www.mediawiki.org/wiki/Help:Magic_words mediawiki.org/wiki/Help:Magic_words]
 
|Topic2=[[Manual:Extension/BlueSpiceInsertMagic| Extension:BlueSpiceInsertMagic]]
 
|Topic2=[[Manual:Extension/BlueSpiceInsertMagic| Extension:BlueSpiceInsertMagic]]
 
}}
 
}}

Attachments

Discussions