X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FChangesList.php;h=f75c5d5bc1a091f2154ef2a3a498ca7733d2436e;hb=b8880963ce764fa363072dc76cc698e809a93238;hp=b51b166f3cdefc52ccea299a01833b22fafb103b;hpb=854a37a73ab0b901298dabb546e76ba8b012425c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ChangesList.php b/includes/ChangesList.php index b51b166f3c..f75c5d5bc1 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -1,4 +1,12 @@ mAttribs = $rc->mAttribs; @@ -17,46 +29,69 @@ 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 + * @param $context RequestContext 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( 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 bool $value + * @param $value Boolean */ public function setWatchlistDivs( $value = true ) { $this->watchlist = $value; @@ -68,36 +103,70 @@ class ChangesList { */ private function preCacheMessages() { if( !isset( $this->message ) ) { - foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '. - 'blocklink history boteditletter semicolon-separator pipe-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(); @@ -107,12 +176,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; @@ -123,30 +192,30 @@ class ChangesList { 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 ) { @@ -156,44 +225,40 @@ 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->link( + $s .= Linker::linkKnown( $rc->getMovedToTitle(), $this->message['hist'], array(), - array( 'action' => 'history' ), - array( 'known', 'noclasses' ) + array( 'action' => 'history' ) ) . ') . . '; # "[[x]] moved to [[y]]" $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir'; - $s .= wfMsg( + $s .= wfMsgHtml( $msg, - $this->skin->link( + Linker::linkKnown( $rc->getTitle(), null, array(), - array( 'redirect' => 'no' ), - array( 'known', 'noclasses' ) + array( 'redirect' => 'no' ) ), - $this->skin->link( - $rc->getMovedToTitle(), - null, - array(), - array(), - array( 'known', 'noclasses' ) - ) + 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 .= Xml::element( 'h4', null, $date ) . "\n