!! Version 2 # @todo expand !! functionhooks var !! endfunctionhooks !! test #vardefine, #vardefineecho and #var !! wikitext {{#vardefine: a | Test }} "{{#var: a }}" "{{#vardefineecho: a | Test 2 }}, {{#var: a }}" !! html

"Test" "Test 2, Test 2"

!! end !! test #varexists !! wikitext {{#varexists: a }}{{#vardefine: a }} "{{#varexists: a }}" !! html

"1"

!! end !! test #var_final !! wikitext "{{#var_final: a }}" {{#vardefine: a | something }}"{{#var: a }}" {{#vardefine: a | final }}"{{#var_final: a }}" !! html

"final" "something" "final"

!! end !! test #varexists incorporating #if functionality !! wikitext {{#vardefine: a }}"{{#varexists: a | yes | no }}" "{{#varexists: b | yes | no }}" !! html

"yes" "no"

!! end !! test Variables should not be reset on special page inclusion (old bug, solved in Variables 2.0) !! wikitext {{#vardefine: a | 1 }}{{#vardefine: | {{Special:AllPages}} }} "{{#var: a }}" !! html

"1"

!! end !! test Default values for #var !! wikitext "{{#var: a | 1 }}" {{#vardefine: a | 0 }}"{{#var: a | 1 }}" !! html

"1" "0"

!! end !! test The default value of #var should not be expanded if it does not apply. !! wikitext {{#vardefine: a | 1 }}"{{#var: a | {{#vardefineecho: b | 2 }} }}" "{{#var: b | 3 }}" !! html

"1" "3"

!! end !! test The else value of #varexists should not be expanded if the if value applies. !! wikitext {{#vardefine: a | w }}"{{#varexists: a | x | {{#vardefineecho: b | y }} }}" "{{#var: b | z }}" !! html

"x" "z"

!! end !! test The if value of #varexists should not be expanded if the else value applies. !! wikitext "{{#varexists: a | {{#vardefineecho: b | x }} | y }}" "{{#var: b | z }}" !! html

"y" "z"

!! end !! test Empty string is a valid variable name as well. !! wikitext "{{#var_final: }}" {{#vardefine: | 1 }}"{{#var: }}" !! html

"1" "1"

!! end !! test Integers are valid variable names, but even though their actually strings, they are cast to int when used as array keys. !! wikitext "{{#var_final: 1 }}" {{#vardefine: 1 | x }}"{{#var: 1 }}" !! html

"x" "x"

!! end !! article Template:EchoVarA !! text {{#var: a }} !! endarticle !! article Template:IssetA !! text {{#varexists: a }} !! endarticle !! article Template:DefineA !! text {{#vardefine: a | w }} !! endarticle !! article Template:DefineEchoA !! text {{#vardefineecho: a | z }} !! endarticle !! test By default, there shouldn't be any template caching if Variables are used. !! config egVariablesAreVolatile=true !! wikitext "{{IssetA}}" {{#vardefine: a | x }}"{{EchoVarA}}" "{{IssetA}}" {{#vardefine: a | y }}"{{EchoVarA}}" !! html

"" "x" "1" "y"

!! end !! test This is also true for vardefine(echo). !! config egVariablesAreVolatile=true !! wikitext {{DefineA}}"{{#var: a }}" {{#vardefine: a | x }}"{{#var: a }}" {{DefineA}}"{{#var: a }}" "{{DefineEchoA}}" "{{#vardefineecho: a | y }}" "{{DefineEchoA}}" "{{#var: a }}" !! html

"w" "x" "w" "z" "y" "z" "z"

!! end !! test However, it's possible to activate the legacy behavior to activate template caching. !! config egVariablesAreVolatile=false !! wikitext "{{IssetA}}" {{#vardefine: a | x }}"{{EchoVarA}}" "{{IssetA}}" {{#vardefine: a | y }}"{{EchoVarA}}" !! html

"" "x" "" "x"

!! end !! test This also deativates it for vardefine(echo). !! config egVariablesAreVolatile=false !! wikitext {{DefineA}}"{{#var: a }}" {{#vardefine: a | x }}"{{#var: a }}" {{DefineA}}"{{#var: a }}" "{{DefineEchoA}}" "{{#vardefineecho: a | y }}" "{{DefineEchoA}}" "{{#var: a }}" !! html

"w" "x" "x" "z" "y" "z" "y"

!! end !! test Variables can be substituted. !! options pst !! wikitext "{{subst:#vardefineecho: d | 1 }}" "{{subst:#var: d }}" !! html "1" "1" !! end !! test Substitutions are parsed in a different parser run than other Variables. !! options pst !! wikitext "{{subst:#vardefine: d | 1 }}" "{{#vardefine: d | 2 }}" "{{subst:#var: d }}" "{{subst:#vardefine: d | 3 }}" "{{#var: d }}" !! html "" "{{#vardefine: d | 2 }}" "1" "" "{{#var: d }}" !! end !! test #var_final can be substituted as well. !! options pst !! wikitext "{{subst:#vardefineecho: a | x }}" "{{subst:#var_final: a }}" "{{subst:#vardefine: a | y }}" !! html "x" "y" "" !! end !! test (Simple) Wikitext in #var_final is parsed !! wikitext {{#vardefine:a| [[Lunar Prospector]] }} obtained by {{#var_final:a}} !! html

obtained by Lunar Prospector

!! end !! test Even when #var_final is substituted !! options pst !! wikitext "{{subst:#vardefine:a| [[Lunar Prospector]] }}" obtained by {{subst:#var_final:a}} !! html "" obtained by [[Lunar Prospector]] !! end !! test Even when it is a category link !! options cat !! wikitext {{#vardefine: a | x }}{{#var_final: a }}{{#vardefine: a | [[Category:MediaWiki User's Guide]] }} !! html cat=MediaWiki_User's_Guide sort= !! end !! test And substituted !! options pst !! wikitext {{subst:#vardefine: a | x }}{{subst:#var_final: a }}{{subst:#vardefine: a | [[Category:MediaWiki User's Guide]] }} !! html [[Category:MediaWiki User's Guide]] !! end !! test #var_final with nowiki tags !! wikitext {{#vardefine:test|1 '''Test''' '''nowiki'''}}{{#var_final:test}}{{#vardefine:test|2 '''Test''' '''nowiki'''}} !! html

2 Test '''<i>nowiki</i>'''

!! end !! test #var_final substituted, with nowiki tags !! options pst !! wikitext {{subst:#vardefine:test|1 '''Test''' '''nowiki'''}}{{subst:#var_final:test}}{{subst:#vardefine:test|2 '''Test''' '''nowiki'''}} !! html 2 '''Test''' '''nowiki''' !! end