Index: trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php |
— | — | @@ -1,7 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * UserActivity class |
5 | | - * @todo FIXME: database queries should use Database class |
6 | 5 | */ |
7 | 6 | class UserActivity { |
8 | 7 | |
— | — | @@ -58,31 +57,56 @@ |
59 | 58 | } |
60 | 59 | } |
61 | 60 | |
| 61 | + /** |
| 62 | + * Sets the value of class member variable $name to $value. |
| 63 | + */ |
62 | 64 | public function setActivityToggle( $name, $value ) { |
63 | 65 | $this->$name = $value; |
64 | 66 | } |
65 | 67 | |
66 | 68 | private function setEdits() { |
67 | 69 | $dbr = wfGetDB( DB_SLAVE ); |
68 | | - $rel_sql = ''; |
69 | | - $user_sql = ''; |
70 | 70 | |
| 71 | + $where = array(); |
| 72 | + |
71 | 73 | 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)"; |
73 | 89 | } |
74 | 90 | |
75 | 91 | if ( !empty( $this->show_current_user ) ) { |
76 | | - $user_sql = " WHERE rc_user = {$this->user_id}"; |
| 92 | + $where['rc_user'] = $this->user_id; |
77 | 93 | } |
78 | 94 | |
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 | + ); |
87 | 111 | |
88 | 112 | foreach ( $res as $row ) { |
89 | 113 | // Special pages aren't editable, so ignore them |
— | — | @@ -131,23 +155,46 @@ |
132 | 156 | return false; |
133 | 157 | } |
134 | 158 | |
135 | | - $rel_sql = ''; |
136 | | - $user_sql = ''; |
| 159 | + $where = array(); |
| 160 | + $where[] = 'vote_page_id = page_id'; |
| 161 | + |
137 | 162 | 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)"; |
139 | 178 | } |
140 | 179 | if ( $this->show_current_user ) { |
141 | | - $user_sql = " AND vote_user_id = {$this->user_id}"; |
| 180 | + $where['vote_user_id'] = $this->user_id; |
142 | 181 | } |
143 | 182 | |
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 | + |
152 | 199 | foreach ( $res as $row ) { |
153 | 200 | $username = $row->username; |
154 | 201 | $this->items[] = array( |
— | — | @@ -173,26 +220,47 @@ |
174 | 221 | return false; |
175 | 222 | } |
176 | 223 | |
177 | | - $rel_sql = ''; |
178 | | - $user_sql = ''; |
| 224 | + $where = array(); |
| 225 | + $where[] = 'comment_page_id = page_id'; |
179 | 226 | |
180 | 227 | 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)"; |
182 | 243 | } |
183 | 244 | |
184 | 245 | if ( !empty( $this->show_current_user ) ) { |
185 | | - $user_sql = "AND Comment_user_id = {$this->user_id}"; |
| 246 | + $where['Comment_user_id'] = $this->user_id; |
186 | 247 | } |
187 | 248 | |
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 | + ); |
195 | 264 | |
196 | | - $res = $dbr->query( $sql, __METHOD__ ); |
197 | 265 | foreach ( $res as $row ) { |
198 | 266 | $show_comment = true; |
199 | 267 | |
— | — | @@ -240,24 +308,48 @@ |
241 | 309 | |
242 | 310 | private function setGiftsSent() { |
243 | 311 | $dbr = wfGetDB( DB_SLAVE ); |
244 | | - $rel_sql = ''; |
245 | | - $user_sql = ''; |
246 | 312 | |
| 313 | + $where = array(); |
| 314 | + |
247 | 315 | 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)"; |
249 | 331 | } |
| 332 | + |
250 | 333 | 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; |
252 | 335 | } |
253 | 336 | |
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 | + |
262 | 354 | foreach ( $res as $row ) { |
263 | 355 | $this->items[] = array( |
264 | 356 | 'id' => $row->ug_id, |
— | — | @@ -276,31 +368,56 @@ |
277 | 369 | |
278 | 370 | private function setGiftsRec() { |
279 | 371 | $dbr = wfGetDB( DB_SLAVE ); |
280 | | - $rel_sql = ''; |
281 | | - $user_sql = ''; |
282 | 372 | |
| 373 | + $where = array(); |
| 374 | + |
283 | 375 | 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)"; |
285 | 391 | } |
286 | 392 | |
287 | 393 | 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; |
289 | 395 | } |
290 | 396 | |
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 | + |
299 | 414 | foreach ( $res as $row ) { |
300 | 415 | global $wgUploadPath; |
301 | 416 | $user_title = Title::makeTitle( NS_USER, $row->ug_user_name_to ); |
302 | 417 | $user_title_from = Title::makeTitle( NS_USER, $row->ug_user_name_from ); |
303 | 418 | |
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="" />'; |
305 | 422 | $view_gift_link = SpecialPage::getTitleFor( 'ViewGift' ); |
306 | 423 | |
307 | 424 | $html = wfMsg( 'useractivity-gift', |
— | — | @@ -337,28 +454,53 @@ |
338 | 455 | |
339 | 456 | private function setSystemGiftsRec() { |
340 | 457 | $dbr = wfGetDB( DB_SLAVE ); |
341 | | - $rel_sql = ''; |
342 | | - $user_sql = ''; |
343 | 458 | |
| 459 | + $where = array(); |
| 460 | + |
344 | 461 | 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)"; |
346 | 477 | } |
347 | 478 | |
348 | 479 | if ( !empty( $this->show_current_user ) ) { |
349 | | - $user_sql = "WHERE sg_user_id = {$this->user_id}"; |
| 480 | + $where['sg_user_id'] = $this->user_id; |
350 | 481 | } |
351 | 482 | |
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 | + |
359 | 499 | foreach ( $res as $row ) { |
360 | 500 | global $wgUploadPath; |
361 | 501 | $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="" />'; |
363 | 505 | $system_gift_link = SpecialPage::getTitleFor( 'ViewSystemGift' ); |
364 | 506 | |
365 | 507 | $html = wfMsg( 'useractivity-award', "<b><a href=\"{$user_title->escapeFullURL()}\">{$row->sg_user_name}</a></b>" ) . |
— | — | @@ -392,24 +534,47 @@ |
393 | 535 | |
394 | 536 | private function setRelationships() { |
395 | 537 | $dbr = wfGetDB( DB_SLAVE ); |
| 538 | + |
| 539 | + $where = array(); |
| 540 | + |
396 | 541 | 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)"; |
400 | 557 | } |
| 558 | + |
401 | 559 | 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; |
405 | 561 | } |
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__ ); |
413 | 562 | |
| 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 | + |
414 | 579 | foreach ( $res as $row ) { |
415 | 580 | if ( $row->r_type == 1 ) { |
416 | 581 | $r_type = 'friend'; |
— | — | @@ -419,7 +584,7 @@ |
420 | 585 | |
421 | 586 | $user_name_short = substr( $row->r_user_name, 0, 25 ); |
422 | 587 | if ( $row->r_user_name != $user_name_short ) { |
423 | | - $user_name_short .= '...'; |
| 588 | + $user_name_short .= wfMsg( 'ellipsis' ); |
424 | 589 | } |
425 | 590 | |
426 | 591 | $this->items_grouped[$r_type][$row->r_user_name_relation]['users'][$row->r_user_name][] = array( |
— | — | @@ -455,26 +620,49 @@ |
456 | 621 | |
457 | 622 | private function setMessagesSent() { |
458 | 623 | $dbr = wfGetDB( DB_SLAVE ); |
459 | | - $rel_sql = ''; |
460 | | - $user_sql = ''; |
461 | 624 | |
| 625 | + $where = array(); |
| 626 | + // We do *not* want to display private messages... |
| 627 | + $where['ub_type'] = 0; |
| 628 | + |
462 | 629 | 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)"; |
464 | 645 | } |
465 | 646 | |
466 | 647 | 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; |
468 | 649 | } |
469 | 650 | |
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 | + ); |
477 | 666 | |
478 | | - $res = $dbr->query( $sql, __METHOD__ ); |
479 | 667 | foreach ( $res as $row ) { |
480 | 668 | // Ignore nonexistent (for example, renamed) users |
481 | 669 | $uid = User::idFromName( $row->ub_user_name ); |
— | — | @@ -482,21 +670,23 @@ |
483 | 671 | continue; |
484 | 672 | } |
485 | 673 | |
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( |
487 | 677 | 'id' => $row->ub_id, |
488 | 678 | 'type' => 'user_message', |
489 | 679 | 'timestamp' => $row->item_date, |
490 | 680 | 'pagetitle' => '', |
491 | 681 | 'namespace' => '', |
492 | | - 'username' => stripslashes( $row->ub_user_name_from ), |
| 682 | + 'username' => $from, |
493 | 683 | 'userid' => $row->ub_user_id_from, |
494 | | - 'comment' => stripslashes( $row->ub_user_name ), |
| 684 | + 'comment' => $to, |
495 | 685 | 'minor' => 0, |
496 | 686 | 'new' => 0 |
497 | 687 | ); |
498 | 688 | |
499 | 689 | // 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; |
501 | 691 | |
502 | 692 | $this->items[] = array( |
503 | 693 | 'id' => $row->ub_id, |
— | — | @@ -504,9 +694,9 @@ |
505 | 695 | 'timestamp' => $row->item_date, |
506 | 696 | 'pagetitle' => '', |
507 | 697 | 'namespace' => $this->fixItemComment( $row->ub_message ), |
508 | | - 'username' => stripslashes( $row->ub_user_name_from ), |
| 698 | + 'username' => $from, |
509 | 699 | 'userid' => $row->ub_user_id_from, |
510 | | - 'comment' => stripslashes( $row->ub_user_name ), |
| 700 | + 'comment' => $to, |
511 | 701 | 'new' => '0', |
512 | 702 | 'minor' => 0 |
513 | 703 | ); |
— | — | @@ -515,28 +705,51 @@ |
516 | 706 | |
517 | 707 | private function setSystemMessages() { |
518 | 708 | $dbr = wfGetDB( DB_SLAVE ); |
519 | | - $rel_sql = ''; |
520 | | - $user_sql = ''; |
521 | 709 | |
| 710 | + $where = array(); |
| 711 | + |
522 | 712 | 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)"; |
524 | 728 | } |
525 | 729 | |
526 | 730 | if ( !empty( $this->show_current_user ) ) { |
527 | | - $user_sql = " WHERE um_user_id = {$this->user_id}"; |
| 731 | + $where['um_user_id'] = $this->user_id; |
528 | 732 | } |
529 | 733 | |
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 | + |
536 | 749 | foreach ( $res as $row ) { |
537 | 750 | $user_title = Title::makeTitle( NS_USER, $row->um_user_name ); |
538 | 751 | $user_name_short = substr( $row->um_user_name, 0, 15 ); |
539 | 752 | if ( $row->um_user_name != $user_name_short ) { |
540 | | - $user_name_short .= '...'; |
| 753 | + $user_name_short .= wfMsg( 'ellipsis' ); |
541 | 754 | } |
542 | 755 | $this->activityLines[] = array( |
543 | 756 | 'type' => 'system_message', |
— | — | @@ -703,7 +916,12 @@ |
704 | 917 | $pages .= " <a href=\"{$page_title->escapeFullURL()}\">{$page_name}</a>"; |
705 | 918 | if ( $count_users == 1 && $count_actions > 1 ) { |
706 | 919 | $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 | + ) ); |
708 | 926 | } |
709 | 927 | $pages_count++; |
710 | 928 | } |
— | — | @@ -737,7 +955,9 @@ |
738 | 956 | $pages .= " <a href=\"{$page_title2->escapeFullURL()}\">{$page_name2}</a>"; |
739 | 957 | } |
740 | 958 | if ( $count_actions2 > 1 ) { |
741 | | - $pages .= ' (' . wfMsg( "useractivity-group-{$type}", $count_actions2 ) . ')'; |
| 959 | + $pages .= ' (' . wfMsg( |
| 960 | + "useractivity-group-{$type}", $count_actions2 |
| 961 | + ) . ')'; |
742 | 962 | } |
743 | 963 | $pages_count++; |
744 | 964 | |
— | — | @@ -772,7 +992,8 @@ |
773 | 993 | 'data' => wfMsgExt( |
774 | 994 | "useractivity-{$type}", |
775 | 995 | 'parsemag', |
776 | | - $users, $count_users, $pages, $pages_count, $userNameForGender |
| 996 | + $users, $count_users, $pages, $pages_count, |
| 997 | + $userNameForGender |
777 | 998 | ) |
778 | 999 | ); |
779 | 1000 | } |
— | — | @@ -811,11 +1032,11 @@ |
812 | 1033 | $comment = str_replace( '<', '<', $comment ); |
813 | 1034 | $comment = str_replace( '>', '>', $comment ); |
814 | 1035 | $comment = str_replace( '&', '%26', $comment ); |
815 | | - $comment = str_replace( '%26quot;', "\"", $comment ); |
| 1036 | + $comment = str_replace( '%26quot;', '"', $comment ); |
816 | 1037 | } |
817 | 1038 | $preview = substr( $comment, 0, 75 ); |
818 | 1039 | if ( $preview != $comment ) { |
819 | | - $preview .= '...'; |
| 1040 | + $preview .= wfMsg( 'ellipsis' ); |
820 | 1041 | } |
821 | 1042 | return stripslashes( $preview ); |
822 | 1043 | } |