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

Revision: 60531
Author:   ashley
Date:     2009-12-31 22:11:40 +0000 (Thu, 31 Dec 2009)

Log Message:
-----------
UserActivity:
*remove network-related stuff
*fix SiteActivityHook.php for PHP 5.3+
*fix bug in SiteActivityHook.php: when limit param was specified, the hook 
would return limit-1 results (i.e. limit=5, amount of returned results=4)
*a bunch of i18n fixes
*commented out some unused messages
*special pages cannot be edited, so don't show "Foo edited Main Page, 
Special:Log/delete"
*add __METHOD__ to SQL queries
*ignore nonexistent users in setMessagesSent()
*more braces
*bump version number from 1.0 to 1.1

Modified Paths:
--------------
    trunk/extensions/SocialProfile/UserActivity/SiteActivityHook.php
    trunk/extensions/SocialProfile/UserActivity/UserActivity.body.php
    trunk/extensions/SocialProfile/UserActivity/UserActivity.i18n.php
    trunk/extensions/SocialProfile/UserActivity/UserActivity.php
    trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php

Modified: trunk/extensions/SocialProfile/UserActivity/SiteActivityHook.php
===================================================================
--- trunk/extensions/SocialProfile/UserActivity/SiteActivityHook.php    
2009-12-31 21:58:46 UTC (rev 60530)
+++ trunk/extensions/SocialProfile/UserActivity/SiteActivityHook.php    
2009-12-31 22:11:40 UTC (rev 60531)
@@ -7,30 +7,36 @@
        die( "Not a valid entry point.\n" );
 }
 
-
 $wgHooks['ParserFirstCallInit'][] = 'wfSiteActivity';
+/**
+ * Register <siteactivity> hook with the Parser
+ * @param $parser Object: instance of Parser
+ * @return true
+ */
 function wfSiteActivity( &$parser ) {
        $parser->setHook( 'siteactivity', 'getSiteActivity' );
        return true;
 }
 
