Gallery slideshow: Support MMV
[lhc/web/wiklou.git] / languages / Language.php
index 71d350f..1b5580c 100644 (file)
@@ -2713,7 +2713,7 @@ class Language {
        public function uc( $str, $first = false ) {
                if ( $first ) {
                        if ( $this->isMultibyte( $str ) ) {
-                               return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
+                               return $this->mbUpperChar( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
                        } else {
                                return ucfirst( $str );
                        }
@@ -2722,6 +2722,28 @@ class Language {
                }
        }
 
+       /**
+        * Convert character to uppercase, allowing overrides of the default mb_upper
+        * behaviour, which is buggy in many ways. Having a conversion table can be
+        * useful during transitions between PHP versions where unicode changes happen.
+        * This can make some resources unreachable on-wiki, see discussion at T219279.
+        * Providing such a conversion table can allow to manage the transition period.
+        *
+        * @since 1.34
+        *
+        * @param string $char
+        *
+        * @return string
+        */
+       protected function mbUpperChar( $char ) {
+               global $wgOverrideUcfirstCharacters;
+               if ( array_key_exists( $char, $wgOverrideUcfirstCharacters ) ) {
+                       return $wgOverrideUcfirstCharacters[$char];
+               } else {
+                       return mb_strtoupper( $char );
+               }
+       }
+
        /**
         * @param string $str
         * @return mixed|string
@@ -2854,7 +2876,7 @@ class Language {
        }
 
        /**
-        * @return array
+        * @return string
         */
        function fallback8bitEncoding() {
                return self::$dataCache->getItem( $this->mCode, 'fallback8bitEncoding' );
@@ -3556,12 +3578,8 @@ class Language {
         * @return string
         */
        private function truncateInternal(
-               $string, $length, $ellipsis, $adjustLength, $measureLength, $getSubstring
+               $string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring
        ) {
-               if ( !is_callable( $measureLength ) || !is_callable( $getSubstring ) ) {
-                       throw new InvalidArgumentException( 'Invalid callback provided' );
-               }
-
                # Check if there is no need to truncate
                if ( $measureLength( $string ) <= abs( $length ) ) {
                        return $string; // no need to truncate
@@ -3701,6 +3719,7 @@ class Language {
                                        }
                                } elseif ( $dispLen > $length && $dispLen > strlen( $ellipsis ) ) {
                                        # String in fact does need truncation, the truncation point was OK.
+                                       // @phan-suppress-next-line PhanTypeInvalidExpressionArrayDestructuring
                                        list( $ret, $openTags ) = $maybeState; // reload state
                                        $ret = $this->removeBadCharLast( $ret ); // multi-byte char fix
                                        $ret .= $ellipsis; // add ellipsis
@@ -4023,15 +4042,12 @@ class Language {
         * Checks that convertPlural was given an array and pads it to requested
         * amount of forms by copying the last one.
         *
-        * @param array $forms Array of forms given to convertPlural
+        * @param array $forms
         * @param int $count How many forms should there be at least
-        * @return array Padded array of forms or an exception if not an array
+        * @return array Padded array of forms
         */
        protected function preConvertPlural( /* Array */ $forms, $count ) {
-               while ( count( $forms ) < $count ) {
-                       $forms[] = $forms[count( $forms ) - 1];
-               }
-               return $forms;
+               return array_pad( $forms, $count, end( $forms ) );
        }
 
        /**
@@ -4409,18 +4425,6 @@ class Language {
                return $this->mHtmlCode;
        }
 
-       /**
-        * @param string $code
-        * @deprecated since 1.32, use Language::factory to create a new object instead.
-        */
-       public function setCode( $code ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               $this->mCode = $code;
-               // Ensure we don't leave incorrect cached data lying around
-               $this->mHtmlCode = null;
-               $this->mParentLanguage = false;
-       }
-
        /**
         * Get the language code from a file name. Inverse of getFileName()
         * @param string $filename $prefix . $languageCode . $suffix
@@ -4857,6 +4861,8 @@ class Language {
         * @param array $query Optional URL query parameter string
         * @param bool $atend Optional param for specified if this is the last page
         * @return string
+        * @deprecated since 1.33, use SpecialPage::viewPrevNext()
+        *  instead.
         */
        public function viewPrevNext( Title $title, $offset, $limit,
                array $query = [], $atend = false