X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FChangesList.php;h=3efa66f9c5aa55041c3275f64f990551fc765bc8;hb=246d7c081a7dd9b6b6c65bfd0377f62967dd8765;hp=c438b58a78c611b30b6e7f6447242867904163b7;hpb=83765b1b0d17d1dc7f92a8bf554d5904a292e6c8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ChangesList.php b/includes/ChangesList.php index c438b58a78..3efa66f9c5 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -3,10 +3,9 @@ /** * @todo document */ -class RCCacheEntry extends RecentChange -{ +class RCCacheEntry extends RecentChange { var $secureName, $link; - var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ; + var $curlink , $difflink, $lastlink, $usertalklink, $versionlink; var $userlink, $timestamp, $watched; static function newFromParent( $rc ) { @@ -15,7 +14,7 @@ class RCCacheEntry extends RecentChange $rc2->mExtra = $rc->mExtra; return $rc2; } -} ; +} /** * Class to show various lists of changes: @@ -25,13 +24,13 @@ class RCCacheEntry extends RecentChange */ class ChangesList { # Called by history lists and recent changes - # + public $skin; /** * Changeslist contructor * @param Skin $skin */ - function __construct( &$skin ) { + public function __construct( &$skin ) { $this->skin =& $skin; $this->preCacheMessages(); } @@ -47,7 +46,8 @@ class ChangesList { $sk = $user->getSkin(); $list = NULL; if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) { - return $user->getOption( 'usenewrc' ) ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk ); + return $user->getOption( 'usenewrc' ) ? + new EnhancedChangesList( $sk ) : new OldChangesList( $sk ); } else { return $list; } @@ -58,7 +58,6 @@ class ChangesList { * they are called often, we call them once and save them in $this->message */ private function preCacheMessages() { - // Precache various messages if( !isset( $this->message ) ) { foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '. 'blocklink history boteditletter semicolon-separator' ) as $msg ) { @@ -78,10 +77,10 @@ class ChangesList { * @return string */ protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) { - $f = $new ? '' . $this->message['newpageletter'] . '' - : $nothing; - $f .= $minor ? '' . $this->message['minoreditletter'] . '' - : $nothing; + $f = $new ? + '' . $this->message['newpageletter'] . '' : $nothing; + $f .= $minor ? + '' . $this->message['minoreditletter'] . '' : $nothing; $f .= $bot ? '' . $this->message['boteditletter'] . '' : $nothing; $f .= $patrolled ? '!' : $nothing; return $f; @@ -99,6 +98,42 @@ class ChangesList { $this->rclistOpen = false; return ''; } + + /** + * Show formatted char difference + * @param int $old bytes + * @param int $new bytes + * @returns string + */ + public static function showCharacterDifference( $old, $new ) { + global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode; + $szdiff = $new - $old; + + $code = $wgLang->getCode(); + static $fastCharDiff = array(); + if ( !isset($fastCharDiff[$code]) ) { + $fastCharDiff[$code] = $wgMiserMode || wfMsgNoTrans( 'rc-change-size' ) === '$1'; + } + + $formatedSize = $wgLang->formatNum($szdiff); + + if ( !$fastCharDiff[$code] ) { + $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize ); + } + + if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) { + $tag = 'strong'; + } else { + $tag = 'span'; + } + if( $szdiff === 0 ) { + return "<$tag class='mw-plusminus-null'>($formatedSize)"; + } elseif( $szdiff > 0 ) { + return "<$tag class='mw-plusminus-pos'>(+$formatedSize)"; + } else { + return "<$tag class='mw-plusminus-neg'>($formatedSize)"; + } + } /** * Returns text for the end of RC @@ -114,20 +149,18 @@ class ChangesList { protected function insertMove( &$s, $rc ) { # Diff - $s .= '(' . $this->message['diff'] . ') ('; + $s .= '(' . $this->message['diff'] . ') ('; # Hist - $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'], 'action=history' ) . - ') . . '; - + $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'], + 'action=history' ) . ') . . '; # "[[x]] moved to [[y]]" $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir'; $s .= wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ), $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) ); } - protected function insertDateHeader(&$s, $rc_timestamp) { + protected function insertDateHeader( &$s, $rc_timestamp ) { global $wgLang; - # Make date header if necessary $date = $wgLang->date( $rc_timestamp, true, true ); if( $date != $this->lastdate ) { @@ -140,21 +173,19 @@ class ChangesList { } } - protected function insertLog(&$s, $title, $logtype) { + protected function insertLog( &$s, $title, $logtype ) { $logname = LogPage::logName( $logtype ); - $s .= '(' . $this->skin->makeKnownLinkObj( $title, $logname ) . ')'; + $s .= '(' . $this->skin->makeKnownLinkObj($title, $logname ) . ')'; } - protected function insertDiffHist(&$s, &$rc, $unpatrolled) { + protected function insertDiffHist( &$s, &$rc, $unpatrolled ) { # Diff link - if( !$this->userCan($rc,Revision::DELETED_TEXT) ) { + if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) { $diffLink = $this->message['diff']; - } else if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) { + } else if( !$this->userCan($rc,Revision::DELETED_TEXT) ) { $diffLink = $this->message['diff']; } else { - $rcidparam = $unpatrolled - ? array( 'rcid' => $rc->mAttribs['rc_id'] ) - : array(); + $rcidparam = $unpatrolled ? array( 'rcid' => $rc->mAttribs['rc_id'] ) : array(); $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], wfArrayToCGI( array( 'curid' => $rc->mAttribs['rc_cur_id'], @@ -163,83 +194,73 @@ class ChangesList { $rcidparam ), '', '', ' tabindex="'.$rc->counter.'"'); } - $s .= '('.$diffLink.') ('; - + $s .= '('.$diffLink.') ('; # History link $s .= $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['hist'], wfArrayToCGI( array( 'curid' => $rc->mAttribs['rc_cur_id'], 'action' => 'history' ) ) ); - $s .= ') . . '; + $s .= ') . . '; } - protected function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) { - # Article link + protected function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) { + global $wgContLang; # If it's a new article, there is no diff link, but if it hasn't been # patrolled yet, we need to give users a way to do so - $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) - ? 'rcid='.$rc->mAttribs['rc_id'] - : ''; + $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) ? + 'rcid='.$rc->mAttribs['rc_id'] : ''; if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) { $articlelink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params ); $articlelink = ''.$articlelink.''; } else { - $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params ); + $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params ); } + # Bolden pages watched by this user if( $watched ) { $articlelink = "{$articlelink}"; - } else { - $articlelink = '' . $articlelink . ''; } - global $wgContLang; + # RTL/LTR marker $articlelink .= $wgContLang->getDirMark(); - wfRunHooks('ChangesListInsertArticleLink', - array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched)); + wfRunHooks( 'ChangesListInsertArticleLink', + array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) ); - $s .= ' '.$articlelink; + $s .= " $articlelink"; } - protected function insertTimestamp(&$s, $rc) { + protected function insertTimestamp( &$s, $rc ) { global $wgLang; - # Timestamp - $s .= $this->message['semicolon-separator'] . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . '; + $s .= $this->message['semicolon-separator'] . + $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . '; } /** Insert links to user page, user talk page and eventually a blocking link */ public function insertUserRelatedLinks( &$s, &$rc ) { - if ( $this->isDeleted( $rc,Revision::DELETED_USER ) ) { - $s .= ' ' . wfMsgHtml( 'rev-deleted-user' ) . ''; + if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) { + $s .= ' ' . wfMsgHtml( 'rev-deleted-user' ) . ''; } else { - $s .= '' . - $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ) . - '' . - $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ) . - ''; + $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); + $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); } } /** insert a formatted action */ - protected function insertAction(&$s, &$rc) { - # Add action + protected function insertAction( &$s, &$rc ) { if( $rc->mAttribs['rc_type'] == RC_LOG ) { - // log action - if ( $this->isDeleted($rc,LogPage::DELETED_ACTION) ) { - $s .= ' ' . wfMsgHtml('rev-deleted-event') . ''; + if( $this->isDeleted( $rc, LogPage::DELETED_ACTION ) ) { + $s .= ' ' . wfMsgHtml( 'rev-deleted-event' ) . ''; } else { - $s .= ' ' . LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'], - $rc->getTitle(), $this->skin, LogPage::extractParams($rc->mAttribs['rc_params']), true, true ); + $s .= ' '.LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'], + $rc->getTitle(), $this->skin, LogPage::extractParams( $rc->mAttribs['rc_params'] ), true, true ); } } } /** insert a formatted comment */ - protected function insertComment(&$s, &$rc) { - # Add comment + protected function insertComment( &$s, &$rc ) { if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) { - // log comment - if ( $this->isDeleted($rc,Revision::DELETED_COMMENT) ) { - $s .= ' ' . wfMsgHtml('rev-deleted-comment') . ''; + if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) { + $s .= ' ' . wfMsgHtml( 'rev-deleted-comment' ) . ''; } else { $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() ); } @@ -261,10 +282,10 @@ class ChangesList { protected function numberofWatchingusers( $count ) { global $wgLang; static $cache = array(); - if ( $count > 0 ) { - if ( !isset( $cache[$count] ) ) { - $cache[$count] = wfMsgExt('number_of_watching_users_RCview', - array('parsemag', 'escape'), $wgLang->formatNum($count)); + if( $count > 0 ) { + if( !isset( $cache[$count] ) ) { + $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview', + array('parsemag', 'escape' ), $wgLang->formatNum( $count ) ); } return $cache[$count]; } else { @@ -279,7 +300,7 @@ class ChangesList { * @return bool */ public static function isDeleted( $rc, $field ) { - return ($rc->mAttribs['rc_deleted'] & $field) == $field; + return ( $rc->mAttribs['rc_deleted'] & $field ) == $field; } /** @@ -295,12 +316,54 @@ class ChangesList { $permission = ( $rc->mAttribs['rc_deleted'] & Revision::DELETED_RESTRICTED ) == Revision::DELETED_RESTRICTED ? 'suppressrevision' : 'deleterevision'; - wfDebug( "Checking for $permission due to $field match on $rc->mAttribs['rc_deleted']\n" ); + wfDebug( "Checking for $permission due to $field match on {$rc->mAttribs['rc_deleted']}\n" ); return $wgUser->isAllowed( $permission ); } else { return true; } } + + protected function maybeWatchedLink( $link, $watched=false ) { + if( $watched ) { + return '' . $link . ''; + } else { + return '' . $link . ''; + } + } + + /** Inserts a rollback link */ + protected function insertRollback( &$s, &$rc ) { + global $wgUser; + if( !$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) { + $page = $rc->getTitle(); + /** Check for rollback and edit permissions, disallow special pages, and only + * show a link on the top-most revision */ + if ($wgUser->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] ) + { + $rev = new Revision( array( + 'id' => $rc->mAttribs['rc_this_oldid'], + 'user' => $rc->mAttribs['rc_user'], + 'user_text' => $rc->mAttribs['rc_user_text'], + 'deleted' => $rc->mAttribs['rc_deleted'] + ) ); + $rev->setTitle( $page ); + $s .= ' '.$this->skin->generateRollback( $rev ); + } + } + } + + protected function insertTags( &$s, &$rc, &$classes ) { + if ( empty($rc->mAttribs['ts_tags']) ) + return; + + list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' ); + $classes = array_merge( $classes, $newClasses ); + $s .= ' ' . $tagSummary; + } + + protected function insertExtra( &$s, &$rc, &$classes ) { + ## Empty, used for subclassers to add anything special. + } } @@ -311,90 +374,92 @@ class OldChangesList extends ChangesList { /** * Format a line using the old system (aka without any javascript). */ - public function recentChangesLine( &$rc, $watched = false ) { - global $wgContLang, $wgRCShowChangedSize, $wgUser; - - $fname = 'ChangesList::recentChangesLineOld'; - wfProfileIn( $fname ); - - # Extract DB fields into local scope - // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. - extract( $rc->mAttribs ); - + public function recentChangesLine( &$rc, $watched = false, $linenumber = NULL ) { + global $wgLang, $wgRCShowChangedSize, $wgUser; + wfProfileIn( __METHOD__ ); # Should patrol-related stuff be shown? - $unpatrolled = $wgUser->useRCPatrol() && $rc_patrolled == 0; + $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs['rc_patrolled']; - $dateheader = ""; // $s now contains only
  • ...
  • , for hooks' convenience. - $this->insertDateHeader($dateheader,$rc_timestamp); + $dateheader = ''; // $s now contains only
  • ...
  • , for hooks' convenience. + $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] ); $s = ''; + $classes = array(); + // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468) + if( $linenumber ) { + if( $linenumber & 1 ) { + $classes[] = 'mw-line-odd'; + } + else { + $classes[] = 'mw-line-even'; + } + } // Moved pages - if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { + if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) { $this->insertMove( $s, $rc ); // Log entries - } elseif( $rc_log_type ) { - $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL ); - $this->insertLog( $s, $logtitle, $rc_log_type ); + } elseif( $rc->mAttribs['rc_log_type'] ) { + $logtitle = Title::newFromText( 'Log/'.$rc->mAttribs['rc_log_type'], NS_SPECIAL ); + $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] ); // Log entries (old format) or log targets, and special pages - } elseif( $rc_namespace == NS_SPECIAL ) { - list( $specialName, $specialSubpage ) = SpecialPage::resolveAliasWithSubpage( $rc_title ); - if ( $specialName == 'Log' ) { - $this->insertLog( $s, $rc->getTitle(), $specialSubpage ); - } else { - wfDebug( "Unexpected special page in recentchanges\n" ); + } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) { + list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $rc->mAttribs['rc_title'] ); + if( $name == 'Log' ) { + $this->insertLog( $s, $rc->getTitle(), $subpage ); } // Regular entries } else { - wfProfileIn($fname.'-page'); - - $this->insertDiffHist($s, $rc, $unpatrolled); - + $this->insertDiffHist( $s, $rc, $unpatrolled ); # M, N, b and ! (minor, new, bot and unpatrolled) - $s .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '', $rc_bot ); - $this->insertArticleLink($s, $rc, $unpatrolled, $watched); - - wfProfileOut($fname.'-page'); + $s .= $this->recentChangesFlags( $rc->mAttribs['rc_new'], $rc->mAttribs['rc_minor'], + $unpatrolled, '', $rc->mAttribs['rc_bot'] ); + $this->insertArticleLink( $s, $rc, $unpatrolled, $watched ); } - - wfProfileIn( $fname.'-rest' ); - - $this->insertTimestamp($s,$rc); - + # Edit/log timestamp + $this->insertTimestamp( $s, $rc ); + # Bytes added or removed if( $wgRCShowChangedSize ) { - $s .= ( $rc->getCharacterDifference() == '' ? '' : $rc->getCharacterDifference() . ' . . ' ); + $cd = $rc->getCharacterDifference(); + if( $cd != '' ) { + $s .= "$cd . . "; + } } # User tool links - $this->insertUserRelatedLinks($s,$rc); + $this->insertUserRelatedLinks( $s, $rc ); # Log action text (if any) - $this->insertAction($s, $rc); + $this->insertAction( $s, $rc ); # Edit or log comment - $this->insertComment($s, $rc); - + $this->insertComment( $s, $rc ); + # Tags + $this->insertTags( $s, $rc, $classes ); + # Rollback + $this->insertRollback( $s, $rc ); + # For subclasses + $this->insertExtra( $s, $rc, $classes ); + # Mark revision as deleted if so - if ( !$rc_log_type && $this->isDeleted($rc,Revision::DELETED_TEXT) ) + if( !$rc->mAttribs['rc_log_type'] && $this->isDeleted($rc,Revision::DELETED_TEXT) ) { $s .= ' ' . wfMsgHtml( 'deletedrev' ) . ''; - if($rc->numberofWatchingusers > 0) { - $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers)); + } + # How many users watch this page + if( $rc->numberofWatchingusers > 0 ) { + $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview', + array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers ) ); } wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) ); - - $s = "
  • $s
  • \n"; - wfProfileOut( $fname.'-rest' ); - - wfProfileOut( $fname ); - return $dateheader . $s; + wfProfileOut( __METHOD__ ); + return "$dateheader
  • $s
  • \n"; } } /** - * Generate a list of changes using an Enhanced system (use javascript). + * Generate a list of changes using an Enhanced system (uses javascript). */ class EnhancedChangesList extends ChangesList { - /** * Add the JavaScript file for enhanced changeslist * @ return string @@ -415,18 +480,21 @@ class EnhancedChangesList extends ChangesList { * Format a line for enhanced recentchange (aka with javascript and block of lines). */ public function recentChangesLine( &$baseRC, $watched = false ) { - global $wgLang, $wgContLang, $wgUser; + global $wgLang, $wgUser; + + wfProfileIn( __METHOD__ ); # Create a specialised object $rc = RCCacheEntry::newFromParent( $baseRC ); # Extract fields from DB into the function scope (rc_xxxx variables) - // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. + // FIXME: Would be good to replace this extract() call with something + // that explicitly initializes variables. extract( $rc->mAttribs ); - $curIdEq = 'curid=' . $rc_cur_id; + $curIdEq = array( 'curid' => $rc_cur_id ); # If it's a new day, add the headline and flush the cache - $date = $wgLang->date( $rc_timestamp, true); + $date = $wgLang->date( $rc_timestamp, true ); $ret = ''; if( $date != $this->lastdate ) { # Process current cache @@ -448,34 +516,37 @@ class EnhancedChangesList extends ChangesList { // Page moves if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir"; - $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ), - $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) ); + $clink = wfMsg( $msg, $this->skin->linkKnown( $rc->getTitle(), null, + array(), array( 'redirect' => 'no' ) ), + $this->skin->linkKnown( $rc->getMovedToTitle() ) ); + // New unpatrolled pages + } else if( $rc->unpatrolled && $rc_type == RC_NEW ) { + $clink = $this->skin->linkKnown( $rc->getTitle(), null, array(), + array( 'rcid' => $rc_id ) ); + // Log entries + } else if( $rc_type == RC_LOG ) { + if( $rc_log_type ) { + $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type ); + $clink = '(' . $this->skin->linkKnown( $logtitle, + LogPage::logName($rc_log_type) ) . ')'; + } else { + $clink = $this->skin->link( $rc->getTitle() ); + } + $watched = false; // Log entries (old format) and special pages } elseif( $rc_namespace == NS_SPECIAL ) { list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title ); if ( $specialName == 'Log' ) { # Log updates, etc $logname = LogPage::logName( $logtype ); - $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')'; + $clink = '(' . $this->skin->linkKnown( $rc->getTitle(), $logname ) . ')'; } else { wfDebug( "Unexpected special page in recentchanges\n" ); $clink = ''; } - // New unpatrolled pages - } else if( $rc->unpatrolled && $rc_type == RC_NEW ) { - $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" ); - // Log entries - } else if( $rc_type == RC_LOG ) { - if( $rc_log_type ) { - $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type ); - $clink = '(' . $this->skin->makeKnownLinkObj( $logtitle, LogPage::logName($rc_log_type) ) . ')'; - } else { - $clink = $this->skin->makeLinkObj( $rc->getTitle(), '' ); - } - $watched = false; // Edits } else { - $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' ); + $clink = $this->skin->linkKnown( $rc->getTitle() ); } # Don't show unusable diff links @@ -483,49 +554,54 @@ class EnhancedChangesList extends ChangesList { $showdifflinks = false; } - $time = $wgContLang->time( $rc_timestamp, true, true ); + $time = $wgLang->time( $rc_timestamp, true, true ); $rc->watched = $watched; $rc->link = $clink; $rc->timestamp = $time; $rc->numberofWatchingusers = $baseRC->numberofWatchingusers; - # Make "cur" and "diff" links + # Make "cur" and "diff" links. Don't use link(), it's too slow if + # called too many times (50% of CPU time on RecentChanges!). if( $rc->unpatrolled ) { - $rcIdQuery = "&rcid={$rc_id}"; + $rcIdQuery = array( 'rcid' => $rc_id ); } else { - $rcIdQuery = ''; + $rcIdQuery = array(); } - $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid"; - $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery"; - $aprops = ' tabindex="'.$baseRC->counter.'"'; - $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['cur'], $querycur, '' ,'', $aprops ); + $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $rc_this_oldid ); + $querydiff = $curIdEq + array( 'diff' => $rc_this_oldid, 'oldid' => + $rc_last_oldid ) + $rcIdQuery; - # Make "diff" an "cur" links if( !$showdifflinks ) { - $curLink = $this->message['cur']; - $diffLink = $this->message['diff']; - } else if( $rc_type == RC_NEW || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { - if( $rc_type != RC_NEW ) { + $curLink = $this->message['cur']; + $diffLink = $this->message['diff']; + } else if( in_array( $rc_type, array(RC_NEW,RC_LOG,RC_MOVE,RC_MOVE_OVER_REDIRECT) ) ) { + if ( $rc_type != RC_NEW ) { $curLink = $this->message['cur']; + } else { + $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) ); + $curLink = "counter}\">{$this->message['cur']}"; } $diffLink = $this->message['diff']; } else { - $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], $querydiff, '' ,'', $aprops ); + $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) ); + $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) ); + $diffLink = "counter}\">{$this->message['diff']}"; + $curLink = "counter}\">{$this->message['cur']}"; } # Make "last" link - if( !$showdifflinks ) { + if( !$showdifflinks || !$rc_last_oldid ) { $lastLink = $this->message['last']; - } else if( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { + } else if( $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { $lastLink = $this->message['last']; } else { - $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'], - $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery ); + $lastLink = $this->skin->linkKnown( $rc->getTitle(), $this->message['last'], + array(), $curIdEq + array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) + $rcIdQuery ); } # Make user links if( $this->isDeleted($rc,Revision::DELETED_USER) ) { - $rc->userlink = ' ' . wfMsgHtml('rev-deleted-user') . ''; + $rc->userlink = ' ' . wfMsgHtml( 'rev-deleted-user' ) . ''; } else { $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text ); $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text ); @@ -550,8 +626,12 @@ class EnhancedChangesList extends ChangesList { if( !isset( $this->rc_cache[$secureName] ) ) { $this->rc_cache[$secureName] = array(); } + array_push( $this->rc_cache[$secureName], $rc ); } + + wfProfileOut( __METHOD__ ); + return $ret; } @@ -560,6 +640,9 @@ class EnhancedChangesList extends ChangesList { */ protected function recentChangesBlockGroup( $block ) { global $wgLang, $wgContLang, $wgRCShowChangedSize; + + wfProfileIn( __METHOD__ ); + $r = ''; # Collate list of users @@ -570,7 +653,7 @@ class EnhancedChangesList extends ChangesList { $curId = $currentRevision = 0; # Some catalyst variables... $namehidden = true; - $alllogs = true; + $allLogs = true; foreach( $block as $rcObj ) { $oldid = $rcObj->mAttribs['rc_last_oldid']; if( $rcObj->mAttribs['rc_new'] ) { @@ -589,7 +672,7 @@ class EnhancedChangesList extends ChangesList { $unpatrolled = true; } if( $rcObj->mAttribs['rc_type'] != RC_LOG ) { - $alllogs = false; + $allLogs = false; } # Get the latest entry with a page_id and oldid # since logs may not have these. @@ -617,17 +700,18 @@ class EnhancedChangesList extends ChangesList { array_push( $users, $text ); } - $users = ' [' . implode( $this->message['semicolon-separator'], $users ) . ']'; + $users = ' [' . + implode( $this->message['semicolon-separator'], $users ) . ']'; # ID for JS visibility toggle $jsid = $this->rcCacheIndex; # onclick handler to toggle hidden/expanded $toggleLink = "onclick='toggleVisibility($jsid); return false'"; # Title for tags - $expandTitle = htmlspecialchars( wfMsg('rc-enhanced-expand') ); - $closeTitle = htmlspecialchars( wfMsg('rc-enhanced-hide') ); + $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) ); + $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) ); - $tl = "" . $this->sideArrow() . ""; + $tl = ""; $tl .= ""; $r .= '
    '.$tl.' '; @@ -639,9 +723,11 @@ class EnhancedChangesList extends ChangesList { # Article link if( $namehidden ) { - $r .= ' ' . wfMsgHtml('rev-deleted-event') . ''; - } else { + $r .= ' ' . wfMsgHtml( 'rev-deleted-event' ) . ''; + } else if( $allLogs ) { $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched ); + } else { + $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched ); } $r .= $wgContLang->getDirMark(); @@ -655,9 +741,9 @@ class EnhancedChangesList extends ChangesList { } # Total change link $r .= ' '; - if( !$alllogs ) { + if( !$allLogs ) { $r .= '('; - if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) { + if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT ) ) { $r .= $nchanges[$n]; } else if( $isnew ) { $r .= $nchanges[$n]; @@ -665,11 +751,21 @@ class EnhancedChangesList extends ChangesList { $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(), $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" ); } - $r .= ') . . '; } + # History + if( $allLogs ) { + // don't show history link for logs + } else if( $namehidden || !$block[0]->getTitle()->exists() ) { + $r .= $this->message['semicolon-separator'] . $this->message['hist'] . ')'; + } else { + $r .= $this->message['semicolon-separator'] . $this->skin->makeKnownLinkObj( $block[0]->getTitle(), + $this->message['hist'], $curIdEq . '&action=history' ) . ')'; + } + $r .= ' . . '; + # Character difference (does not apply if only log items) - if( $wgRCShowChangedSize && !$alllogs ) { + if( $wgRCShowChangedSize && !$allLogs ) { $last = 0; $first = count($block) - 1; # Some events (like logs) have an "empty" size, so we need to skip those... @@ -690,26 +786,20 @@ class EnhancedChangesList extends ChangesList { } } - # History - if( $alllogs ) { - // don't show history link for logs - } else if( $namehidden || !$block[0]->getTitle()->exists() ) { - $r .= '(' . $this->message['history'] . ')'; - } else { - $r .= '(' . $this->skin->makeKnownLinkObj( $block[0]->getTitle(), - $this->message['history'], $curIdEq.'&action=history' ) . ')'; - } - $r .= $users; $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers); $r .= "
    \n"; # Sub-entries - $r .= '
    '; + $r .= '
    '; + $r .= '
    '; foreach( $block as $rcObj ) { - # Get rc_xxxx variables - // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. + # Extract fields from DB into the function scope (rc_xxxx variables) + // FIXME: Would be good to replace this extract() call with something + // that explicitly initializes variables. + # Classes to apply -- TODO implement + $classes = array(); extract( $rcObj->mAttribs ); #$r .= '
    '.$this->spacerArrow(); @@ -729,9 +819,10 @@ class EnhancedChangesList extends ChangesList { } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) { $link = ''.$rcObj->timestamp.' '; } else { - $rcIdEq = ($rcObj->unpatrolled && $rc_type == RC_NEW) ? '&rcid='.$rcObj->mAttribs['rc_id'] : ''; - - $link = ''.$this->skin->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp, $curIdEq.'&'.$o.$rcIdEq ).''; + $rcIdEq = ($rcObj->unpatrolled && $rc_type == RC_NEW) ? + '&rcid='.$rcObj->mAttribs['rc_id'] : ''; + $link = ''.$this->skin->makeKnownLinkObj( $rcObj->getTitle(), + $rcObj->timestamp, $curIdEq.'&'.$o.$rcIdEq ).''; if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) ) $link = ''.$link.' '; } @@ -754,9 +845,14 @@ class EnhancedChangesList extends ChangesList { $r .= $rcObj->userlink; $r .= $rcObj->usertalklink; // log action - parent::insertAction( $r, $rcObj ); + $this->insertAction( $r, $rcObj ); // log comment - parent::insertComment( $r, $rcObj ); + $this->insertComment( $r, $rcObj ); + # Rollback + $this->insertRollback( $r, $rcObj ); + # Tags + $this->insertTags( $r, $rcObj, $classes ); + # Mark revision as deleted if( !$rc_log_type && $this->isDeleted($rcObj,Revision::DELETED_TEXT) ) { $r .= ' ' . wfMsgHtml( 'deletedrev' ) . ''; @@ -767,16 +863,10 @@ class EnhancedChangesList extends ChangesList { $r .= "
    \n"; $this->rcCacheIndex++; - return $r; - } - protected function maybeWatchedLink( $link, $watched=false ) { - if( $watched ) { - // FIXME: css style might be more appropriate - return '' . $link . ''; - } else { - return '' . $link . ''; - } + wfProfileOut( __METHOD__ ); + + return $r; } /** @@ -802,7 +892,7 @@ class EnhancedChangesList extends ChangesList { protected function sideArrow() { global $wgContLang; $dir = $wgContLang->isRTL() ? 'l' : 'r'; - return $this->arrow( $dir, '+', wfMsg('rc-enhanced-expand') ); + return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) ); } /** @@ -811,7 +901,7 @@ class EnhancedChangesList extends ChangesList { * @return string HTML tag */ protected function downArrow() { - return $this->arrow( 'd', '-', wfMsg('rc-enhanced-hide') ); + return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) ); } /** @@ -835,17 +925,19 @@ class EnhancedChangesList extends ChangesList { * @return string a HTML formated line (generated using $r) */ protected function recentChangesBlockLine( $rcObj ) { - global $wgContLang, $wgRCShowChangedSize; + global $wgRCShowChangedSize; + + wfProfileIn( __METHOD__ ); - # Get rc_xxxx variables - // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. + # Extract fields from DB into the function scope (rc_xxxx variables) + // FIXME: Would be good to replace this extract() call with something + // that explicitly initializes variables. + $classes = array(); // TODO implement extract( $rcObj->mAttribs ); - $curIdEq = 'curid='.$rc_cur_id; + $curIdEq = "curid={$rc_cur_id}"; $r = ''; - $r .= '
    ' . $this->spacerArrow() . ' '; - # Flag and Timestamp if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { $r .= '    '; // 4 flags -> 4 spaces @@ -853,33 +945,27 @@ class EnhancedChangesList extends ChangesList { $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, ' ', $rc_bot ); } $r .= ' '.$rcObj->timestamp.' '; - # Article or log link if( $rc_log_type ) { $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL ); $logname = LogPage::logName( $rc_log_type ); $r .= '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')'; - } else if( !$this->userCan($rcObj,Revision::DELETED_TEXT) ) { - $r .= '' . $rcObj->link . ''; } else { - $r .= $this->maybeWatchedLink( $rcObj->link, $rcObj->watched ); + $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched ); } - # Diff and hist links if ( $rc_type != RC_LOG ) { - $r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator']; - $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ')'; + $r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator']; + $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), $this->message['hist'], + $curIdEq.'&action=history' ) . ')'; } $r .= ' . . '; - # Character diff - if( $wgRCShowChangedSize ) { - $r .= ( $rcObj->getCharacterDifference() == '' ? '' : ' ' . $rcObj->getCharacterDifference() . ' . . ' ) ; + if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) { + $r .= "$cd . . "; } - # User/talk $r .= ' '.$rcObj->userlink . $rcObj->usertalklink; - # Log action (if any) if( $rc_log_type ) { if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) { @@ -889,21 +975,17 @@ class EnhancedChangesList extends ChangesList { $this->skin, LogPage::extractParams($rc_params), true, true ); } } - - # Edit or log comment - if( $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) { - // log comment - if ( $this->isDeleted($rcObj,LogPage::DELETED_COMMENT) ) { - $r .= ' ' . wfMsg('rev-deleted-comment') . ''; - } else { - $r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() ); - } - } - + $this->insertComment( $r, $rcObj ); + $this->insertRollback( $r, $rcObj ); + # Tags + $this->insertTags( $r, $rcObj, $classes ); # Show how many people are watching this if enabled $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers); $r .= "
    \n"; + + wfProfileOut( __METHOD__ ); + return $r; } @@ -915,6 +997,9 @@ class EnhancedChangesList extends ChangesList { if( count ( $this->rc_cache ) == 0 ) { return ''; } + + wfProfileIn( __METHOD__ ); + $blockOut = ''; foreach( $this->rc_cache as $block ) { if( count( $block ) < 2 ) { @@ -924,6 +1009,8 @@ class EnhancedChangesList extends ChangesList { } } + wfProfileOut( __METHOD__ ); + return '
    '.$blockOut.'
    '; }