-function getSiteActivity( $input, $args, &$parser ) {
+function getSiteActivity( $input, $args, $parser ) {
        global $wgMemc, $wgScriptPath;
 
        $parser->disableCache();
 
        $limit = ( isset( $args['limit'] ) && is_numeric( $args['limit'] ) ) ? 
$args['limit'] : 10;
 
+       // so that <siteactivity limit=5 /> will return 5 items instead of 4...
+       $fixedLimit = $limit + 1;
+
        wfLoadExtensionMessages( 'UserActivity' );
 
-       $key = wfMemcKey( 'site_activity', 'all', $limit );
+       $key = wfMemcKey( 'site_activity', 'all', $fixedLimit );
        $data = $wgMemc->get( $key );
        if ( !$data ) {
                wfDebug( "Got site activity from DB\n" );
-               $rel = new UserActivity( '', 'ALL', $limit );
+               $rel = new UserActivity( '', 'ALL', $fixedLimit );
 
                $rel->setActivityToggle( 'show_votes', 0 );
-               $rel->setActivityToggle( 'show_network_updates', 0 );
                $activity = $rel->getActivityListGrouped();
                $wgMemc->set( $key, $activity, 60 * 2 );
        } else {
@@ -40,15 +46,17 @@
 
        $output = '';
        if ( $activity ) {
+               $output .= '<div class="mp-site-activity">
+                       <h2>' . wfMsg( 'useractivity-siteactivity' ) . '</h2>';
 
-               $output .= '<div class="mp-site-activity"><h2>' . wfMsg( 
'useractivity-siteactivity' ) . '</h2>';
-
                $x = 1;
                foreach ( $activity as $item ) {
-                       if ( $x < $limit ) {
-                               $output .= '<div class="mp-activity' . ( ( $x 
== $limit ) ? ' mp-activity-boarder-fix' : '' ) . '">
-                               <img src="' . $wgScriptPath . 
'/extensions/SocialProfile/images/' . UserActivity::getTypeIcon( $item['type'] 
) . '" alt="' . UserActivity::getTypeIcon( $item['type'] ) . '" border="0" />'
-                               . $item['data'] . '</div>';
+                       if ( $x < $fixedLimit ) {
+                               $typeIcon = UserActivity::getTypeIcon( 
$item['type'] );
+                               $output .= '<div class="mp-activity' . ( ( $x 
== $fixedLimit ) ? ' mp-activity-boarder-fix' : '' ) . '">
+                               <img src="' . $wgScriptPath . 
'/extensions/SocialProfile/images/' . $typeIcon . '" alt="' . $typeIcon . '" 
border="0" />'
+                               . $item['data'] .
+                               '</div>';
                                $x++;
                        }
                }

Modified: trunk/extensions/SocialProfile/UserActivity/UserActivity.body.php
===================================================================
--- trunk/extensions/SocialProfile/UserActivity/UserActivity.body.php   
2009-12-31 21:58:46 UTC (rev 60530)
+++ trunk/extensions/SocialProfile/UserActivity/UserActivity.body.php   
2009-12-31 22:11:40 UTC (rev 60531)
@@ -15,7 +15,7 @@
         * @param $par Mixed: parameter passed to the page or null
         */
        public function execute( $par ) {
-               global $wgUser, $wgOut, $wgRequest, $wgSitename, $wgScriptPath;
+               global $wgUser, $wgOut, $wgRequest, $wgScriptPath;
 
                wfLoadExtensionMessages( 'UserActivity' );
 
@@ -30,42 +30,60 @@
                $rel_type = $wgRequest->getVal( 'rel_type' );
                $item_type = $wgRequest->getVal( 'item_type' );
 
-               if ( !$rel_type ) $rel_type = 1;
-               if ( !$item_type ) $item_type = 'all';
+               if ( !$rel_type ) {
+                       $rel_type = 1;
+               }
+               if ( !$item_type ) {
+                       $item_type = 'all';
+               }
 
-               if ( $item_type == 'edits' || $item_type == 'all' ) $edits = 1;
-               if ( $item_type == 'votes' || $item_type == 'all' ) $votes = 0;
-               if ( $item_type == 'comments' || $item_type == 'all' ) 
$comments = 1;
-               if ( $item_type == 'gifts' || $item_type == 'all' ) $gifts = 1;
-               if ( $item_type == 'relationships' || $item_type == 'all' ) 
$relationships = 1;
-               if ( $item_type == 'advancements' || $item_type == 'all' ) 
$messages = 1;
-               if ( $item_type == 'awards' || $item_type == 'all' ) 
$system_gifts = 1;
-               if ( $item_type == 'messages' || $item_type == 'all' ) 
$messages_sent = 1;
-               if ( $item_type == 'thoughts' || $item_type == 'all' ) 
$network_updates = 1;
+               if ( $item_type == 'edits' || $item_type == 'all' ) {
+                       $edits = 1;
+               }
+               if ( $item_type == 'votes' || $item_type == 'all' ) {
+                       $votes = 0;
+               }
+               if ( $item_type == 'comments' || $item_type == 'all' ) {
+                       $comments = 1;
+               }
+               if ( $item_type == 'gifts' || $item_type == 'all' ) {
+                       $gifts = 1;
+               }
+               if ( $item_type == 'relationships' || $item_type == 'all' ) {
+                       $relationships = 1;
+               }
+               if ( $item_type == 'advancements' || $item_type == 'all' ) {
+                       $messages = 1;
+               }
+               if ( $item_type == 'awards' || $item_type == 'all' ) {
+                       $system_gifts = 1;
+               }
+               if ( $item_type == 'messages' || $item_type == 'all' ) {
+                       $messages_sent = 1;
+               }
 
                /*
                $output .= '<div class="user-home-links-container">
-               <h2>' . wfMsg('useractivity-filter') . '</h2>
+               <h2>' . wfMsg( 'useractivity-filter' ) . '</h2>
                <div class="user-home-links">';
 
                $lines = explode( "\n", wfMsgForContent( 'useractivity-filter' 
) );
                foreach( $lines as $line ) {
-
-                       if( strpos($line, '*') !== 0 ){
+                       if( strpos( $line, '*' ) !== 0 ) {
                                continue;
                        } else {
-                               $line = explode( '|' , trim($line, '* '), 3 );
+                               $line = explode( '|' , trim( $line, '* ' ), 3 );
                                $filter = $line[0];
                                $link_text = $line[1];
                                $link_image = $line[2];
-                               $output .= "<a href=\"" . 
$this_title->escapeFullURL("item_type={$filter}") . "\">
-                                       <img 
src=\"{$wgScriptPath}/extensions/SocialProfile/images/" . 
UserActivity::getTypeIcon($link_image) . "\"/>{$link_text}
+                               $output .= '<a href="' . 
$this_title->escapeFullURL( "item_type={$filter}" ) . "\">
+                                       <img 
src=\"{$wgScriptPath}/extensions/SocialProfile/images/" . 
UserActivity::getTypeIcon( $link_image ) . "\"/>
+                                       {$link_text}
                                </a>";
                        }
-
                }
 
-                       $output .= '<a href="' . $this_title->escapeFullURL() . 
'">' . wfMsg( 'useractivity-all' ) . '</a>
+               $output .= '<a href="' . $this_title->escapeFullURL() . '">' . 
wfMsg( 'useractivity-all' ) . '</a>
                        </div>
                 </div>
                */
@@ -82,11 +100,6 @@
                $rel->setActivityToggle( 'show_system_gifts', $system_gifts );
                $rel->setActivityToggle( 'show_messages_sent', $messages_sent );
 
-               // An extra toggle for ArmchairGM
-               if ( $wgSitename == 'ArmchairGM' ) {
-                       $rel->setActivityToggle( 'show_network_updates', 
$network_updates );
-               }
-
                /**
                 * Get all relationship activity
                 */
@@ -97,15 +110,17 @@
                        $x = 1;
 
                        foreach ( $activity as $item ) {
-
                                if ( $x < 40 ) {
-
-                                       if ( ( ( count( $activity ) > 40 ) && ( 
$x == 39 ) ) || ( ( count( $activity ) < 40 ) && ( $x == ( count( $activity ) - 
1 ) ) ) ) {
+                                       if (
+                                               ( ( count( $activity ) > 40 ) 
&& ( $x == 39 ) ) ||
+                                               ( ( count( $activity ) < 40 ) 
&& ( $x == ( count( $activity ) - 1 ) ) )
+                                       ) {
                                                $border_fix = ' border-fix';
                                        }
 
+                                       $typeIcon = UserActivity::getTypeIcon( 
$item['type'] );
                                        $output .= "<div 
class=\"user-home-activity{$border_fix}\">
-                                               <img 
src=\"{$wgScriptPath}/extensions/SocialProfile/images/" . 
UserActivity::getTypeIcon( $item['type'] ) . "\" alt=\"\" border=\"0\" />
+                                               <img 
src=\"{$wgScriptPath}/extensions/SocialProfile/images/" . $typeIcon . "\" 
alt=\"\" border=\"0\" />
                                                {$item["data"]}
                                        </div>";
                                        $x++;

Modified: trunk/extensions/SocialProfile/UserActivity/UserActivity.i18n.php
===================================================================
--- trunk/extensions/SocialProfile/UserActivity/UserActivity.i18n.php   
2009-12-31 21:58:46 UTC (rev 60530)
+++ trunk/extensions/SocialProfile/UserActivity/UserActivity.i18n.php   
2009-12-31 22:11:40 UTC (rev 60531)
@@ -14,25 +14,24 @@
  */
 $messages['en'] = array(
        'useractivity' => "Friends' activity",
-       'useractivity-award' => 'received an award', // FIXME: message lego
+       'useractivity-award' => '$1 received an award',
        'useractivity-all' => 'View all',
-       'useractivity-gift' => 'received a gift from', // FIXME: message logo
-       'useractivity-group-edit' => 'edits', // CHECKME: message lego (as well 
as the messages below)?
-       'useractivity-group-comment' => 'comments',
-       'useractivity-group-user_message' => 'messages',
-       'useractivity-group-friend' => 'friends',
-       'useractivity-filter' => 'Filter',
-       'useractivity-network-thought' => 'has a thought for the $1 network', 
// FIXME: message lego
-       'useractivity-title' => "Friends' activity",
+       #'useractivity-comment' => '{{PLURAL:$1|commented on the page|commented 
on the following pages: }}',
+       #'useractivity-commentedpage' => 'commented on the page',
+       'useractivity-edit' => '$1 {{PLURAL:$4|edited the page|edited the 
following pages:}} $3',
+       'useractivity-foe' => '$1 {{PLURAL:$2|is now foes with|are now foes 
with}} $3',
+       'useractivity-friend' => '$1 {{PLURAL:$2|is now friends with|are now 
friends with}} $3',
+       'useractivity-gift' => '$1 received a gift from $2',
+       #'useractivity-gift-sent' => 'sent a gift to',
+       'useractivity-group-edit' => '{{PLURAL:$1|one edit|$1 edits}}',
+       'useractivity-group-comment' => '{{PLURAL:$1|one comment|$1 comments}}',
+       'useractivity-group-user_message' => '{{PLURAL:$1|one message|$1 
messages}}',
+       'useractivity-group-friend' => '{{PLURAL:$1|one friend|$1 friends}}',
+       #'useractivity-filter' => 'Filter',
        'useractivity-siteactivity' => 'Site activity',
