r91858 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91857‎ | r91858 | r91859 >
Date:04:06, 11 July 2011
Author:ashley
Status:deferred
Tags:
Comment:
SocialProfile: get rid of DIY truncation code in favor of Language::truncate(), which has existed since the beginning of time (r4473, to be exact)
Modified paths:
  • /trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserStats/TopFansByStat.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php
@@ -568,6 +568,8 @@
569569 * table and set them in the appropriate class member variables.
570570 */
571571 private function setRelationships() {
 572+ global $wgLang;
 573+
572574 $dbr = wfGetDB( DB_SLAVE );
573575
574576 $where = array();
@@ -617,10 +619,7 @@
618620 $r_type = 'foe';
619621 }
620622
621 - $user_name_short = substr( $row->r_user_name, 0, 25 );
622 - if ( $row->r_user_name != $user_name_short ) {
623 - $user_name_short .= wfMsg( 'ellipsis' );
624 - }
 623+ $user_name_short = $wgLang->truncate( $row->r_user_name, 25 );
625624
626625 $this->items_grouped[$r_type][$row->r_user_name_relation]['users'][$row->r_user_name][] = array(
627626 'id' => $row->r_id,
@@ -748,6 +747,8 @@
749748 * member variables.
750749 */
751750 private function setSystemMessages() {
 751+ global $wgLang;
 752+
752753 $dbr = wfGetDB( DB_SLAVE );
753754
754755 $where = array();
@@ -791,10 +792,8 @@
792793
793794 foreach ( $res as $row ) {
794795 $user_title = Title::makeTitle( NS_USER, $row->um_user_name );
795 - $user_name_short = substr( $row->um_user_name, 0, 15 );
796 - if ( $row->um_user_name != $user_name_short ) {
797 - $user_name_short .= wfMsg( 'ellipsis' );
798 - }
 796+ $user_name_short = $wgLang->truncate( $row->um_user_name, 15 );
 797+
799798 $this->activityLines[] = array(
800799 'type' => 'system_message',
801800 'timestamp' => $row->item_date,
@@ -929,6 +928,8 @@
930929 * @param $has_page Boolean: true by default
931930 */
932931 function simplifyPageActivity( $type, $has_page = true ) {
 932+ global $wgLang;
 933+
933934 if ( !isset( $this->items_grouped[$type] ) || !is_array( $this->items_grouped[$type] ) ) {
934935 return '';
935936 }
@@ -1026,10 +1027,7 @@
10271028 }
10281029
10291030 $user_title = Title::makeTitle( NS_USER, $user_name );
1030 - $user_name_short = substr( $user_name, 0, 15 );
1031 - if ( $user_name != $user_name_short ) {
1032 - $user_name_short .= wfMsg( 'ellipsis' );
1033 - }
 1031+ $user_name_short = $wgLang->truncate( $user_name, 15 );
10341032
10351033 $users .= " <b><a href=\"{$user_title->escapeFullURL()}\">{$user_name_short}</a></b>";
10361034 }
@@ -1090,6 +1088,7 @@
10911089 * @return String: "fixed" comment
10921090 */
10931091 function fixItemComment( $comment ) {
 1092+ global $wgLang;
10941093 if ( !$comment ) {
10951094 return '';
10961095 } else {
@@ -1098,10 +1097,7 @@
10991098 $comment = str_replace( '&', '%26', $comment );
11001099 $comment = str_replace( '%26quot;', '"', $comment );
11011100 }
1102 - $preview = substr( $comment, 0, 75 );
1103 - if ( $preview != $comment ) {
1104 - $preview .= wfMsg( 'ellipsis' );
1105 - }
 1101+ $preview = $wgLang->truncate( $comment, 75 );
11061102 return stripslashes( $preview );
11071103 }
11081104
Index: trunk/extensions/SocialProfile/UserStats/TopFansByStat.php
@@ -15,7 +15,7 @@
1616 * @param $par Mixed: parameter passed to the page or null
1717 */
1818 public function execute( $par ) {
19 - global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUploadPath, $wgScriptPath;
 19+ global $wgRequest, $wgLang, $wgOut, $wgMemc, $wgUploadPath, $wgScriptPath;
2020 global $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly;
2121
2222 // Load CSS
@@ -118,11 +118,7 @@
119119 $out .= '<div class="top-users">';
120120
121121 foreach ( $user_list as $user ) {
122 - if ( $user['user_name'] == substr( $user['user_name'], 0, 22 ) ) {
123 - $user_name = $user['user_name'];
124 - } else {
125 - $user_name = substr( $user['user_name'], 0, 22 ) . wfMsg( 'ellipsis' );
126 - }
 122+ $user_name = $wgLang->truncate( $user['user_name'], 22 );
127123 $user_title = Title::makeTitle( NS_USER, $user['user_name'] );
128124 $avatar = new wAvatar( $user['user_id'], 'm' );
129125 $commentIcon = $avatar->getAvatarImage();

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r4473Add Language::truncate() method for truncating strings to a certain byte...vibber20:43, 1 August 2004

Status & tagging log