Merge "fix merge of Iec98e472" into Wikidata
[lhc/web/wiklou.git] / languages / Language.php
index d1a38bb..472871f 100644 (file)
@@ -32,7 +32,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 
 # Read language names
 global $wgLanguageNames;
-require_once( dirname( __FILE__ ) . '/Names.php' );
+require_once( __DIR__ . '/Names.php' );
 
 if ( function_exists( 'mb_strtoupper' ) ) {
        mb_internal_encoding( 'UTF-8' );
@@ -419,6 +419,16 @@ class Language {
         */
        public function setNamespaces( array $namespaces ) {
                $this->namespaceNames = $namespaces;
+               $this->mNamespaceIds = null;
+       }
+
+       /**
+        * Resets all of the namespace caches. Mainly used for testing
+        */
+       public function resetNamespaces( ) {
+               $this->namespaceNames = null;
+               $this->mNamespaceIds = null;
+               $this->namespaceAliases = null;
        }
 
        /**
@@ -800,7 +810,7 @@ class Language {
         * @return string
         */
        function getMessageFromDB( $msg ) {
-               return wfMsgExt( $msg, array( 'parsemag', 'language' => $this ) );
+               return wfMessage( $msg )->inLanguage( $this )->text();
        }
 
        /**
@@ -2865,7 +2875,7 @@ class Language {
          *
          * An example of this function being called:
          * <code>
-         * wfMsg( 'message', $wgLang->formatNum( $num ) )
+         * wfMessage( 'message' )->numParams( $num )->text()
          * </code>
          *
          * See LanguageGu.php for the Gujarati implementation and
@@ -3005,7 +3015,7 @@ class Language {
        function listToText( array $l ) {
                $s = '';
                $m = count( $l ) - 1;
-               
+
                if ( $m === 0 ) {
                        return $l[0];
                } elseif ( $m === 1 ) {
@@ -3032,10 +3042,7 @@ class Language {
         */
        function commaList( array $list ) {
                return implode(
-                       wfMsgExt(
-                               'comma-separator',
-                               array( 'parsemag', 'escapenoentities', 'language' => $this )
-                       ),
+                       wfMessage( 'comma-separator' )->inLanguage( $this )->escaped(),
                        $list
                );
        }
@@ -3048,10 +3055,7 @@ class Language {
         */
        function semicolonList( array $list ) {
                return implode(
-                       wfMsgExt(
-                               'semicolon-separator',
-                               array( 'parsemag', 'escapenoentities', 'language' => $this )
-                       ),
+                       wfMessage( 'semicolon-separator' )->inLanguage( $this )->escaped(),
                        $list
                );
        }
@@ -3063,10 +3067,7 @@ class Language {
         */
        function pipeList( array $list ) {
                return implode(
-                       wfMsgExt(
-                               'pipe-separator',
-                               array( 'escapenoentities', 'language' => $this )
-                       ),
+                       wfMessage( 'pipe-separator' )->inLanguage( $this )->escaped(),
                        $list
                );
        }
@@ -3091,7 +3092,7 @@ class Language {
        function truncate( $string, $length, $ellipsis = '...', $adjustLength = true ) {
                # Use the localized ellipsis character
                if ( $ellipsis == '...' ) {
-                       $ellipsis = wfMsgExt( 'ellipsis', array( 'escapenoentities', 'language' => $this ) );
+                       $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped();
                }
                # Check if there is no need to truncate
                if ( $length == 0 ) {
@@ -3189,7 +3190,7 @@ class Language {
        function truncateHtml( $text, $length, $ellipsis = '...' ) {
                # Use the localized ellipsis character
                if ( $ellipsis == '...' ) {
-                       $ellipsis = wfMsgExt( 'ellipsis', array( 'escapenoentities', 'language' => $this ) );
+                       $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped();
                }
                # Check if there is clearly no need to truncate
                if ( $length <= 0 ) {
@@ -4116,7 +4117,7 @@ class Language {
                $dirmark = ( $oppositedm ? $this->getDirMark( true ) : '' ) .
                        $this->getDirMark();
                $details = $details ? $dirmark . $this->getMessageFromDB( 'word-separator' ) .
-                       wfMsgExt( 'parentheses', array( 'escape', 'replaceafter', 'language' => $this ), $details ) : '';
+                       wfMessage( 'parentheses' )->rawParams( $details )->inLanguage( $this )->escaped() : '';
                return $page . $details;
        }
 
@@ -4196,7 +4197,17 @@ class Language {
         * @return array Associative array with plural form, and plural rule as key-value pairs
         */
        public function getCompiledPluralRules() {
-               return self::$dataCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' );
+               $pluralRules = self::$dataCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' );
+               $fallbacks = Language::getFallbacksFor( $this->mCode );
+               if ( !$pluralRules ) {
+                       foreach ( $fallbacks as $fallbackCode ) {
+                               $pluralRules = self::$dataCache->getItem( strtolower( $fallbackCode ), 'compiledPluralRules' );
+                               if ( $pluralRules ) {
+                                       break;
+                               }
+                       }
+               }
+               return $pluralRules;
        }
 
        /**
@@ -4205,7 +4216,17 @@ class Language {
         * @return array Associative array with plural form, and plural rule as key-value pairs
         */
        public function getPluralRules() {
-               return self::$dataCache->getItem( strtolower( $this->mCode ), 'pluralRules' );
+               $pluralRules = self::$dataCache->getItem( strtolower( $this->mCode ), 'pluralRules' );
+               $fallbacks = Language::getFallbacksFor( $this->mCode );
+               if ( !$pluralRules ) {
+                       foreach ( $fallbacks as $fallbackCode ) {
+                               $pluralRules = self::$dataCache->getItem( strtolower( $fallbackCode ), 'pluralRules' );
+                               if ( $pluralRules ) {
+                                       break;
+                               }
+                       }
+               }
+               return $pluralRules;
        }
 
        /**