Sometimes it is desired that wiki markup be parsed (or remain unparsed) under certain conditions. Since certain characters or character sequences are processed before reaching the parser function, we have to use escapes to prevent markup being parsed prematurely. MediaWiki does not have built-in mechanism for this, so we have to make our own:
- \l (less than) is translated to <
- \g (greater than) is translated to >
- \o (open double curly braces) is translated to {{
- \c (close double curly braces) is translated to }}
- \p (pipe) is translated to |
- \\ is translated to \
- \n is translated to a newline
{{ #vardefine: i | 0 }}{{ #while: expr | <esc>{{ #var: i }} < 5</esc> |* <esc>{{ #var: i }}{{ #vardefine: i | {{ #expr: {{ #var: i }} + 1 }} }}</esc> }}
produces the following:
- 0
- 1
- 2
- 3
- 4
MediaWiki does not support nested tags of the same type (see bug #1310). Given the following:
<esc>{{ #ifexpr:... | <esc>{{ templateB | param }}</esc> | param }}</esc>
The text:
{{ #ifexpr:... | <esc>{{ templateB | param }}
is passed to the underlying function instead of:
{{ #ifexpr:... | <esc>{{ templateB | param }}</esc> | param }}
A workaround is to explicitly write out the nested escape sequences:
<esc>{{ #ifexpr:... | \o templateB \p param \c | param }}</esc>
Another solution is to apply the modification given in the discussion of bug #1310.
If you would like your extension to make use of character escapes, the class CharacterEscapes contains two static functions for replacing characters with escapes (CharacterEscapesHooks::charEsc()) and replacing escapes with characters (CharacterEscapesHooks::charUnesc()).
- Extension:Control Structure Functions
- Extension:VariablesExtension