r84804 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84803‎ | r84804 | r84805 >
Date:16:22, 26 March 2011
Author:ashley
Status:deferred
Tags:
Comment:
SocialProfile: more bug #27732 work: rewrote UserActivity's raw SQL queries to use MediaWiki's Database functions. Not very highly tested, so there's a chance that this breaks stuff...
Modified paths:
  • /trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php
@@ -1,7 +1,6 @@
22 <?php
33 /**
44 * UserActivity class
5 - * @todo FIXME: database queries should use Database class
65 */
76 class UserActivity {
87
@@ -58,31 +57,56 @@
5958 }
6059 }
6160
 61+ /**
 62+ * Sets the value of class member variable $name to $value.
 63+ */
6264 public function setActivityToggle( $name, $value ) {
6365 $this->$name = $value;
6466 }
6567
6668 private function setEdits() {
6769 $dbr = wfGetDB( DB_SLAVE );
68 - $rel_sql = '';
69 - $user_sql = '';
7070
 71+ $where = array();
 72+
7173 if ( !empty( $this->rel_type ) ) {
72 - $rel_sql = " WHERE rc_user IN (SELECT r_user_id_relation FROM {$dbr->tableName( 'user_relationship' )} WHERE r_user_id={$this->user_id} AND r_type={$this->rel_type}) ";
 74+ $users = $dbr->select(
 75+ 'user_relationship',
 76+ 'r_user_id_relation',
 77+ array(
 78+ 'r_user_id' => $this->user_id,
 79+ 'r_type' => $this->rel_type
 80+ ),
 81+ __METHOD__
 82+ );
 83+ $userArray = array();
 84+ foreach ( $users as $user ) {
 85+ $userArray[] = $user;
 86+ }
 87+ $userIDs = implode( ',', $userArray );
 88+ $where[] = "rc_user IN ($userIDs)";
7389 }
7490
7591 if ( !empty( $this->show_current_user ) ) {
76 - $user_sql = " WHERE rc_user = {$this->user_id}";
 92+ $where['rc_user'] = $this->user_id;
7793 }
7894
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,
81 - rc_namespace, rc_cur_id, rc_this_oldid, rc_last_oldid,
82 - rc_log_action
83 - FROM {$dbr->tableName( 'recentchanges' )}
84 - {$rel_sql} {$user_sql}
85 - ORDER BY rc_id DESC LIMIT 0," . $this->item_max;
86 - $res = $dbr->query( $sql, __METHOD__ );
 95+ $res = $dbr->select(
 96+ 'recentchanges',
 97+ array(
 98+ 'UNIX_TIMESTAMP(rc_timestamp) AS item_date', 'rc_title',
 99+ 'rc_user', 'rc_user_text', 'rc_comment', 'rc_id', 'rc_minor',
 100+ 'rc_new', 'rc_namespace', 'rc_cur_id', 'rc_this_oldid',
 101+ 'rc_last_oldid', 'rc_log_action'
 102+ ),
 103+ $where,
 104+ __METHOD__,
 105+ array(
 106+ 'ORDER BY' => 'rc_id DESC',
 107+ 'LIMIT' => $this->item_max,
 108+ 'OFFSET' => 0
 109+ )
 110+ );
87111
88112 foreach ( $res as $row ) {
89113 // Special pages aren't editable, so ignore them
@@ -131,23 +155,46 @@
132156 return false;
133157 }
134158
135 - $rel_sql = '';
136 - $user_sql = '';
 159+ $where = array();
 160+ $where[] = 'vote_page_id = page_id';
 161+
137162 if ( $this->rel_type ) {
138 - $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}) ";
 163+ $users = $dbr->select(
 164+ 'user_relationship',
 165+ 'r_user_id_relation',
 166+ array(
 167+ 'r_user_id' => $this->user_id,
 168+ 'r_type' => $this->rel_type
 169+ ),
 170+ __METHOD__
 171+ );
 172+ $userArray = array();
 173+ foreach ( $users as $user ) {
 174+ $userArray[] = $user;
 175+ }
 176+ $userIDs = implode( ',', $userArray );
 177+ $where[] = "vote_user_id IN ($userIDs)";
