Localisation updates from https://translatewiki.net.
[lhc/web/wiklou.git] / languages / Language.php
index f13f9d6..0a6ccd3 100644 (file)
@@ -30,9 +30,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
        exit( 1 );
 }
 
-if ( function_exists( 'mb_strtoupper' ) ) {
-       mb_internal_encoding( 'UTF-8' );
-}
+mb_internal_encoding( 'UTF-8' );
 
 use CLDRPluralRuleParser\Evaluator;
 
@@ -944,14 +942,14 @@ class Language {
         * @param string $key
         * @return string
         */
-       function getMonthAbbreviation( $key ) {
+       public function getMonthAbbreviation( $key ) {
                return $this->getMessageFromDB( self::$mMonthAbbrevMsgs[$key - 1] );
        }
 
        /**
         * @return array
         */
-       function getMonthAbbreviationsArray() {
+       public function getMonthAbbreviationsArray() {
                $monthNames = [ '' ];
                for ( $i = 1; $i < 13; $i++ ) {
                        $monthNames[] = $this->getMonthAbbreviation( $i );
@@ -963,7 +961,7 @@ class Language {
         * @param string $key
         * @return string
         */
-       function getWeekdayName( $key ) {
+       public function getWeekdayName( $key ) {
                return $this->getMessageFromDB( self::$mWeekdayMsgs[$key - 1] );
        }
 
@@ -1091,7 +1089,7 @@ class Language {
         * @throws MWException
         * @return string
         */
-       function sprintfDate( $format, $ts, DateTimeZone $zone = null, &$ttl = null ) {
+       public function sprintfDate( $format, $ts, DateTimeZone $zone = null, &$ttl = null ) {
                $s = '';
                $raw = false;
                $roman = false;
@@ -1557,7 +1555,7 @@ class Language {
         *
         * @param string $ts
         *
-        * @return string
+        * @return int[]
         */
        private static function tsToIranian( $ts ) {
                $gy = substr( $ts, 0, 4 ) -1600;
@@ -1615,7 +1613,7 @@ class Language {
         *
         * @param string $ts
         *
-        * @return string
+        * @return int[]
         */
        private static function tsToHijri( $ts ) {
                $year = substr( $ts, 0, 4 );
@@ -1667,7 +1665,7 @@ class Language {
         *
         * @param string $ts
         *
-        * @return string
+        * @return int[]
         */
        private static function tsToHebrew( $ts ) {
                # Parse date
@@ -2069,7 +2067,7 @@ class Language {
         *   get user timecorrection setting)
         * @return int
         */
-       function userAdjust( $ts, $tz = false ) {
+       public function userAdjust( $ts, $tz = false ) {
                global $wgUser, $wgLocalTZoffset;
 
                if ( $tz === false ) {
@@ -2216,7 +2214,7 @@ class Language {
         *   validateTimeZone() in Special:Preferences
         * @return string
         */
-       function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
+       public function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
                $ts = wfTimestamp( TS_MW, $ts );
                if ( $adj ) {
                        $ts = $this->userAdjust( $ts, $timecorrection );
@@ -2235,7 +2233,7 @@ class Language {
         *   validateTimeZone() in Special:Preferences
         * @return string
         */
-       function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
+       public function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
                $ts = wfTimestamp( TS_MW, $ts );
                if ( $adj ) {
                        $ts = $this->userAdjust( $ts, $timecorrection );
@@ -2255,7 +2253,7 @@ class Language {
         *   validateTimeZone() in Special:Preferences
         * @return string
         */
-       function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false ) {
+       public function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false ) {
                $ts = wfTimestamp( TS_MW, $ts );
                if ( $adj ) {
                        $ts = $this->userAdjust( $ts, $timecorrection );
@@ -2561,7 +2559,7 @@ class Language {
         * @param string $key
         * @return array|null
         */
-       function getMessage( $key ) {
+       public function getMessage( $key ) {
                return self::$dataCache->getSubitem( $this->mCode, 'messages', $key );
        }
 
@@ -2578,7 +2576,7 @@ class Language {
         * @param string $string
         * @return string
         */
-       function iconv( $in, $out, $string ) {
+       public function iconv( $in, $out, $string ) {
                # This is a wrapper for iconv in all languages except esperanto,
                # which does some nasty x-conversions beforehand
 
@@ -2592,7 +2590,7 @@ class Language {
                return $text;
        }
 
-       // callback functions for uc(), lc(), ucwords(), ucwordbreaks()
+       // callback functions for ucwords(), ucwordbreaks()
 
        /**
         * @param array $matches
@@ -2610,24 +2608,6 @@ class Language {
                return mb_strtoupper( $matches[0] );
        }
 
-       /**
-        * @param array $matches
-        * @return string
-        */
-       function ucCallback( $matches ) {
-               list( $wikiUpperChars ) = self::getCaseMaps();
-               return strtr( $matches[1], $wikiUpperChars );
-       }
-
-       /**
-        * @param array $matches
-        * @return string
-        */
-       function lcCallback( $matches ) {
-               list( , $wikiLowerChars ) = self::getCaseMaps();
-               return strtr( $matches[1], $wikiLowerChars );
-       }
-
        /**
         * @param array $matches
         * @return string
@@ -2636,15 +2616,6 @@ class Language {
                return mb_strtoupper( $matches[0] );
        }
 
-       /**
-        * @param array $matches
-        * @return string
-        */
-       function ucwordsCallbackWiki( $matches ) {
-               list( $wikiUpperChars ) = self::getCaseMaps();
-               return strtr( $matches[0], $wikiUpperChars );
-       }
-
        /**
         * Make a string's first character uppercase
         *
@@ -2652,7 +2623,7 @@ class Language {
         *
         * @return string
         */
-       function ucfirst( $str ) {
+       public function ucfirst( $str ) {
                $o = ord( $str );
                if ( $o < 96 ) { // if already uppercase...
                        return $str;
@@ -2672,28 +2643,15 @@ class Language {
         *
         * @return string
         */
-       function uc( $str, $first = false ) {
-               if ( function_exists( 'mb_strtoupper' ) ) {
-                       if ( $first ) {
-                               if ( $this->isMultibyte( $str ) ) {
-                                       return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
-                               } else {
-                                       return ucfirst( $str );
-                               }
-                       } else {
-                               return $this->isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str );
-                       }
-               } else {
+       public function uc( $str, $first = false ) {
+               if ( $first ) {
                        if ( $this->isMultibyte( $str ) ) {
-                               $x = $first ? '^' : '';
-                               return preg_replace_callback(
-                                       "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/",
-                                       [ $this, 'ucCallback' ],
-                                       $str
-                               );
+                               return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
                        } else {
-                               return $first ? ucfirst( $str ) : strtoupper( $str );
+                               return ucfirst( $str );
                        }
+               } else {
+                       return $this->isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str );
                }
        }
 
@@ -2721,27 +2679,14 @@ class Language {
         * @return mixed|string
         */
        function lc( $str, $first = false ) {
-               if ( function_exists( 'mb_strtolower' ) ) {
-                       if ( $first ) {
-                               if ( $this->isMultibyte( $str ) ) {
-                                       return mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
-                               } else {
-                                       return strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 );
-                               }
-                       } else {
-                               return $this->isMultibyte( $str ) ? mb_strtolower( $str ) : strtolower( $str );
-                       }
-               } else {
+               if ( $first ) {
                        if ( $this->isMultibyte( $str ) ) {
-                               $x = $first ? '^' : '';
-                               return preg_replace_callback(
-                                       "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/",
-                                       [ $this, 'lcCallback' ],
-                                       $str
-                               );
+                               return mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
                        } else {
-                               return $first ? strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 ) : strtolower( $str );
+                               return strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 );
                        }
+               } else {
+                       return $this->isMultibyte( $str ) ? mb_strtolower( $str ) : strtolower( $str );
                }
        }
 
@@ -2765,19 +2710,11 @@ class Language {
                        $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)| ([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
 
                        // function to use to capitalize a single char
-                       if ( function_exists( 'mb_strtoupper' ) ) {
-                               return preg_replace_callback(
-                                       $replaceRegexp,
-                                       [ $this, 'ucwordsCallbackMB' ],
-                                       $str
-                               );
-                       } else {
-                               return preg_replace_callback(
-                                       $replaceRegexp,
-                                       [ $this, 'ucwordsCallbackWiki' ],
-                                       $str
-                               );
-                       }
+                       return preg_replace_callback(
+                               $replaceRegexp,
+                               [ $this, 'ucwordsCallbackMB' ],
+                               $str
+                       );
                } else {
                        return ucwords( strtolower( $str ) );
                }
@@ -2800,19 +2737,11 @@ class Language {
                        $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|" .
                                "$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
 
-                       if ( function_exists( 'mb_strtoupper' ) ) {
-                               return preg_replace_callback(
-                                       $replaceRegexp,
-                                       [ $this, 'ucwordbreaksCallbackMB' ],
-                                       $str
-                               );
-                       } else {
-                               return preg_replace_callback(
-                                       $replaceRegexp,
-                                       [ $this, 'ucwordsCallbackWiki' ],
-                                       $str
-                               );
-                       }
+                       return preg_replace_callback(
+                               $replaceRegexp,
+                               [ $this, 'ucwordbreaksCallbackMB' ],
+                               $str
+                       );
                } else {
                        return preg_replace_callback(
                                '/\b([\w\x80-\xff]+)\b/',
@@ -3966,10 +3895,11 @@ class Language {
         * match up with it.
         *
         * @param string $str The validated block duration in English
+        * @param User $user User object to use timezone from or null for $wgUser
         * @return string Somehow translated block duration
         * @see LanguageFi.php for example implementation
         */
-       function translateBlockExpiry( $str ) {
+       function translateBlockExpiry( $str, User $user = null ) {
                $duration = SpecialBlock::getSuggestedDurations( $this );
                foreach ( $duration as $show => $value ) {
                        if ( strcmp( $str, $value ) == 0 ) {
@@ -3995,10 +3925,12 @@ class Language {
                } else { // It's an absolute timestamp.
                        if ( $time === 0 ) {
                                // wfTimestamp() handles 0 as current time instead of epoch.
-                               return $this->timeanddate( '19700101000000' );
-                       } else {
-                               return $this->timeanddate( $time );
+                               $time = '19700101000000';
                        }
+                       if ( $user ) {
+                               return $this->userTimeAndDate( $time, $user );
+                       }
+                       return $this->timeanddate( $time );
                }
        }
 
@@ -4258,6 +4190,17 @@ class Language {
                return $lang;
        }
 
+       /**
+        * Compare with an other language object
+        *
+        * @since 1.28
+        * @param Language $lang
+        * @return boolean
+        */
+       public function equals( Language $lang ) {
+               return $lang->getCode() === $this->mCode;
+       }
+
        /**
         * Get the internal language code for this language object
         *
@@ -4496,26 +4439,6 @@ class Language {
                return $this->convertGrammar( trim( $m[2] ), trim( $m[1] ) );
        }
 
-       /**
-        * @throws MWException
-        * @return array
-        */
-       static function getCaseMaps() {
-               static $wikiUpperChars, $wikiLowerChars;
-               if ( isset( $wikiUpperChars ) ) {
-                       return [ $wikiUpperChars, $wikiLowerChars ];
-               }
-
-               $arr = wfGetPrecompiledData( 'Utf8Case.ser' );
-               if ( $arr === false ) {
-                       throw new MWException(
-                               "Utf8Case.ser is missing, please run \"make\" in the serialized directory\n" );
-               }
-               $wikiUpperChars = $arr['wikiUpperChars'];
-               $wikiLowerChars = $arr['wikiLowerChars'];
-               return [ $wikiUpperChars, $wikiLowerChars ];
-       }
-
        /**
         * Decode an expiry (block, protection, etc) which has come from the DB
         *