Index: trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php |
— | — | @@ -255,49 +255,40 @@ |
256 | 256 | |
257 | 257 | public function getUserBoardMessages( $user_id, $user_id_2 = 0, $limit = 0, $page = 0 ) { |
258 | 258 | global $wgUser, $wgOut, $wgTitle; |
259 | | - |
260 | 259 | $dbr = wfGetDB( DB_SLAVE ); |
261 | 260 | |
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} "; |
266 | 267 | } |
267 | 268 | |
268 | 269 | 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 |
270 | 271 | (ub_user_id={$user_id_2} AND ub_user_id_from={$user_id}) )"; |
271 | 272 | if ( !( $user_id == $wgUser->getID() || $user_id_2 == $wgUser->getID() ) ) { |
272 | | - $where['ub_type'] = 0; |
| 273 | + $user_sql .= " AND ub_type = 0 "; |
273 | 274 | } |
274 | 275 | } else { |
275 | | - $where['ub_user_id'] = $user_id; |
| 276 | + $user_sql = "ub_user_id = {$user_id}"; |
276 | 277 | if ( $user_id != $wgUser->getID() ) { |
277 | | - $where['ub_type'] = 0; |
| 278 | + $user_sql .= " AND ub_type = 0 "; |
278 | 279 | } |
279 | 280 | 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() }) "; |
281 | 282 | } |
282 | 283 | } |
283 | 284 | |
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__ ); |
300 | 292 | $messages = array(); |
301 | | - |
302 | 293 | foreach ( $res as $row ) { |
303 | 294 | $parser = new Parser(); |
304 | 295 | $message_text = $parser->parse( $row->ub_message, $wgTitle, $wgOut->parserOptions(), true ); |
— | — | @@ -314,7 +305,6 @@ |
315 | 306 | 'type' => $row->ub_type |
316 | 307 | ); |
317 | 308 | } |
318 | | - |
319 | 309 | return $messages; |
320 | 310 | } |
321 | 311 | |
— | — | @@ -322,26 +312,21 @@ |
323 | 313 | global $wgUser; |
324 | 314 | $dbr = wfGetDB( DB_SLAVE ); |
325 | 315 | |
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 |
328 | 317 | (ub_user_id={$user_id_2} AND ub_user_id_from={$user_id}) )"; |
329 | 318 | |
330 | 319 | if ( !( $user_id == $wgUser->getID() || $user_id_2 == $wgUser->getID() ) ) { |
331 | | - $where['ub_type'] = 0; |
| 320 | + $user_sql .= " AND ub_type = 0 "; |
332 | 321 | } |
| 322 | + $sql = "SELECT count(*) AS the_count |
| 323 | + FROM {$dbr->tableName( 'user_board' )} |
| 324 | + WHERE {$user_sql}"; |
333 | 325 | |
334 | | - $res = $dbr->select( |
335 | | - 'user_board', |
336 | | - 'COUNT(*) AS the_count', |
337 | | - $where, |
338 | | - __METHOD__ |
339 | | - ); |
340 | | - |
| 326 | + $res = $dbr->query( $sql, __METHOD__ ); |
341 | 327 | $row = $dbr->fetchObject( $res ); |
342 | 328 | if ( $row ) { |
343 | 329 | $count = $row->the_count; |
344 | 330 | } |
345 | | - |
346 | 331 | return $count; |
347 | 332 | } |
348 | 333 | |
— | — | @@ -362,17 +347,12 @@ |
363 | 348 | $delete_link = ''; |
364 | 349 | |
365 | 350 | 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>'; |
372 | 353 | } |
373 | 354 | if ( $wgUser->getName() == $message['user_name'] || $wgUser->isAllowed( 'userboard-delete' ) ) { |
374 | 355 | $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> |
377 | 357 | </span>'; |
378 | 358 | } |
379 | 359 | if ( $message['type'] == 1 ) { |