139178 }
140179 if ( $this->show_current_user ) {
141 - $user_sql = " AND vote_user_id = {$this->user_id}";
 180+ $where['vote_user_id'] = $this->user_id;
142181 }
143182
144 - $sql = "SELECT UNIX_TIMESTAMP(vote_date) AS item_date, username,
145 - page_title, vote_count, comment_count, vote_ip,
146 - vote_user_id
147 - FROM {$dbr->tableName( 'Vote' )} v, {$dbr->tableName( 'page' )} p
148 - WHERE v.vote_page_id=p.page_id
149 - {$rel_sql} {$user_sql}
150 - ORDER BY vote_date DESC LIMIT 0," . $this->item_max;
151 - $res = $dbr->query( $sql, __METHOD__ );
 183+ $res = $dbr->select(
 184+ array( 'Vote', 'page' ),
 185+ array(
 186+ 'UNIX_TIMESTAMP(vote_date) AS item_date', 'username',
 187+ 'page_title', 'vote_count', 'comment_count', 'vote_ip',
 188+ 'vote_user_id'
 189+ ),
 190+ $where,
 191+ __METHOD__,
 192+ array(
 193+ 'ORDER BY' => 'vote_date DESC',
 194+ 'LIMIT' => $this->item_max,
 195+ 'OFFSET' => 0
 196+ )
 197+ );
 198+
