Manual:Magic words/hi



जादुई शब्द कई विकिटेक्स्ट स्ट्रिंग्स को एक ID से मानचित्रित करने की तकनीक है जिसे एक फ़ंक्शन से संबद्ध किया जाता है। वेरिएबल्स और पार्सर फ़ंक्शन्स, दोनों इस तकनीक का इस्तेमाल करते हैं। उस ID पर मानचित्रित सभी टेक्स्ट को फ़ंक्शन के लौटाए वैल्यू से बदल दिया जाएगा। टेक्स्ट स्ट्रिंग्स और ID के बीच का मानचित्रण की मदद से लोड किए जाने वाले एक फ़ाइल के   वेरिएबल में रखा जाता है।

डिफ़ॉल्ट जादुई शब्द में लागू किए जाते हैं।



जादुई शब्द कैसे काम करते हैं
जब भी मीडियाविकि को दो धनुकोष्ठकों के अंदर टेक्स्ट मिलती है, इसे तय करना होगा कि XXX वेरिएबल होगी, पार्सर फ़ंक्शन होगी, या कोई साँचा होगा। ऐसा करने के लिए यह कुछ प्रश्न पूछता है।


 * 1) क्या इसका कोई संबद्ध जादुई शब्द ID है?  मार्कअप रूप को सुलझाने के पहले चरण पर मीडियाविकि 'XXX' को एक जादुई शब्द ID में बदलने की कोशिश करता है। अनुवाद टेबल को $magicWords से परिभाषित किया जाता है।
 * 2) *अगर 'XXX' से कोई जादुई शब्द ID संबद्ध नहीं होता है, 'XXX' को एक साँचा मान लिया जाता है।
 * 3) क्या यह एक वेरिएबल है? अगर जादुई शब्द ID मिल जाती है, मीडियाविकि जाँचता है कि इसमें कोई पैरामीटर है कि नहीं।
 * 4) *अगर कोई पैरामीटर नहीं मिलते, मीडियाविकि जाँचता है कि जादुई शब्द ID को एक वेरिएबल ID के रूप में घोषित किया गया है कि नहीं। इसे जाँचने के लिए यह  कॉल करके जादुई शब्द सेवाओं की सूची प्राप्त करता है। इस विधि में वेरिएबल ID, वेरिएबल ID-ओं की एक ठोस सूची ( देखें) और  हुक से जुड़े सभी फ़ंक्शन्स द्वारा प्रदत्त अनुकूलित वेरिएबल ID-ओं की सूची से प्राप्त किए जाते हैं।
 * 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.

{{note|1= By convention:


 * The magic words called variables are capitalised, case-sensitive and do not have space characters.
 * Parserfunctions are prefixed with a hash sign ( {{# ), are case insensitive and do not include space characters.

This is however a convention and one not consistently applied (for historic reasons).


 * Variables do not have space characters, but some translations of variables in other languages DO have spaces
 * Variables generally are capitalised and case-sensitive, but some parser functions also use this convention.
 * Some parser functions start with a hash sign, but some do not.

Where possible you should follow the conventions when defining or translating magic words. Magic words are higher in priority than templates, so any magic word defined, will block the usage of that defined name as a template. Following the conventions avoids adding more and more potential collisions. }}

Defining magic words
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. Also, make sure that you initialize  as an empty array before adding language-specific values or you will get errors when trying to load the magic word and will need to rebuild your localization cache before it will work.

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. Thus the format is

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  but should not be done in extensions.

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:



Localisation

 *  See Help:Magic words#Localisation for help. 

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

Behavior switches (double underscore magic words)
Behavior switches are a special type of magic word. They can be recognized by their use of double underscores (rather than double braces). Example:

These magic words typically do not 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 most standard behavior switches is defined in. If no specific effect is defined, the magic word will simply set a page property in the page_props table. This can also be checked later by testing if  is null or the empty string

Custom behavior switch
Here is an example extension implementing a custom __CUSTOM__ behaviour switch

custom/extension.json - This is minimal, a real extension would fill out more fields. custom/custom.i18n.php

custom/MyHooks.php