-       'useractivity-edit' => '{{PLURAL:$1|edited the page|edited the 
following pages: }}', // CHECKME: message lego?
-       'useractivity-comment' => '{{PLURAL:$1|commented on the page|commented 
on the following pages: }}', // CHECKME: message lego?
-       'useractivity-user_message' => '{{PLURAL:$1|sent a message to|sent 
messages to}}',
-       'useractivity-votedpage' => 'voted for the page', // FIXME: message lego
-       'useractivity-commentedpage' => 'commented on the page', // FIXME: 
message lego
-       'useractivity-giftsent' => 'sent a gift to', // FIXME: message lego
-       'useractivity-friend' => '{{PLURAL:$2|is now friends with|are now 
friends with}}', // FIXME: message lego
-       'useractivity-foe' => '{{PLURAL:$2|is now foes with|are now foes 
with}}', // FIXME: message lego
+       'useractivity-title' => "Friends' activity",
+       'useractivity-user_message' => '$1 {{PLURAL:$4|sent a message to|sent 
messages to}} $3',
+       #'useractivity-votedpage' => 'voted for the page',
 );
 
 /** Finnish (Suomi)
@@ -40,21 +39,21 @@
  */
 $messages['fi'] = array(
        'useractivity' => 'Ystävien aktiivisuus',
-       'useractivity-award' => 'sai palkinnon',
+       'useractivity-award' => '$1 sai palkinnon',
        'useractivity-all' => 'Katso kaikki',
-       'useractivity-gift' => 'sai lahjan käyttäjältä',
-       'useractivity-group-edit' => 'muokkausta',
-       'useractivity-group-comment' => 'kommenttia',
-       'useractivity-group-user_message' => 'viestiä',
-       'useractivity-group-friend' => 'ystävät',
-       'useractivity-title' => 'Ystävien aktiivisuus',
+       #'useractivity-comment' => '{{PLURAL:$1|kommentoi sivua|kommentoi 
seuraavia sivuja: }}',
+       #'useractivity-commentedpage' => 'kommentoi sivua',
+       'useractivity-edit' => '$1 {{PLURAL:$2|muokkasi|muokkasivat}} 
{{PLURAL:$4|sivua|seuraavia sivuja:}} $3',
+       'useractivity-foe' => '$1 {{PLURAL:$2|on nyt vihollinen 
käyttäjälle|ovat nyt vihollisia käyttäjille}} $3',
+       'useractivity-friend' => '$1 {{PLURAL:$2|on nyt ystävä käyttäjälle|ovat 
nyt ystäviä käyttäjille}} $3',
+       'useractivity-gift' => '$1 sai lahjan käyttäjältä $2',
+       #'useractivity-gift-sent' => 'lähetti lahjan käyttäjälle',
+       'useractivity-group-edit' => '{{PLURAL:$1|yksi muokkaus|$1 
muokkausta}}',
+       'useractivity-group-comment' => '{{PLURAL:$1|yksi kommentti|$1 
kommenttia}}',
+       'useractivity-group-user_message' => '{{PLURAL:$1|yksi viesti|$1 
viestiä}}',
+       'useractivity-group-friend' => '{{PLURAL:$1|yksi ystävä|$1 ystävät}}',
        'useractivity-siteactivity' => 'Sivuston aktiivisuus',
-       'useractivity-edit' => '{{PLURAL:$2|muokkasi|muokkasivat}} 
{{PLURAL:$1|sivua|seuraavia sivuja: }}',
-       'useractivity-comment' => '{{PLURAL:$1|kommentoi sivua|kommentoi 
seuraavia sivuja: }}',
-       'useractivity-user_message' => '{{PLURAL:$1|lähetti viestin 
käyttäjälle|lähetti viestejä käyttäjille}}',
-       'useractivity-votedpage' => 'äänesti sivua',
-       'useractivity-commentedpage' => 'kommentoi sivua',
-       'useractivity-giftsent' => 'lähetti lahjan käyttäjälle',
-       'useractivity-friend' => '{{PLURAL:$2|on nyt ystävä käyttäjälle|ovat 
nyt ystäviä käyttäjille}}',
-       'useractivity-foe' => '{{PLURAL:$2|on nyt vihollinen käyttäjälle|ovat 
nyt vihollisia käyttäjille}}',
+       'useractivity-title' => 'Ystävien aktiivisuus',
+       'useractivity-user_message' => '$1 {{PLURAL:$4|lähetti viestin 
käyttäjälle|lähetti viestejä käyttäjille}} $3',
+       #'useractivity-votedpage' => 'äänesti sivua',
 );

Modified: trunk/extensions/SocialProfile/UserActivity/UserActivity.php
===================================================================
--- trunk/extensions/SocialProfile/UserActivity/UserActivity.php        
2009-12-31 21:58:46 UTC (rev 60530)
+++ trunk/extensions/SocialProfile/UserActivity/UserActivity.php        
2009-12-31 22:11:40 UTC (rev 60531)
@@ -4,7 +4,7 @@
  *
  * @file
  * @ingroup Extensions
