Manual:Magic words/pt-br



Palavras mágicas são uma técnica de mapeamento de uma variedade de strings de texto wiki para um único ID que está associado a uma função. Ambos variáveis e funções do analisador usam esta técnica. Todo o texto mapeado para esse ID será substituído valor de retorno da função. O mapeamento entre as strings de texto e a identificação é armazenado na variável $magicWords em um arquivo que pode ser carregado utilizando $wgExtensionMessagesFiles.

As palavras mágicas padrão estão implementadas no arquivo CoreParserFunctions.php.

Como as palavras mágicas funcionam?
Sempre que o MediaWiki encontra texto entre chaves duplas ele deve decidir se XXX é uma variável, função de analisador, ou predefinição. Para isso, ele faz uma série de perguntas:


 * 1) Será que ele tem um ID de palavra mágica associado? Como um primeiro passo na solução de marcação do formulário .  This method gets its list of variable IDs from a hard coded list of variable IDs (see Help:Variables) and from a list of custom variable IDs provided by all functions attached to the hook MagicWordwgVariableIDs.
 * 2) **If the magic word ID has been classified as a variable, hooks MediaWiki calls the functions associated with the event name 'ParserGetVariableValueSwitch' until one is found that recognizes the magic word and can return its value.
 * 3) Is it a parser function? If there are any parameters or if the magic word ID is missing from the list of variable magic word IDs, then MediaWiki assumes that the magic word is a parser function or template. If the magic word ID is found in the list of parser functions declared via a call to , it is treated as a parser function and rendered using the function named  .  Otherwise, it is presumed to be a template.
 * 1) Is it a parser function? If there are any parameters or if the magic word ID is missing from the list of variable magic word IDs, then MediaWiki assumes that the magic word is a parser function or template. If the magic word ID is found in the list of parser functions declared via a call to , it is treated as a parser function and rendered using the function named  .  Otherwise, it is presumed to be a template.

Definindo palavras mágicas
Para as palavras mágicas fazerem sua mágica, precisamos definir duas coisas:
 * um mapeamento entre wikitexto e uma ID de palavra mágica
 * um mapeamento entre uma ID de palavra mágica e alguma função PHP que interprete a palavra mágica.

Mapeamento de wikitexto para IDs de palavras mágicas
The variable $magicWords is used to associate each magic word ID with a language-dependent array that describes all the text strings that mapped to the magic word ID.

The first element of this array is a flag indicating whether or not the magic word is case sensitive. The remaining elements are a list of text that should be associated with the magic word ID. If the case sensitive flag is 0, any case variant of the names in the array will match. If the case sensitive flag is 1, only exact case matches will be associated with the magic word ID.

This association is created by $magicWords in a file registered using $wgExtensionMessagesFiles[].

In the example below, a Spanish MediaWiki installation will associate the magic word ID 'MAG_CUSTOM' with "#personalizado", "#custom", "#PERSONALIZADO", "#CUSTOM" and all other case variants. In an English MediaWiki only "#custom" in various case combinations will be mapped to 'MAG_CUSTOM':

Arquivo

Arquivo de inicialização de extensão :

Note that "ExampleMagic" is a different to the key you would use for a plain internationalization file (normally just the title of the extension, i.e. "Example"). "Magic" has been appended deliberately so one does not overwrite the other.

Associando uma ID de palavra mágica a uma função PHP
The mechanism for associating magic word IDs with rendering functions depends on whether the magic word will be used as a parser function or a variable. For more information, please see:


 * Manual:Parser functions
 * Manual:Variables

Registrando palavras mágicas
In MediaWiki 1.8 and beyond there is no explicit requirement to register magic word IDs. Registering the parser function or variables that use them is sufficient. For versions prior to 1.8, see below.

Localização

 * ''See Help:Magic words#Localisation for help.

You can read more on definition and usage of magic words for localisation at Localisation#PLURAL and GENDER support in JavaScript, Localisation#Localizing namespaces and special page aliases, Localisation#Switches in messages…; Localisation#Be aware of PLURAL use on all numbers, Localisation#Users have grammatical genders, Avoid  in messages.

Palavras mágicas em versões do MediaWiki anteriores à v1.8
Versões anteriores à 1.8 do MediaWiki diferiam das seguintes formas:

 Manual:Hooks/LanguageGetMagic did not pass a language parameter. To simulate this parameter, extensions backported to 1.7 or earlier can extract the language of $wgContLang on their own and proceed as normal and/or offer a language independent process for selecting the ID-text mapping. Extensions that used magic words had to explicitly register their magic word IDs using the hook MagicWordMagicWords. This method simply asked the implementer to supply the ID of the magic word.

 

Comutadores de comportamento (palavras mágicas com duplo sublinhado)
Behavior switches are a special type of magic word. They can be recognized by their use of double underscores (rather than double braces). For example,.

These magic words typically do no output any content, but instead change the behavior of a page and/or set a page property. These magic words are listed in  and also at Help:Magic words#Behavior switches. The effect of each behavior switch is defined in. If no specific effect is defined, the magic word will simply set a page property in the page_props table.

Ver também

 * Help:Magic words - List of Variables like and
 * Markup spec