Extension:Variables/Pre MW 1.12

From MediaWiki.org
Jump to: navigation, search

This page describes the usage of the Variables extension in MediaWikis before version 1.12. From MediaWiki 1.12 on you can use one of the more current versions, starting from Variables 1.4. Currently the last available version for MW 1.12 is Variables 1.3.1.1.

Because in MediaWiki 1.12 significant parts of the parser were rewritten, Variables extension behaves differently in older MW versions. The following is an overview of the behaviors you should be aware of.

[edit] Usage with ParserFunctions

In MediaWiki wikis before version 1.12 it must be noted that everything in conditional parser functions such as #ifexpr gets executed (though only one result gets displayed), regardless of the condition, see Help:Extension:ParserFunctions. This applies also to #vardefine. Thus:

{{#ifexpr:..|
    {{#vardefine:a|b}}|
    {{#vardefine:a|c}}
}}

first assigns b and then c (hence effectively just c) regardless of the condition, while

{{#vardefine:a | {{#ifexpr:..|b|c}} }}

assigns only the applicable value.

Similarly

{{#ifexpr:..| {{#vardefine:a|b}}|}}

assigns b regardless of the condition, while

{{#vardefine:a | {{#ifexpr:..|b|{{#var:a}} }} }}

conditionally assigns value b to variable a (a dummy assignment of the value of a to a is done if the condition is not fulfilled).

[edit] Control Structure Functions

Another way around the aforementioned limitation is to use the Control Structure Functions extension, which allows one to delay the parsing of wiki markup through the use of character escape sequences. So, the first above example becomes this:

{{#ifexpr:..|
    \o#vardefine:a\pb\c|
    \o#vardefine:a\pc\c
}}

Alternatively, the Character Escapes extension can be used to automate the escape sequences:

{{#ifexpr:..|
    <esc>{{#vardefine:a|b}}</esc>|
    <esc>{{#vardefine:a|c}}</esc>
}}

The Control Structure Functions extension also has loop functions that support character escape sequences. The wiki markup:

{{ #vardefine: i | 0 }}{{
  #while: expr
  | <esc>{{ #var: i }} < 3</esc>
  | <esc>
* {{ #var: i }}{{ #vardefine: i | {{ #expr: {{ #var: i }} + 1 }} }}</esc>
}}

produces the following:

  • 0
  • 1
  • 2
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox