From 131132d72c83c907af5a47402290ec5cdb6663a1 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Wed, 13 Jun 2018 13:49:29 -0400 Subject: [PATCH] Replace use of deprecated Language::truncate() 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 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/maintenance/orphans.php b/maintenance/orphans.php index 7acf6d8279..d7decc1b45 100644 --- a/maintenance/orphans.php +++ b/maintenance/orphans.php @@ -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 ] ); -- 2.20.1