152199 foreach ( $res as $row ) {
153200 $username = $row->username;
154201 $this->items[] = array(
@@ -173,26 +220,47 @@
174221 return false;
175222 }
176223
177 - $rel_sql = '';
178 - $user_sql = '';
 224+ $where = array();
 225+ $where[] = 'comment_page_id = page_id';
179226
180227 if ( !empty( $this->rel_type ) ) {
181 - $rel_sql = "AND Comment_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})";
 228+ $users = $dbr->select(
 229+ 'user_relationship',
 230+ 'r_user_id_relation',
 231+ array(
 232+ 'r_user_id' => $this->user_id,
 233+ 'r_type' => $this->rel_type
 234+ ),
 235+ __METHOD__
 236+ );
 237+ $userArray = array();
 238+ foreach ( $users as $user ) {
 239+ $userArray[] = $user;
 240+ }
 241+ $userIDs = implode( ',', $userArray );
 242+ $where[] = "Comment_user_id IN ($userIDs)";
182243 }
183244
184245 if ( !empty( $this->show_current_user ) ) {
185 - $user_sql = "AND Comment_user_id = {$this->user_id}";
 246+ $where['Comment_user_id'] = $this->user_id;
186247 }
187248
188 - $sql = "SELECT UNIX_TIMESTAMP(comment_date) AS item_date,
189 - Comment_Username, Comment_IP, page_title, Comment_Text,
190 - Comment_user_id, page_namespace, CommentID
191 - FROM {$dbr->tableName( 'Comments' )} c, {$dbr->tableName( 'page' )} p
192 - WHERE c.comment_page_id=p.page_id
193 - {$rel_sql} {$user_sql}
194 - ORDER BY comment_date DESC LIMIT 0," . $this->item_max;
 249+ $res = $dbr->select(
 250+ array( 'Comments', 'page' ),
 251+ array(
 252+ 'UNIX_TIMESTAMP(comment_date) AS item_date',
 253+ 'Comment_Username', 'Comment_IP', 'page_title', 'Comment_Text',
 254+ 'Comment_user_id', 'page_namespace', 'CommentID'
 255+ ),
 256+ $where,
 257+ __METHOD__,
 258+ array(
 259+ 'ORDER BY' => 'comment_date DESC',
 260+ 'LIMIT' => $this->item_max,
 261+ 'OFFSET' => 0
 262+ )
 263+ );
195264
196 - $res = $dbr->query( $sql, __METHOD__ );
197265 foreach ( $res as $row ) {
198266 $show_comment = true;
199267
@@ -240,24 +308,48 @@
241309
242310 private function setGiftsSent() {
243311 $dbr = wfGetDB( DB_SLAVE );
244 - $rel_sql = '';
245 - $user_sql = '';
246312
 313+ $where = array();
 314+
247315 if( $this->rel_type ) {
248 - $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})";
 316+ $users = $dbr->select(
 317+ 'user_relationship',
 318+ 'r_user_id_relation',
 319+ array(
 320+ 'r_user_id' => $this->user_id,
 321+ 'r_type' => $this->rel_type
 322+ ),
 323+ __METHOD__
 324+ );
 325+ $userArray = array();
 326+ foreach ( $users as $user ) {
 327+ $userArray[] = $user;
 328+ }
 329+ $userIDs = implode( ',', $userArray );
 330+ $where[] = "ug_user_id_to IN ($userIDs)";
249331 }
 332+
250333 if( $this->show_current_user ) {
251 - $user_sql = "WHERE ug_user_id_from = {$this->user_id}";
 334+ $where['ug_user_id_from'] = $this->user_id;
252335 }
253336
254 - $sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from,
255 - ug_user_id_to, ug_user_name_to,
256 - UNIX_TIMESTAMP(ug_date) AS item_date, gift_name, gift_id
257 - FROM {$dbr->tableName( 'user_gift' )}
258 - INNER JOIN {$dbr->tableName( 'gift' )} ON gift_id = ug_gift_id
259 - {$rel_sql} {$user_sql}
260 - ORDER BY ug_id DESC LIMIT 0,{$this->item_max}";
261 - $res = $dbr->query( $sql, __METHOD__ );
 337+ $res = $dbr->select(
 338+ array( 'user_gift', 'gift' ),
 339+ array(
 340+ 'ug_id', 'ug_user_id_from', 'ug_user_name_from',
 341+ 'ug_user_id_to', 'ug_user_name_to',
 342+ 'UNIX_TIMESTAMP(ug_date) AS item_date', 'gift_name', 'gift_id'
 343+ ),
 344+ $where,
 345+ __METHOD__,
 346+ array(
 347+ 'ORDER BY' => 'ug_id DESC',
 348+ 'LIMIT' => $this->item_max,
 349+ 'OFFSET' => 0
 350+ ),
 351+ array( 'gift' => array( 'INNER JOIN', 'gift_id = ug_gift_id' ) )
 352+ );
 353+
262354 foreach ( $res as $row ) {
263355 $this->items[] = array(
264356 'id' => $row->ug_id,
@@ -276,31 +368,56 @@
277369
278370 private function setGiftsRec() {
279371 $dbr = wfGetDB( DB_SLAVE );
280 - $rel_sql = '';
281 - $user_sql = '';
282372
 373+ $where = array();
 374+
283375 if ( !empty( $this->rel_type ) ) {
284 - $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} )";
 376+ $users = $dbr->select(
 377+ 'user_relationship',
 378+ 'r_user_id_relation',
 379+ array(
 380+ 'r_user_id' => $this->user_id,
 381+ 'r_type' => $this->rel_type
 382+ ),
 383+ __METHOD__
 384+ );
 385+ $userArray = array();
 386+ foreach ( $users as $user ) {
 387+ $userArray[] = $user;
 388+ }
 389+ $userIDs = implode( ',', $userArray );
 390+ $where[] = "ug_user_id_to IN ($userIDs)";
285391 }
286392
287393 if ( !empty( $this->show_current_user ) ) {
288 - $user_sql = "WHERE ug_user_id_to = {$this->user_id}";
 394+ $where['ug_user_id_to'] = $this->user_id;
289395 }
290396
291 - $sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from,
292 - ug_user_id_to, ug_user_name_to,
293 - UNIX_TIMESTAMP(ug_date) AS item_date, gift_name, gift_id
294 - FROM {$dbr->tableName( 'user_gift' )}
295 - INNER JOIN {$dbr->tableName( 'gift' )} ON gift_id = ug_gift_id
296 - {$rel_sql} {$user_sql}
297 - ORDER BY ug_id DESC LIMIT 0,{$this->item_max}";
298 - $res = $dbr->query( $sql, __METHOD__ );
 397+ $res = $dbr->select(
 398+ array( 'user_gift', 'gift' ),
 399+ array(
 400+ 'ug_id', 'ug_user_id_from', 'ug_user_name_from',
 401+ 'ug_user_id_to', 'ug_user_name_to',
 402+ 'UNIX_TIMESTAMP(ug_date) AS item_date', 'gift_name', 'gift_id'
 403+ ),
 404+ $where,
 405+ __METHOD__,
 406+ array(
 407+ 'ORDER BY' => 'ug_id DESC',
 408+ 'LIMIT' => $this->item_max,
 409+ 'OFFSET' => 0
 410+ ),
 411+ array( 'gift' => array( 'INNER JOIN', 'gift_id = ug_gift_id' ) )
 412+ );
 413+
299414 foreach ( $res as $row ) {
300415 global $wgUploadPath;
301416 $user_title = Title::makeTitle( NS_USER, $row->ug_user_name_to );
302417 $user_title_from = Title::makeTitle( NS_USER, $row->ug_user_name_from );
303418
304 - $gift_image = '<img src="' . $wgUploadPath . '/awards/' . Gifts::getGiftImage( $row->gift_id, 'm' ) . '" border="0" alt="" />';
 419+ $gift_image = '<img src="' . $wgUploadPath . '/awards/' .
 420+ Gifts::getGiftImage( $row->gift_id, 'm' ) .
 421+ '" border="0" alt="" />';
305422 $view_gift_link = SpecialPage::getTitleFor( 'ViewGift' );
306423
307424 $html = wfMsg( 'useractivity-gift',
@@ -337,28 +454,53 @@
338455
339456 private function setSystemGiftsRec() {
340457 $dbr = wfGetDB( DB_SLAVE );
341 - $rel_sql = '';
342 - $user_sql = '';
343458
 459+ $where = array();
 460+
344461 if ( !empty( $this->rel_type ) ) {
345 - $rel_sql = "WHERE sg_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} )";
 462+ $users = $dbr->select(
 463+ 'user_relationship',
 464+ 'r_user_id_relation',
 465+ array(
 466+ 'r_user_id' => $this->user_id,
 467+ 'r_type' => $this->rel_type
 468+ ),
 469+ __METHOD__
 470+ );
 471+ $userArray = array();
 472+ foreach ( $users as $user ) {
 473+ $userArray[] = $user;
 474+ }
 475+ $userIDs = implode( ',', $userArray );
 476+ $where[] = "sg_user_id IN ($userIDs)";
346477 }
347478
348479 if ( !empty( $this->show_current_user ) ) {
349 - $user_sql = "WHERE sg_user_id = {$this->user_id}";
 480+ $where['sg_user_id'] = $this->user_id;
350481 }
351482
352 - $sql = "SELECT sg_id, sg_user_id, sg_user_name,
353 - UNIX_TIMESTAMP(sg_date) AS item_date, gift_name, gift_id
354 - FROM {$dbr->tableName( 'user_system_gift' )}
355 - INNER JOIN {$dbr->tableName( 'system_gift' )} ON gift_id = sg_gift_id
356 - {$rel_sql} {$user_sql}
357 - ORDER BY sg_id DESC LIMIT 0,{$this->item_max}";
358 - $res = $dbr->query( $sql, __METHOD__ );
 483+ $res = $dbr->select(
 484+ array( 'user_system_gift', 'system_gift' ),
 485+ array(
 486+ 'sg_id', 'sg_user_id', 'sg_user_name',
 487+ 'UNIX_TIMESTAMP(sg_date) AS item_date', 'gift_name', 'gift_id'
 488+ ),
 489+ $where,
 490+ __METHOD__,
 491+ array(
 492+ 'ORDER BY' => 'sg_id DESC',
 493+ 'LIMIT' => $this->item_max,
 494+ 'OFFSET' => 0
 495+ ),
 496+ array( 'system_gift' => array( 'INNER JOIN', 'gift_id = sg_gift_id' ) )
 497+ );
 498+
359499 foreach ( $res as $row ) {
360500 global $wgUploadPath;
361501 $user_title = Title::makeTitle( NS_USER, $row->sg_user_name );
362 - $system_gift_image = '<img src="' . $wgUploadPath . '/awards/' . SystemGifts::getGiftImage( $row->gift_id, 'm' ) . '" border="0" alt="" />';
 502+ $system_gift_image = '<img src="' . $wgUploadPath . '/awards/' .
 503+ SystemGifts::getGiftImage( $row->gift_id, 'm' ) .
 504+ '" border="0" alt="" />';
363505 $system_gift_link = SpecialPage::getTitleFor( 'ViewSystemGift' );
364506
365507 $html = wfMsg( 'useractivity-award', "<b><a href=\"{$user_title->escapeFullURL()}\">{$row->sg_user_name}</a></b>" ) .
@@ -392,24 +534,47 @@
393535
394536 private function setRelationships() {
395537 $dbr = wfGetDB( DB_SLAVE );
 538+
 539+ $where = array();
 540+
396541 if ( !empty( $this->rel_type ) ) {
397 - $rel_sql = "WHERE r_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} )";
398 - } else {
399 - $rel_sql = '';
 542+ $users = $dbr->select(
 543+ 'user_relationship',
 544+ 'r_user_id_relation',
 545+ array(
 546+ 'r_user_id' => $this->user_id,
 547+ 'r_type' => $this->rel_type
 548+ ),
 549+ __METHOD__
 550+ );
 551+ $userArray = array();
 552+ foreach ( $users as $user ) {
 553+ $userArray[] = $user;
 554+ }
 555+ $userIDs = implode( ',', $userArray );
 556+ $where[] = "r_user_id IN ($userIDs)";
400557 }
 558+
401559 if ( !empty( $this->show_current_user ) ) {
402 - $user_sql = "WHERE r_user_id = {$this->user_id}";
403 - } else {
404 - $user_sql = '';
 560+ $where['r_user_id'] = $this->user_id;
405561 }
406 - $sql = "SELECT r_id, r_user_id, r_user_name, r_user_id_relation,
407 - r_user_name_relation, r_type,
408 - UNIX_TIMESTAMP(r_date) AS item_date
409 - FROM {$dbr->tableName( 'user_relationship' )}
410 - {$rel_sql} {$user_sql}
411 - ORDER BY r_id DESC LIMIT 0,{$this->item_max}";
412 - $res = $dbr->query( $sql, __METHOD__ );
413562
 563+ $res = $dbr->select(
 564+ 'user_relationship',
 565+ array(
 566+ 'r_id', 'r_user_id', 'r_user_name', 'r_user_id_relation',
 567+ 'r_user_name_relation', 'r_type',
 568+ 'UNIX_TIMESTAMP(r_date) AS item_date'
 569+ ),
 570+ $where,
 571+ __METHOD__,
 572+ array(
 573+ 'ORDER BY' => 'r_id DESC',
 574+ 'LIMIT' => $this->item_max,
 575+ 'OFFSET' => 0
 576+ )
 577+ );
 578+
414579 foreach ( $res as $row ) {
415580 if ( $row->r_type == 1 ) {
416581 $r_type = 'friend';
@@ -419,7 +584,7 @@
420585
421586 $user_name_short = substr( $row->r_user_name, 0, 25 );
422587 if ( $row->r_user_name != $user_name_short ) {
423 - $user_name_short .= '...';
 588+ $user_name_short .= wfMsg( 'ellipsis' );
424589 }
425590
426591 $this->items_grouped[$r_type][$row->r_user_name_relation]['users'][$row->r_user_name][] = array(
@@ -455,26 +620,49 @@
456621
457622 private function setMessagesSent() {
458623 $dbr = wfGetDB( DB_SLAVE );
459 - $rel_sql = '';
460 - $user_sql = '';
461624
 625+ $where = array();
 626+ // We do *not* want to display private messages...
 627+ $where['ub_type'] = 0;
 628+
462629 if ( !empty( $this->rel_type ) ) {
463 - $rel_sql = " ub_user_id_from IN (SELECT r_user_id_relation FROM {$dbr->tableName( 'user_relationship' )} WHERE r_user_id={$this->user_id} AND r_type={$this->rel_type} ) AND";
 630+ $users = $dbr->select(
 631+ 'user_relationship',
 632+ 'r_user_id_relation',
 633+ array(
 634+ 'r_user_id' => $this->user_id,
 635+ 'r_type' => $this->rel_type
 636+ ),
 637+ __METHOD__
 638+ );
 639+ $userArray = array();
 640+ foreach ( $users as $user ) {
 641+ $userArray[] = $user;
 642+ }
 643+ $userIDs = implode( ',', $userArray );
 644+ $where[] = "ub_user_id_from IN ($userIDs)";
464645 }
465646
466647 if ( !empty( $this->show_current_user ) ) {
467 - $user_sql = " ub_user_id_from = {$this->user_id} AND";
 648+ $where['ub_user_id_from'] = $this->user_id;
468649 }
469650
470 - $sql = "SELECT ub_id, ub_user_id, ub_user_name, ub_user_id_from,
471 - ub_user_name_from,
472 - UNIX_TIMESTAMP(ub_date) AS item_date,
473 - ub_message
474 - FROM {$dbr->tableName( 'user_board' )} WHERE
475 - {$rel_sql} {$user_sql} ub_type=0
476 - ORDER BY ub_id DESC LIMIT 0,{$this->item_max}";
 651+ $res = $dbr->select(
 652+ 'user_board',
 653+ array(
 654+ 'ub_id', 'ub_user_id', 'ub_user_name', 'ub_user_id_from',
 655+ 'ub_user_name_from', 'UNIX_TIMESTAMP(ub_date) AS item_date',
 656+ 'ub_message'
 657+ ),
 658+ $where,
 659+ __METHOD__,
 660+ array(
 661+ 'ORDER BY' => 'ub_id DESC',
 662+ 'LIMIT' => $this->item_max,
 663+ 'OFFSET' => 0
 664+ )
 665+ );
477666
478 - $res = $dbr->query( $sql, __METHOD__ );
479667 foreach ( $res as $row ) {
480668 // Ignore nonexistent (for example, renamed) users
481669 $uid = User::idFromName( $row->ub_user_name );
@@ -482,21 +670,23 @@
483671 continue;
484672 }
485673
486 - $this->items_grouped['user_message'][stripslashes( $row->ub_user_name )]['users'][stripslashes( $row->ub_user_name_from )][] = array(
 674+ $to = stripslashes( $row->ub_user_name );
 675+ $from = stripslashes( $row->ub_user_name_from );
 676+ $this->items_grouped['user_message'][$to]['users'][$from][] = array(
487677 'id' => $row->ub_id,
488678 'type' => 'user_message',
489679 'timestamp' => $row->item_date,
490680 'pagetitle' => '',
491681 'namespace' => '',
492 - 'username' => stripslashes( $row->ub_user_name_from ),
 682+ 'username' => $from,
493683 'userid' => $row->ub_user_id_from,
494 - 'comment' => stripslashes( $row->ub_user_name ),
 684+ 'comment' => $to,
495685 'minor' => 0,
496686 'new' => 0
497687 );
498688
499689 // set last timestamp
500 - $this->items_grouped['user_message'][stripslashes( $row->ub_user_name )]['timestamp'] = $row->item_date;
 690+ $this->items_grouped['user_message'][$to]['timestamp'] = $row->item_date;
501691
502692 $this->items[] = array(
503693 'id' => $row->ub_id,
@@ -504,9 +694,9 @@
505695 'timestamp' => $row->item_date,
506696 'pagetitle' => '',
507697 'namespace' => $this->fixItemComment( $row->ub_message ),
508 - 'username' => stripslashes( $row->ub_user_name_from ),
 698+ 'username' => $from,
509699 'userid' => $row->ub_user_id_from,
510 - 'comment' => stripslashes( $row->ub_user_name ),
 700+ 'comment' => $to,
511701 'new' => '0',
512702 'minor' => 0
513703 );
@@ -515,28 +705,51 @@
516706
517707 private function setSystemMessages() {
518708 $dbr = wfGetDB( DB_SLAVE );
519 - $rel_sql = '';
520 - $user_sql = '';
521709
 710+ $where = array();
 711+
522712 if ( !empty( $this->rel_type ) ) {
523 - $rel_sql = " WHERE um_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} )";
 713+ $users = $dbr->select(
 714+ 'user_relationship',
 715+ 'r_user_id_relation',
 716+ array(
 717+ 'r_user_id' => $this->user_id,
 718+ 'r_type' => $this->rel_type
 719+ ),
 720+ __METHOD__
 721+ );
 722+ $userArray = array();
 723+ foreach ( $users as $user ) {
 724+ $userArray[] = $user;
 725+ }
 726+ $userIDs = implode( ',', $userArray );
 727+ $where[] = "um_user_id IN ($userIDs)";
524728 }
525729
526730 if ( !empty( $this->show_current_user ) ) {
527 - $user_sql = " WHERE um_user_id = {$this->user_id}";
 731+ $where['um_user_id'] = $this->user_id;
528732 }
529733
530 - $sql = "SELECT um_id, um_user_id, um_user_name, um_type, um_message,
531 - UNIX_TIMESTAMP(um_date) AS item_date
532 - FROM {$dbr->tableName( 'user_system_messages' )}
533 - {$rel_sql} {$user_sql}
534 - ORDER BY um_id DESC LIMIT 0,{$this->item_max}";
535 - $res = $dbr->query( $sql, __METHOD__ );
 734+ $res = $dbr->select(
 735+ 'user_system_messages',
 736+ array(
 737+ 'um_id', 'um_user_id', 'um_user_name', 'um_type', 'um_message',
 738+ 'UNIX_TIMESTAMP(um_date) AS item_date'
 739+ ),
 740+ $where,
 741+ __METHOD__,
 742+ array(
 743+ 'ORDER BY' => 'um_id DESC',
 744+ 'LIMIT' => $this->item_max,
 745+ 'OFFSET' => 0
 746+ )
 747+ );
 748+
536749 foreach ( $res as $row ) {
537750 $user_title = Title::makeTitle( NS_USER, $row->um_user_name );
538751 $user_name_short = substr( $row->um_user_name, 0, 15 );
539752 if ( $row->um_user_name != $user_name_short ) {
540 - $user_name_short .= '...';
 753+ $user_name_short .= wfMsg( 'ellipsis' );
541754 }
542755 $this->activityLines[] = array(
543756 'type' => 'system_message',
@@ -703,7 +916,12 @@
704917 $pages .= " <a href=\"{$page_title->escapeFullURL()}\">{$page_name}</a>";
705918 if ( $count_users == 1 && $count_actions > 1 ) {
706919 $pages .= wfMsg( 'word-separator' );
707 - $pages .= wfMsg( 'parentheses', wfMsgExt( "useractivity-group-{$type}", 'parsemag', $count_actions, $user_name ) );
 920+ $pages .= wfMsg( 'parentheses', wfMsgExt(
 921+ "useractivity-group-{$type}",
 922+ 'parsemag',
 923+ $count_actions,
 924+ $user_name
 925+ ) );
708926 }
709927 $pages_count++;
710928 }
@@ -737,7 +955,9 @@
738956 $pages .= " <a href=\"{$page_title2->escapeFullURL()}\">{$page_name2}</a>";
739957 }
740958 if ( $count_actions2 > 1 ) {
741 - $pages .= ' (' . wfMsg( "useractivity-group-{$type}", $count_actions2 ) . ')';
 959+ $pages .= ' (' . wfMsg(
 960+ "useractivity-group-{$type}", $count_actions2
 961+ ) . ')';
742962 }
743963 $pages_count++;
744964
@@ -772,7 +992,8 @@
773993 'data' => wfMsgExt(
774994 "useractivity-{$type}",
775995 'parsemag',
776 - $users, $count_users, $pages, $pages_count, $userNameForGender
 996+ $users, $count_users, $pages, $pages_count,
 997+ $userNameForGender
777998 )
778999 );
7791000 }
@@ -811,11 +1032,11 @@
8121033 $comment = str_replace( '<', '&lt;', $comment );
8131034 $comment = str_replace( '>', '&gt;', $comment );
8141035 $comment = str_replace( '&', '%26', $comment );
815 - $comment = str_replace( '%26quot;', "\"", $comment );
 1036+ $comment = str_replace( '%26quot;', '"', $comment );
8161037 }
8171038 $preview = substr( $comment, 0, 75 );
8181039 if ( $preview != $comment ) {
819 - $preview .= '...';
 1040+ $preview .= wfMsg( 'ellipsis' );
8201041 }
8211042 return stripslashes( $preview );
8221043 }

Status & tagging log