X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FChangesList.php;h=9f092991618834462453b236a3f01ee8da422885;hb=a88a955ebfa5f626a3e52afc85bc036ee5dd465d;hp=41d20398b24229e1802676121edfe69c3aef92d1;hpb=6730363fa10f78b5df5610a86736ce862f05f7f2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ChangesList.php b/includes/ChangesList.php index 41d20398b2..9f09299161 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,14 +24,15 @@ class RCCacheEntry extends RecentChange */ class ChangesList { # Called by history lists and recent changes - # + public $skin; + protected $watchlist = false; /** * Changeslist contructor - * @param Skin $skin + * @param $skin Skin */ - function __construct( &$skin ) { - $this->skin =& $skin; + public function __construct( $skin ) { + $this->skin = $skin; $this->preCacheMessages(); } @@ -45,23 +45,31 @@ class ChangesList { */ public static function newFromUser( &$user ) { $sk = $user->getSkin(); - $list = NULL; + $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; } } + + /** + * Sets the list to use a
  • tag + * @param $value Boolean + */ + public function setWatchlistDivs( $value = true ) { + $this->watchlist = $value; + } /** * As we use the same small set of messages in various methods and that * 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 ) { + foreach ( explode( ' ', 'cur diff hist last blocklink history ' . + 'semicolon-separator pipe-separator' ) as $msg ) { $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) ); } } @@ -70,26 +78,95 @@ 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 $new Boolean + * @param $minor Boolean + * @param $patrolled Boolean + * @param $nothing String to use for empty space + * @param $bot Boolean + * @return String */ protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) { - $f = $new ? '' . $this->message['newpageletter'] . '' - : $nothing; - $f .= $minor ? '' . $this->message['minoreditletter'] . '' - : $nothing; - $f .= $bot ? '' . $this->message['boteditletter'] . '' : $nothing; - $f .= $patrolled ? '!' : $nothing; + $f = $new ? self::flag( 'newpage' ) : $nothing; + $f .= $minor ? self::flag( 'minor' ) : $nothing; + $f .= $bot ? self::flag( 'bot' ) : $nothing; + $f .= $patrolled ? self::flag( 'unpatrolled' ) : $nothing; return $f; } + /** + * Provide the element appropriate to a given abbreviated flag, + * namely the flag indicating a new page, a minor edit, a bot edit, or an + * 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 + */ + public static function flag( $key ) { + 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; + } + } + + if ( self::usePatrol() ) { + $flags[] = self::flagLine( 'unpatrolled' ); + } + + return '
    ' . + wfMsgExt( 'recentchanges-label-legend', 'parseinline', + $wgLang->commaList( $flags ) ) . '
    '; + } + /** * Returns text for the start of the tabular part of RC - * @return string + * @return String */ public function beginRecentChangesList() { $this->rc_cache = array(); @@ -99,10 +176,46 @@ class ChangesList { $this->rclistOpen = false; return ''; } + + /** + * Show formatted char difference + * @param $old Integer: bytes + * @param $new Integer: 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 - * @return string + * @return String */ public function endRecentChangesList() { if( $this->rclistOpen ) { @@ -112,101 +225,154 @@ class ChangesList { } } - protected function insertMove( &$s, $rc ) { + public function insertMove( &$s, $rc ) { # Diff $s .= '(' . $this->message['diff'] . ') ('; # Hist - $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'], 'action=history' ) . - ') . . '; - + $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->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ), - $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) ); + $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) { + public function insertDateHeader( &$s, $rc_timestamp ) { global $wgLang; - # Make date header if necessary $date = $wgLang->date( $rc_timestamp, true, true ); if( $date != $this->lastdate ) { - if( '' != $this->lastdate ) { + if( $this->lastdate != '' ) { $s .= "\n"; } - $s .= '

    '.$date."

    \n