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