Merge "skins: Minor code clean up"
[lhc/web/wiklou.git] / languages / Language.php
index 190f2bf..37f4137 100644 (file)
@@ -30,8 +30,6 @@ if ( !defined( 'MEDIAWIKI' ) ) {
        exit( 1 );
 }
 
-mb_internal_encoding( 'UTF-8' );
-
 use CLDRPluralRuleParser\Evaluator;
 
 /**
@@ -942,14 +940,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 );
@@ -961,7 +959,7 @@ class Language {
         * @param string $key
         * @return string
         */
-       function getWeekdayName( $key ) {
+       public function getWeekdayName( $key ) {
                return $this->getMessageFromDB( self::$mWeekdayMsgs[$key - 1] );
        }
 
@@ -1089,7 +1087,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 = 'unused' ) {
                $s = '';
                $raw = false;
                $roman = false;
@@ -1454,7 +1452,9 @@ class Language {
                        }
                }
 
-               if ( $usedSecond ) {
+               if ( $ttl === 'unused' ) {
+                       // No need to calculate the TTL, the caller wont use it anyway.
+               } elseif ( $usedSecond ) {
                        $ttl = 1;
                } elseif ( $usedMinute ) {
                        $ttl = 60 - substr( $ts, 12, 2 );
@@ -2067,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 ) {
@@ -2214,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 );
@@ -2233,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 );
@@ -2253,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 );
@@ -2559,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 );
        }
 
@@ -2576,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
 
@@ -2623,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;
@@ -2643,7 +2643,7 @@ class Language {
         *
         * @return string
         */
-       function uc( $str, $first = false ) {
+       public function uc( $str, $first = false ) {
                if ( $first ) {
                        if ( $this->isMultibyte( $str ) ) {
                                return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
@@ -4190,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
         *