r85507 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85506‎ | r85507 | r85508 >
Date:01:48, 6 April 2011
Author:ashley
Status:deferred
Tags:
Comment:
SocialProfile: remove an unused global, document a few functions, add FIXMEs, rename some variables and break some long lines
Modified paths:
  • /trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php
@@ -149,11 +149,12 @@
150150 * @return Integer: amount of new messages
151151 */
152152 static function getNewMessageCountDB( $user_id ) {
 153+ global $wgMemc;
 154+
153155 wfDebug( "Got new message count for id $user_id from DB\n" );
154156
155 - global $wgMemc;
156157 $key = wfMemcKey( 'user', 'newboardmessage', $user_id );
157 - $new_count = 0;
 158+ $newCount = 0;
158159 /* @todo FIXME: why is this commented out? This obviously should be
159160 enabled, because without this, this function is basically identical
160161 to clearNewMessagesCount...
@@ -165,13 +166,13 @@
166167 __METHOD__
167168 );
168169 if ( $s !== false ) {
169 - $new_count = $s->count;
 170+ $newCount = $s->count;
170171 }
171172 */
172173
173 - $wgMemc->set( $key, $new_count );
 174+ $wgMemc->set( $key, $newCount );
174175
175 - return $new_count;
 176+ return $newCount;
176177 }
177178
178179 /**
@@ -185,7 +186,6 @@
186187 * @return Integer: amount of new messages
187188 */
188189 static function getNewMessageCount( $user_id ) {
189 - global $wgMemc;
190190 $data = self::getNewMessageCountCache( $user_id );
191191
192192 if ( $data != '' ) {
@@ -253,6 +253,19 @@
254254 }
255255 }
256256
 257+ /**
 258+ * Get the user board messages for the user with the ID $user_id.
 259+ *
 260+ * @todo FIXME: rewrite this function to be compatible with non-MySQL DBMS
 261+ * @param $user_id Integer: user ID number
 262+ * @param $user_id_2 Integer: user ID number of the second user; only used
 263+ * in board-to-board stuff
 264+ * @param $limit Integer: used to build the LIMIT and OFFSET for the SQL
 265+ * query
 266+ * @param $page Integer: used to build the LIMIT and OFFSET for the SQL
 267+ * query
 268+ * @return Array: array of user board messages
 269+ */
257270 public function getUserBoardMessages( $user_id, $user_id_2 = 0, $limit = 0, $page = 0 ) {
258271 global $wgUser, $wgOut, $wgTitle;
259272 $dbr = wfGetDB( DB_SLAVE );
@@ -269,12 +282,12 @@
270283 $user_sql = "( (ub_user_id={$user_id} AND ub_user_id_from={$user_id_2}) OR
271284 (ub_user_id={$user_id_2} AND ub_user_id_from={$user_id}) )";
272285 if ( !( $user_id == $wgUser->getID() || $user_id_2 == $wgUser->getID() ) ) {
273 - $user_sql .= " AND ub_type = 0 ";
 286+ $user_sql .= ' AND ub_type = 0 ';
274287 }
275288 } else {
276289 $user_sql = "ub_user_id = {$user_id}";
277290 if ( $user_id != $wgUser->getID() ) {
278 - $user_sql .= " AND ub_type = 0 ";
 291+ $user_sql .= ' AND ub_type = 0 ';
279292 }
280293 if ( $wgUser->isLoggedIn() ) {
281294 $user_sql .= " OR (ub_user_id={$user_id} AND ub_user_id_from={$wgUser->getID() }) ";
@@ -308,17 +321,27 @@
309322 return $messages;
310323 }
311324
 325+ /**
 326+ * Get the amount of board-to-board messages sent between the users whose
 327+ * IDs are $user_id and $user_id_2.
 328+ *
 329+ * @todo FIXME: rewrite this function to be compatible with non-MySQL DBMS
 330+ * @param $user_id Integer: user ID of the first user
 331+ * @param $user_id_2 Integer: user ID of the second user
 332+ * @return Integer: the amount of board-to-board messages
 333+ */
312334 public function getUserBoardToBoardCount( $user_id, $user_id_2 ) {
313335 global $wgUser;
 336+
314337 $dbr = wfGetDB( DB_SLAVE );
315338
316339 $user_sql = " ( (ub_user_id={$user_id} AND ub_user_id_from={$user_id_2}) OR
317340 (ub_user_id={$user_id_2} AND ub_user_id_from={$user_id}) )";
318341
319342 if ( !( $user_id == $wgUser->getID() || $user_id_2 == $wgUser->getID() ) ) {
320 - $user_sql .= " AND ub_type = 0 ";
 343+ $user_sql .= ' AND ub_type = 0 ';
321344 }
322 - $sql = "SELECT count(*) AS the_count
 345+ $sql = "SELECT COUNT(*) AS the_count
323346 FROM {$dbr->tableName( 'user_board' )}
324347 WHERE {$user_sql}";
325348
@@ -336,7 +359,6 @@
337360 $output = ''; // Prevent E_NOTICE
338361 $messages = $this->getUserBoardMessages( $user_id, $user_id_2, $count, $page );
339362 if ( $messages ) {
340 -
341363 foreach ( $messages as $message ) {
342364 $user = Title::makeTitle( NS_USER, $message['user_name_from'] );
343365 $avatar = new wAvatar( $message['user_id_from'], 'm' );
@@ -347,12 +369,15 @@
348370 $delete_link = '';
349371
350372 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>';
 373+ $board_to_board = '<a href="' . UserBoard::getUserBoardToBoardURL( $message['user_name'], $message['user_name_from'] ) . '">' .
 374+ wfMsgHtml( 'userboard_board-to-board' ) . '</a>';
 375+ $board_link = '<a href="' . UserBoard::getUserBoardURL( $message['user_name_from'] ) . '">' .
 376+ wfMsgHtml( 'userboard_sendmessage', $message['user_name_from'] ) . '</a>';
353377 }
354378 if ( $wgUser->getName() == $message['user_name'] || $wgUser->isAllowed( 'userboard-delete' ) ) {
355379 $delete_link = "<span class=\"user-board-red\">
356 - <a href=\"javascript:void(0);\" onclick=\"javascript:delete_message({$message['id']})\">" . wfMsgHtml( 'userboard_delete' ) . '</a>
 380+ <a href=\"javascript:void(0);\" onclick=\"javascript:delete_message({$message['id']})\">" .
 381+ wfMsgHtml( 'userboard_delete' ) . '</a>
357382 </span>';
358383 }
359384 if ( $message['type'] == 1 ) {
@@ -386,8 +411,8 @@
387412 </div>";
388413 }
389414 } elseif ( $wgUser->getName() == $wgTitle->getText() ) {
390 - $output .= '<div class="no-info-container">'
391 - . wfMsgHtml( 'userboard_nomessages' ) .
 415+ $output .= '<div class="no-info-container">' .
 416+ wfMsgHtml( 'userboard_nomessages' ) .
392417 '</div>';
393418
394419 }

Status & tagging log