Manual:Variable/fr


 * Cette page concerne la création de variables. Pour l'aide à propos de l'utilisation des variables par défaut, voir . Pour les variables globales PHP utilisées en interne dans MediaWiki, voir Manual:wg variable.

Variables are bits of wikitext that look like templates but have no parameters and have been assigned hard-coded values. Standard wiki markup such as or  are examples of variables. You can also extend wiki markup by defining your own custom variables.

The term is something of a misnomer because there is nothing variable about a variable. End users cannot change the value of a variable because it is predetermined by a bundle of PHP code that calculates its value. The term "variables" comes from the source of their value: a PHP variable or something that could be assigned to a variable, e.g. a string, a number, an expression, or a function return value.

Définir des variables personnalisées
Les variables sont un cas particulier de mots magiques donc notre première étape sera de définir la variable comme un mot magique :


 * 1) Choose a magic word ID for your variable. This is only an internal identifier that is used to tie together the various parts of the variable definition: the names that appear in wiki text, and the PHP code that assigns a value to the variable. It is best to choose an ID that will be uniquely associated with your extension and is unlikely to be confused with other magic word IDs used by other extensions.  A common strategy is to use something like   where canonicalname is the name under which you will register your extension (see Registering custom variables below).
 * 2) Define the names that will appear in wiki text. To accomplish this, you will need to define a  array in a file. See  for more information. Your names can be case sensitive and language dependent.
 * 3) Provide PHP code to assign a value to the variable. To accomplish this, you will need to define and register a hook function with.

Note that the only difference between this process and the general process for defining magic words is the last step: defining a hook function for. Parser functions have a different method for associating an ID with PHP code. See Manual:Parser functions for more information.

Enregistrer des variables personnalisées
Ceci est un processus en deux étapes :


 * 1) Define the variable so that it gets included in . This requires adding a member to  .  For more information, please see Registering features with MediaWiki.
 * 2) Declare the magic word ID as a variable. To accomplish this we write and assign a hook to, the subject of this article.

Exemples
''Note: if you wish to use this example as a coding template, please replace  with something unique to your project so that there is less risk of name clashes with MediaWiki or any of its extensions. For example, if your extension was named  and you were reasonably sure that no-one else had an extension with constants, variables, functions, or classes beginning 'BEST_', 'wgBEST', 'wfBEST', or even 'BEST' you might want to replace 'My' with 'BEST'.''

Fichier

Fichier

Pour plus d’informations

 * - discusses default magic words built into the core MediaWiki package
 * - reviews the different kinds of magic words and how MediaWiki tells apart variables, parser functions, and templates.
 * Spécifications du langage Markup