Replace use of deprecated Language::truncate()
authorC. Scott Ananian <cscott@cscott.net>
Wed, 13 Jun 2018 17:49:29 +0000 (13:49 -0400)
committerC. Scott Ananian <cscott@cscott.net>
Mon, 9 Jul 2018 18:07:23 +0000 (14:07 -0400)
Follow-up to I2291c69d9df17c1a9e4ab1b7d4cbc73bc51d3ebb -- this code uses
sprintf to align text, which won't really work for multibyte UTF8 or
unicode combining characters.  Alas.  Do the best we can for now.

Bug: T197492
Change-Id: Iaa4d7bd64588ca1f215921339d84f960380ae12b

maintenance/orphans.php

index 7acf6d8..d7decc1 100644 (file)
@@ -108,13 +108,20 @@ class Orphans extends Maintenance {
                        foreach ( $result as $row ) {
                                $comment = $commentStore->getComment( 'rev_comment', $row )->text;
                                if ( $comment !== '' ) {
-                                       $comment = '(' . $wgContLang->truncate( $comment, 40 ) . ')';
+                                       $comment = '(' . $wgContLang->truncateForVisual( $comment, 40 ) . ')';
                                }
-                               $this->output( sprintf( "%10d %10d %14s %20s %s\n",
+                               $rev_user_text = $wgContLang->truncateForVisual( $row->rev_user_text, 20 );
+                               # pad $rev_user_text to 20 characters.  Note that this may
+                               # yield poor results if $rev_user_text contains combining
+                               # or half-width characters.  Alas.
+                               if ( mb_strlen( $rev_user_text ) < 20 ) {
+                                       $rev_user_text = str_repeat( ' ', 20 - mb_strlen( $rev_user_text ) );
+                               }
+                               $this->output( sprintf( "%10d %10d %14s %s %s\n",
                                        $row->rev_id,
                                        $row->rev_page,
                                        $row->rev_timestamp,
-                                       $wgContLang->truncate( $row->rev_user_text, 17 ),
+                                       $rev_user_text,
                                        $comment ) );
                                if ( $fix ) {
                                        $dbw->delete( 'revision', [ 'rev_id' => $row->rev_id ] );