X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FChangesList.php;h=e0183c4c5a90be5074e017d4d69af13697a21496;hb=af28c6f55abdf3d00b18cc44af8ca41e22955491;hp=1bfdc39bf5ea779bdc024279118d346298fb1b7f;hpb=eb62ec3e7086b3da23ff24c5c0c0867844e1a6f9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ChangesList.php b/includes/ChangesList.php index 1bfdc39bf5..e0183c4c5a 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -1,4 +1,12 @@ mAttribs = $rc->mAttribs; @@ -17,46 +29,70 @@ class RCCacheEntry extends RecentChange { } /** - * Class to show various lists of changes: - * - what links here - * - related changes - * - recent changes + * Base class for all changes lists */ -class ChangesList { - # Called by history lists and recent changes +class ChangesList extends ContextSource { + + /** + * @var Skin + */ public $skin; + protected $watchlist = false; + protected $message; + /** - * Changeslist contructor - * @param Skin $skin - */ - public function __construct( &$skin ) { - $this->skin =& $skin; + * Changeslist contructor + * + * @param $obj Skin or IContextSource + */ + public function __construct( $obj ) { + if ( $obj instanceof IContextSource ) { + $this->setContext( $obj ); + $this->skin = $obj->getSkin(); + } else { + $this->setContext( $obj->getContext() ); + $this->skin = $obj; + } $this->preCacheMessages(); } /** - * Fetch an appropriate changes list class for the specified user + * Fetch an appropriate changes list class for the main context + * This first argument used to be an User object. + * + * @deprecated in 1.18; use newFromContext() instead + * @param $unused string|User Unused + * @return ChangesList|EnhancedChangesList|OldChangesList derivative + */ + public static function newFromUser( $unused ) { + wfDeprecated( __METHOD__, '1.18' ); + return self::newFromContext( RequestContext::getMain() ); + } + + /** + * Fetch an appropriate changes list class for the specified context * Some users might want to use an enhanced list format, for instance * - * @param $user User to fetch the list class for - * @return ChangesList derivative + * @param $context IContextSource to use + * @return ChangesList|EnhancedChangesList|OldChangesList derivative */ - public static function newFromUser( &$user ) { - $sk = $user->getSkin(); - $list = NULL; - if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) { - return $user->getOption( 'usenewrc' ) ? - new EnhancedChangesList( $sk ) : new OldChangesList( $sk ); + public static function newFromContext( IContextSource $context ) { + $user = $context->getUser(); + $sk = $context->getSkin(); + $list = null; + if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) { + $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) ); + return $new ? new EnhancedChangesList( $context ) : new OldChangesList( $context ); } else { return $list; } } - + /** * Sets the list to use a
'.$tl.' '; + $tl = ''; + $r .= " | $tl | "; # Main line - $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot ); + $r .= '' . $this->recentChangesFlags( array( + 'newpage' => $isnew, + 'minor' => false, + 'unpatrolled' => $unpatrolled, + 'bot' => $bot , + ) ); # Timestamp - $r .= ' '.$block[0]->timestamp.' | '; + $r .= ' '.$block[0]->timestamp.' | '; # Article link if( $namehidden ) { $r .= ' ' . wfMsgHtml( 'rev-deleted-event' ) . ''; - } else if( $allLogs ) { + } elseif( $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(); + $r .= $this->getLanguage()->getDirMark(); $queryParams['curid'] = $curId; # Changes message $n = count($block); static $nchanges = array(); if ( !isset( $nchanges[$n] ) ) { - $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ); + $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $n ) ); } # Total change link $r .= ' '; + $logtext = ''; if( !$allLogs ) { - $r .= '('; - if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT ) ) { - $r .= $nchanges[$n]; - } else if( $isnew ) { - $r .= $nchanges[$n]; + if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) { + $logtext .= $nchanges[$n]; + } elseif( $isnew ) { + $logtext .= $nchanges[$n]; } else { $params = $queryParams; $params['diff'] = $currentRevision; $params['oldid'] = $oldid; - - $r .= $this->skin->link( + + $logtext .= Linker::link( $block[0]->getTitle(), $nchanges[$n], array(), @@ -898,21 +918,25 @@ class EnhancedChangesList extends ChangesList { # History if( $allLogs ) { // don't show history link for logs - } else if( $namehidden || !$block[0]->getTitle()->exists() ) { - $r .= $this->message['pipe-separator'] . $this->message['hist'] . ')'; + } elseif( $namehidden || !$block[0]->getTitle()->exists() ) { + $logtext .= $this->message['pipe-separator'] . $this->message['hist']; } else { $params = $queryParams; $params['action'] = 'history'; - $r .= $this->message['pipe-separator'] . - $this->skin->link( + $logtext .= $this->message['pipe-separator'] . + Linker::linkKnown( $block[0]->getTitle(), $this->message['hist'], array(), - $params, - array( 'known', 'noclasses' ) - ) . ')'; + $params + ); } + + if( $logtext !== '' ) { + $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped(); + } + $r .= ' . . '; # Character difference (does not apply if only log items) @@ -920,10 +944,10 @@ class EnhancedChangesList extends ChangesList { $last = 0; $first = count($block) - 1; # Some events (like logs) have an "empty" size, so we need to skip those... - while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === NULL ) { + while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) { $last++; } - while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === NULL ) { + while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) { $first--; } # Get net change @@ -940,74 +964,68 @@ class EnhancedChangesList extends ChangesList { $r .= $users; $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers); - $r .= " |
'.$this->spacerArrow(); - $r .= ' | ||||
'; - $r .= $this->spacerIndent() . $this->spacerIndent(); - $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, ' ', $rc_bot ); - $r .= ' | ';
+ $r .= '';
+ $r .= $this->recentChangesFlags( array(
+ 'newpage' => $rcObj->mAttribs['rc_new'],
+ 'minor' => $rcObj->mAttribs['rc_minor'],
+ 'unpatrolled' => $rcObj->unpatrolled,
+ 'bot' => $rcObj->mAttribs['rc_bot'],
+ ) );
+ $r .= ' | ';
$params = $queryParams;
- if( $rc_this_oldid != 0 ) {
- $params['oldid'] = $rc_this_oldid;
+ if( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
+ $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
}
# Log timestamp
- if( $rc_type == RC_LOG ) {
+ if( $type == RC_LOG ) {
$link = $rcObj->timestamp;
# Revision link
- } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
+ } elseif( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
$link = ''.$rcObj->timestamp.' ';
} else {
- if ( $rcObj->unpatrolled && $rc_type == RC_NEW) {
+ if ( $rcObj->unpatrolled && $type == RC_NEW) {
$params['rcid'] = $rcObj->mAttribs['rc_id'];
}
- $link = $this->skin->link(
+ $link = Linker::linkKnown(
$rcObj->getTitle(),
$rcObj->timestamp,
array(),
- $params,
- array( 'known', 'noclasses' )
+ $params
);
if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
$link = ''.$link.' ';
}
$r .= $link . '';
- if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
- $r .= ' (';
- $r .= $rcObj->curlink;
- $r .= $this->message['pipe-separator'];
- $r .= $rcObj->lastlink;
- $r .= ')';
+ if ( !$type == RC_LOG || $type == RC_NEW ) {
+ $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink . $this->message['pipe-separator'] . $rcObj->lastlink )->escaped();
}
$r .= ' . . ';
# Character diff
- if( $wgRCShowChangedSize ) {
- $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
+ if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
+ $r .= $rcObj->getCharacterDifference() . ' . . ' ;
}
- # User links
- $r .= $rcObj->userlink;
- $r .= $rcObj->usertalklink;
- // log action
- $this->insertAction( $r, $rcObj );
- // log comment
- $this->insertComment( $r, $rcObj );
+
+ if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
+ $r .= $this->insertLogEntry( $rcObj );
+ } else {
+ # User links
+ $r .= $rcObj->userlink;
+ $r .= $rcObj->usertalklink;
+ $r .= $this->insertComment( $rcObj );
+ }
+
# Rollback
$this->insertRollback( $r, $rcObj );
# Tags
@@ -1015,7 +1033,7 @@ class EnhancedChangesList extends ChangesList {
$r .= " | |
' . $this->spacerArrow() . ' '; + $r .= ' | '; # Flag and Timestamp - if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { - $r .= ' '; // 4 flags -> 4 spaces + if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) { + $r .= ' '; // 4 flags -> 4 spaces } else { - $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, ' ', $rc_bot ); + $r .= $this->recentChangesFlags( array( + 'newpage' => $type == RC_NEW, + 'minor' => $rcObj->mAttribs['rc_minor'], + 'unpatrolled' => $rcObj->unpatrolled, + 'bot' => $rcObj->mAttribs['rc_bot'], + ) ); } - $r .= ' '.$rcObj->timestamp.' | '; + $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->link( - $logtitle, - $logname, - array(), - array(), - array( 'known', 'noclasses' ) - ) . ')'; + if( $logType ) { + $logtitle = SpecialPage::getTitleFor( 'Log', $logType ); + $logname = LogPage::logName( $logType ); + $r .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, htmlspecialchars( $logname ) ) )->escaped(); } else { $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched ); } # Diff and hist links - if ( $rc_type != RC_LOG ) { - $r .= ' ('. $rcObj->difflink . $this->message['pipe-separator']; + if ( $type != RC_LOG ) { $query['action'] = 'history'; - $r .= $this->skin->link( + $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown( $rcObj->getTitle(), $this->message['hist'], array(), - $query, - array( 'known', 'noclasses' ) - ) . ')'; + $query + ) )->escaped(); } $r .= ' . . '; # Character diff 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) ) { - $r .= ' ' . wfMsgHtml('rev-deleted-event') . ''; - } else { - $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(), - $this->skin, LogPage::extractParams($rc_params), true, true ); - } + + if ( $type == RC_LOG ) { + $r .= $this->insertLogEntry( $rcObj ); + } else { + $r .= ' '.$rcObj->userlink . $rcObj->usertalklink; + $r .= $this->insertComment( $rcObj ); + $r .= $this->insertRollback( $r, $rcObj ); } - $this->insertComment( $r, $rcObj ); - $this->insertRollback( $r, $rcObj ); + # Tags + $classes = explode( ' ', $classes ); $this->insertTags( $r, $rcObj, $classes ); # Show how many people are watching this if enabled $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers); @@ -1159,6 +1171,8 @@ class EnhancedChangesList extends ChangesList { /** * If enhanced RC is in use, this function takes the previously cached * RC lines, arranges them, and outputs the HTML + * + * @return string */ protected function recentChangesBlock() { if( count ( $this->rc_cache ) == 0 ) { @@ -1182,8 +1196,9 @@ class EnhancedChangesList extends ChangesList { } /** - * Returns text for the end of RC + * Returns text for the end of RC * If enhanced RC is in use, returns pretty much all the text + * @return string */ public function endRecentChangesList() { return $this->recentChangesBlock() . parent::endRecentChangesList(); |