Merge "Accessibility: Make the collapsible sidebar screen reader friendly"
[lhc/web/wiklou.git] / languages / Language.php
index 2523814..dc87bc8 100644 (file)
@@ -30,10 +30,6 @@ if ( !defined( 'MEDIAWIKI' ) ) {
        exit( 1 );
 }
 
-# Read language names
-global $wgLanguageNames;
-require_once __DIR__ . '/Names.php';
-
 if ( function_exists( 'mb_strtoupper' ) ) {
        mb_internal_encoding( 'UTF-8' );
 }
@@ -49,12 +45,14 @@ class FakeConverter {
         */
        public $mLang;
        function __construct( $langobj ) { $this->mLang = $langobj; }
+       function autoConvert( $text, $variant = false ) { return $text; }
        function autoConvertToAllVariants( $text ) { return array( $this->mLang->getCode() => $text ); }
        function convert( $t ) { return $t; }
        function convertTo( $text, $variant ) { return $text; }
        function convertTitle( $t ) { return $t->getPrefixedText(); }
        function convertNamespace( $ns ) { return $this->mLang->getFormattedNsText( $ns ); }
        function getVariants() { return array( $this->mLang->getCode() ); }
+       function getVariantFallbacks( $variant ) { return $this->mLang->getCode(); }
        function getPreferredVariant() { return $this->mLang->getCode(); }
        function getDefaultVariant() { return $this->mLang->getCode(); }
        function getURLVariant() { return ''; }
@@ -66,6 +64,8 @@ class FakeConverter {
        function convertCategoryKey( $key ) { return $key; }
        function convertLinkToAllVariants( $text ) { return $this->autoConvertToAllVariants( $text ); }
        function armourMath( $text ) { return $text; }
+       function validateVariant( $variant = null ) { return $variant === $this->mLang->getCode() ? $variant : null; }
+       function translate( $text, $variant ) { return $text; }
 }
 
 /**
@@ -228,7 +228,7 @@ class Language {
                // Check if there is a language class for the code
                $class = self::classFromCode( $code );
                self::preloadLanguageClass( $class );
-               if ( MWInit::classExists( $class ) ) {
+               if ( class_exists( $class ) ) {
                        $lang = new $class;
                        return $lang;
                }
@@ -242,7 +242,7 @@ class Language {
 
                        $class = self::classFromCode( $fallbackCode );
                        self::preloadLanguageClass( $class );
-                       if ( MWInit::classExists( $class ) ) {
+                       if ( class_exists( $class ) ) {
                                $lang = Language::newFromCode( $fallbackCode );
                                $lang->setCode( $code );
                                return $lang;
@@ -392,7 +392,8 @@ class Language {
                }
 
                if ( $coreLanguageNames === null ) {
-                       include MWInit::compiledPath( 'languages/Names.php' );
+                       global $IP;
+                       include "$IP/languages/Names.php";
                }
 
                if ( isset( $coreLanguageNames[$tag] )
@@ -682,7 +683,18 @@ class Language {
                                }
                        }
 
-                       $this->namespaceAliases = $aliases;
+                       # Also add converted namespace names as aliases, to avoid confusion.
+                       $convertedNames = array();
+                       foreach ( $this->getVariants() as $variant ) {
+                               if ( $variant === $this->mCode ) {
+                                       continue;
+                               }
+                               foreach ( $this->getNamespaces() as $ns => $_ ) {
+                                       $convertedNames[$this->getConverter()->convertNamespace( $ns, $variant )] = $ns;
+                               }
+                       }
+
+                       $this->namespaceAliases = $aliases + $convertedNames;
                }
                return $this->namespaceAliases;
        }
@@ -863,7 +875,8 @@ class Language {
                static $coreLanguageNames;
 
                if ( $coreLanguageNames === null ) {
-                       include MWInit::compiledPath( 'languages/Names.php' );
+                       global $IP;
+                       include "$IP/languages/Names.php";
                }
 
                $names = array();
@@ -2089,9 +2102,8 @@ class Language {
                $segments = array();
 
                foreach ( $intervals as $intervalName => $intervalValue ) {
-                       // Give grep a chance to find the usages:
-                       // duration-centuries, duration-decades, duration-years, duration-days,
-                       // duration-hours, duration-minutes, duration-seconds
+                       // Messages: duration-seconds, duration-minutes, duration-hours, duration-days, duration-weeks,
+                       // duration-years, duration-decades, duration-centuries, duration-millennia
                        $message = wfMessage( 'duration-' . $intervalName )->numParams( $intervalValue );
                        $segments[] = $message->inLanguage( $this )->escaped();
                }
@@ -2276,6 +2288,8 @@ class Language {
                        // Timestamp within the past week: show the day of the week and time
                        $format = $this->getDateFormatString( 'time', $user->getDatePreference() ?: 'default' );
                        $weekday = self::$mWeekdayMsgs[$ts->timestamp->format( 'w' )];
+                       // Messages:
+                       // sunday-at, monday-at, tuesday-at, wednesday-at, thursday-at, friday-at, saturday-at
                        $ts = wfMessage( "$weekday-at" )
                                ->inLanguage( $this )
                                ->params( $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) ) )
@@ -2603,7 +2617,7 @@ class Language {
         */
        function checkTitleEncoding( $s ) {
                if ( is_array( $s ) ) {
-                       wfDebugDieBacktrace( 'Given array to checkTitleEncoding.' );
+                       throw new MWException( 'Given array to checkTitleEncoding.' );
                }
                if ( StringUtils::isUtf8( $s ) ) {
                        return $s;
@@ -3054,7 +3068,7 @@ class Language {
         * Normally we output all numbers in plain en_US style, that is
         * 293,291.235 for twohundredninetythreethousand-twohundredninetyone
         * point twohundredthirtyfive. However this is not suitable for all
-        * languages, some such as Pakaran want ੨੯੩,੨੯੫.੨੩੫ and others such as
+        * languages, some such as Punjabi want ੨੯੩,੨੯੫.੨੩੫ and others such as
         * Icelandic just want to use commas instead of dots, and dots instead
         * of commas like "293.291,235".
         *
@@ -3621,7 +3635,7 @@ class Language {
                foreach ( $forms as $index => $form ) {
                        if ( preg_match( '/^\d+=/i', $form ) ) {
                                $pos = strpos( $form, '=' );
-                               if ( substr( $form, 0, $pos ) === (string) $count ) {
+                               if ( substr( $form, 0, $pos ) === (string)$count ) {
                                        return substr( $form, $pos + 1 );
                                }
                                unset( $forms[$index] );
@@ -3935,6 +3949,16 @@ class Language {
                return self::$dataCache->getItem( $this->mCode, 'linkTrail' );
        }
 
+       /**
+        * A regular expression character set to match legal word-prefixing
+        * characters which should be merged onto a link of the form foo[[bar]].
+        *
+        * @return string
+        */
+       public function linkPrefixCharset() {
+               return self::$dataCache->getItem( $this->mCode, 'linkPrefixCharset' );
+       }
+
        /**
         * @return Language
         */