Merge "Get to the point about howto download Vector :p"
[lhc/web/wiklou.git] / languages / Language.php
index 115a918..01fb986 100644 (file)
@@ -143,6 +143,12 @@ class Language {
         */
        static private $fallbackLanguageCache = array();
 
+       /**
+        * Cache for language names
+        * @var MapCacheLRU|null
+        */
+       static private $languageNameCache;
+
        /**
         * Get a cached or new language object for a given language code
         * @param string $code
@@ -494,7 +500,7 @@ class Language {
                        # Re-order by namespace ID number...
                        ksort( $this->namespaceNames );
 
-                       wfRunHooks( 'LanguageGetNamespaces', array( &$this->namespaceNames ) );
+                       Hooks::run( 'LanguageGetNamespaces', array( &$this->namespaceNames ) );
                }
 
                return $this->namespaceNames;
@@ -731,6 +737,8 @@ class Language {
        }
 
        /**
+        * @deprecated since 1.24, doesn't handle conflicting aliases. Use
+        *   SpecialPageFactory::getLocalNameFor instead.
         * @param string $name
         * @return string
         */
@@ -846,6 +854,33 @@ class Language {
         * @since 1.20
         */
        public static function fetchLanguageNames( $inLanguage = null, $include = 'mw' ) {
+               wfProfileIn( __METHOD__ );
+               $cacheKey = $inLanguage === null ? 'null' : $inLanguage;
+               $cacheKey .= ":$include";
+               if ( self::$languageNameCache === null ) {
+                       self::$languageNameCache = new MapCacheLRU( 20 );
+               }
+               if ( self::$languageNameCache->has( $cacheKey ) ) {
+                       $ret = self::$languageNameCache->get( $cacheKey );
+               } else {
+                       $ret = self::fetchLanguageNamesUncached( $inLanguage, $include );
+                       self::$languageNameCache->set( $cacheKey, $ret );
+               }
+               wfProfileOut( __METHOD__ );
+               return $ret;
+       }
+
+       /**
+        * Uncached helper for fetchLanguageNames
+        * @param null|string $inLanguage Code of language in which to return the names
+        *              Use null for autonyms (native names)
+        * @param string $include One of:
+        *              'all' all available languages
+        *              'mw' only if the language is defined in MediaWiki or wgExtraLanguageNames (default)
+        *              'mwfile' only if the language is in 'mw' *and* has a message file
+        * @return array Language code => language name
+        */
+       private static function fetchLanguageNamesUncached( $inLanguage = null, $include = 'mw' ) {
                global $wgExtraLanguageNames;
                static $coreLanguageNames;
 
@@ -863,7 +898,7 @@ class Language {
 
                if ( $inLanguage ) {
                        # TODO: also include when $inLanguage is null, when this code is more efficient
-                       wfRunHooks( 'LanguageGetTranslatedLanguageNames', array( &$names, $inLanguage ) );
+                       Hooks::run( 'LanguageGetTranslatedLanguageNames', array( &$names, $inLanguage ) );
                }
 
                $mwNames = $wgExtraLanguageNames + $coreLanguageNames;
@@ -3127,7 +3162,7 @@ class Language {
                }
                $this->mMagicHookDone = true;
                wfProfileIn( 'LanguageGetMagic' );
-               wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
+               Hooks::run( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
                wfProfileOut( 'LanguageGetMagic' );
        }
 
@@ -3174,7 +3209,7 @@ class Language {
 
        /**
         * Get special page names, as an associative array
-        *   case folded alias => real name
+        *   canonical name => array of valid names, including aliases
         * @return array
         */
        function getSpecialPageAliases() {
@@ -3183,7 +3218,7 @@ class Language {
                        // Initialise array
                        $this->mExtendedSpecialPageAliases =
                                self::$dataCache->getItem( $this->mCode, 'specialPageAliases' );
-                       wfRunHooks( 'LanguageGetSpecialPageAliases',
+                       Hooks::run( 'LanguageGetSpecialPageAliases',
                                array( &$this->mExtendedSpecialPageAliases, $this->getCode() ) );
                }
 
@@ -3310,7 +3345,7 @@ class Language {
                                // the string does not have any number part. Eg: .12345
                                return $sign . $groupedNumber;
                        }
-                       $start = $end = strlen( $integerPart[0] );
+                       $start = $end = ($integerPart) ? strlen( $integerPart[0] ) : 0;
                        while ( $start > 0 ) {
                                $match = $matches[0][$numMatches - 1];
                                $matchLen = strlen( $match );
@@ -4226,7 +4261,7 @@ class Language {
        public static function getMessagesFileName( $code ) {
                global $IP;
                $file = self::getFileName( "$IP/languages/messages/Messages", $code, '.php' );
-               wfRunHooks( 'Language::getMessagesFileName', array( $code, &$file ) );
+               Hooks::run( 'Language::getMessagesFileName', array( $code, &$file ) );
                return $file;
        }