http://www.mediawiki.org/wiki/Special:Code/MediaWiki/91858

Revision: 91858
Author:   ashley
Date:     2011-07-11 04:06:18 +0000 (Mon, 11 Jul 2011)
Log Message:
-----------
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
    trunk/extensions/SocialProfile/UserStats/TopFansByStat.php

Modified: trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php   
2011-07-11 03:29:06 UTC (rev 91857)
+++ trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php   
2011-07-11 04:06:18 UTC (rev 91858)
@@ -568,6 +568,8 @@
         * table and set them in the appropriate class member variables.
         */
        private function setRelationships() {
+               global $wgLang;
+
                $dbr = wfGetDB( DB_SLAVE );
 
                $where = array();
@@ -617,10 +619,7 @@
                                $r_type = 'foe';
                        }
 
-                       $user_name_short = substr( $row->r_user_name, 0, 25 );
-                       if ( $row->r_user_name != $user_name_short ) {
-                               $user_name_short .= wfMsg( 'ellipsis' );
-                       }
+                       $user_name_short = $wgLang->truncate( 
$row->r_user_name, 25 );
 
                        
$this->items_grouped[$r_type][$row->r_user_name_relation]['users'][$row->r_user_name][]
 = array(
                                'id' => $row->r_id,
@@ -748,6 +747,8 @@
         * member variables.
         */
        private function setSystemMessages() {
+               global $wgLang;
+
                $dbr = wfGetDB( DB_SLAVE );
 
                $where = array();
@@ -791,10 +792,8 @@
 
                foreach ( $res as $row ) {
                        $user_title = Title::makeTitle( NS_USER, 
$row->um_user_name );
-                       $user_name_short = substr( $row->um_user_name, 0, 15 );
-                       if ( $row->um_user_name != $user_name_short ) {
-                               $user_name_short .= wfMsg( 'ellipsis' );
-                       }
+                       $user_name_short = $wgLang->truncate( 
$row->um_user_name, 15 );
+
                        $this->activityLines[] = array(
                                'type' => 'system_message',
                                'timestamp' => $row->item_date,
@@ -929,6 +928,8 @@
         * @param $has_page Boolean: true by default
         */
        function simplifyPageActivity( $type, $has_page = true ) {
+               global $wgLang;
+
                if ( !isset( $this->items_grouped[$type] ) || !is_array( 
$this->items_grouped[$type] ) ) {
                        return '';
                }
@@ -1026,10 +1027,7 @@
                                }
 
                                $user_title = Title::makeTitle( NS_USER, 
$user_name );
-                               $user_name_short = substr( $user_name, 0, 15 );
-                               if ( $user_name != $user_name_short ) {
-                                       $user_name_short .= wfMsg( 'ellipsis' );
-                               }
+                               $user_name_short = $wgLang->truncate( 
$user_name, 15 );
 
                                $users .= " <b><a 
href=\"{$user_title->escapeFullURL()}\">{$user_name_short}</a></b>";
                        }
@@ -1090,6 +1088,7 @@
         * @return String: "fixed" comment
         */
        function fixItemComment( $comment ) {
+               global $wgLang;
                if ( !$comment ) {
                        return '';
                } else {
@@ -1098,10 +1097,7 @@
                        $comment = str_replace( '&', '%26', $comment );
                        $comment = str_replace( '%26quot;', '"', $comment );
                }
-               $preview = substr( $comment, 0, 75 );
-               if ( $preview != $comment ) {
-                       $preview .= wfMsg( 'ellipsis' );
-               }
+               $preview = $wgLang->truncate( $comment, 75 );
                return stripslashes( $preview );
        }
 

Modified: trunk/extensions/SocialProfile/UserStats/TopFansByStat.php
===================================================================
--- trunk/extensions/SocialProfile/UserStats/TopFansByStat.php  2011-07-11 
03:29:06 UTC (rev 91857)
+++ trunk/extensions/SocialProfile/UserStats/TopFansByStat.php  2011-07-11 
04:06:18 UTC (rev 91858)
@@ -15,7 +15,7 @@
         * @param $par Mixed: parameter passed to the page or null
         */
        public function execute( $par ) {
-               global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUploadPath, 
$wgScriptPath;
+               global $wgRequest, $wgLang, $wgOut, $wgMemc, $wgUploadPath, 
$wgScriptPath;
                global $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly;
 
                // Load CSS
@@ -118,11 +118,7 @@
                $out .= '<div class="top-users">';
 
                foreach ( $user_list as $user ) {
-                       if ( $user['user_name'] == substr( $user['user_name'], 
0, 22 ) ) {
-                               $user_name = $user['user_name'];
-                       } else {
-                               $user_name = substr( $user['user_name'], 0, 22 
) . wfMsg( 'ellipsis' );
-                       }
+                       $user_name = $wgLang->truncate( $user['user_name'], 22 
);
                        $user_title = Title::makeTitle( NS_USER, 
$user['user_name'] );
                        $avatar = new wAvatar( $user['user_id'], 'm' );
                        $commentIcon = $avatar->getAvatarImage();


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to