Merge "Change job table params from blob to mediumblob"
[lhc/web/wiklou.git] / languages / Language.php
index bbf2576..71d350f 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 use CLDRPluralRuleParser\Evaluator;
+use Wikimedia\Assert\Assert;
 
 /**
  * Internationalisation code
@@ -385,6 +386,7 @@ class Language {
         */
        public static function isValidCode( $code ) {
                static $cache = [];
+               Assert::parameterType( 'string', $code, '$code' );
                if ( !isset( $cache[$code] ) ) {
                        // People think language codes are html safe, so enforce it.
                        // Ideally we should only allow a-zA-Z0-9-
@@ -404,20 +406,11 @@ class Language {
         *
         * @param string $code
         *
-        * @throws MWException
         * @since 1.18
         * @return bool
         */
        public static function isValidBuiltInCode( $code ) {
-               if ( !is_string( $code ) ) {
-                       if ( is_object( $code ) ) {
-                               $addmsg = " of class " . get_class( $code );
-                       } else {
-                               $addmsg = '';
-                       }
-                       $type = gettype( $code );
-                       throw new MWException( __METHOD__ . " must be passed a string, $type given$addmsg" );
-               }
+               Assert::parameterType( 'string', $code, '$code' );
 
                return (bool)preg_match( '/^[a-z0-9-]{2,}$/', $code );
        }
@@ -2845,9 +2838,9 @@ class Language {
        }
 
        /**
+        * TODO: $s is not always a string per T218883
         * @param string $s
         * @return string
-        * @throws MWException
         */
        function checkTitleEncoding( $s ) {
                if ( is_array( $s ) ) {
@@ -3522,8 +3515,8 @@ class Language {
         * Truncate a string to a specified number of characters, appending an optional
         * string (e.g. for ellipsis).
         *
-        * This provides multibyte version of truncate() method of this class, suitable for truncation
-        * based on number of characters, instead of number of bytes.
+        * This provides multibyte version of truncateForDatabase() method of this class,
+        * suitable for truncation based on number of characters, instead of number of bytes.
         *
         * If $length is negative, the string will be truncated from the beginning.
         *
@@ -3593,14 +3586,12 @@ class Language {
                                $length -= $ellipsisLength;
                                $string = $getSubstring( $string, 0, $length ); // xyz...
                                $string = $this->removeBadCharLast( $string );
-                               $string = rtrim( $string );
-                               $string = $string . $ellipsis;
+                               $string = rtrim( $string ) . $ellipsis;
                        } else {
                                $length += $ellipsisLength;
                                $string = $getSubstring( $string, $length ); // ...xyz
                                $string = $this->removeBadCharFirst( $string );
-                               $string = ltrim( $string );
-                               $string = $ellipsis . $string;
+                               $string = $ellipsis . ltrim( $string );
                        }
                }