Allow extensions to define magic words by simply including a $magicWords variable...
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 4 Sep 2007 02:48:34 +0000 (02:48 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 4 Sep 2007 02:48:34 +0000 (02:48 +0000)
includes/MessageCache.php
languages/Language.php

index f06f44d..10c95a7 100644 (file)
@@ -695,8 +695,14 @@ class MessageCache {
         * Load messages from a given file
         */
        function loadMessagesFile( $filename ) {
+               $magicWords = false;
                require( $filename );
                $this->addMessagesByLang( $messages );
+
+               if ( $magicWords !== false ) {
+                       global $wgContLang;
+                       $wgContLang->addMagicWordsByLang( $magicWords );
+               }
        }
 }
 
index 69721ff..3f9d98f 100644 (file)
@@ -59,6 +59,7 @@ class FakeConverter {
 
 class Language {
        var $mConverter, $mVariants, $mCode, $mLoaded = false;
+       var $mMagicExtensions = array(), $mMagicHookDone = false;
 
        static public $mLocalisationKeys = array( 'fallback', 'namespaceNames',
                'skinNames', 'mathNames', 
@@ -1128,8 +1129,8 @@ class Language {
 
        # Fill a MagicWord object with data from here
        function getMagic( &$mw ) {
-               if ( !isset( $this->mMagicExtensions ) ) {
-                       $this->mMagicExtensions = array();
+               if ( !$this->mMagicHookDone ) {
+                       $this->mMagicHookDone = true;
                        wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
                }
                if ( isset( $this->mMagicExtensions[$mw->mId] ) ) {
@@ -1152,6 +1153,24 @@ class Language {
                $mw->mSynonyms = array_slice( $rawEntry, 1 );
        }
 
+       /**
+        * Add magic words to the extension array
+        */
+       function addMagicWordsByLang( $newWords ) {
+               $code = $this->getCode();
+               $fallbackChain = array();
+               while ( $code && !in_array( $code, $fallbackChain ) ) {
+                       $fallbackChain[] = $code;
+                       $code = self::getFallbackFor( $code );
+               }
+               $fallbackChain = array_reverse( $fallbackChain );
+               foreach ( $fallbackChain as $code ) {
+                       if ( isset( $newWords[$code] ) ) {
+                               $this->mMagicExtensions = $newWords[$code] + $this->mMagicExtensions;
+                       }
+               }
+       }
+
        /**
         * Get special page names, as an associative array
         *   case folded alias => real name