- * @version 1.0
+ * @version 1.1
  * @author Aaron Wright <aaron.wri...@gmail.com>
  * @author David Pean <david.p...@gmail.com>
  * @author Jack Phoenix <j...@countervandalism.net>
@@ -22,9 +22,9 @@
 // Extension credits that will show up on Special:Version
 $wgExtensionCredits['specialpage'][] = array(
        'name' => 'UserActivity',
-       'version' => '1.0',
+       'version' => '1.1',
+       'author' => array( 'Aaron Wright', 'David Pean', 'Jack Phoenix' ),
        'description' => "Shows users' social activity",
-       'author' => array( 'Aaron Wright', 'David Pean', 'Jack Phoenix' ),
        'url' => 'http://www.mediawiki.org/wiki/Extension:SocialProfile'
 );
 

Modified: trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php   
2009-12-31 21:58:46 UTC (rev 60530)
+++ trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php   
2009-12-31 22:11:40 UTC (rev 60531)
@@ -26,13 +26,11 @@
        var $show_system_gifts = 1;
        var $show_system_messages = 1;
        var $show_messages_sent = 1;
-       var $show_network_updates = 0;
 
        /**
         * Constructor
-        * @private
         */
-       /* private */ function __construct( $username, $filter, $item_max ) {
+       public function __construct( $username, $filter, $item_max ) {
                if ( $username ) {
                        $title1 = Title::newFromDBkey( $username );
                        $this->user_name = $title1->getText();
@@ -46,10 +44,18 @@
        }
 
        private function setFilter( $filter ) {
-               if ( strtoupper( $filter ) == 'USER' ) $this->show_current_user 
= true;
-               if ( strtoupper( $filter ) == 'FRIENDS' ) $this->rel_type = 1;
-               if ( strtoupper( $filter ) == 'FOES' ) $this->rel_type = 2;
-               if ( strtoupper( $filter ) == 'ALL' ) $this->show_all = true;
+               if ( strtoupper( $filter ) == 'USER' ) {
+                       $this->show_current_user = true;
+               }
+               if ( strtoupper( $filter ) == 'FRIENDS' ) {
+                       $this->rel_type = 1;
+               }
+               if ( strtoupper( $filter ) == 'FOES' ) {
+                       $this->rel_type = 2;
+               }
+               if ( strtoupper( $filter ) == 'ALL' ) {
+                       $this->show_all = true;
+               }
        }
 
        public function setActivityToggle( $name, $value ) {
@@ -69,14 +75,19 @@
                        $user_sql = " WHERE rc_user = {$this->user_id}";
                }
 
-               $sql = "SELECT UNIX_TIMESTAMP(rc_timestamp) AS item_date, 
rc_title, rc_user, rc_user_text, rc_comment, rc_id, rc_minor, rc_new,
+               $sql = "SELECT UNIX_TIMESTAMP(rc_timestamp) AS item_date, 
rc_title,
+                               rc_user, rc_user_text, rc_comment, rc_id, 
rc_minor, rc_new,
                                rc_namespace, rc_cur_id, rc_this_oldid, 
rc_last_oldid
                        FROM {$dbr->tableName( 'recentchanges' )}
                        {$rel_sql} {$user_sql}
                        ORDER BY rc_id DESC LIMIT 0," . $this->item_max;
-               $res = $dbr->query( $sql );
+               $res = $dbr->query( $sql, __METHOD__ );
 
                while ( $row = $dbr->fetchObject( $res ) ) {
+                       // Special pages aren't editable, so ignore 'em
+                       if ( $row->rc_namespace == NS_SPECIAL ) {
+                               continue;
+                       }
                        $title = Title::makeTitle( $row->rc_namespace, 
$row->rc_title );
                        
$this->items_grouped['edit'][$title->getPrefixedText()]['users'][$row->rc_user_text][]
 = array(
                                'id' => 0,
@@ -93,7 +104,6 @@
 
                        // set last timestamp
                        
$this->items_grouped['edit'][$title->getPrefixedText()]['timestamp'] = 
$row->item_date;
-                       // 
$this->items['edits'][$title->getPrefixedText()]['displayed'] = 0;
 
                        $this->items[] = array(
                                'id' => 0,
@@ -120,17 +130,21 @@
 
                $rel_sql = '';
                $user_sql = '';
-               if ( $this->rel_type )
+               if ( $this->rel_type ) {
                        $rel_sql = " AND vote_user_id IN (SELECT 
r_user_id_relation FROM {$dbr->tableName( 'user_relationship' )} WHERE 
r_user_id={$this->user_id} AND r_type={$this->rel_type}) ";
-               if ( $this->show_current_user )
+               }
+               if ( $this->show_current_user ) {
                        $user_sql = " AND vote_user_id = {$this->user_id}";
+               }
 
-               $sql = "SELECT UNIX_TIMESTAMP(vote_date) AS item_date, 
username, page_title, vote_count, comment_count, vote_ip, vote_user_id
+               $sql = "SELECT UNIX_TIMESTAMP(vote_date) AS item_date, username,
+                                       page_title, vote_count, comment_count, 
vote_ip,
+                                       vote_user_id
                        FROM {$dbr->tableName( 'Vote' )} v, {$dbr->tableName( 
'page' )} p
                        WHERE v.vote_page_id=p.page_id
                        {$rel_sql} {$user_sql}
                        ORDER BY vote_date DESC LIMIT 0," . $this->item_max;
-               $res = $dbr->query( $sql );
+               $res = $dbr->query( $sql, __METHOD__ );
                while ( $row = $dbr->fetchObject( $res ) ) {
                        $username = $row->username;
                        $this->items[] = array(
@@ -167,17 +181,19 @@
                        $user_sql = "AND Comment_user_id = {$this->user_id}";
                }
 
-               $sql = "SELECT UNIX_TIMESTAMP(comment_date) AS item_date, 
Comment_Username, Comment_IP, page_title, Comment_Text, Comment_user_id, 
page_namespace, CommentID
+               $sql = "SELECT UNIX_TIMESTAMP(comment_date) AS item_date,
+                                       Comment_Username, Comment_IP, 
page_title, Comment_Text,
+                                       Comment_user_id, page_namespace, 
CommentID
                        FROM {$dbr->tableName( 'Comments' )} c, 
{$dbr->tableName( 'page' )} p
                        WHERE c.comment_page_id=p.page_id
                        {$rel_sql} {$user_sql}
                        ORDER BY comment_date DESC LIMIT 0," . $this->item_max;
 
-               $res = $dbr->query( $sql );
-               global $wgFilterComments;
+               $res = $dbr->query( $sql, __METHOD__ );
                while ( $row = $dbr->fetchObject( $res ) ) {
                        $show_comment = true;
 
+                       global $wgFilterComments;
                        if ( $wgFilterComments ) {
                                if ( $row->vote_count <= 4 ) {
                                        $show_comment = false;
@@ -224,16 +240,21 @@
                $rel_sql = '';
                $user_sql = '';
 
-               if( $this->rel_type )
+               if( $this->rel_type ) {
                        $rel_sql = "WHERE ug_user_id_to IN (SELECT 
r_user_id_relation FROM {$dbr->tableName( 'user_relationship' )} WHERE 
r_user_id={$this->user_id} AND r_type={$this->rel_type})";
-               if( $this->show_current_user )
+               }
+               if( $this->show_current_user ) {
                        $user_sql = "WHERE ug_user_id_from = {$this->user_id}";
+               }
 
-               $sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from, 
ug_user_id_to, ug_user_name_to, UNIX_TIMESTAMP(ug_date) AS item_date,gift_name, 
gift_id
-                       FROM {$dbr->tableName( 'user_gift' )} INNER JOIN 
{$dbr->tableName( 'gift' )} ON gift_id = ug_gift_id
+               $sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from,
+                                       ug_user_id_to, ug_user_name_to,
+                                       UNIX_TIMESTAMP(ug_date) AS item_date, 
gift_name, gift_id
+                       FROM {$dbr->tableName( 'user_gift' )}
+                       INNER JOIN {$dbr->tableName( 'gift' )} ON gift_id = 
ug_gift_id
                        {$rel_sql} {$user_sql}
                        ORDER BY ug_id DESC LIMIT 0,{$this->item_max}";
-               $res = $dbr->query( $sql );
+               $res = $dbr->query( $sql, __METHOD__ );
                while ( $row = $dbr->fetchObject( $res ) ) {
                        $this->items[] = array(
                                'id' => $row->ug_id,
@@ -263,11 +284,14 @@
                        $user_sql = "WHERE ug_user_id_to = {$this->user_id}";
                }
 
-               $sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from, 
ug_user_id_to, ug_user_name_to, UNIX_TIMESTAMP(ug_date) AS item_date,gift_name, 
gift_id
-                       FROM {$dbr->tableName( 'user_gift' )} INNER JOIN 
{$dbr->tableName( 'gift' )} ON gift_id = ug_gift_id
+               $sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from,
+                                       ug_user_id_to, ug_user_name_to,
+                                       UNIX_TIMESTAMP(ug_date) AS item_date, 
gift_name, gift_id
+                       FROM {$dbr->tableName( 'user_gift' )}
+                       INNER JOIN {$dbr->tableName( 'gift' )} ON gift_id = 
ug_gift_id
                        {$rel_sql} {$user_sql}
                        ORDER BY ug_id DESC LIMIT 0,{$this->item_max}";
-               $res = $dbr->query( $sql );
+               $res = $dbr->query( $sql, __METHOD__ );
                while ( $row = $dbr->fetchObject( $res ) ) {
                        global $wgUploadPath;
                        $user_title = Title::makeTitle( NS_USER, 
$row->ug_user_name_to );
@@ -276,8 +300,11 @@
                        $gift_image = '<img src="' . $wgUploadPath . '/awards/' 
. Gifts::getGiftImage( $row->gift_id, 'm' ) . '" border="0" alt="" />';
                        $view_gift_link = SpecialPage::getTitleFor( 'ViewGift' 
);
 
-                       $html = wfMsg( 'useractivity-gift' ) . ' ' .   "<a 
href=\"{$user_title_from->escapeFullURL()}\" 
rel=\"nofollow\">{$user_title_from->getText()}</a>
-                       <div class=\"item\">
+                       $html = wfMsg( 'useractivity-gift',
+                               "<b><a 
href=\"{$user_title->escapeFullURL()}\">{$row->ug_user_name_to}</a></b>",
+                               "<a 
href=\"{$user_title_from->escapeFullURL()}\">{$user_title_from->getText()}</a>"
+                       ) .
+                       "<div class=\"item\">
                                <a href=\"" . $view_gift_link->escapeFullURL( 
'gift_id=' . $row->ug_id ) . "\" rel=\"nofollow\">
                                        {$gift_image}
                                        {$row->gift_name}
@@ -287,7 +314,7 @@
                        $this->activityLines[] = array(
                                'type' => 'gift-rec',
                                'timestamp' => $row->item_date,
-                               'data' => "<b><a 
href=\"{$user_title->escapeFullURL()}\">{$row->ug_user_name_to}</a></b> {$html}"
+                               'data' => ' ' . $html
                        );
 
                        $this->items[] = array(
@@ -318,20 +345,22 @@
                        $user_sql = "WHERE sg_user_id = {$this->user_id}";
                }
 
-               $sql = "SELECT sg_id, sg_user_id, sg_user_name, 
UNIX_TIMESTAMP(sg_date) AS item_date,gift_name, gift_id
-                       FROM {$dbr->tableName( 'user_system_gift' )} INNER JOIN 
{$dbr->tableName( 'system_gift' )} ON gift_id = sg_gift_id
+               $sql = "SELECT sg_id, sg_user_id, sg_user_name,
+                                       UNIX_TIMESTAMP(sg_date) AS item_date, 
gift_name, gift_id
+                       FROM {$dbr->tableName( 'user_system_gift' )}
+                       INNER JOIN {$dbr->tableName( 'system_gift' )} ON 
gift_id = sg_gift_id
                        {$rel_sql} {$user_sql}
                        ORDER BY sg_id DESC LIMIT 0,{$this->item_max}";
-               $res = $dbr->query( $sql );
+               $res = $dbr->query( $sql, __METHOD__ );
                while ( $row = $dbr->fetchObject( $res ) ) {
                        global $wgUploadPath;
                        $user_title = Title::makeTitle( NS_USER, 
$row->sg_user_name );
                        $system_gift_image = '<img src="' . $wgUploadPath . 
'/awards/' . SystemGifts::getGiftImage( $row->gift_id, 'm' ) . '" border="0" 
alt="" />';
                        $system_gift_link = SpecialPage::getTitleFor( 
'ViewSystemGift' );
 
-                       $html = wfMsg( 'useractivity-award' ) . "
-                       <div class=\"item\">
-                               <a href=\"" . $system_gift_link->escapeFullURL( 
'gift_id=' . $row->sg_id ) . "\" rel=\"nofollow\">
+                       $html = wfMsg( 'useractivity-award', "<b><a 
href=\"{$user_title->escapeFullURL()}\">{$row->sg_user_name}</a></b>" ) .
+                       '<div class="item">
+                               <a href="' . $system_gift_link->escapeFullURL( 
'gift_id=' . $row->sg_id ) . "\" rel=\"nofollow\">
                                        {$system_gift_image}
                                        {$row->gift_name}
                                </a>
@@ -340,7 +369,7 @@
                        $this->activityLines[] = array(
                                'type' => 'system_gift',
                                'timestamp' => $row->item_date,
-                               'data' => "<b><a 
href=\"{$user_title->escapeFullURL()}\">{$row->sg_user_name}</a></b> {$html}"
+                               'data' => ' ' . $html
                        );
 
                        $this->items[] = array(
@@ -374,7 +403,7 @@
                        FROM {$dbr->tableName( 'user_relationship' )}
                        {$rel_sql} {$user_sql}
                        ORDER BY r_id DESC LIMIT 0,{$this->item_max}";
-               $res = $dbr->query( $sql );
+               $res = $dbr->query( $sql, __METHOD__ );
 
                while ( $row = $dbr->fetchObject( $res ) ) {
                        if ( $row->r_type == 1 ) {
@@ -384,10 +413,10 @@
                        }
 
                        $user_name_short = substr( $row->r_user_name, 0, 25 );
-                       if ( $row->r_user_name != $user_name_short )
+                       if ( $row->r_user_name != $user_name_short ) {
                                $user_name_short .= '...';
+                       }
 
-                       // $title = Title::makeTitle( $row->page_namespace, 
$row->page_title );
                        
$this->items_grouped[$r_type][$row->r_user_name_relation]['users'][$row->r_user_name][]
 = array(
                                'id' => $row->r_id,
                                'type' => $r_type,
@@ -432,13 +461,20 @@
                        $user_sql = " ub_user_id_from = {$this->user_id} AND";
                }
 
-               $sql = "SELECT ub_id, ub_user_id, ub_user_name, 
ub_user_id_from, ub_user_name_from, UNIX_TIMESTAMP(ub_date) AS item_date, 
ub_message
+               $sql = "SELECT ub_id, ub_user_id, ub_user_name, ub_user_id_from,
+                               ub_user_name_from, UNIX_TIMESTAMP(ub_date) AS 
item_date,
+                               ub_message
                        FROM {$dbr->tableName( 'user_board' )} WHERE
                        {$rel_sql} {$user_sql}  ub_type=0
                        ORDER BY ub_id DESC LIMIT 0,{$this->item_max}";
 
-               $res = $dbr->query( $sql );
+               $res = $dbr->query( $sql, __METHOD__ );
                while ( $row = $dbr->fetchObject( $res ) ) {
+                       // Ignore nonexistent (for example, renamed) users
+                       $uid = User::idFromName( $row->ub_user_name );
+                       if ( !$uid ) {
+                               continue;
+                       }
 
                        $this->items_grouped['user_message'][stripslashes( 
$row->ub_user_name )]['users'][stripslashes( $row->ub_user_name_from )][] = 
array(
                                'id' => $row->ub_id,
@@ -488,16 +524,17 @@
                        FROM {$dbr->tableName( 'user_system_messages' )}
                        {$rel_sql} {$user_sql}
                        ORDER BY um_id DESC LIMIT 0,{$this->item_max}";
-               $res = $dbr->query( $sql );
+               $res = $dbr->query( $sql, __METHOD__ );
                while ( $row = $dbr->fetchObject( $res ) ) {
                        $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 )
+                       if ( $row->um_user_name != $user_name_short ) {
                                $user_name_short .= '...';
+                       }
                        $this->activityLines[] = array(
                                'type' => 'system_message',
                                'timestamp' => $row->item_date,
-                               'data' => "<b><a 
href=\"{$user_title->escapeFullURL()}\">{$user_name_short}</a></b> 
{$row->um_message}"
+                               'data' => ' ' . "<b><a 
href=\"{$user_title->escapeFullURL()}\">{$user_name_short}</a></b> 
{$row->um_message}"
                        );
 
                        $this->items[] = array(
@@ -515,67 +552,6 @@
                }
        }
 
-       /**
-        * Retrieves sport network updates from the database (for ArmchairGM)
-        */
-       private function setNetworkUpdates() {
-               $dbr = wfGetDB( DB_SLAVE );
-               if ( $this->rel_type )
-                       $rel_sql = " WHERE us_user_id IN (SELECT 
r_user_id_relation FROM {$dbr->tableName( 'user_relationship' )} WHERE 
r_user_id={$this->user_id} AND r_type={$this->rel_type} )";
-               if ( $this->show_current_user )
-                       $user_sql = " WHERE us_user_id = {$this->user_id}";
-               $sql = "SELECT us_id, us_user_id, us_user_name, us_text, 
UNIX_TIMESTAMP(us_date) AS item_date,
-                       us_sport_id, us_team_id
-                       FROM {$dbr->tableName( 'user_status' )}
-                       {$rel_sql} {$user_sql}
-                       ORDER BY us_id DESC LIMIT 0,{$this->item_max}";
-               $res = $dbr->query( $sql );
-               while ( $row = $dbr->fetchObject( $res ) ) {
-                       if ( $row->us_team_id ) {
-                               $team = SportsTeams::getTeam( $row->us_team_id 
);
-                               $network_name = $team['name'];
-                       } else {
-                               $sport = SportsTeams::getSport( 
$row->us_sport_id );
-                               $network_name = $sport['name'];
-                       }
-                       $this->items[] = array(
-                               'id' => $row->us_id,
-                               'type' => 'network_update',
-                               'timestamp' => $row->item_date,
-                               'pagetitle' => '',
-                               'namespace' => '',
-                               'username' => $row->us_user_name,
-                               'userid' => $row->us_user_id,
-                               'comment' => $row->us_text,
-                               'sport_id' => $row->us_sport_id,
-                               'team_id' => $row->us_team_id,
-                               'network' => $network_name
-                       );
-
-                       $user_title = Title::makeTitle( NS_USER, 
$row->us_user_name );
-                       $user_name_short = substr( $row->us_user_name, 0, 15 );
-                       if ( $row->us_user_name != $user_name_short )
-                               $user_name_short .= '...';
-                       $page_link = '<a href="' . SportsTeams::getNetworkURL( 
$row->us_sport_id, $row->us_team_id ) . "\" 
rel=\"nofollow\">{$network_name}</a> ";
-                       $network_image = SportsTeams::getLogo( 
$row->us_sport_id, $row->us_team_id, 's' );
-
-                       $html = wfMsg( 'useractivity-network-thought', 
$page_link ) . '
-                                       <div class="item">
-                                               <a href="' . 
SportsTeams::getNetworkURL( $row->us_sport_id, $row->us_team_id ) . "\" 
rel=\"nofollow\">
-                                                       {$network_image}
-                                                       \"{$row->us_text}\"
-                                               </a>
-                                       </div>";
-
-                       $this->activityLines[] = array(
-                               'type' => 'network_update',
-                               'timestamp' => $row->item_date,
-                               'data' => "<b><a 
href=\"{$user_title->escapeFullURL()}\">{$user_name_short}</a></b> {$html}"
-                       );
-
-               }
-       }
-
        public function getEdits() {
                $this->setEdits();
                return $this->items;
@@ -621,43 +597,66 @@
                return $this->items;
        }
 
-       public function getNetworkUpdates() {
-               $this->setNetworkUpdates();
-               return $this->items;
-       }
-
        public function getActivityList() {
-               if ( $this->show_edits ) $this->setEdits();
-               if ( $this->show_votes ) $this->setVotes();
-               if ( $this->show_comments ) $this->setComments();
-               if ( $this->show_gifts_sent ) $this->setGiftsSent();
-               if ( $this->show_gifts_rec ) $this->setGiftsRec();
-               if ( $this->show_relationships ) $this->setRelationships();
-               if ( $this->show_system_messages ) $this->getSystemMessages();
-               if ( $this->show_system_gifts ) $this->getSystemGiftsRec();
-               if ( $this->show_messages_sent ) $this->getMessagesSent();
-               if ( $this->show_network_updates ) $this->getNetworkUpdates();
+               if ( $this->show_edits ) {
+                       $this->setEdits();
+               }
+               if ( $this->show_votes ) {
+                       $this->setVotes();
+               }
+               if ( $this->show_comments ) {
+                       $this->setComments();
+               }
+               if ( $this->show_gifts_sent ) {
+                       $this->setGiftsSent();
+               }
+               if ( $this->show_gifts_rec ) {
+                       $this->setGiftsRec();
+               }
+               if ( $this->show_relationships ) {
+                       $this->setRelationships();
+               }
+               if ( $this->show_system_messages ) {
+                       $this->getSystemMessages();
+               }
+               if ( $this->show_system_gifts ) {
+                       $this->getSystemGiftsRec();
+               }
+               if ( $this->show_messages_sent ) {
+                       $this->getMessagesSent();
+               }
 
-               if ( $this->items )
+               if ( $this->items ) {
                        usort( $this->items, array( 'UserActivity', 'sortItems' 
) );
+               }
                return $this->items;
        }
 
        public function getActivityListGrouped() {
                $this->getActivityList();
 
-               if ( $this->show_edits ) $this->simplifyPageActivity( 'edit' );
-               if ( $this->show_comments ) $this->simplifyPageActivity( 
'comment' );
-               if ( $this->show_relationships ) $this->simplifyPageActivity( 
'friend' );
-               if ( $this->show_relationships ) $this->simplifyPageActivity( 
'foe' );
-               if ( $this->show_messages_sent ) $this->simplifyPageActivity( 
'user_message' );
-               // if( $this->show_system_messages ) 
$this->simplifyPageActivity( 'system_messages', false );
+               if ( $this->show_edits ) {
+                       $this->simplifyPageActivity( 'edit' );
+               }
+               if ( $this->show_comments ) {
+                       $this->simplifyPageActivity( 'comment' );
+               }
+               if ( $this->show_relationships ) {
+                       $this->simplifyPageActivity( 'friend' );
+               }
+               if ( $this->show_relationships ) {
+                       $this->simplifyPageActivity( 'foe' );
+               }
+               if ( $this->show_messages_sent ) {
+                       $this->simplifyPageActivity( 'user_message' );
+               }
 
                if ( !isset( $this->activityLines ) ) {
                        $this->activityLines = array();
                }
-               if ( isset( $this->activityLines ) && is_array( 
$this->activityLines ) )
+               if ( isset( $this->activityLines ) && is_array( 
$this->activityLines ) ) {
                        usort( $this->activityLines, array( 'UserActivity', 
'sortItems' ) );
+               }
                return $this->activityLines;
        }
 
@@ -689,12 +688,11 @@
                                $count_actions = count( $action );
 
                                if ( $has_page && !isset( 
$this->displayed[$type][$page_name] ) ) {
+                                       $this->displayed[$type][$page_name] = 1;
 
-                                       $this->displayed[ $type ][ $page_name ] 
= 1;
-
                                        $pages .= " <a 
href=\"{$page_title->escapeFullURL()}\">{$page_name}</a>";
                                        if ( $count_users == 1 && 
$count_actions > 1 ) {
-                                               $pages .= " ($count_actions " . 
wfMsg( "useractivity-group-{$type}" ) . ")";
+                                               $pages .= ' (' . wfMsgExt( 
"useractivity-group-{$type}", 'parsemag', $count_actions ) . ')';
                                        }
                                        $pages_count++;
                                }
@@ -703,25 +701,31 @@
                                // see if we can stack any other singles
                                if ( $count_users == 1 ) {
                                        foreach ( $this->items_grouped[$type] 
as $page_name2 => $page_data2 ) {
-
-                                               if ( !isset( 
$this->displayed[$type][$page_name2] ) && count( $page_data2['users'] ) == 1  ) 
{
-
+                                               if ( !isset( 
$this->displayed[$type][$page_name2] ) &&
+                                                       count( 
$page_data2['users'] ) == 1
+                                               ) {
                                                        foreach ( 
$page_data2['users'] as $user_name2 => $action2 ) {
-
                                                                if ( 
$user_name2 == $user_name && $pages_count < 5 ) {
                                                                        
$count_actions2 = count( $action2 );
 
-                                                                       if ( 
$type == 'friend' || $type == 'foe' || $type == 'user_message' ) {
+                                                                       if (
+                                                                               
$type == 'friend' ||
+                                                                               
$type == 'foe' ||
+                                                                               
$type == 'user_message'
+                                                                       ) {
                                                                                
$page_title2 = Title::newFromText( 'User:' . $page_name2 );
                                                                        } else {
                                                                                
$page_title2 = Title::newFromText( $page_name2 );
                                                                        }
 
-                                                                       if ( 
$pages )
-                                                                               
$pages .= ", ";
-                                                                       $pages 
.= ( ( $page_title2 instanceOf Title ) ? " <a 
href=\"{$page_title2->escapeFullURL()}\">{$page_name2}</a>" : '' );
+                                                                       if ( 
$pages ) {
+                                                                               
$pages .= ', ';
+                                                                       }
+                                                                       if ( 
$page_title2 instanceof Title ) {
+                                                                               
$pages .= " <a href=\"{$page_title2->escapeFullURL()}\">{$page_name2}</a>";
+                                                                       }
                                                                        if ( 
$count_actions2 > 1 ) {
-                                                                               
$pages .= " ($count_actions2 " . wfMsg( "useractivity-group-{$type}" ) . ")";
+                                                                               
$pages .= ' (' . wfMsg( "useractivity-group-{$type}", $count_actions2 ) . ')';
                                                                        }
                                                                        
$pages_count++;
 
@@ -734,15 +738,18 @@
 
                                $user_index++;
 
-                               if ( $users && $count_users > 2 )
+                               if ( $users && $count_users > 2 ) {
                                        $users .= ', ';
-                               if ( $user_index ==  $count_users && 
$count_users > 1 )
+                               }
+                               if ( $user_index ==  $count_users && 
$count_users > 1 ) {
                                        $users .= wfMsg( 'and' );
+                               }
 
                                $user_title = Title::makeTitle( NS_USER, 
$user_name );
                                $user_name_short = substr( $user_name, 0, 15 );
-                               if ( $user_name != $user_name_short )
+                               if ( $user_name != $user_name_short ) {
                                        $user_name_short .= '...';
+                               }
 
                                $users .= " <b><a 
href=\"{$user_title->escapeFullURL()}\">{$user_name_short}</a></b>";
                        }
@@ -750,7 +757,10 @@
                                $this->activityLines[] = array(
                                        'type' => $type,
                                        'timestamp' => $page_data['timestamp'],
-                                       'data' => $users . ' ' . wfMsgExt( 
"useractivity-{$type}", 'parsemag', $pages_count, $count_users ) . $pages
+                                       'data' => wfMsgExt(
+                                               "useractivity-{$type}", 
'parsemag',
+                                               $users, $count_users, $pages, 
$pages_count
+                                       )
                                );
                        }
                }
@@ -772,18 +782,12 @@
                                return 'addedFriendIcon.png';
                        case 'foe':
                                return 'addedFoeIcon.png';
-                       case 'challenge_sent':
-                               return 'challengeIcon.png';
-                       case 'challenge_rec':
-                               return 'challengeIcon.png';
                        case 'system_message':
                                return 'challengeIcon.png';
                        case 'system_gift':
                                return 'awardIcon.png';
                        case 'user_message':
                                return 'emailIcon.gif';
-                       case 'network_update':
-                               return 'note.gif';
                }
        }
 
@@ -791,10 +795,10 @@
                if ( !$comment ) {
                        return '';
                } else {
-                       $comment = str_replace( "<", "&lt;", $comment );
-                       $comment = str_replace( ">", "&gt;", $comment );
-                       $comment = str_replace( "&", "%26", $comment );
-                       $comment = str_replace( "%26quot;", "\"", $comment );
+                       $comment = str_replace( '<', '&lt;', $comment );
+                       $comment = str_replace( '>', '&gt;', $comment );
+                       $comment = str_replace( '&', '%26', $comment );
+                       $comment = str_replace( '%26quot;', "\"", $comment );
                }
                $preview = substr( $comment, 0, 75 );
                if ( $preview != $comment ) {
@@ -803,10 +807,10 @@
                return stripslashes( $preview );
        }
 
-       private static function sortItems( $x, $y ){
-               if( $x['timestamp'] == $y['timestamp'] ){
+       private static function sortItems( $x, $y ) {
+               if( $x['timestamp'] == $y['timestamp'] ) {
                        return 0;
-               } else if ( $x['timestamp'] > $y['timestamp'] ) {
+               } elseif ( $x['timestamp'] > $y['timestamp'] ) {
                        return - 1;
                } else {
                        return 1;



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

Reply via email to