r60531 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60530‎ | r60531 | r60532 >
Date:22:11, 31 December 2009
Author:ashley
Status:deferred
Tags:
Comment:
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 (modified) (history)
  • /trunk/extensions/SocialProfile/UserActivity/UserActivity.body.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserActivity/UserActivity.i18n.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserActivity/UserActivity.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserActivity/UserActivity.i18n.php
@@ -14,25 +14,24 @@
1515 */
1616 $messages['en'] = array(
1717 'useractivity' => "Friends' activity",
18 - 'useractivity-award' => 'received an award', // FIXME: message lego
 18+ 'useractivity-award' => '$1 received an award',
1919 'useractivity-all' => 'View all',
20 - 'useractivity-gift' => 'received a gift from', // FIXME: message logo
21 - 'useractivity-group-edit' => 'edits', // CHECKME: message lego (as well as the messages below)?
22 - 'useractivity-group-comment' => 'comments',
23 - 'useractivity-group-user_message' => 'messages',
24 - 'useractivity-group-friend' => 'friends',
25 - 'useractivity-filter' => 'Filter',
26 - 'useractivity-network-thought' => 'has a thought for the $1 network', // FIXME: message lego
27 - 'useractivity-title' => "Friends' activity",
 20+ #'useractivity-comment' => '{{PLURAL:$1|commented on the page|commented on the following pages: }}',
 21+ #'useractivity-commentedpage' => 'commented on the page',
 22+ 'useractivity-edit' => '$1 {{PLURAL:$4|edited the page|edited the following pages:}} $3',
 23+ 'useractivity-foe' => '$1 {{PLURAL:$2|is now foes with|are now foes with}} $3',
 24+ 'useractivity-friend' => '$1 {{PLURAL:$2|is now friends with|are now friends with}} $3',
 25+ 'useractivity-gift' => '$1 received a gift from $2',
 26+ #'useractivity-gift-sent' => 'sent a gift to',
 27+ 'useractivity-group-edit' => '{{PLURAL:$1|one edit|$1 edits}}',
 28+ 'useractivity-group-comment' => '{{PLURAL:$1|one comment|$1 comments}}',
 29+ 'useractivity-group-user_message' => '{{PLURAL:$1|one message|$1 messages}}',
 30+ 'useractivity-group-friend' => '{{PLURAL:$1|one friend|$1 friends}}',
 31+ #'useractivity-filter' => 'Filter',
2832 'useractivity-siteactivity' => 'Site activity',
29 - 'useractivity-edit' => '{{PLURAL:$1|edited the page|edited the following pages: }}', // CHECKME: message lego?
30 - 'useractivity-comment' => '{{PLURAL:$1|commented on the page|commented on the following pages: }}', // CHECKME: message lego?
31 - 'useractivity-user_message' => '{{PLURAL:$1|sent a message to|sent messages to}}',
32 - 'useractivity-votedpage' => 'voted for the page', // FIXME: message lego
33 - 'useractivity-commentedpage' => 'commented on the page', // FIXME: message lego
34 - 'useractivity-giftsent' => 'sent a gift to', // FIXME: message lego
35 - 'useractivity-friend' => '{{PLURAL:$2|is now friends with|are now friends with}}', // FIXME: message lego
36 - 'useractivity-foe' => '{{PLURAL:$2|is now foes with|are now foes with}}', // FIXME: message lego
 33+ 'useractivity-title' => "Friends' activity",
 34+ 'useractivity-user_message' => '$1 {{PLURAL:$4|sent a message to|sent messages to}} $3',
 35+ #'useractivity-votedpage' => 'voted for the page',
3736 );
3837
3938 /** Finnish (Suomi)
@@ -40,21 +39,21 @@
4140 */
4241 $messages['fi'] = array(
4342 'useractivity' => 'Ystävien aktiivisuus',
44 - 'useractivity-award' => 'sai palkinnon',
 43+ 'useractivity-award' => '$1 sai palkinnon',
4544 'useractivity-all' => 'Katso kaikki',
46 - 'useractivity-gift' => 'sai lahjan käyttäjältä',
47 - 'useractivity-group-edit' => 'muokkausta',
48 - 'useractivity-group-comment' => 'kommenttia',
49 - 'useractivity-group-user_message' => 'viestiä',
50 - 'useractivity-group-friend' => 'ystävät',
51 - 'useractivity-title' => 'Ystävien aktiivisuus',
 45+ #'useractivity-comment' => '{{PLURAL:$1|kommentoi sivua|kommentoi seuraavia sivuja: }}',
 46+ #'useractivity-commentedpage' => 'kommentoi sivua',
 47+ 'useractivity-edit' => '$1 {{PLURAL:$2|muokkasi|muokkasivat}} {{PLURAL:$4|sivua|seuraavia sivuja:}} $3',
 48+ 'useractivity-foe' => '$1 {{PLURAL:$2|on nyt vihollinen käyttäjälle|ovat nyt vihollisia käyttäjille}} $3',
 49+ 'useractivity-friend' => '$1 {{PLURAL:$2|on nyt ystävä käyttäjälle|ovat nyt ystäviä käyttäjille}} $3',
 50+ 'useractivity-gift' => '$1 sai lahjan käyttäjältä $2',
 51+ #'useractivity-gift-sent' => 'lähetti lahjan käyttäjälle',
 52+ 'useractivity-group-edit' => '{{PLURAL:$1|yksi muokkaus|$1 muokkausta}}',
 53+ 'useractivity-group-comment' => '{{PLURAL:$1|yksi kommentti|$1 kommenttia}}',
 54+ 'useractivity-group-user_message' => '{{PLURAL:$1|yksi viesti|$1 viestiä}}',
 55+ 'useractivity-group-friend' => '{{PLURAL:$1|yksi ystävä|$1 ystävät}}',
5256 'useractivity-siteactivity' => 'Sivuston aktiivisuus',
53 - 'useractivity-edit' => '{{PLURAL:$2|muokkasi|muokkasivat}} {{PLURAL:$1|sivua|seuraavia sivuja: }}',
54 - 'useractivity-comment' => '{{PLURAL:$1|kommentoi sivua|kommentoi seuraavia sivuja: }}',
55 - 'useractivity-user_message' => '{{PLURAL:$1|lähetti viestin käyttäjälle|lähetti viestejä käyttäjille}}',
56 - 'useractivity-votedpage' => 'äänesti sivua',
57 - 'useractivity-commentedpage' => 'kommentoi sivua',
58 - 'useractivity-giftsent' => 'lähetti lahjan käyttäjälle',
59 - 'useractivity-friend' => '{{PLURAL:$2|on nyt ystävä käyttäjälle|ovat nyt ystäviä käyttäjille}}',
60 - 'useractivity-foe' => '{{PLURAL:$2|on nyt vihollinen käyttäjälle|ovat nyt vihollisia käyttäjille}}',
 57+ 'useractivity-title' => 'Ystävien aktiivisuus',
 58+ 'useractivity-user_message' => '$1 {{PLURAL:$4|lähetti viestin käyttäjälle|lähetti viestejä käyttäjille}} $3',
 59+ #'useractivity-votedpage' => 'äänesti sivua',
6160 );
Index: trunk/extensions/SocialProfile/UserActivity/UserActivity.php
@@ -4,7 +4,7 @@
55 *
66 * @file
77 * @ingroup Extensions
8 - * @version 1.0
 8+ * @version 1.1
