r84806 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84805‎ | r84806 | r84807 >
Date:17:45, 26 March 2011
Author:ashley
Status:deferred
Tags:
Comment:
SocialProfile: revert r84617, causes bug #28251. Some Database wizard can rewrite this to use the proper Database functions, it's way beyond me
Modified paths:
  • /trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php
@@ -255,49 +255,40 @@
256256
257257 public function getUserBoardMessages( $user_id, $user_id_2 = 0, $limit = 0, $page = 0 ) {
258258 global $wgUser, $wgOut, $wgTitle;
259 -
260259 $dbr = wfGetDB( DB_SLAVE );
261260
262 - $where = array();
263 - $limitvalue = 0;
264 - if ( $limit > 0 && $page ) {
265 - $limitvalue = $page * $limit - ( $limit );
 261+ if ( $limit > 0 ) {
 262+ $limitvalue = 0;
 263+ if ( $page ) {
 264+ $limitvalue = $page * $limit - ( $limit );
 265+ }
 266+ $limit_sql = " LIMIT {$limitvalue},{$limit} ";
266267 }
267268
268269 if ( $user_id_2 ) {
269 - $where[] = "( (ub_user_id={$user_id} AND ub_user_id_from={$user_id_2}) OR
 270+ $user_sql = "( (ub_user_id={$user_id} AND ub_user_id_from={$user_id_2}) OR
270271 (ub_user_id={$user_id_2} AND ub_user_id_from={$user_id}) )";
271272 if ( !( $user_id == $wgUser->getID() || $user_id_2 == $wgUser->getID() ) ) {
272 - $where['ub_type'] = 0;
 273+ $user_sql .= " AND ub_type = 0 ";
273274 }
274275 } else {
275 - $where['ub_user_id'] = $user_id;
 276+ $user_sql = "ub_user_id = {$user_id}";
276277 if ( $user_id != $wgUser->getID() ) {
277 - $where['ub_type'] = 0;
 278+ $user_sql .= " AND ub_type = 0 ";
278279 }
279280 if ( $wgUser->isLoggedIn() ) {
280 - $where[] = " OR (ub_user_id={$user_id} AND ub_user_id_from={$wgUser->getID()}) ";
 281+ $user_sql .= " OR (ub_user_id={$user_id} AND ub_user_id_from={$wgUser->getID() }) ";
281282 }
282283 }
283284
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 -
 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__ );
300292 $messages = array();
301 -
302293 foreach ( $res as $row ) {
303294 $parser = new Parser();
304295 $message_text = $parser->parse( $row->ub_message, $wgTitle, $wgOut->parserOptions(), true );
@@ -314,7 +305,6 @@
315306 'type' => $row->ub_type
316307 );
317308 }
318 -
319309 return $messages;
320310 }
321311
@@ -322,26 +312,21 @@
323313 global $wgUser;
324314 $dbr = wfGetDB( DB_SLAVE );
325315
326 - $where = array();
327 - $where = " ( (ub_user_id={$user_id} AND ub_user_id_from={$user_id_2}) OR
 316+ $user_sql = " ( (ub_user_id={$user_id} AND ub_user_id_from={$user_id_2}) OR
328317 (ub_user_id={$user_id_2} AND ub_user_id_from={$user_id}) )";
329318
330319 if ( !( $user_id == $wgUser->getID() || $user_id_2 == $wgUser->getID() ) ) {
331 - $where['ub_type'] = 0;
 320+ $user_sql .= " AND ub_type = 0 ";
332321 }
 322+ $sql = "SELECT count(*) AS the_count
 323+ FROM {$dbr->tableName( 'user_board' )}
 324+ WHERE {$user_sql}";
333325
334 - $res = $dbr->select(
335 - 'user_board',
336 - 'COUNT(*) AS the_count',
337 - $where,
338 - __METHOD__
339 - );
340 -
 326+ $res = $dbr->query( $sql, __METHOD__ );
341327 $row = $dbr->fetchObject( $res );
342328 if ( $row ) {
343329 $count = $row->the_count;
344330 }
345 -
346331 return $count;
347332 }
348333
@@ -362,17 +347,12 @@
363348 $delete_link = '';
364349
365350 if ( $wgUser->getName() != $message['user_name_from'] ) {
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>';
 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>';
372353 }
373354 if ( $wgUser->getName() == $message['user_name'] || $wgUser->isAllowed( 'userboard-delete' ) ) {
374355 $delete_link = "<span class=\"user-board-red\">
375 - <a href=\"javascript:void(0);\" onclick=\"javascript:delete_message({$message['id']})\">" .
376 - wfMsgHtml( 'userboard_delete' ) . '</a>
 356+ <a href=\"javascript:void(0);\" onclick=\"javascript:delete_message({$message['id']})\">" . wfMsgHtml( 'userboard_delete' ) . '</a>
377357 </span>';
378358 }
379359 if ( $message['type'] == 1 ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84617SocialProfile: remove last raw SQL bits from UserBoard. Untested.ashley18:05, 23 March 2011

Status & tagging log