Extension:Variables/zh

变量（Variables）扩展允许您在一个页面定义变量，然后在同样的页面或包括的模板变化它的值，可能是通过表达式在旧值中赋予的值等.

它很像模板，只是占用内存非常少并且作用只能在1个页面，所以你可以在1个页面使用很多个变量而不需要用大数量的模板在这个wiki缓慢下来. 结合解析器函数组件以达到最好的结果.

Assigns the value specifiedvalue to the (already existing or hereby introduced) variable variablename.


 * 示例： 使iconwidth=25

Works exactly as, but the affected value is printed.


 * 例如： making iconwidth = 

The value of the variable variablename is produced by 如果未定义，会产生空字符串，不会抛出错误.

变量未定义或为空时可以定义值：



相当于：

但这样更加简短. 在版本2.0之前，默认值会自动展开. 从版本2.0开始，默认值只会在真正用到时展开.

值可用于解析器函数.

如果变量已经定义（包括是空字符串时）返回1. 如果没有定义则返回空.

It supports a second and a third parameter to replace these values.

This is equivalent to:



but it is much shorter and better arranged. Before version 2.5 though, both were always expanded. From version 2.5 on the if and else values only get expanded when their cases are actually entered.

Experimental new function introduced in Variables 2.0. This function will output the final, last value a variable has at the end of the page rendering. Naturally, the value will be inserted after the parser went over the entire wiki markup, so this function can't be used in other functions, expecting the right value is being used. Example:

The default value will be used if the variable doesn't exist at the final page rendering stage or if its value is an empty string. The default will be expanded right where the function is used, so the parameter will be expanded, even if it won't be needed.

例子
解析器函数扩展必须已安装以使用#expr.

计算 ： 加入一个至“n”：

Compatibility
The recommended version of the Variables extension for recent MediaWiki releases is listed below. Older versions of the extensions might work as well, but aren't tested for new MediaWiki releases.

注释

 * 本扩展在WMF的wiki不开启，参见T65324、T113859和T151192.

参见

 * Extension:DynamicFunctions##arg:
 * Extension:MyVariables - 在MediaWiki创建新变量
 * Extension:Loops - 提供执行循环的解析器函数
 * Extension:Arrays - Create an array and provide array functions（比如搜索、分离、排序）and set operations (such as intersect, union and diff)
 * Extension:HashTables - 用于处理MediaWiki的hash table的新解析器函数