r63144 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63143‎ | r63144 | r63145 >
Date:22:47, 1 March 2010
Author:aaron
Status:ok
Tags:
Comment:
* Split up logLine() with helper functions
* Added NO_EXTRA_USER_LINKS param to hide talk|contribs links
* Fixed bizarre $time comparison (compared display time and a UNIX const time)
* Added 'flags' param to showLogExtract() params
Modified paths:
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LogEventsList.php
@@ -19,6 +19,7 @@
2020
2121 class LogEventsList {
2222 const NO_ACTION_LINK = 1;
 23+ const NO_EXTRA_USER_LINKS = 2;
2324
2425 private $skin;
2526 private $out;
@@ -271,38 +272,90 @@
272273 * @return String: Formatted HTML list item
273274 */
274275 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 );
276290
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;
279305 $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 = '';
281311 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>';
283314 } 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+ }
286321 }
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 = '';
288340 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>';
290343 } else {
291 - $comment = $wgContLang->getDirMark() . $this->skin->commentBlock( $row->log_comment );
 344+ $comment = $wgContLang->getDirMark() .
 345+ $this->skin->commentBlock( $row->log_comment );
292346 }
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 '';
302357 }
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] ) ) {
307360 $destTitle = Title::newFromText( $paramArray[0] );
308361 if( $destTitle ) {
309362 $revert = '(' . $this->skin->link(
@@ -312,7 +365,7 @@
313366 array(
314367 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
315368 'wpNewTitle' => $title->getPrefixedDBkey(),
316 - 'wpReason' => wfMsgForContent( 'revertmove' ),
 369+ 'wpReason' => wfMsgForContent( 'revertmove' ),
317370 'wpMovetalk' => 0
318371 ),
319372 array( 'known', 'noclasses' )
@@ -325,7 +378,6 @@
326379 } else {
327380 $viewdeleted = $this->message['undeletelink'];
328381 }
329 -
330382 $revert = '(' . $this->skin->link(
331383 SpecialPage::getTitleFor( 'Undelete' ),
332384 $viewdeleted,
@@ -377,9 +429,8 @@
378430 $revert .= ')';
379431 // Show unmerge link
380432 } else if( self::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) {
381 - $merge = SpecialPage::getTitleFor( 'Mergehistory' );
382433 $revert = '(' . $this->skin->link(
383 - $merge,
 434+ SpecialPage::getTitleFor( 'Mergehistory' ),
384435 $this->message['revertmerge'],
385436 array(),
386437 array(
@@ -470,7 +521,8 @@
471522 # Fall back to a blue contributions link
472523 $revert = $this->skin->userToolLinks( 1, $title->getDBkey() );
473524 }
474 - if( $time < '20080129000000' ) {
 525+ $ts = wfTimestamp( TS_UNIX, $row->log_timestamp );
 526+ if( $ts < '20080129000000' ) {
475527 # Suppress $comment from old entries (before 2008-01-29),
476528 # not needed and can contain incorrect links
477529 $comment = '';
@@ -480,26 +532,10 @@
481533 wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
482534 &$comment, &$revert, $row->log_timestamp ) );
483535 }
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 -
496536 if( $revert != '' ) {
497537 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
498538 }
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;
504540 }
505541
506542 /**
@@ -508,23 +544,30 @@
509545 */
510546 private function getShowHideLinks( $row ) {
511547 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 '';
514552 }
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+ }
529572 }
530573 return $del;
531574 }
@@ -609,38 +652,41 @@
610653 * that are processed with wgMsgExt and option 'parse'
611654 * - offset Set to overwrite offset parameter in $wgRequest
612655 * 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)
614658 * @return Integer Number of total log items (not limited by $lim)
615659 */
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;
619664 $defaultParameters = array(
620665 'lim' => 25,
621666 'conds' => array(),
622667 'showIfEmpty' => true,
623668 'msgKey' => array(''),
624 - 'wrap' => "$1"
 669+ 'wrap' => "$1",
 670+ 'flags' => 0
625671 );
626 -
627672 # The + operator appends elements of remaining keys from the right
628673 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
629674 $param += $defaultParameters;
630 -
631 - global $wgUser, $wgOut;
632675 # Convert $param array to individual variables
633676 $lim = $param['lim'];
634677 $conds = $param['conds'];
635678 $showIfEmpty = $param['showIfEmpty'];
636679 $msgKey = $param['msgKey'];
637680 $wrap = $param['wrap'];
638 - if ( !is_array( $msgKey ) )
 681+ $flags = $param['flags'];
 682+ if ( !is_array( $msgKey ) ) {
639683 $msgKey = array( $msgKey );
 684+ }
640685 # 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 );
642687 $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
644689 $pager->setOffset( $param['offset'] );
 690+ }
645691 if( $lim > 0 ) $pager->mLimit = $lim;
646692 $logBody = $pager->getBody();
647693 $s = '';
@@ -681,10 +727,10 @@
682728 array(),
683729 $urlParam
684730 );
685 -
686731 }
687 - if ( $logBody && $msgKey[0] )
 732+ if ( $logBody && $msgKey[0] ) {
688733 $s .= '</div>';
 734+ }
689735
690736 if ( $wrap!='' ) { // Wrap message in html
691737 $s = str_replace( '$1', $s, $wrap );

Follow-up revisions

RevisionCommit summaryAuthorDate
r63260Use NO_EXTRA_USER_LINKS (r63144) to hide clutter from stability log excerptsaaron00:13, 5 March 2010
r89114Fix a regression from r63144: "Fixed bizarre $time comparison (compared displ...raymond15:43, 29 May 2011

Status & tagging log