r84617 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84616‎ | r84617 | r84618 >
Date:18:05, 23 March 2011
Author:ashley
Status:reverted (Comments)
Tags:
Comment:
SocialProfile: remove last raw SQL bits from UserBoard. Untested.
Modified paths:
  • /trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php
@@ -255,40 +255,49 @@
256256
257257 public function getUserBoardMessages( $user_id, $user_id_2 = 0, $limit = 0, $page = 0 ) {
258258 global $wgUser, $wgOut, $wgTitle;
 259+
259260 $dbr = wfGetDB( DB_SLAVE );
260261
261 - if ( $limit > 0 ) {
262 - $limitvalue = 0;
263 - if ( $page ) {
264 - $limitvalue = $page * $limit - ( $limit );
265 - }
266 - $limit_sql = " LIMIT {$limitvalue},{$limit} ";
 262+ $where = array();
 263+ $limitvalue = 0;
 264+ if ( $limit > 0 && $page ) {
 265+ $limitvalue = $page * $limit - ( $limit );
267266 }
268267
269268 if ( $user_id_2 ) {
270 - $user_sql = "( (ub_user_id={$user_id} AND ub_user_id_from={$user_id_2}) OR
 269+ $where[] = "( (ub_user_id={$user_id} AND ub_user_id_from={$user_id_2}) OR
271270 (ub_user_id={$user_id_2} AND ub_user_id_from={$user_id}) )";
272271 if ( !( $user_id == $wgUser->getID() || $user_id_2 == $wgUser->getID() ) ) {
273 - $user_sql .= " AND ub_type = 0 ";
 272+ $where['ub_type'] = 0;
274273 }
275274 } else {
276 - $user_sql = "ub_user_id = {$user_id}";
 275+ $where['ub_user_id'] = $user_id;
277276 if ( $user_id != $wgUser->getID() ) {
278 - $user_sql .= " AND ub_type = 0 ";
 277+ $where['ub_type'] = 0;
279278 }
280279 if ( $wgUser->isLoggedIn() ) {
281 - $user_sql .= " OR (ub_user_id={$user_id} AND ub_user_id_from={$wgUser->getID() }) ";
 280+ $where[] = " OR (ub_user_id={$user_id} AND ub_user_id_from={$wgUser->getID()}) ";
282281 }
283282 }
284283
285 - $sql = "SELECT ub_id, ub_user_id_from, ub_user_name_from, ub_user_id, ub_user_name,
286 - ub_message,UNIX_TIMESTAMP(ub_date) AS unix_time,ub_type
287 - FROM {$dbr->tableName( 'user_board' )}
288 - WHERE {$user_sql}
289 - ORDER BY ub_id DESC
290 - {$limit_sql}";
291 - $res = $dbr->query( $sql, __METHOD__ );
 284+ $res = $dbr->select(
 285+ 'user_board',
 286+ array(
 287+ 'ub_id', 'ub_user_id_from', 'ub_user_name_from', 'ub_user_id',
 288+ 'ub_user_name', 'ub_message',
 289+ 'UNIX_TIMESTAMP(ub_date) AS unix_time', 'ub_type'
 290+ ),
 291+ $where,
 292+ __METHOD__,
 293+ array(
 294+ 'ORDER BY' => 'ub_id DESC',
 295+ 'LIMIT' => $limitvalue,
 296+ 'OFFSET' => $limit
 297+ )
 298+ );
 299+
292300 $messages = array();
 301+
293302 foreach ( $res as $row ) {
294303 $parser = new Parser();
295304 $message_text = $parser->parse( $row->ub_message, $wgTitle, $wgOut->parserOptions(), true );
@@ -305,6 +314,7 @@
306315 'type' => $row->ub_type
307316 );
308317 }
 318+
309319 return $messages;
310320 }
311321
@@ -312,21 +322,26 @@
313323 global $wgUser;
314324 $dbr = wfGetDB( DB_SLAVE );
315325
316 - $user_sql = " ( (ub_user_id={$user_id} AND ub_user_id_from={$user_id_2}) OR
 326+ $where = array();
 327+ $where = " ( (ub_user_id={$user_id} AND ub_user_id_from={$user_id_2}) OR
317328 (ub_user_id={$user_id_2} AND ub_user_id_from={$user_id}) )";
318329
319330 if ( !( $user_id == $wgUser->getID() || $user_id_2 == $wgUser->getID() ) ) {
320 - $user_sql .= " AND ub_type = 0 ";
 331+ $where['ub_type'] = 0;
321332 }
322 - $sql = "SELECT count(*) AS the_count
323 - FROM {$dbr->tableName( 'user_board' )}
324 - WHERE {$user_sql}";
325333
326 - $res = $dbr->query( $sql, __METHOD__ );
 334+ $res = $dbr->select(
 335+ 'user_board',
 336+ 'COUNT(*) AS the_count',
 337+ $where,
 338+ __METHOD__
 339+ );
 340+
327341 $row = $dbr->fetchObject( $res );
328342 if ( $row ) {
329343 $count = $row->the_count;
330344 }
 345+
331346 return $count;
332347 }
333348
@@ -347,12 +362,17 @@
348363 $delete_link = '';
349364
350365 if ( $wgUser->getName() != $message['user_name_from'] ) {
351 - $board_to_board = '<a href="' . UserBoard::getUserBoardToBoardURL( $message['user_name'], $message['user_name_from'] ) . '">' . wfMsgHtml( 'userboard_board-to-board' ) . '</a>';
352 - $board_link = '<a href="' . UserBoard::getUserBoardURL( $message['user_name_from'] ) . '">' . wfMsgHtml( 'userboard_sendmessage', $message['user_name_from'] ) . '</a>';
 366+ $board_to_board = '<a href="' . UserBoard::getUserBoardToBoardURL(
 367+ $message['user_name'],
 368+ $message['user_name_from']
 369+ ) . '">' . wfMsgHtml( 'userboard_board-to-board' ) . '</a>';
 370+ $board_link = '<a href="' . UserBoard::getUserBoardURL( $message['user_name_from'] ) . '">' .
 371+ wfMsgHtml( 'userboard_sendmessage', $message['user_name_from'] ) . '</a>';
353372 }
354373 if ( $wgUser->getName() == $message['user_name'] || $wgUser->isAllowed( 'userboard-delete' ) ) {
355374 $delete_link = "<span class=\"user-board-red\">
356 - <a href=\"javascript:void(0);\" onclick=\"javascript:delete_message({$message['id']})\">" . wfMsgHtml( 'userboard_delete' ) . '</a>
 375+ <a href=\"javascript:void(0);\" onclick=\"javascript:delete_message({$message['id']})\">" .
 376+ wfMsgHtml( 'userboard_delete' ) . '</a>
357377 </span>';
358378 }
359379 if ( $message['type'] == 1 ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r84806SocialProfile: revert r84617, causes bug #28251. Some Database wizard can rew...ashley17:45, 26 March 2011

Comments

#Comment by Jack Phoenix (talk | contribs)   23:46, 23 March 2011

I'd like to get this commit reviewed.

Status & tagging log