99 * @author Aaron Wright <aaron.wright@gmail.com>
1010 * @author David Pean <david.pean@gmail.com>
1111 * @author Jack Phoenix <jack@countervandalism.net>
@@ -22,9 +22,9 @@
2323 // Extension credits that will show up on Special:Version
2424 $wgExtensionCredits['specialpage'][] = array(
2525 'name' => 'UserActivity',
26 - 'version' => '1.0',
 26+ 'version' => '1.1',
 27+ 'author' => array( 'Aaron Wright', 'David Pean', 'Jack Phoenix' ),
2728 'description' => "Shows users' social activity",
28 - 'author' => array( 'Aaron Wright', 'David Pean', 'Jack Phoenix' ),
2929 'url' => 'http://www.mediawiki.org/wiki/Extension:SocialProfile'
3030 );
3131
Index: trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php
@@ -26,13 +26,11 @@
2727 var $show_system_gifts = 1;
2828 var $show_system_messages = 1;
2929 var $show_messages_sent = 1;
30 - var $show_network_updates = 0;
3130
3231 /**
3332 * Constructor
34 - * @private
3533 */
36 - /* private */ function __construct( $username, $filter, $item_max ) {
 34+ public function __construct( $username, $filter, $item_max ) {
3735 if ( $username ) {
3836 $title1 = Title::newFromDBkey( $username );
3937 $this->user_name = $title1->getText();
@@ -46,10 +44,18 @@
4745 }
4846
4947 private function setFilter( $filter ) {
50 - if ( strtoupper( $filter ) == 'USER' ) $this->show_current_user = true;
51 - if ( strtoupper( $filter ) == 'FRIENDS' ) $this->rel_type = 1;
52 - if ( strtoupper( $filter ) == 'FOES' ) $this->rel_type = 2;
53 - if ( strtoupper( $filter ) == 'ALL' ) $this->show_all = true;
 48+ if ( strtoupper( $filter ) == 'USER' ) {
 49+ $this->show_current_user = true;
 50+ }
 51+ if ( strtoupper( $filter ) == 'FRIENDS' ) {
 52+ $this->rel_type = 1;
 53+ }
 54+ if ( strtoupper( $filter ) == 'FOES' ) {
 55+ $this->rel_type = 2;
 56+ }
 57+ if ( strtoupper( $filter ) == 'ALL' ) {
 58+ $this->show_all = true;
 59+ }
5460 }
5561
5662 public function setActivityToggle( $name, $value ) {
@@ -69,14 +75,19 @@
7076 $user_sql = " WHERE rc_user = {$this->user_id}";
7177 }
7278
73 - $sql = "SELECT UNIX_TIMESTAMP(rc_timestamp) AS item_date, rc_title, rc_user, rc_user_text, rc_comment, rc_id, rc_minor, rc_new,
 79+ $sql = "SELECT UNIX_TIMESTAMP(rc_timestamp) AS item_date, rc_title,
 80+ rc_user, rc_user_text, rc_comment, rc_id, rc_minor, rc_new,
7481 rc_namespace, rc_cur_id, rc_this_oldid, rc_last_oldid
7582 FROM {$dbr->tableName( 'recentchanges' )}
7683 {$rel_sql} {$user_sql}
7784 ORDER BY rc_id DESC LIMIT 0," . $this->item_max;
78 - $res = $dbr->query( $sql );
 85+ $res = $dbr->query( $sql, __METHOD__ );
7986
8087 while ( $row = $dbr->fetchObject( $res ) ) {
 88+ // Special pages aren't editable, so ignore 'em
 89+ if ( $row->rc_namespace == NS_SPECIAL ) {
 90+ continue;
 91+ }
8192 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
8293 $this->items_grouped['edit'][$title->getPrefixedText()]['users'][$row->rc_user_text][] = array(
8394 'id' => 0,
@@ -93,7 +104,6 @@
94105
95106 // set last timestamp
96107 $this->items_grouped['edit'][$title->getPrefixedText()]['timestamp'] = $row->item_date;
97 - // $this->items['edits'][$title->getPrefixedText()]['displayed'] = 0;
98108
99109 $this->items[] = array(
100110 'id' => 0,
@@ -120,17 +130,21 @@
121131
122132 $rel_sql = '';
123133 $user_sql = '';
124 - if ( $this->rel_type )
 134+ if ( $this->rel_type ) {
125135 $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}) ";
126 - if ( $this->show_current_user )
 136+ }
 137+ if ( $this->show_current_user ) {
127138 $user_sql = " AND vote_user_id = {$this->user_id}";
 139+ }
128140
129 - $sql = "SELECT UNIX_TIMESTAMP(vote_date) AS item_date, username, page_title, vote_count, comment_count, vote_ip, vote_user_id
 141+ $sql = "SELECT UNIX_TIMESTAMP(vote_date) AS item_date, username,
 142+ page_title, vote_count, comment_count, vote_ip,
 143+ vote_user_id
130144 FROM {$dbr->tableName( 'Vote' )} v, {$dbr->tableName( 'page' )} p
131145 WHERE v.vote_page_id=p.page_id
132146 {$rel_sql} {$user_sql}
133147 ORDER BY vote_date DESC LIMIT 0," . $this->item_max;
134 - $res = $dbr->query( $sql );
 148+ $res = $dbr->query( $sql, __METHOD__ );
135149 while ( $row = $dbr->fetchObject( $res ) ) {
136150 $username = $row->username;
137151 $this->items[] = array(
@@ -167,17 +181,19 @@
168182 $user_sql = "AND Comment_user_id = {$this->user_id}";
169183 }
170184
171 - $sql = "SELECT UNIX_TIMESTAMP(comment_date) AS item_date, Comment_Username, Comment_IP, page_title, Comment_Text, Comment_user_id, page_namespace, CommentID
 185+ $sql = "SELECT UNIX_TIMESTAMP(comment_date) AS item_date,
 186+ Comment_Username, Comment_IP, page_title, Comment_Text,
 187+ Comment_user_id, page_namespace, CommentID
172188 FROM {$dbr->tableName( 'Comments' )} c, {$dbr->tableName( 'page' )} p
173189 WHERE c.comment_page_id=p.page_id
174190 {$rel_sql} {$user_sql}
175191 ORDER BY comment_date DESC LIMIT 0," . $this->item_max;
176192
177 - $res = $dbr->query( $sql );
178 - global $wgFilterComments;
 193+ $res = $dbr->query( $sql, __METHOD__ );
179194 while ( $row = $dbr->fetchObject( $res ) ) {
180195 $show_comment = true;
181196
 197+ global $wgFilterComments;
182198 if ( $wgFilterComments ) {
183199 if ( $row->vote_count <= 4 ) {
184200 $show_comment = false;
@@ -224,16 +240,21 @@
225241 $rel_sql = '';
226242 $user_sql = '';
227243
228 - if( $this->rel_type )
 244+ if( $this->rel_type ) {
229245 $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})";
230 - if( $this->show_current_user )
 246+ }
 247+ if( $this->show_current_user ) {
231248 $user_sql = "WHERE ug_user_id_from = {$this->user_id}";
 249+ }
232250
233 - $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
234 - FROM {$dbr->tableName( 'user_gift' )} INNER JOIN {$dbr->tableName( 'gift' )} ON gift_id = ug_gift_id
 251+ $sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from,
 252+ ug_user_id_to, ug_user_name_to,
 253+ UNIX_TIMESTAMP(ug_date) AS item_date, gift_name, gift_id
 254+ FROM {$dbr->tableName( 'user_gift' )}
 255+ INNER JOIN {$dbr->tableName( 'gift' )} ON gift_id = ug_gift_id
235256 {$rel_sql} {$user_sql}
236257 ORDER BY ug_id DESC LIMIT 0,{$this->item_max}";
237 - $res = $dbr->query( $sql );
 258+ $res = $dbr->query( $sql, __METHOD__ );
238259 while ( $row = $dbr->fetchObject( $res ) ) {
239260 $this->items[] = array(
240261 'id' => $row->ug_id,
@@ -263,11 +284,14 @@
264285 $user_sql = "WHERE ug_user_id_to = {$this->user_id}";
265286 }
266287
267 - $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
268 - FROM {$dbr->tableName( 'user_gift' )} INNER JOIN {$dbr->tableName( 'gift' )} ON gift_id = ug_gift_id
 288+ $sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from,
 289+ ug_user_id_to, ug_user_name_to,
 290+ UNIX_TIMESTAMP(ug_date) AS item_date, gift_name, gift_id
 291+ FROM {$dbr->tableName( 'user_gift' )}
 292+ INNER JOIN {$dbr->tableName( 'gift' )} ON gift_id = ug_gift_id
269293 {$rel_sql} {$user_sql}
270294 ORDER BY ug_id DESC LIMIT 0,{$this->item_max}";
271 - $res = $dbr->query( $sql );
 295+ $res = $dbr->query( $sql, __METHOD__ );
272296 while ( $row = $dbr->fetchObject( $res ) ) {
273297 global $wgUploadPath;
274298 $user_title = Title::makeTitle( NS_USER, $row->ug_user_name_to );
@@ -276,8 +300,11 @@
277301 $gift_image = '<img src="' . $wgUploadPath . '/awards/' . Gifts::getGiftImage( $row->gift_id, 'm' ) . '" border="0" alt="" />';
278302 $view_gift_link = SpecialPage::getTitleFor( 'ViewGift' );
279303
280 - $html = wfMsg( 'useractivity-gift' ) . ' ' . "<a href=\"{$user_title_from->escapeFullURL()}\" rel=\"nofollow\">{$user_title_from->getText()}</a>
281 - <div class=\"item\">
 304+ $html = wfMsg( 'useractivity-gift',
 305+ "<b><a href=\"{$user_title->escapeFullURL()}\">{$row->ug_user_name_to}</a></b>",
 306+ "<a href=\"{$user_title_from->escapeFullURL()}\">{$user_title_from->getText()}</a>"
 307+ ) .
 308+ "<div class=\"item\">
282309 <a href=\"" . $view_gift_link->escapeFullURL( 'gift_id=' . $row->ug_id ) . "\" rel=\"nofollow\">
283310 {$gift_image}
284311 {$row->gift_name}
@@ -287,7 +314,7 @@
288315 $this->activityLines[] = array(
289316 'type' => 'gift-rec',
290317 'timestamp' => $row->item_date,
291 - 'data' => "<b><a href=\"{$user_title->escapeFullURL()}\">{$row->ug_user_name_to}</a></b> {$html}"
 318+ 'data' => ' ' . $html
292319 );
293320
294321 $this->items[] = array(
@@ -318,20 +345,22 @@
319346 $user_sql = "WHERE sg_user_id = {$this->user_id}";
320347 }
321348
322 - $sql = "SELECT sg_id, sg_user_id, sg_user_name, UNIX_TIMESTAMP(sg_date) AS item_date,gift_name, gift_id
323 - FROM {$dbr->tableName( 'user_system_gift' )} INNER JOIN {$dbr->tableName( 'system_gift' )} ON gift_id = sg_gift_id
 349+ $sql = "SELECT sg_id, sg_user_id, sg_user_name,
 350+ UNIX_TIMESTAMP(sg_date) AS item_date, gift_name, gift_id
 351+ FROM {$dbr->tableName( 'user_system_gift' )}
 352+ INNER JOIN {$dbr->tableName( 'system_gift' )} ON gift_id = sg_gift_id
324353 {$rel_sql} {$user_sql}
325354 ORDER BY sg_id DESC LIMIT 0,{$this->item_max}";
326 - $res = $dbr->query( $sql );
 355+ $res = $dbr->query( $sql, __METHOD__ );
327356 while ( $row = $dbr->fetchObject( $res ) ) {
328357 global $wgUploadPath;
329358 $user_title = Title::makeTitle( NS_USER, $row->sg_user_name );
330359 $system_gift_image = '<img src="' . $wgUploadPath . '/awards/' . SystemGifts::getGiftImage( $row->gift_id, 'm' ) . '" border="0" alt="" />';
331360 $system_gift_link = SpecialPage::getTitleFor( 'ViewSystemGift' );
332361
333 - $html = wfMsg( 'useractivity-award' ) . "
334 - <div class=\"item\">
335 - <a href=\"" . $system_gift_link->escapeFullURL( 'gift_id=' . $row->sg_id ) . "\" rel=\"nofollow\">
 362+ $html = wfMsg( 'useractivity-award', "<b><a href=\"{$user_title->escapeFullURL()}\">{$row->sg_user_name}</a></b>" ) .
 363+ '<div class="item">
 364+ <a href="' . $system_gift_link->escapeFullURL( 'gift_id=' . $row->sg_id ) . "\" rel=\"nofollow\">
336365 {$system_gift_image}
337366 {$row->gift_name}
338367 </a>
@@ -340,7 +369,7 @@
341370 $this->activityLines[] = array(
342371 'type' => 'system_gift',
343372 'timestamp' => $row->item_date,
344 - 'data' => "<b><a href=\"{$user_title->escapeFullURL()}\">{$row->sg_user_name}</a></b> {$html}"
 373+ 'data' => ' ' . $html
345374 );
346375
347376 $this->items[] = array(
@@ -374,7 +403,7 @@
375404 FROM {$dbr->tableName( 'user_relationship' )}
376405 {$rel_sql} {$user_sql}
377406 ORDER BY r_id DESC LIMIT 0,{$this->item_max}";
378 - $res = $dbr->query( $sql );
 407+ $res = $dbr->query( $sql, __METHOD__ );
379408
380409 while ( $row = $dbr->fetchObject( $res ) ) {
381410 if ( $row->r_type == 1 ) {
@@ -384,10 +413,10 @@
385414 }
386415
387416 $user_name_short = substr( $row->r_user_name, 0, 25 );
388 - if ( $row->r_user_name != $user_name_short )
 417+ if ( $row->r_user_name != $user_name_short ) {
389418 $user_name_short .= '...';
 419+ }
390420
391 - // $title = Title::makeTitle( $row->page_namespace, $row->page_title );
392421 $this->items_grouped[$r_type][$row->r_user_name_relation]['users'][$row->r_user_name][] = array(
393422 'id' => $row->r_id,
394423 'type' => $r_type,
@@ -432,13 +461,20 @@
433462 $user_sql = " ub_user_id_from = {$this->user_id} AND";
434463 }
435464
436 - $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
 465+ $sql = "SELECT ub_id, ub_user_id, ub_user_name, ub_user_id_from,
 466+ ub_user_name_from, UNIX_TIMESTAMP(ub_date) AS item_date,
 467+ ub_message
437468 FROM {$dbr->tableName( 'user_board' )} WHERE
438469 {$rel_sql} {$user_sql} ub_type=0
439470 ORDER BY ub_id DESC LIMIT 0,{$this->item_max}";
440471
441 - $res = $dbr->query( $sql );
 472+ $res = $dbr->query( $sql, __METHOD__ );
442473 while ( $row = $dbr->fetchObject( $res ) ) {
 474+ // Ignore nonexistent (for example, renamed) users
 475+ $uid = User::idFromName( $row->ub_user_name );
 476+ if ( !$uid ) {
 477+ continue;
 478+ }
443479
444480 $this->items_grouped['user_message'][stripslashes( $row->ub_user_name )]['users'][stripslashes( $row->ub_user_name_from )][] = array(
445481 'id' => $row->ub_id,
@@ -488,16 +524,17 @@
489525 FROM {$dbr->tableName( 'user_system_messages' )}
490526 {$rel_sql} {$user_sql}
491527 ORDER BY um_id DESC LIMIT 0,{$this->item_max}";
492 - $res = $dbr->query( $sql );
 528+ $res = $dbr->query( $sql, __METHOD__ );
493529 while ( $row = $dbr->fetchObject( $res ) ) {
494530 $user_title = Title::makeTitle( NS_USER, $row->um_user_name );
495531 $user_name_short = substr( $row->um_user_name, 0, 15 );
496 - if ( $row->um_user_name != $user_name_short )
 532+ if ( $row->um_user_name != $user_name_short ) {
497533 $user_name_short .= '...';
 534+ }
498535 $this->activityLines[] = array(
499536 'type' => 'system_message',
500537 'timestamp' => $row->item_date,
501 - 'data' => "<b><a href=\"{$user_title->escapeFullURL()}\">{$user_name_short}</a></b> {$row->um_message}"
 538+ 'data' => ' ' . "<b><a href=\"{$user_title->escapeFullURL()}\">{$user_name_short}</a></b> {$row->um_message}"
502539 );
503540
504541 $this->items[] = array(
@@ -515,67 +552,6 @@
516553 }
517554 }
518555
519 - /**
520 - * Retrieves sport network updates from the database (for ArmchairGM)
521 - */
522 - private function setNetworkUpdates() {
523 - $dbr = wfGetDB( DB_SLAVE );
524 - if ( $this->rel_type )
525 - $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} )";
526 - if ( $this->show_current_user )
527 - $user_sql = " WHERE us_user_id = {$this->user_id}";
528 - $sql = "SELECT us_id, us_user_id, us_user_name, us_text, UNIX_TIMESTAMP(us_date) AS item_date,
529 - us_sport_id, us_team_id
530 - FROM {$dbr->tableName( 'user_status' )}
531 - {$rel_sql} {$user_sql}
532 - ORDER BY us_id DESC LIMIT 0,{$this->item_max}";
533 - $res = $dbr->query( $sql );
534 - while ( $row = $dbr->fetchObject( $res ) ) {
535 - if ( $row->us_team_id ) {
536 - $team = SportsTeams::getTeam( $row->us_team_id );
537 - $network_name = $team['name'];
538 - } else {
539 - $sport = SportsTeams::getSport( $row->us_sport_id );
540 - $network_name = $sport['name'];
541 - }
542 - $this->items[] = array(
543 - 'id' => $row->us_id,
544 - 'type' => 'network_update',
545 - 'timestamp' => $row->item_date,
546 - 'pagetitle' => '',
547 - 'namespace' => '',
548 - 'username' => $row->us_user_name,
549 - 'userid' => $row->us_user_id,
550 - 'comment' => $row->us_text,
551 - 'sport_id' => $row->us_sport_id,
552 - 'team_id' => $row->us_team_id,
553 - 'network' => $network_name
554 - );
555 -
556 - $user_title = Title::makeTitle( NS_USER, $row->us_user_name );
557 - $user_name_short = substr( $row->us_user_name, 0, 15 );
558 - if ( $row->us_user_name != $user_name_short )
559 - $user_name_short .= '...';
560 - $page_link = '<a href="' . SportsTeams::getNetworkURL( $row->us_sport_id, $row->us_team_id ) . "\" rel=\"nofollow\">{$network_name}</a> ";
561 - $network_image = SportsTeams::getLogo( $row->us_sport_id, $row->us_team_id, 's' );
562 -
563 - $html = wfMsg( 'useractivity-network-thought', $page_link ) . '
564 - <div class="item">
565 - <a href="' . SportsTeams::getNetworkURL( $row->us_sport_id, $row->us_team_id ) . "\" rel=\"nofollow\">
566 - {$network_image}
567 - \"{$row->us_text}\"
568 - </a>
569 - </div>";
570 -
571 - $this->activityLines[] = array(
572 - 'type' => 'network_update',
573 - 'timestamp' => $row->item_date,
574 - 'data' => "<b><a href=\"{$user_title->escapeFullURL()}\">{$user_name_short}</a></b> {$html}"
575 - );
576 -
577 - }
578 - }
579 -
580556 public function getEdits() {
581557 $this->setEdits();
582558 return $this->items;
@@ -621,43 +597,66 @@
622598 return $this->items;
623599 }
624600
625 - public function getNetworkUpdates() {
626 - $this->setNetworkUpdates();
627 - return $this->items;
628 - }
629 -
630601 public function getActivityList() {
631 - if ( $this->show_edits ) $this->setEdits();
632 - if ( $this->show_votes ) $this->setVotes();
633 - if ( $this->show_comments ) $this->setComments();
634 - if ( $this->show_gifts_sent ) $this->setGiftsSent();
635 - if ( $this->show_gifts_rec ) $this->setGiftsRec();
636 - if ( $this->show_relationships ) $this->setRelationships();
637 - if ( $this->show_system_messages ) $this->getSystemMessages();
638 - if ( $this->show_system_gifts ) $this->getSystemGiftsRec();
639 - if ( $this->show_messages_sent ) $this->getMessagesSent();
640 - if ( $this->show_network_updates ) $this->getNetworkUpdates();
 602+ if ( $this->show_edits ) {
 603+ $this->setEdits();
 604+ }
 605+ if ( $this->show_votes ) {
 606+ $this->setVotes();
 607+ }
 608+ if ( $this->show_comments ) {
 609+ $this->setComments();
 610+ }
 611+ if ( $this->show_gifts_sent ) {
 612+ $this->setGiftsSent();
 613+ }
 614+ if ( $this->show_gifts_rec ) {
 615+ $this->setGiftsRec();
 616+ }
 617+ if ( $this->show_relationships ) {
 618+ $this->setRelationships();
 619+ }
 620+ if ( $this->show_system_messages ) {
 621+ $this->getSystemMessages();
 622+ }
 623+ if ( $this->show_system_gifts ) {
 624+ $this->getSystemGiftsRec();
 625+ }
 626+ if ( $this->show_messages_sent ) {
 627+ $this->getMessagesSent();
 628+ }
641629
642 - if ( $this->items )
 630+ if ( $this->items ) {
643631 usort( $this->items, array( 'UserActivity', 'sortItems' ) );
 632+ }
644633 return $this->items;
645634 }
646635
647636 public function getActivityListGrouped() {
648637 $this->getActivityList();
649638
650 - if ( $this->show_edits ) $this->simplifyPageActivity( 'edit' );
651 - if ( $this->show_comments ) $this->simplifyPageActivity( 'comment' );
652 - if ( $this->show_relationships ) $this->simplifyPageActivity( 'friend' );
653 - if ( $this->show_relationships ) $this->simplifyPageActivity( 'foe' );
654 - if ( $this->show_messages_sent ) $this->simplifyPageActivity( 'user_message' );
655 - // if( $this->show_system_messages ) $this->simplifyPageActivity( 'system_messages', false );
 639+ if ( $this->show_edits ) {
 640+ $this->simplifyPageActivity( 'edit' );
 641+ }
 642+ if ( $this->show_comments ) {
 643+ $this->simplifyPageActivity( 'comment' );
 644+ }
 645+ if ( $this->show_relationships ) {
 646+ $this->simplifyPageActivity( 'friend' );
 647+ }
 648+ if ( $this->show_relationships ) {
 649+ $this->simplifyPageActivity( 'foe' );
 650+ }
 651+ if ( $this->show_messages_sent ) {
 652+ $this->simplifyPageActivity( 'user_message' );
 653+ }
656654
657655 if ( !isset( $this->activityLines ) ) {
658656 $this->activityLines = array();
659657 }
660 - if ( isset( $this->activityLines ) && is_array( $this->activityLines ) )
 658+ if ( isset( $this->activityLines ) && is_array( $this->activityLines ) ) {
661659 usort( $this->activityLines, array( 'UserActivity', 'sortItems' ) );
 660+ }
662661 return $this->activityLines;
663662 }
664663
@@ -689,12 +688,11 @@
690689 $count_actions = count( $action );
691690
692691 if ( $has_page && !isset( $this->displayed[$type][$page_name] ) ) {
 692+ $this->displayed[$type][$page_name] = 1;
693693
694 - $this->displayed[ $type ][ $page_name ] = 1;
695 -
696694 $pages .= " <a href=\"{$page_title->escapeFullURL()}\">{$page_name}</a>";
697695 if ( $count_users == 1 && $count_actions > 1 ) {
698 - $pages .= " ($count_actions " . wfMsg( "useractivity-group-{$type}" ) . ")";
 696+ $pages .= ' (' . wfMsgExt( "useractivity-group-{$type}", 'parsemag', $count_actions ) . ')';
699697 }
700698 $pages_count++;
701699 }
@@ -703,25 +701,31 @@
704702 // see if we can stack any other singles
705703 if ( $count_users == 1 ) {
706704 foreach ( $this->items_grouped[$type] as $page_name2 => $page_data2 ) {
707 -
708 - if ( !isset( $this->displayed[$type][$page_name2] ) && count( $page_data2['users'] ) == 1 ) {
709 -
 705+ if ( !isset( $this->displayed[$type][$page_name2] ) &&
 706+ count( $page_data2['users'] ) == 1
 707+ ) {
710708 foreach ( $page_data2['users'] as $user_name2 => $action2 ) {
711 -
712709 if ( $user_name2 == $user_name && $pages_count < 5 ) {
713710 $count_actions2 = count( $action2 );
714711
715 - if ( $type == 'friend' || $type == 'foe' || $type == 'user_message' ) {
 712+ if (
 713+ $type == 'friend' ||
 714+ $type == 'foe' ||
 715+ $type == 'user_message'
 716+ ) {
716717 $page_title2 = Title::newFromText( 'User:' . $page_name2 );
717718 } else {
718719 $page_title2 = Title::newFromText( $page_name2 );
719720 }
720721
721 - if ( $pages )
722 - $pages .= ", ";
723 - $pages .= ( ( $page_title2 instanceOf Title ) ? " <a href=\"{$page_title2->escapeFullURL()}\">{$page_name2}</a>" : '' );
 722+ if ( $pages ) {
 723+ $pages .= ', ';
 724+ }
 725+ if ( $page_title2 instanceof Title ) {
 726+ $pages .= " <a href=\"{$page_title2->escapeFullURL()}\">{$page_name2}</a>";
 727+ }
724728 if ( $count_actions2 > 1 ) {
725 - $pages .= " ($count_actions2 " . wfMsg( "useractivity-group-{$type}" ) . ")";
 729+ $pages .= ' (' . wfMsg( "useractivity-group-{$type}", $count_actions2 ) . ')';
726730 }
727731 $pages_count++;
728732
@@ -734,15 +738,18 @@
735739
736740 $user_index++;
737741
738 - if ( $users && $count_users > 2 )
 742+ if ( $users && $count_users > 2 ) {
739743 $users .= ', ';
740 - if ( $user_index == $count_users && $count_users > 1 )
 744+ }
 745+ if ( $user_index == $count_users && $count_users > 1 ) {
741746 $users .= wfMsg( 'and' );
 747+ }
742748
743749 $user_title = Title::makeTitle( NS_USER, $user_name );
744750 $user_name_short = substr( $user_name, 0, 15 );
745 - if ( $user_name != $user_name_short )
 751+ if ( $user_name != $user_name_short ) {
746752 $user_name_short .= '...';
 753+ }
747754
748755 $users .= " <b><a href=\"{$user_title->escapeFullURL()}\">{$user_name_short}</a></b>";
749756 }
@@ -750,7 +757,10 @@
751758 $this->activityLines[] = array(
752759 'type' => $type,
753760 'timestamp' => $page_data['timestamp'],
754 - 'data' => $users . ' ' . wfMsgExt( "useractivity-{$type}", 'parsemag', $pages_count, $count_users ) . $pages
 761+ 'data' => wfMsgExt(
 762+ "useractivity-{$type}", 'parsemag',
 763+ $users, $count_users, $pages, $pages_count
 764+ )
755765 );
756766 }
757767 }
@@ -772,18 +782,12 @@
773783 return 'addedFriendIcon.png';
774784 case 'foe':
775785 return 'addedFoeIcon.png';
776 - case 'challenge_sent':
777 - return 'challengeIcon.png';
778 - case 'challenge_rec':
779 - return 'challengeIcon.png';
780786 case 'system_message':
781787 return 'challengeIcon.png';
782788 case 'system_gift':
783789 return 'awardIcon.png';
784790 case 'user_message':
785791 return 'emailIcon.gif';
786 - case 'network_update':
787 - return 'note.gif';
788792 }
789793 }
790794
@@ -791,10 +795,10 @@
792796 if ( !$comment ) {
793797 return '';
794798 } else {
795 - $comment = str_replace( "<", "&lt;", $comment );
796 - $comment = str_replace( ">", "&gt;", $comment );
797 - $comment = str_replace( "&", "%26", $comment );
798 - $comment = str_replace( "%26quot;", "\"", $comment );
 799+ $comment = str_replace( '<', '&lt;', $comment );
 800+ $comment = str_replace( '>', '&gt;', $comment );
 801+ $comment = str_replace( '&', '%26', $comment );
 802+ $comment = str_replace( '%26quot;', "\"", $comment );
799803 }
800804 $preview = substr( $comment, 0, 75 );
801805 if ( $preview != $comment ) {
@@ -803,10 +807,10 @@
804808 return stripslashes( $preview );
805809 }
806810
807 - private static function sortItems( $x, $y ){
808 - if( $x['timestamp'] == $y['timestamp'] ){
 811+ private static function sortItems( $x, $y ) {
 812+ if( $x['timestamp'] == $y['timestamp'] ) {
809813 return 0;
810 - } else if ( $x['timestamp'] > $y['timestamp'] ) {
 814+ } elseif ( $x['timestamp'] > $y['timestamp'] ) {
811815 return - 1;
812816 } else {
813817 return 1;
Index: trunk/extensions/SocialProfile/UserActivity/SiteActivityHook.php
@@ -7,30 +7,36 @@
88 die( "Not a valid entry point.\n" );
99 }
1010
11 -
1211 $wgHooks['ParserFirstCallInit'][] = 'wfSiteActivity';
 12+/**
 13+ * Register <siteactivity> hook with the Parser
 14+ * @param $parser Object: instance of Parser
 15+ * @return true
 16+ */
1317 function wfSiteActivity( &$parser ) {
1418 $parser->setHook( 'siteactivity', 'getSiteActivity' );
1519 return true;
1620 }
1721
18 -function getSiteActivity( $input, $args, &$parser ) {
 22+function getSiteActivity( $input, $args, $parser ) {
1923 global $wgMemc, $wgScriptPath;
2024
2125 $parser->disableCache();
2226
2327 $limit = ( isset( $args['limit'] ) && is_numeric( $args['limit'] ) ) ? $args['limit'] : 10;
2428
 29+ // so that <siteactivity limit=5 /> will return 5 items instead of 4...
 30+ $fixedLimit = $limit + 1;
 31+
2532 wfLoadExtensionMessages( 'UserActivity' );
2633
27 - $key = wfMemcKey( 'site_activity', 'all', $limit );
 34+ $key = wfMemcKey( 'site_activity', 'all', $fixedLimit );
2835 $data = $wgMemc->get( $key );
2936 if ( !$data ) {
3037 wfDebug( "Got site activity from DB\n" );
31 - $rel = new UserActivity( '', 'ALL', $limit );
 38+ $rel = new UserActivity( '', 'ALL', $fixedLimit );
3239
3340 $rel->setActivityToggle( 'show_votes', 0 );
34 - $rel->setActivityToggle( 'show_network_updates', 0 );
3541 $activity = $rel->getActivityListGrouped();
3642 $wgMemc->set( $key, $activity, 60 * 2 );
3743 } else {
@@ -40,15 +46,17 @@
4147
4248 $output = '';
4349 if ( $activity ) {
 50+ $output .= '<div class="mp-site-activity">
 51+ <h2>' . wfMsg( 'useractivity-siteactivity' ) . '</h2>';
4452
45 - $output .= '<div class="mp-site-activity"><h2>' . wfMsg( 'useractivity-siteactivity' ) . '</h2>';
46 -
4753 $x = 1;
4854 foreach ( $activity as $item ) {
49 - if ( $x < $limit ) {
50 - $output .= '<div class="mp-activity' . ( ( $x == $limit ) ? ' mp-activity-boarder-fix' : '' ) . '">
51 - <img src="' . $wgScriptPath . '/extensions/SocialProfile/images/' . UserActivity::getTypeIcon( $item['type'] ) . '" alt="' . UserActivity::getTypeIcon( $item['type'] ) . '" border="0" />'
52 - . $item['data'] . '</div>';
 55+ if ( $x < $fixedLimit ) {
 56+ $typeIcon = UserActivity::getTypeIcon( $item['type'] );
 57+ $output .= '<div class="mp-activity' . ( ( $x == $fixedLimit ) ? ' mp-activity-boarder-fix' : '' ) . '">
 58+ <img src="' . $wgScriptPath . '/extensions/SocialProfile/images/' . $typeIcon . '" alt="' . $typeIcon . '" border="0" />'
 59+ . $item['data'] .
 60+ '</div>';
5361 $x++;
5462 }
5563 }
Index: trunk/extensions/SocialProfile/UserActivity/UserActivity.body.php
@@ -15,7 +15,7 @@
1616 * @param $par Mixed: parameter passed to the page or null
1717 */
1818 public function execute( $par ) {
19 - global $wgUser, $wgOut, $wgRequest, $wgSitename, $wgScriptPath;
 19+ global $wgUser, $wgOut, $wgRequest, $wgScriptPath;
2020
2121 wfLoadExtensionMessages( 'UserActivity' );
2222
@@ -30,42 +30,60 @@
3131 $rel_type = $wgRequest->getVal( 'rel_type' );
3232 $item_type = $wgRequest->getVal( 'item_type' );
3333
34 - if ( !$rel_type ) $rel_type = 1;
35 - if ( !$item_type ) $item_type = 'all';
 34+ if ( !$rel_type ) {
 35+ $rel_type = 1;
 36+ }
 37+ if ( !$item_type ) {
 38+ $item_type = 'all';
 39+ }
3640
37 - if ( $item_type == 'edits' || $item_type == 'all' ) $edits = 1;
38 - if ( $item_type == 'votes' || $item_type == 'all' ) $votes = 0;
39 - if ( $item_type == 'comments' || $item_type == 'all' ) $comments = 1;
40 - if ( $item_type == 'gifts' || $item_type == 'all' ) $gifts = 1;
41 - if ( $item_type == 'relationships' || $item_type == 'all' ) $relationships = 1;
42 - if ( $item_type == 'advancements' || $item_type == 'all' ) $messages = 1;
43 - if ( $item_type == 'awards' || $item_type == 'all' ) $system_gifts = 1;
44 - if ( $item_type == 'messages' || $item_type == 'all' ) $messages_sent = 1;
45 - if ( $item_type == 'thoughts' || $item_type == 'all' ) $network_updates = 1;
 41+ if ( $item_type == 'edits' || $item_type == 'all' ) {
 42+ $edits = 1;
 43+ }
 44+ if ( $item_type == 'votes' || $item_type == 'all' ) {
 45+ $votes = 0;
 46+ }
 47+ if ( $item_type == 'comments' || $item_type == 'all' ) {
 48+ $comments = 1;
 49+ }
 50+ if ( $item_type == 'gifts' || $item_type == 'all' ) {
 51+ $gifts = 1;
 52+ }
 53+ if ( $item_type == 'relationships' || $item_type == 'all' ) {
 54+ $relationships = 1;
 55+ }
 56+ if ( $item_type == 'advancements' || $item_type == 'all' ) {
 57+ $messages = 1;
 58+ }
 59+ if ( $item_type == 'awards' || $item_type == 'all' ) {
 60+ $system_gifts = 1;
 61+ }
 62+ if ( $item_type == 'messages' || $item_type == 'all' ) {
 63+ $messages_sent = 1;
 64+ }
4665
4766 /*
4867 $output .= '<div class="user-home-links-container">
49 - <h2>' . wfMsg('useractivity-filter') . '</h2>
 68+ <h2>' . wfMsg( 'useractivity-filter' ) . '</h2>
5069 <div class="user-home-links">';
5170
5271 $lines = explode( "\n", wfMsgForContent( 'useractivity-filter' ) );
5372 foreach( $lines as $line ) {
54 -
55 - if( strpos($line, '*') !== 0 ){
 73+ if( strpos( $line, '*' ) !== 0 ) {
5674 continue;
5775 } else {
58 - $line = explode( '|' , trim($line, '* '), 3 );
 76+ $line = explode( '|' , trim( $line, '* ' ), 3 );
5977 $filter = $line[0];
6078 $link_text = $line[1];
6179 $link_image = $line[2];
62 - $output .= "<a href=\"" . $this_title->escapeFullURL("item_type={$filter}") . "\">
63 - <img src=\"{$wgScriptPath}/extensions/SocialProfile/images/" . UserActivity::getTypeIcon($link_image) . "\"/>{$link_text}
 80+ $output .= '<a href="' . $this_title->escapeFullURL( "item_type={$filter}" ) . "\">
 81+ <img src=\"{$wgScriptPath}/extensions/SocialProfile/images/" . UserActivity::getTypeIcon( $link_image ) . "\"/>
 82+ {$link_text}
6483 </a>";
6584 }
66 -
6785 }
6886
69 - $output .= '<a href="' . $this_title->escapeFullURL() . '">' . wfMsg( 'useractivity-all' ) . '</a>
 87+ $output .= '<a href="' . $this_title->escapeFullURL() . '">' . wfMsg( 'useractivity-all' ) . '</a>
7088 </div>
7189 </div>
7290 */
@@ -82,11 +100,6 @@
83101 $rel->setActivityToggle( 'show_system_gifts', $system_gifts );
84102 $rel->setActivityToggle( 'show_messages_sent', $messages_sent );
85103
86 - // An extra toggle for ArmchairGM
87 - if ( $wgSitename == 'ArmchairGM' ) {
88 - $rel->setActivityToggle( 'show_network_updates', $network_updates );
89 - }
90 -
91104 /**
92105 * Get all relationship activity
93106 */
@@ -97,15 +110,17 @@
98111 $x = 1;
99112
100113 foreach ( $activity as $item ) {
101 -
102114 if ( $x < 40 ) {
103 -
104 - if ( ( ( count( $activity ) > 40 ) && ( $x == 39 ) ) || ( ( count( $activity ) < 40 ) && ( $x == ( count( $activity ) - 1 ) ) ) ) {
 115+ if (
 116+ ( ( count( $activity ) > 40 ) && ( $x == 39 ) ) ||
 117+ ( ( count( $activity ) < 40 ) && ( $x == ( count( $activity ) - 1 ) ) )
 118+ ) {
105119 $border_fix = ' border-fix';
106120 }
107121
 122+ $typeIcon = UserActivity::getTypeIcon( $item['type'] );
108123 $output .= "<div class=\"user-home-activity{$border_fix}\">
109 - <img src=\"{$wgScriptPath}/extensions/SocialProfile/images/" . UserActivity::getTypeIcon( $item['type'] ) . "\" alt=\"\" border=\"0\" />
 124+ <img src=\"{$wgScriptPath}/extensions/SocialProfile/images/" . $typeIcon . "\" alt=\"\" border=\"0\" />
110125 {$item["data"]}
111126 </div>";
112127 $x++;

Status & tagging log