X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FChangesList.php;h=f75c5d5bc1a091f2154ef2a3a498ca7733d2436e;hb=b8880963ce764fa363072dc76cc698e809a93238;hp=629211e2c04f576a12380fa27836df9b668dbd3f;hpb=8794e3f68f477ac781e953a1d53b8efac112e94d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ChangesList.php b/includes/ChangesList.php index 629211e2c0..f75c5d5bc1 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -1,4 +1,12 @@ mAttribs = $rc->mAttribs; @@ -17,78 +29,144 @@ 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 RequestContext + */ + public function __construct( $obj ) { + if ( $obj instanceof RequestContext ) { + $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 Unused + * @return ChangesList|EnhancedChangesList|OldChangesList derivative + */ + public static function newFromUser( $unused ) { + 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 - */ - 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 ); + * @param $context RequestContext to use + * @return ChangesList|EnhancedChangesList|OldChangesList derivative + */ + public static function newFromContext( RequestContext $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 $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() { 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' ) ); } } } - /** * 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 ? - '' . $this->message['newpageletter'] . '' : $nothing; - $f .= $minor ? - '' . $this->message['minoreditletter'] . '' : $nothing; - $f .= $bot ? '' . $this->message['boteditletter'] . '' : $nothing; - $f .= $patrolled ? '!' : $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; } + /** + * 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 $flag String: 'newpage', 'unpatrolled', 'minor', or 'bot' + * @return String: Raw HTML + */ + public static function flag( $flag ) { + static $messages = null; + if ( is_null( $messages ) ) { + $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' ); + } + } + + # Inconsistent naming, bleh + $map = array( + 'newpage' => 'newpage', + 'minor' => 'minoredit', + 'bot' => 'botedit', + 'unpatrolled' => 'unpatrolled', + 'minoredit' => 'minoredit', + 'botedit' => 'botedit', + ); + $flag = $map[$flag]; + + 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(); @@ -98,34 +176,46 @@ 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; + global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode; $szdiff = $new - $old; - $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $wgLang->formatNum( $szdiff ) ); + + $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'; + $tag = 'span'; } if( $szdiff === 0 ) { return "<$tag class='mw-plusminus-null'>($formatedSize)"; } elseif( $szdiff > 0 ) { return "<$tag class='mw-plusminus-pos'>(+$formatedSize)"; - } else { + } else { return "<$tag class='mw-plusminus-neg'>($formatedSize)"; } } /** - * Returns text for the end of RC - * @return string + * Returns text for the end of RC + * @return String */ public function endRecentChangesList() { if( $this->rclistOpen ) { @@ -135,80 +225,135 @@ class ChangesList { } } - protected function insertMove( &$s, $rc ) { + /** + * @param $s + * @param $rc RecentChange + * @return void + */ + public function insertMove( &$s, $rc ) { # Diff $s .= '(' . $this->message['diff'] . ') ('; # Hist - $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'], - 'action=history' ) . ') . . '; + $s .= Linker::linkKnown( + $rc->getMovedToTitle(), + $this->message['hist'], + array(), + array( '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(), '' ) ); + $s .= wfMsgHtml( + $msg, + Linker::linkKnown( + $rc->getTitle(), + null, + array(), + array( 'redirect' => 'no' ) + ), + Linker::linkKnown( $rc->getMovedToTitle() ) + ); } - 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->getLang()->date( $rc_timestamp, true, true ); if( $date != $this->lastdate ) { - if( '' != $this->lastdate ) { + if( $this->lastdate != '' ) { $s .= "\n"; } - $s .= '

    '.$date."

    \n