]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/ChangesList.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / includes / ChangesList.php
index 9f092991618834462453b236a3f01ee8da422885..b8bc4f5580e42ef3e0c29e0b388d6953e9f10fa4 100644 (file)
@@ -1,4 +1,12 @@
 <?php
+/**
+ * Classes to show various lists of changes:
+ * - watchlist
+ * - related changes
+ * - recent changes
+ *
+ * @file
+ */
 
 /**
  * @todo document
@@ -17,13 +25,9 @@ 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
        public $skin;
        protected $watchlist = false;
 
@@ -44,11 +48,13 @@ class ChangesList {
         * @return ChangesList derivative
         */
        public static function newFromUser( &$user ) {
+               global $wgRequest;
+
                $sk = $user->getSkin();
                $list = null;
                if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
-                       return $user->getOption( 'usenewrc' ) ?
-                               new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
+                       $new = $wgRequest->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
+                       return $new ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
                } else {
                        return $list;
                }
@@ -85,7 +91,7 @@ class ChangesList {
         * @param $bot Boolean
         * @return String
         */
-       protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&nbsp;', $bot = false ) {
+       protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&#160;', $bot = false ) {
                $f = $new ? self::flag( 'newpage' ) : $nothing;
                $f .= $minor ? self::flag( 'minor' ) : $nothing;
                $f .= $bot ? self::flag( 'bot' ) : $nothing;
@@ -123,47 +129,6 @@ class ChangesList {
                        . '</abbr>';
        }
 
-       /**
-        * 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 '<div class="mw-rc-label-legend">' .
-                       wfMsgExt( 'recentchanges-label-legend', 'parseinline',
-                       $wgLang->commaList( $flags ) ) . '</div>';
-       }
-
        /**
         * Returns text for the start of the tabular part of RC
         * @return String
@@ -595,14 +560,14 @@ class EnhancedChangesList extends ChangesList {
         * @return String
         */
        public function beginRecentChangesList() {
-               global $wgStylePath, $wgStyleVersion;
+               global $wgOut;
                $this->rc_cache = array();
                $this->rcMoveIndex = 0;
                $this->rcCacheIndex = 0;
                $this->lastdate = '';
                $this->rclistOpen = false;
-               $script = Html::linkedScript( $wgStylePath . "/common/enhancedchanges.js?$wgStyleVersion" );
-               return $script;
+               $wgOut->addModules( 'mediawiki.legacy.enhancedchanges' );
+               return '';
        }
        /**
         * Format a line for enhanced recentchange (aka with javascript and block of lines).
@@ -628,7 +593,7 @@ class EnhancedChangesList extends ChangesList {
                        # Process current cache
                        $ret = $this->recentChangesBlock();
                        $this->rc_cache = array();
-                       $ret .= Xml::element( 'h4', null, $date );
+                       $ret .= Xml::element( 'h4', null, $date ) . "\n";
                        $this->lastdate = $date;
                }
 
@@ -771,7 +736,15 @@ class EnhancedChangesList extends ChangesList {
 
                wfProfileIn( __METHOD__ );
 
-               $r = '<table class="mw-enhanced-rc"><tr>';
+               # Add the namespace and title of the block as part of the class
+               if ( $block[0]->mAttribs['rc_log_type'] ) {
+                       # Log entry
+                       $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs['rc_log_type'] . '-' . $block[0]->mAttribs['rc_title'] );
+               } else {
+                       $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
+               }
+               $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
+                       Html::openElement( 'tr' );
 
                # Collate list of users
                $userlinks = array();
@@ -841,13 +814,13 @@ class EnhancedChangesList extends ChangesList {
 
                $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
                $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
-               $r .= '<td class="mw-enhanced-rc">'.$tl.'&nbsp;';
+               $r .= '<td class="mw-enhanced-rc">'.$tl.'&#160;';
 
                # Main line
-               $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
+               $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&#160;', $bot );
 
                # Timestamp
-               $r .= '&nbsp;'.$block[0]->timestamp.'&nbsp;</td><td style="padding:0px;">';
+               $r .= '&#160;'.$block[0]->timestamp.'&#160;</td><td style="padding:0px;">';
 
                # Article link
                if( $namehidden ) {
@@ -951,8 +924,8 @@ class EnhancedChangesList extends ChangesList {
                        #$r .= '<tr><td valign="top">'.$this->spacerArrow();
                        $r .= '<tr><td style="vertical-align:top;font-family:monospace; padding:0px;">';
                        $r .= $this->spacerIndent() . $this->spacerIndent();
-                       $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
-                       $r .= '&nbsp;</td><td style="vertical-align:top; padding:0px;"><span style="font-family:monospace">';
+                       $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&#160;', $rc_bot );
+                       $r .= '&#160;</td><td style="vertical-align:top; padding:0px;"><span style="font-family:monospace">';
 
                        $params = $queryParams;
 
@@ -1067,7 +1040,7 @@ class EnhancedChangesList extends ChangesList {
         * @return String: HTML <td> tag
         */
        protected function spacerIndent() {
-               return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
+               return '&#160;&#160;&#160;&#160;&#160;';
        }
 
        /**
@@ -1082,19 +1055,27 @@ class EnhancedChangesList extends ChangesList {
                # Extract fields from DB into the function scope (rc_xxxx variables)
                // FIXME: Would be good to replace this extract() call with something
                // that explicitly initializes variables.
-               $classes = array(); // TODO implement
+               // TODO implement
                extract( $rcObj->mAttribs );
                $query['curid'] = $rc_cur_id;
 
-               $r = '<table class="mw-enhanced-rc"><tr>';
-               $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow() . '&nbsp;';
+               if( $rc_log_type ) {
+                       # Log entry
+                       $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-log-' . $rc_log_type . '-' . $rcObj->mAttribs['rc_title'] );
+               } else {
+                       $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
+               }
+               $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
+                       Html::openElement( 'tr' );
+
+               $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow() . '&#160;';
                # Flag and Timestamp
                if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
-                       $r .= '&nbsp;&nbsp;&nbsp;&nbsp;'; // 4 flags -> 4 spaces
+                       $r .= '&#160;&#160;&#160;&#160;'; // 4 flags -> 4 spaces
                } else {
-                       $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
+                       $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&#160;', $rc_bot );
                }
-               $r .= '&nbsp;'.$rcObj->timestamp.'&nbsp;</td><td style="padding:0px;">';
+               $r .= '&#160;'.$rcObj->timestamp.'&#160;</td><td style="padding:0px;">';
                # Article or log link
                if( $rc_log_type ) {
                        $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
@@ -1140,6 +1121,7 @@ class EnhancedChangesList extends ChangesList {
                $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);