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
  • tag - * @param bool $value + * @param $value Boolean */ public function setWatchlistDivs( $value = true ) { $this->watchlist = $value; @@ -75,21 +111,19 @@ class ChangesList { } } - /** * Returns the appropriate flags for new page, minor change and patrolling - * @param bool $new - * @param bool $minor - * @param bool $patrolled - * @param string $nothing, string to use for empty space - * @param bool $bot - * @return string + * @param $flags Array Associative array of 'flag' => Bool + * @param $nothing String to use for empty space + * @return String */ - protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) { - $f = $new ? self::flag( 'newpage' ) : $nothing; - $f .= $minor ? self::flag( 'minor' ) : $nothing; - $f .= $bot ? self::flag( 'bot' ) : $nothing; - $f .= $patrolled ? self::flag( 'unpatrolled' ) : $nothing; + protected function recentChangesFlags( $flags, $nothing = ' ' ) { + $f = ''; + foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){ + $f .= isset( $flags[$flag] ) && $flags[$flag] + ? self::flag( $flag ) + : $nothing; + } return $f; } @@ -99,74 +133,41 @@ class ChangesList { * unpatrolled edit. By default in English it will contain "N", "m", "b", * "!" respectively, plus it will have an appropriate title and class. * - * @param $key string 'newpage', 'unpatrolled', 'minor', or 'bot' - * @return string Raw HTML + * @param $flag String: 'newpage', 'unpatrolled', 'minor', or 'bot' + * @return String: Raw HTML */ - public static function flag( $key ) { + public static function flag( $flag ) { static $messages = null; if ( is_null( $messages ) ) { - foreach ( explode( ' ', 'minoreditletter boteditletter newpageletter ' . - 'unpatrolledletter recentchanges-label-minor recentchanges-label-bot ' . - 'recentchanges-label-newpage recentchanges-label-unpatrolled' ) as $msg ) { - $messages[$msg] = wfMsgExt( $msg, 'escapenoentities' ); - } - } - # Inconsistent naming, bleh - if ( $key == 'newpage' || $key == 'unpatrolled' ) { - $key2 = $key; - } else { - $key2 = $key . 'edit'; - } - return "" - . $messages["${key2}letter"] - . ''; - } - - /** - * Some explanatory wrapper text for the given flag, to be used in a legend - * explaining what the flags mean. For instance, "N - new page". See - * also flag(). - * - * @param $key string 'newpage', 'unpatrolled', 'minor', or 'bot' - * @return string Raw HTML - */ - private static function flagLine( $key ) { - return wfMsgExt( "recentchanges-legend-$key", array( 'escapenoentities', - 'replaceafter' ), self::flag( $key ) ); - } - - /** - * A handy legend to tell users what the little "m", "b", and so on mean. - * - * @return string Raw HTML - */ - public static function flagLegend() { - global $wgGroupPermissions, $wgLang; - - $flags = array( self::flagLine( 'newpage' ), - self::flagLine( 'minor' ) ); - - # Don't show info on bot edits unless there's a bot group of some kind - foreach ( $wgGroupPermissions as $rights ) { - if ( isset( $rights['bot'] ) && $rights['bot'] ) { - $flags[] = self::flagLine( 'bot' ); - break; + $messages = array( + 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ), + 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ), + 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ), + 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ), + ); + foreach( $messages as &$value ) { + $value[0] = wfMsgExt( $value[0], 'escapenoentities' ); + $value[1] = wfMsgExt( $value[1], 'escapenoentities' ); } } - if ( self::usePatrol() ) { - $flags[] = self::flagLine( 'unpatrolled' ); - } + # Inconsistent naming, bleh + $map = array( + 'newpage' => 'newpage', + 'minor' => 'minoredit', + 'bot' => 'botedit', + 'unpatrolled' => 'unpatrolled', + 'minoredit' => 'minoredit', + 'botedit' => 'botedit', + ); + $flag = $map[$flag]; - return '
    ' . - wfMsgExt( 'recentchanges-label-legend', 'parseinline', - $wgLang->commaList( $flags ) ) . '
    '; + return "" . $messages[$flag][0] . ''; } /** * Returns text for the start of the tabular part of RC - * @return string + * @return String */ public function beginRecentChangesList() { $this->rc_cache = array(); @@ -176,12 +177,12 @@ class ChangesList { $this->rclistOpen = false; return ''; } - + /** * Show formatted char difference - * @param int $old bytes - * @param int $new bytes - * @returns string + * @param $old Integer: bytes + * @param $new Integer: bytes + * @return String */ public static function showCharacterDifference( $old, $new ) { global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode; @@ -192,30 +193,40 @@ class ChangesList { if ( !isset($fastCharDiff[$code]) ) { $fastCharDiff[$code] = $wgMiserMode || wfMsgNoTrans( 'rc-change-size' ) === '$1'; } - - $formatedSize = $wgLang->formatNum($szdiff); + + $formattedSize = $wgLang->formatNum($szdiff); if ( !$fastCharDiff[$code] ) { - $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize ); + $formattedSize = wfMsgExt( 'rc-change-size', array( 'parsemag' ), $formattedSize ); } - + if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) { $tag = 'strong'; } else { - $tag = 'span'; + $tag = 'span'; + } + + if ( $szdiff === 0 ) { + $formattedSizeClass = 'mw-plusminus-null'; + } + if ( $szdiff > 0 ) { + $formattedSize = '+' . $formattedSize; + $formattedSizeClass = 'mw-plusminus-pos'; } - 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)"; + if ( $szdiff < 0 ) { + $formattedSizeClass = 'mw-plusminus-neg'; } + + $formattedTotalSize = wfMsgExt( 'rc-change-size-new', 'parsemag', $wgLang->formatNum( $new ) ); + + return Html::element( $tag, + array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ), + wfMessage( 'parentheses', $formattedSize )->plain() ) . $wgLang->getDirMark(); } /** - * Returns text for the end of RC - * @return string + * Returns text for the end of RC + * @return String */ public function endRecentChangesList() { if( $this->rclistOpen ) { @@ -225,44 +236,11 @@ class ChangesList { } } - protected function insertMove( &$s, $rc ) { - # Diff - $s .= '(' . $this->message['diff'] . ') ('; - # Hist - $s .= $this->skin->link( - $rc->getMovedToTitle(), - $this->message['hist'], - array(), - array( 'action' => 'history' ), - array( 'known', 'noclasses' ) - ) . ') . . '; - # "[[x]] moved to [[y]]" - $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir'; - $s .= wfMsg( - $msg, - $this->skin->link( - $rc->getTitle(), - null, - array(), - array( 'redirect' => 'no' ), - array( 'known', 'noclasses' ) - ), - $this->skin->link( - $rc->getMovedToTitle(), - null, - array(), - array(), - array( 'known', 'noclasses' ) - ) - ); - } - - protected function insertDateHeader( &$s, $rc_timestamp ) { - global $wgLang; + public function insertDateHeader( &$s, $rc_timestamp ) { # Make date header if necessary - $date = $wgLang->date( $rc_timestamp, true, true ); + $date = $this->getLanguage()->date( $rc_timestamp, true, true ); if( $date != $this->lastdate ) { - if( '' != $this->lastdate ) { + if( $this->lastdate != '' ) { $s .= "\n"; } $s .= Xml::element( 'h4', null, $date ) . "\n