From: C. Scott Ananian Date: Wed, 13 Jun 2018 17:49:29 +0000 (-0400) Subject: Remove most uses of deprecated Language::truncate() X-Git-Tag: 1.34.0-rc.0~4783^2~2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;h=0935e47a721787c830e6d85ed59a3e4d4d58846c;p=lhc%2Fweb%2Fwiklou.git Remove most uses of deprecated Language::truncate() The Language::truncate() function was split into Language::truncateForVisual() (which measures characters) and Language::truncateForDatabase() (which measures bytes) in 1.31, but the patch which soft-deprecated Language::truncate() didn't actually remove all the uses in the codebase. Replace most of those old uses now, which should actually improve the situation for non-latin-alphabet users who were getting unfairly squeezed in a number of places. Bug: T197492 Change-Id: I2291c69d9df17c1a9e4ab1b7d4cbc73bc51d3ebb --- diff --git a/includes/CommentStore.php b/includes/CommentStore.php index 8a1901c747..484b8464dd 100644 --- a/includes/CommentStore.php +++ b/includes/CommentStore.php @@ -458,16 +458,7 @@ class CommentStore { $comment = CommentStoreComment::newUnsavedComment( $comment, $data ); # Truncate comment in a Unicode-sensitive manner - $comment->text = $this->lang->truncate( $comment->text, self::MAX_COMMENT_LENGTH ); - if ( mb_strlen( $comment->text, 'UTF-8' ) > self::COMMENT_CHARACTER_LIMIT ) { - $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this->lang )->escaped(); - if ( mb_strlen( $ellipsis ) >= self::COMMENT_CHARACTER_LIMIT ) { - // WTF? - $ellipsis = '...'; - } - $maxLength = self::COMMENT_CHARACTER_LIMIT - mb_strlen( $ellipsis, 'UTF-8' ); - $comment->text = mb_substr( $comment->text, 0, $maxLength, 'UTF-8' ) . $ellipsis; - } + $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT ); if ( $this->stage > MIGRATION_OLD && !$comment->id ) { $dbData = $comment->data; @@ -530,7 +521,7 @@ class CommentStore { $comment = $this->createComment( $dbw, $comment, $data ); if ( $this->stage <= MIGRATION_WRITE_BOTH ) { - $fields[$key] = $this->lang->truncate( $comment->text, 255 ); + $fields[$key] = $this->lang->truncateForDatabase( $comment->text, 255 ); } if ( $this->stage >= MIGRATION_WRITE_BOTH ) { diff --git a/includes/content/TextContent.php b/includes/content/TextContent.php index 2494177b30..c0582962b5 100644 --- a/includes/content/TextContent.php +++ b/includes/content/TextContent.php @@ -75,7 +75,7 @@ class TextContent extends AbstractContent { $text = $this->getNativeData(); - $truncatedtext = $wgContLang->truncate( + $truncatedtext = $wgContLang->truncateForDatabase( preg_replace( "/[\n\r]/", ' ', $text ), max( 0, $maxlength ) ); diff --git a/includes/gallery/TraditionalImageGallery.php b/includes/gallery/TraditionalImageGallery.php index a87322d46d..479ca5d9bd 100644 --- a/includes/gallery/TraditionalImageGallery.php +++ b/includes/gallery/TraditionalImageGallery.php @@ -226,7 +226,7 @@ class TraditionalImageGallery extends ImageGalleryBase { $nt, htmlspecialchars( is_int( $this->getCaptionLength() ) ? - $lang->truncate( $nt->getText(), $this->getCaptionLength() ) : + $lang->truncateForVisual( $nt->getText(), $this->getCaptionLength() ) : $nt->getText() ), [ @@ -286,7 +286,7 @@ class TraditionalImageGallery extends ImageGalleryBase { } /** - * Length to truncate filename to in caption when using "showfilename" (if int). + * Length (in characters) to truncate filename to in caption when using "showfilename" (if int). * A value of 'true' will truncate the filename to one line using CSS, while * 'false' will disable truncating. * diff --git a/includes/search/SearchHighlighter.php b/includes/search/SearchHighlighter.php index a97429e0c4..2cec241e40 100644 --- a/includes/search/SearchHighlighter.php +++ b/includes/search/SearchHighlighter.php @@ -525,12 +525,12 @@ class SearchHighlighter { } --$contextlines; // truncate function changes ... to relevant i18n message. - $pre = $wgContLang->truncate( $m[1], - $contextchars, '...', false ); + $pre = $wgContLang->truncateForVisual( $m[1], - $contextchars, '...', false ); if ( count( $m ) < 3 ) { $post = ''; } else { - $post = $wgContLang->truncate( $m[3], $contextchars, '...', false ); + $post = $wgContLang->truncateForVisual( $m[3], $contextchars, '...', false ); } $found = $m[2];