Index: trunk/phase3/includes/LogEventsList.php |
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | |
21 | 21 | class LogEventsList { |
22 | 22 | const NO_ACTION_LINK = 1; |
| 23 | + const NO_EXTRA_USER_LINKS = 2; |
23 | 24 | |
24 | 25 | private $skin; |
25 | 26 | private $out; |
— | — | @@ -271,38 +272,90 @@ |
272 | 273 | * @return String: Formatted HTML list item |
273 | 274 | */ |
274 | 275 | public function logLine( $row ) { |
275 | | - global $wgLang, $wgUser, $wgContLang; |
| 276 | + $classes = array( 'mw-logline-' . $row->log_type ); |
| 277 | + $title = Title::makeTitle( $row->log_namespace, $row->log_title ); |
| 278 | + // Log time |
| 279 | + $time = $this->logTimestamp( $row ); |
| 280 | + // User links |
| 281 | + $userLink = $this->logUserLinks( $row ); |
| 282 | + // Extract extra parameters |
| 283 | + $paramArray = LogPage::extractParams( $row->log_params ); |
| 284 | + // Event description |
| 285 | + $action = $this->logAction( $row, $title, $paramArray ); |
| 286 | + // Log comment |
| 287 | + $comment = $this->logComment( $row ); |
| 288 | + // Add review/revert links and such... |
| 289 | + $revert = $this->logActionLinks( $row, $title, $paramArray, $comment ); |
276 | 290 | |
277 | | - $title = Title::makeTitle( $row->log_namespace, $row->log_title ); |
278 | | - $classes = array( "mw-logline-{$row->log_type}" ); |
| 291 | + // Some user can hide log items and have review links |
| 292 | + $del = $this->getShowHideLinks( $row ); |
| 293 | + if( $del != '' ) $del .= ' '; |
| 294 | + |
| 295 | + // Any tags... |
| 296 | + list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'logevent' ); |
| 297 | + $classes = array_merge( $classes, $newClasses ); |
| 298 | + |
| 299 | + return Xml::tags( 'li', array( "class" => implode( ' ', $classes ) ), |
| 300 | + $del . "$time $userLink $action $comment $revert $tagDisplay" ) . "\n"; |
| 301 | + } |
| 302 | + |
| 303 | + private function logTimestamp( $row ) { |
| 304 | + global $wgLang; |
279 | 305 | $time = $wgLang->timeanddate( wfTimestamp( TS_MW, $row->log_timestamp ), true ); |
280 | | - // User links |
| 306 | + return htmlspecialchars( $time ); |
| 307 | + } |
| 308 | + |
| 309 | + private function logUserLinks( $row ) { |
| 310 | + $userLinks = ''; |
281 | 311 | if( self::isDeleted( $row, LogPage::DELETED_USER ) ) { |
282 | | - $userLink = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>'; |
| 312 | + $userLinks = '<span class="history-deleted">' . |
| 313 | + wfMsgHtml( 'rev-deleted-user' ) . '</span>'; |
283 | 314 | } else { |
284 | | - $userLink = $this->skin->userLink( $row->log_user, $row->user_name ) . |
285 | | - $this->skin->userToolLinks( $row->log_user, $row->user_name, true, 0, $row->user_editcount ); |
| 315 | + $userLinks = $this->skin->userLink( $row->log_user, $row->user_name ); |
| 316 | + // Talk|Contribs links... |
| 317 | + if( !( $this->flags & self::NO_EXTRA_USER_LINKS ) ) { |
| 318 | + $userLinks .= $this->skin->userToolLinks( |
| 319 | + $row->log_user, $row->user_name, true, 0, $row->user_editcount ); |
| 320 | + } |
286 | 321 | } |
287 | | - // Comment |
| 322 | + return $userLinks; |
| 323 | + } |
| 324 | + |
| 325 | + private function logAction( $row, $title, $paramArray ) { |
| 326 | + $action = ''; |
| 327 | + if( self::isDeleted( $row, LogPage::DELETED_ACTION ) ) { |
| 328 | + $action = '<span class="history-deleted">' . |
| 329 | + wfMsgHtml( 'rev-deleted-event' ) . '</span>'; |
| 330 | + } else { |
| 331 | + $action = LogPage::actionText( |
| 332 | + $row->log_type, $row->log_action, $title, $this->skin, $paramArray, true ); |
| 333 | + } |
| 334 | + return $action; |
| 335 | + } |
| 336 | + |
| 337 | + private function logComment( $row ) { |
| 338 | + global $wgContLang; |
| 339 | + $comment = ''; |
288 | 340 | if( self::isDeleted( $row, LogPage::DELETED_COMMENT ) ) { |
289 | | - $comment = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>'; |
| 341 | + $comment = '<span class="history-deleted">' . |
| 342 | + wfMsgHtml( 'rev-deleted-comment' ) . '</span>'; |
290 | 343 | } else { |
291 | | - $comment = $wgContLang->getDirMark() . $this->skin->commentBlock( $row->log_comment ); |
| 344 | + $comment = $wgContLang->getDirMark() . |
| 345 | + $this->skin->commentBlock( $row->log_comment ); |
292 | 346 | } |
293 | | - // Extract extra parameters |
294 | | - $paramArray = LogPage::extractParams( $row->log_params ); |
295 | | - $revert = $del = ''; |
296 | | - // Some user can hide log items and have review links |
297 | | - if( !( $this->flags & self::NO_ACTION_LINK ) && $wgUser->isAllowed( 'deletedhistory' ) ) { |
298 | | - // Don't show useless link to people who cannot hide revisions |
299 | | - if( $row->log_deleted || $wgUser->isAllowed( 'deleterevision' ) ) { |
300 | | - $del = $this->getShowHideLinks( $row ) . ' '; |
301 | | - } |
| 347 | + return $comment; |
| 348 | + } |
| 349 | + |
| 350 | + // @TODO: split up! |
| 351 | + private function logActionLinks( $row, $title, $paramArray, &$comment ) { |
| 352 | + global $wgUser, $wgLang; |
| 353 | + if( ( $this->flags & self::NO_ACTION_LINK ) // we don't want to see the action |
| 354 | + || self::isDeleted( $row, LogPage::DELETED_ACTION ) ) // action is hidden |
| 355 | + { |
| 356 | + return ''; |
302 | 357 | } |
303 | | - // Add review links and such... |
304 | | - if( ( $this->flags & self::NO_ACTION_LINK ) || ( $row->log_deleted & LogPage::DELETED_ACTION ) ) { |
305 | | - // Action text is suppressed... |
306 | | - } else if( self::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) { |
| 358 | + $revert = ''; |
| 359 | + if( self::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) { |
307 | 360 | $destTitle = Title::newFromText( $paramArray[0] ); |
308 | 361 | if( $destTitle ) { |
309 | 362 | $revert = '(' . $this->skin->link( |
— | — | @@ -312,7 +365,7 @@ |
313 | 366 | array( |
314 | 367 | 'wpOldTitle' => $destTitle->getPrefixedDBkey(), |
315 | 368 | 'wpNewTitle' => $title->getPrefixedDBkey(), |
316 | | - 'wpReason' => wfMsgForContent( 'revertmove' ), |
| 369 | + 'wpReason' => wfMsgForContent( 'revertmove' ), |
317 | 370 | 'wpMovetalk' => 0 |
318 | 371 | ), |
319 | 372 | array( 'known', 'noclasses' ) |
— | — | @@ -325,7 +378,6 @@ |
326 | 379 | } else { |
327 | 380 | $viewdeleted = $this->message['undeletelink']; |
328 | 381 | } |
329 | | - |
330 | 382 | $revert = '(' . $this->skin->link( |
331 | 383 | SpecialPage::getTitleFor( 'Undelete' ), |
332 | 384 | $viewdeleted, |
— | — | @@ -377,9 +429,8 @@ |
378 | 430 | $revert .= ')'; |
379 | 431 | // Show unmerge link |
380 | 432 | } else if( self::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) { |
381 | | - $merge = SpecialPage::getTitleFor( 'Mergehistory' ); |
382 | 433 | $revert = '(' . $this->skin->link( |
383 | | - $merge, |
| 434 | + SpecialPage::getTitleFor( 'Mergehistory' ), |
384 | 435 | $this->message['revertmerge'], |
385 | 436 | array(), |
386 | 437 | array( |
— | — | @@ -470,7 +521,8 @@ |
471 | 522 | # Fall back to a blue contributions link |
472 | 523 | $revert = $this->skin->userToolLinks( 1, $title->getDBkey() ); |
473 | 524 | } |
474 | | - if( $time < '20080129000000' ) { |
| 525 | + $ts = wfTimestamp( TS_UNIX, $row->log_timestamp ); |
| 526 | + if( $ts < '20080129000000' ) { |
475 | 527 | # Suppress $comment from old entries (before 2008-01-29), |
476 | 528 | # not needed and can contain incorrect links |
477 | 529 | $comment = ''; |
— | — | @@ -480,26 +532,10 @@ |
481 | 533 | wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray, |
482 | 534 | &$comment, &$revert, $row->log_timestamp ) ); |
483 | 535 | } |
484 | | - // Event description |
485 | | - if( self::isDeleted( $row, LogPage::DELETED_ACTION ) ) { |
486 | | - $action = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>'; |
487 | | - } else { |
488 | | - $action = LogPage::actionText( $row->log_type, $row->log_action, $title, |
489 | | - $this->skin, $paramArray, true ); |
490 | | - } |
491 | | - |
492 | | - // Any tags... |
493 | | - list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'logevent' ); |
494 | | - $classes = array_merge( $classes, $newClasses ); |
495 | | - |
496 | 536 | if( $revert != '' ) { |
497 | 537 | $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>'; |
498 | 538 | } |
499 | | - |
500 | | - $time = htmlspecialchars( $time ); |
501 | | - |
502 | | - return Xml::tags( 'li', array( "class" => implode( ' ', $classes ) ), |
503 | | - $del . $time . ' ' . $userLink . ' ' . $action . ' ' . $comment . ' ' . $revert . " $tagDisplay" ) . "\n"; |
| 539 | + return $revert; |
504 | 540 | } |
505 | 541 | |
506 | 542 | /** |
— | — | @@ -508,23 +544,30 @@ |
509 | 545 | */ |
510 | 546 | private function getShowHideLinks( $row ) { |
511 | 547 | global $wgUser; |
512 | | - if( $row->log_type == 'suppress' ) { |
513 | | - return ''; // No one can hide items from the oversight log |
| 548 | + if( ( $this->flags & self::NO_ACTION_LINK ) // we don't want to see the links |
| 549 | + || $row->log_type == 'suppress' ) // no one can hide items from the suppress log |
| 550 | + { |
| 551 | + return ''; |
514 | 552 | } |
515 | | - $canHide = $wgUser->isAllowed( 'deleterevision' ); |
516 | | - // If event was hidden from sysops |
517 | | - if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) { |
518 | | - $del = $this->skin->revDeleteLinkDisabled( $canHide ); |
519 | | - } else { |
520 | | - $target = SpecialPage::getTitleFor( 'Log', $row->log_type ); |
521 | | - $page = Title::makeTitle( $row->log_namespace, $row->log_title ); |
522 | | - $query = array( |
523 | | - 'target' => $target->getPrefixedDBkey(), |
524 | | - 'type' => 'logging', |
525 | | - 'ids' => $row->log_id, |
526 | | - ); |
527 | | - $del = $this->skin->revDeleteLink( $query, |
528 | | - self::isDeleted( $row, LogPage::DELETED_RESTRICTED ), $canHide ); |
| 553 | + $del = ''; |
| 554 | + // Don't show useless link to people who cannot hide revisions |
| 555 | + if( $wgUser->isAllowed( 'deletedhistory' ) ) { |
| 556 | + if( $row->log_deleted || $wgUser->isAllowed( 'deleterevision' ) ) { |
| 557 | + $canHide = $wgUser->isAllowed( 'deleterevision' ); |
| 558 | + // If event was hidden from sysops |
| 559 | + if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) { |
| 560 | + $del = $this->skin->revDeleteLinkDisabled( $canHide ); |
| 561 | + } else { |
| 562 | + $target = SpecialPage::getTitleFor( 'Log', $row->log_type ); |
| 563 | + $query = array( |
| 564 | + 'target' => $target->getPrefixedDBkey(), |
| 565 | + 'type' => 'logging', |
| 566 | + 'ids' => $row->log_id, |
| 567 | + ); |
| 568 | + $del = $this->skin->revDeleteLink( $query, |
| 569 | + self::isDeleted( $row, LogPage::DELETED_RESTRICTED ), $canHide ); |
| 570 | + } |
| 571 | + } |
529 | 572 | } |
530 | 573 | return $del; |
531 | 574 | } |
— | — | @@ -609,38 +652,41 @@ |
610 | 653 | * that are processed with wgMsgExt and option 'parse' |
611 | 654 | * - offset Set to overwrite offset parameter in $wgRequest |
612 | 655 | * set to '' to unset offset |
613 | | - * - wrap String: Wrap the message in html (usually something like "<div ...>$1</div>"). |
| 656 | + * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>"). |
| 657 | + * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS) |
614 | 658 | * @return Integer Number of total log items (not limited by $lim) |
615 | 659 | */ |
616 | | - public static function showLogExtract( &$out, $types=array(), $page='', $user='', |
617 | | - $param = array() ) { |
618 | | - |
| 660 | + public static function showLogExtract( |
| 661 | + &$out, $types=array(), $page='', $user='', $param = array() |
| 662 | + ) { |
| 663 | + global $wgUser, $wgOut; |
619 | 664 | $defaultParameters = array( |
620 | 665 | 'lim' => 25, |
621 | 666 | 'conds' => array(), |
622 | 667 | 'showIfEmpty' => true, |
623 | 668 | 'msgKey' => array(''), |
624 | | - 'wrap' => "$1" |
| 669 | + 'wrap' => "$1", |
| 670 | + 'flags' => 0 |
625 | 671 | ); |
626 | | - |
627 | 672 | # The + operator appends elements of remaining keys from the right |
628 | 673 | # handed array to the left handed, whereas duplicated keys are NOT overwritten. |
629 | 674 | $param += $defaultParameters; |
630 | | - |
631 | | - global $wgUser, $wgOut; |
632 | 675 | # Convert $param array to individual variables |
633 | 676 | $lim = $param['lim']; |
634 | 677 | $conds = $param['conds']; |
635 | 678 | $showIfEmpty = $param['showIfEmpty']; |
636 | 679 | $msgKey = $param['msgKey']; |
637 | 680 | $wrap = $param['wrap']; |
638 | | - if ( !is_array( $msgKey ) ) |
| 681 | + $flags = $param['flags']; |
| 682 | + if ( !is_array( $msgKey ) ) { |
639 | 683 | $msgKey = array( $msgKey ); |
| 684 | + } |
640 | 685 | # Insert list of top 50 (or top $lim) items |
641 | | - $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 ); |
| 686 | + $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, $flags ); |
642 | 687 | $pager = new LogPager( $loglist, $types, $user, $page, '', $conds ); |
643 | | - if ( isset( $param['offset'] ) ) # Tell pager to ignore $wgRequest offset |
| 688 | + if ( isset( $param['offset'] ) ) { # Tell pager to ignore $wgRequest offset |
644 | 689 | $pager->setOffset( $param['offset'] ); |
| 690 | + } |
645 | 691 | if( $lim > 0 ) $pager->mLimit = $lim; |
646 | 692 | $logBody = $pager->getBody(); |
647 | 693 | $s = ''; |
— | — | @@ -681,10 +727,10 @@ |
682 | 728 | array(), |
683 | 729 | $urlParam |
684 | 730 | ); |
685 | | - |
686 | 731 | } |
687 | | - if ( $logBody && $msgKey[0] ) |
| 732 | + if ( $logBody && $msgKey[0] ) { |
688 | 733 | $s .= '</div>'; |
| 734 | + } |
689 | 735 | |
690 | 736 | if ( $wrap!='' ) { // Wrap message in html |
691 | 737 | $s = str_replace( '$1', $s, $wrap ); |