Merge "HistoryAction: Implement HistoryPageToolLinks hook for adding more links"
[lhc/web/wiklou.git] / languages / Language.php
index 28469ef..7f04a68 100644 (file)
@@ -1090,7 +1090,7 @@ class Language {
         * @param string $ts 14-character timestamp
         *      YYYYMMDDHHMMSS
         *      01234567890123
-        * @param DateTimeZone $zone Timezone of $ts
+        * @param DateTimeZone|null $zone Timezone of $ts
         * @param int &$ttl The amount of time (in seconds) the output may be cached for.
         * Only makes sense if $ts is the current time.
         * @todo handling of "o" format character for Iranian, Hebrew, Hijri & Thai?
@@ -1883,6 +1883,14 @@ class Language {
                        # Add 543 years to the Gregorian calendar
                        # Months and days are identical
                        $gy_offset = $gy + 543;
+                       # fix for dates between 1912 and 1941
+                       # https://en.wikipedia.org/?oldid=836596673#New_year
+                       if ( $gy >= 1912 && $gy <= 1940 ) {
+                               if ( $gm <= 3 ) {
+                                       $gy_offset--;
+                               }
+                               $gm = ( $gm - 3 ) % 12;
+                       }
                } elseif ( ( !strcmp( $cName, 'minguo' ) ) || !strcmp( $cName, 'juche' ) ) {
                        # Minguo dates
                        # Deduct 1911 years from the Gregorian calendar
@@ -3405,32 +3413,26 @@ class Language {
         * Take a list of strings and build a locale-friendly comma-separated
         * list, using the local comma-separator message.
         * The last two strings are chained with an "and".
-        * NOTE: This function will only work with standard numeric array keys (0, 1, 2…)
         *
-        * @param string[] $l
+        * @param string[] $list
         * @return string
         */
-       function listToText( array $l ) {
-               $m = count( $l ) - 1;
-               if ( $m < 0 ) {
+       public function listToText( array $list ) {
+               $itemCount = count( $list );
+               if ( $itemCount < 1 ) {
                        return '';
                }
-               if ( $m > 0 ) {
+               $text = array_pop( $list );
+               if ( $itemCount > 1 ) {
                        $and = $this->msg( 'and' )->escaped();
                        $space = $this->msg( 'word-separator' )->escaped();
-                       if ( $m > 1 ) {
+                       $comma = '';
+                       if ( $itemCount > 2 ) {
                                $comma = $this->msg( 'comma-separator' )->escaped();
                        }
+                       $text = implode( $comma, $list ) . $and . $space . $text;
                }
-               $s = $l[$m];
-               for ( $i = $m - 1; $i >= 0; $i-- ) {
-                       if ( $i == $m - 1 ) {
-                               $s = $l[$i] . $and . $space . $s;
-                       } else {
-                               $s = $l[$i] . $comma . $s;
-                       }
-               }
-               return $s;
+               return $text;
        }
 
        /**
@@ -3489,6 +3491,7 @@ class Language {
         * @return string
         */
        function truncate( $string, $length, $ellipsis = '...', $adjustLength = true ) {
+               wfDeprecated( __METHOD__, '1.31' );
                return $this->truncateForDatabase( $string, $length, $ellipsis, $adjustLength );
        }
 
@@ -4076,7 +4079,7 @@ 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
+        * @param User|null $user User object to use timezone from or null for $wgUser
         * @param int $now Current timestamp, for formatting relative block durations
         * @return string Somehow translated block duration
         * @see LanguageFi.php for example implementation
@@ -4400,7 +4403,7 @@ class Language {
         * @return bool
         */
        public function equals( Language $lang ) {
-               return $lang->getCode() === $this->mCode;
+               return $lang === $this || $lang->getCode() === $this->mCode;
        }
 
        /**