Add top help link to MediaWiki.org in several pages via indicator
[lhc/web/wiklou.git] / languages / Language.php
index fb04255..d203c0f 100644 (file)
@@ -318,7 +318,7 @@ class Language {
                // see bugs 37564, 37587, 36938
                $cache[$code] =
                        strcspn( $code, ":/\\\000&<>'\"" ) === strlen( $code )
-                       && !preg_match( Title::getTitleInvalidRegex(), $code );
+                       && !preg_match( MediaWikiTitleCodec::getTitleInvalidRegex(), $code );
 
                return $cache[$code];
        }
@@ -500,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;
@@ -854,7 +854,6 @@ 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 ) {
@@ -866,7 +865,6 @@ class Language {
                        $ret = self::fetchLanguageNamesUncached( $inLanguage, $include );
                        self::$languageNameCache->set( $cacheKey, $ret );
                }
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -898,7 +896,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;
@@ -911,6 +909,7 @@ class Language {
                }
 
                if ( $include === 'all' ) {
+                       ksort( $names );
                        return $names;
                }
 
@@ -932,9 +931,11 @@ class Language {
                                }
                        }
 
+                       ksort( $namesMwFile );
                        return $namesMwFile;
                }
 
+               ksort( $returnMw );
                # 'mw' option; default if it's not one of the other two options (all/mwfile)
                return $returnMw;
        }
@@ -959,7 +960,17 @@ class Language {
         * @return string
         */
        function getMessageFromDB( $msg ) {
-               return wfMessage( $msg )->inLanguage( $this )->text();
+               return $this->msg( $msg )->text();
+       }
+
+       /**
+        * Get message object in this language. Only for use inside this class.
+        *
+        * @param string $msg Message name
+        * @return Message
+        */
+       protected function msg( $msg ) {
+               return wfMessage( $msg )->inLanguage( $this );
        }
 
        /**
@@ -3161,9 +3172,7 @@ class Language {
                        return;
                }
                $this->mMagicHookDone = true;
-               wfProfileIn( 'LanguageGetMagic' );
-               wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
-               wfProfileOut( 'LanguageGetMagic' );
+               Hooks::run( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
        }
 
        /**
@@ -3218,7 +3227,7 @@ class Language {
                        // Initialise array
                        $this->mExtendedSpecialPageAliases =
                                self::$dataCache->getItem( $this->mCode, 'specialPageAliases' );
-                       wfRunHooks( 'LanguageGetSpecialPageAliases',
+                       Hooks::run( 'LanguageGetSpecialPageAliases',
                                array( &$this->mExtendedSpecialPageAliases, $this->getCode() ) );
                }
 
@@ -3345,7 +3354,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 );
@@ -3403,10 +3412,10 @@ class Language {
                        return '';
                }
                if ( $m > 0 ) {
-                       $and = $this->getMessageFromDB( 'and' );
-                       $space = $this->getMessageFromDB( 'word-separator' );
+                       $and = $this->msg( 'and' )->escaped();
+                       $space = $this->msg( 'word-separator' )->escaped();
                        if ( $m > 1 ) {
-                               $comma = $this->getMessageFromDB( 'comma-separator' );
+                               $comma = $this->msg( 'comma-separator' )->escaped();
                        }
                }
                $s = $l[$m];
@@ -4261,7 +4270,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;
        }
 
@@ -4432,7 +4441,6 @@ class Language {
                        return array( $wikiUpperChars, $wikiLowerChars );
                }
 
-               wfProfileIn( __METHOD__ );
                $arr = wfGetPrecompiledData( 'Utf8Case.ser' );
                if ( $arr === false ) {
                        throw new MWException(
@@ -4440,7 +4448,6 @@ class Language {
                }
                $wikiUpperChars = $arr['wikiUpperChars'];
                $wikiLowerChars = $arr['wikiLowerChars'];
-               wfProfileOut( __METHOD__ );
                return array( $wikiUpperChars, $wikiLowerChars );
        }
 
@@ -4640,17 +4647,22 @@ class Language {
         * Make a list item, used by various special pages
         *
         * @param string $page Page link
-        * @param string $details Text between brackets
+        * @param string $details HTML safe text between brackets
         * @param bool $oppositedm Add the direction mark opposite to your
         *   language, to display text properly
-        * @return string
+        * @return HTML escaped string
         */
        function specialList( $page, $details, $oppositedm = true ) {
-               $dirmark = ( $oppositedm ? $this->getDirMark( true ) : '' ) .
-                       $this->getDirMark();
-               $details = $details ? $dirmark . $this->getMessageFromDB( 'word-separator' ) .
-                       wfMessage( 'parentheses' )->rawParams( $details )->inLanguage( $this )->escaped() : '';
-               return $page . $details;
+               if ( !$details ) {
+                       return $page;
+               }
+
+               $dirmark = ( $oppositedm ? $this->getDirMark( true ) : '' ) . $this->getDirMark();
+               return
+                       $page .
+                       $dirmark .
+                       $this->msg( 'word-separator' )->escaped() .
+                       $this->msg( 'parentheses' )->rawParams( $details )->escaped();
        }
 
        /**