Extensión:Variables
![]() Estado de lanzamiento: estable |
|
---|---|
Implementación | Función del analizador |
Descripción | Introduce funciones del analizador para tratar con las variables de ámbito de página. |
Autor(es) |
|
Mantenedor(es) | MGChecker |
Última versión | 2.5.1 (2019-07-11) |
MediaWiki | 1.29+ |
PHP | 5.5+ |
Cambios de la base de datos | No |
Composer | mediawiki/variables |
Licencia | ISC Licencia |
Descarga | README RELEASE-NOTES |
|
|
Quarterly downloads | 151 (Ranked 69th) |
Public wikis using | 1,808 (Ranked 201st) |
Traduce la extensión Variables si está disponible en translatewiki.net | |
Función de vagabundo | variables |
Asuntos | Tareas abiertas · Reportar un bug |
La extensión Variables permite definir una variable en una página, usarla más tarde en esa misma página o en las plantillas incluidas, cambiar su valor, posiblemente a un valor dado por una expresión en términos del valor anterior, etc.
Semejante a una plantilla, aunque más ligero y su alcance es una página. Te permite emplear múltiples variables en una página sin impactar el desempeño de la wiki, como sucede cuando se maneja un gran número de plantillas. Combina esta extensión con la extensión Extensión:ParserFunctions para mejores resultados.
#var_final
parser function is shown as deprecated in MediaWiki 1.35 or above, due to changes in the parser. However, it will continue to work in this versions. See task T276627 and task T236809 for further information.
Asignar un valor a una variable
#vardefine
{{#vardefine:nombredelavariable|valorespecificado}}
Asigna el valor valorespecificado a la variable (que ya existe o se introduce) nombredelavariable.
- Ejemplo:
{{#vardefine:iconwidth|25}}
haciendoiconwidth = 25
#vardefineecho
{{#vardefineecho:nombredelavariable|valorespecificado}}
Funciona exactamente como #vardefine
, pero el valor afectado se imprime.
- Ejemplo: making
iconwidth = {{#vardefineecho:iconwidth|25}}
Recuperación del valor de una variable
#var
El valor de la variable nombredelavariable se produce por
{{#var:nombredelavariable}}
Si no definido, esto produce una cadena vacía; no da una mensaje de error.
Es posible definir un valor para el caso que la variable no está definido o está nula:
{{#var:nombredelavariable | valorpredeterminado }}
Esto es equivalente a:
{{#if: {{#var:nombredelavariable}} | {{#var:nombredelavariable }} | valorpredeterminado }}
pero es mucho más corto y mejor organizado. Aunque antes de versión 2.0, el valor predeterminado siempre estaba expandido. Desde version 2.0, el valor predeterminado solamente está expandido si realmente se usa.
El valor puede usarse en funciones del analizador, etc.
#varexists
{{#varexists:nombredelavariable }}
returns 1 if the variable is already defined. If the variable is not defined the return value is void.
It supports a second and a third parameter to replace these values.
{{#varexists:variablename | if-value | else-value }}
This is equivalent to:
{{#if: {{#varexists: variablename }} | if-value | else-value }}
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.
#var_final
Experimental 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:
{{#var_final:variablename | defaultvalue}}
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.
Ejemplos
The Extensión:ParserFunctions extension must also be installed to use #expr
.
Compute x = 2*a + b
:
{{#vardefine:x|{{#expr:2*{{#var:a}}+{{#var:b}}}}}}
Agregar uno a n:
{{#vardefine:n|{{#expr:{{#var:n}}+1}}}}
Instalación
- Descarga y extrae los archivos en un directorio denominado «
Variables
» dentro de la carpetaextensions/
. - Añade el siguiente código en la parte final de tu
LocalSettings.php
:wfLoadExtension( 'Variables' );
- Configure as required
Hecho – Navega a Special:Version en el wiki para verificar que la extensión se haya instalado correctamente.
Para quienes usan MediaWiki 1.30 o versiones anteriores:
Estas instrucciones describen la nueva forma de instalar extensiones usando wfLoadExtension()
.
Si necesitas instalar esta extensión en versiones anteriores (MediaWiki 1.30 y anteriores), debes usar lo siguiente en lugar de wfLoadExtension( 'Variables' );
:
require_once "$IP/extensions/Variables/Variables.php";
Configuration
This extension provides two configuration parameters:
$egVariablesAreVolatile
- Allows to disable the parser frame being marked as volatile by the extension, i.e. disable template caching.
- Default:
true;
$egVariablesDisabledFunctions
- Allows to disable specified parser functions provided by this extension.
- Default:
[];
- Example:
[ 'var_final', 'vardefineecho' ];
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.
1.19 | 1.20 | 1.21 | 1.22 | 1.23 | 1.24 | 1.25 | 1.26 | 1.27 | 1.28 | 1.29 | 1.30 | 1.31 | 1.32 | 1.33 | 1.34 | master | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2.x | 2.1.x | 2.2.x | 2.5.x, master |
Alternatives
As this extension will not be enabled for wikis run by the Wikimedia Foundation (WMF), here are some alternatives:[1][2][3][4]
- If you use Variables as cache for expensive operations, you can transform the section where you need them into a template and pass the required information as template parameters instead. This will work until you reach the expansion depth limit, which can be increased if necessary.
- If you use Variables to do more complex template operations than possible with simple Extensión:ParserFunctions , and if you have sufficient permissions on the server, you can use Scribunto's Lua functionality instead. You may not be able to install Scribunto on shared hosting. Note that this does not add support for global Variables. However, Extension:VariablesLua adds a Scribunto interface for the Variables store.
- Don't use variables, instead duplicate the information you need as a variable. If that information is acquired by an expensive template call, performance may suffer. This will work until you reach the node count limit.
- If you require variables just for autonumbering, you could look into Extension:NumerAlpha .
Véase también
- Extensión:PhpTags
- Extension:MyVariables - Creates new variables in the MediaWiki sense
- Extension:Loops — Provides parser functions for performing loops
- Extension:Arrays — Create an array and provide array functions (such as search, split, and sort) and set operations (such as intersect, union and diff)
- Extension:HashTables — New parser functions for handling hash tables in MediaWiki
References
- ↑ 1.0 1.1 phab:T9865
- ↑ 2.0 2.1 phab:T65324
- ↑ 3.0 3.1 phab:T113859
- ↑ 4.0 4.1 phab:T151192
![]() | Esta extensión está incluida en los siguientes paquetes y/o granjas wiki: This is not an authoritative list. Some wiki farms/hosts may contain this extension even if they are not listed here. Always check with your wiki farms/hosts or bundle to confirm. |
- Stable extensions/es
- Parser function extensions/es
- Extensions supporting Composer/es
- ISC licensed extensions/es
- Extensions in Wikimedia version control/es
- InternalParseBeforeSanitize extensions/es
- ParserClearState extensions/es
- ParserFirstCallInit extensions/es
- All extensions/es
- Extensions included in BlueSpice/es
- Extensions included in Canasta/es
- Extensions included in Fandom/es
- Extensions included in Miraheze/es
- Extensions included in ProWiki/es
- Extensions included in semantic::core/es
- Extensions included in wiki.gg/es
- Extensions included in WikiForge/es
- Modifiable variables extensions/es