Manual:Magic words/vi



Từ ma thuật là một phương pháp để nhóm một số loại các xâu từ wiki thành một ID mà có liên kết với một hàm. Cả biến và hàm tính toán đều sử dụng phương pháp này. Tất cả văn bản được nhóm tới ID đó sẽ được thay thế bằng giá trị trả về của hàm. The mapping between the text strings and the ID is stored in the variable  in a file that can be loaded using.

The default magic words are implemented in.

Làm thế nào những từ ma thuật hoạt động
Whenever MediaWiki finds text between double braces it must decide whether XXX is a variable, parser function, or template. To do so, it asks a series of questions:


 * 1) Does it have an associated magic word ID? As a first step in resolving markup of the form , MediaWiki attempts to translate XXX to a magic word ID. The translation table is defined by $magicWords.
 * 2) * If no magic word ID is associated with XXX, XXX is presumed to be a template.
 * 3) Is it a variable? If a magic word ID is found, MediaWiki next checks to see if it has any parameters.
 * 4) * If no parameters are found, MediaWiki checks to see if the magic word ID has been declared as a variable ID. To check this, it retrieves the list of magic words serving by calling . This method gets its list of variable IDs from a hard coded list of variable IDs (see ) and from a list of custom variable IDs provided by all functions attached to the hook.
 * 5) ** If the magic word ID has been classified as a variable, hooks MediaWiki calls the functions associated with the event name until one is found that recognizes the magic word and can return its value.
 * 6) 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.
 * 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.

Định nghĩa từ ma thuật
For magic words to do their magic we must define two things:
 * a mapping between wiki text and a magic word ID
 * a mapping between a magic word ID and some php function that interprets the magic word.

Mapping wiki text to magic word IDs
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. Important: This only sets up the back end i18n mapping, you still have to write other code to make MediaWiki use the magic word for anything

The first element of this array is an integer 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. Như vậy dạng của nó là

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

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':

File :

In part of the extension.json file:

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.

In inline PHP
You can associate magic words inline in PHP rather than through a i18n file. This is useful when defining hooks in

Associating a magic word ID with a PHP function
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:



Đăng ký từ ma thuật
There is no explicit requirement to register magic word IDs. Registering the parser function or variables that use them is sufficient.

Địa phương hoá

 * Xem Help:Magic words#Localisation để thêm trợ giúp

You can read more on definition and usage of magic words for localisation at Manual:Messages API, Manual:Language#Namespaces; Avoid  in messages.

Công tắc chuyển hành vi (các từ ma thuật kép được gạch chân)
Công tắc chuyển hành vi là một loại từ ma thuật đặc biệt. Chúng có thể được nhận ra bằng cách sử dụng dấu gạch dưới kép (thay vì dấu ngoặc kép). Ví dụ.

Những từ ma thuật này thường không thêm bất kỳ nội dung nào, nhưng lại thay đổi cách mà trang được thể hiện hay đặt thuộc tính của trang. 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.

Xem thêm

 * - List of Variables like and