fixing bug 20186: allow filtering SpecialContributions for RevisionDeleted edits...
[lhc/web/wiklou.git] / includes / specials / SpecialRecentchanges.php
index 4f43c8e..26ff43b 100644 (file)
@@ -5,6 +5,8 @@
  * @ingroup SpecialPage
  */
 class SpecialRecentChanges extends SpecialPage {
+       var $rcOptions, $rcSubpage;
+
        public function __construct() {
                parent::__construct( 'Recentchanges' );
                $this->includable( true );
@@ -23,11 +25,11 @@ class SpecialRecentChanges extends SpecialPage {
                $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
                $opts->add( 'from', '' );
 
-               $opts->add( 'hideminor',     (bool)$wgUser->getOption( 'hideminor' ) );
+               $opts->add( 'hideminor',     $wgUser->getBoolOption( 'hideminor' ) );
                $opts->add( 'hidebots',      true  );
                $opts->add( 'hideanons',     false );
                $opts->add( 'hideliu',       false );
-               $opts->add( 'hidepatrolled', false );
+               $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'hidepatrolled' ) );
                $opts->add( 'hidemyself',    false );
 
                $opts->add( 'namespace', '', FormOptions::INTNULL );
@@ -35,11 +37,12 @@ class SpecialRecentChanges extends SpecialPage {
 
                $opts->add( 'categories', '' );
                $opts->add( 'categories_any', false );
+               $opts->add( 'tagfilter', '' );
                return $opts;
        }
 
        /**
-        * Get a FormOptions object with options as specified by the user
+        * Create a FormOptions object with options as specified by the user
         *
         * @return FormOptions
         */
@@ -50,7 +53,7 @@ class SpecialRecentChanges extends SpecialPage {
                $opts->fetchValuesFromRequest( $wgRequest );
 
                // Give precedence to subpage syntax
-               if ( $parameters !== null ) {
+               if( $parameters !== null ) {
                        $this->parseParameters( $parameters, $opts );
                }
 
@@ -59,62 +62,77 @@ class SpecialRecentChanges extends SpecialPage {
        }
 
        /**
-        * Get a FormOptions object sepcific for feed requests
+        * Create a FormOptions object specific for feed requests and return it
         *
         * @return FormOptions
         */
        public function feedSetup() {
                global $wgFeedLimit, $wgRequest;
                $opts = $this->getDefaultOptions();
-               $opts->fetchValuesFromRequest( $wgRequest, array( 'days', 'limit', 'hideminor' ) );
+               # Feed is cached on limit,hideminor,namespace; other params would randomly not work
+               $opts->fetchValuesFromRequest( $wgRequest, array( 'limit', 'hideminor', 'namespace' ) );
                $opts->validateIntBounds( 'limit', 0, $wgFeedLimit );
                return $opts;
        }
 
+       /**
+        * Get the current FormOptions for this request
+        */
+       public function getOptions() {
+               if ( $this->rcOptions === null ) {
+                       global $wgRequest;
+                       $feedFormat = $wgRequest->getVal( 'feed' );
+                       $this->rcOptions = $feedFormat ? $this->feedSetup() : $this->setup( $this->rcSubpage );
+               }
+               return $this->rcOptions;
+       }
+
+
        /**
         * Main execution point
         *
-        * @param $parameters string
+        * @param $subpage string
         */
-       public function execute( $parameters ) {
+       public function execute( $subpage ) {
                global $wgRequest, $wgOut;
+               $this->rcSubpage = $subpage;
                $feedFormat = $wgRequest->getVal( 'feed' );
 
                # 10 seconds server-side caching max
                $wgOut->setSquidMaxage( 10 );
-
+               # Check if the client has a cached version
                $lastmod = $this->checkLastModified( $feedFormat );
-               if( $lastmod === false ){
+               if( $lastmod === false ) {
                        return;
                }
 
-               $opts = $feedFormat ? $this->feedSetup() : $this->setup( $parameters );
+               $opts = $this->getOptions();
                $this->setHeaders();
                $this->outputHeader();
 
                // Fetch results, prepare a batch link existence check query
-               $rows = array();
-               $batch = new LinkBatch;
                $conds = $this->buildMainQueryConds( $opts );
                $rows = $this->doMainQuery( $conds, $opts );
                if( $rows === false ){
-                       $this->doHeader( $opts );
+                       if( !$this->including() ) {
+                               $this->doHeader( $opts );
+                       }
                        return;
                }
 
-               foreach( $rows as $row ) {
-                       if ( !$feedFormat ) {
-                               // User page and talk links
+               if( !$feedFormat ) {
+                       $batch = new LinkBatch;
+                       foreach( $rows as $row ) {
                                $batch->add( NS_USER, $row->rc_user_text  );
                                $batch->add( NS_USER_TALK, $row->rc_user_text  );
+                               $batch->add( $row->rc_namespace, $row->rc_title );
                        }
+                       $batch->execute();
                }
-
-               if ( $feedFormat ) {
-                       list( $feed, $feedObj ) = $this->getFeedObject( $feedFormat );
-                       $feed->execute( $feedObj, $rows, $opts['limit'], $opts['hideminor'], $lastmod );
+               if( $feedFormat ) {
+                       list( $changesFeed, $formatter ) = $this->getFeedObject( $feedFormat );
+                       $changesFeed->execute( $formatter, $rows, $lastmod, $opts );
                } else {
-                       $batch->execute();
                        $this->webOutput( $rows, $opts );
                }
 
@@ -127,12 +145,12 @@ class SpecialRecentChanges extends SpecialPage {
         * @return array
         */
        public function getFeedObject( $feedFormat ){
-               $feed = new ChangesFeed( $feedFormat, 'rcfeed' );
-               $feedObj = $feed->getFeedObject(
+               $changesFeed = new ChangesFeed( $feedFormat, 'rcfeed' );
+               $formatter = $changesFeed->getFeedObject(
                        wfMsgForContent( 'recentchanges' ),
                        wfMsgForContent( 'recentchanges-feed-description' )
                );
-               return array( $feed, $feedObj );
+               return array( $changesFeed, $formatter );
        }
 
        /**
@@ -144,21 +162,21 @@ class SpecialRecentChanges extends SpecialPage {
         */
        public function parseParameters( $par, FormOptions $opts ) {
                $bits = preg_split( '/\s*,\s*/', trim( $par ) );
-               foreach ( $bits as $bit ) {
-                       if ( 'hidebots' === $bit ) $opts['hidebots'] = true;
-                       if ( 'bots' === $bit ) $opts['hidebots'] = false;
-                       if ( 'hideminor' === $bit ) $opts['hideminor'] = true;
-                       if ( 'minor' === $bit ) $opts['hideminor'] = false;
-                       if ( 'hideliu' === $bit ) $opts['hideliu'] = true;
-                       if ( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true;
-                       if ( 'hideanons' === $bit ) $opts['hideanons'] = true;
-                       if ( 'hidemyself' === $bit ) $opts['hidemyself'] = true;
-
-                       if ( is_numeric( $bit ) ) $opts['limit'] =  $bit;
+               foreach( $bits as $bit ) {
+                       if( 'hidebots' === $bit ) $opts['hidebots'] = true;
+                       if( 'bots' === $bit ) $opts['hidebots'] = false;
+                       if( 'hideminor' === $bit ) $opts['hideminor'] = true;
+                       if( 'minor' === $bit ) $opts['hideminor'] = false;
+                       if( 'hideliu' === $bit ) $opts['hideliu'] = true;
+                       if( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true;
+                       if( 'hideanons' === $bit ) $opts['hideanons'] = true;
+                       if( 'hidemyself' === $bit ) $opts['hidemyself'] = true;
+
+                       if( is_numeric( $bit ) ) $opts['limit'] =  $bit;
 
                        $m = array();
-                       if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1];
-                       if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1];
+                       if( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1];
+                       if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1];
                }
        }
 
@@ -168,14 +186,14 @@ class SpecialRecentChanges extends SpecialPage {
         * update the timestamp
         *
         * @param $feedFormat String
-        * @return int or false
+        * @return string or false
         */
        public function checkLastModified( $feedFormat ) {
                global $wgUseRCPatrol, $wgOut;
                $dbr = wfGetDB( DB_SLAVE );
-               $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __FUNCTION__ );
-               if ( $feedFormat || !$wgUseRCPatrol ) {
-                       if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
+               $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
+               if( $feedFormat || !$wgUseRCPatrol ) {
+                       if( $lastmod && $wgOut->checkLastModified( $lastmod ) ) {
                                # Client cache fresh and headers sent, nothing more to do.
                                return false;
                        }
@@ -227,12 +245,12 @@ class SpecialRecentChanges extends SpecialPage {
                $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
                $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
 
-               if ( $opts['hideminor'] )  $conds['rc_minor'] = 0;
-               if ( $opts['hidebots'] )   $conds['rc_bot'] = 0;
-               if ( $hidePatrol )         $conds['rc_patrolled'] = 0;
-               if ( $forcebot )           $conds['rc_bot'] = 1;
-               if ( $hideLoggedInUsers )  $conds[] = 'rc_user = 0';
-               if ( $hideAnonymousUsers ) $conds[] = 'rc_user != 0';
+               if( $opts['hideminor'] )  $conds['rc_minor'] = 0;
+               if( $opts['hidebots'] )   $conds['rc_bot'] = 0;
+               if( $hidePatrol )         $conds['rc_patrolled'] = 0;
+               if( $forcebot )           $conds['rc_bot'] = 1;
+               if( $hideLoggedInUsers )  $conds[] = 'rc_user = 0';
+               if( $hideAnonymousUsers ) $conds[] = 'rc_user != 0';
 
                if( $opts['hidemyself'] ) {
                        if( $wgUser->getId() ) {
@@ -243,8 +261,8 @@ class SpecialRecentChanges extends SpecialPage {
                }
 
                # Namespace filtering
-               if ( $opts['namespace'] !== '' ) {
-                       if ( !$opts['invert'] ) {
+               if( $opts['namespace'] !== '' ) {
+                       if( !$opts['invert'] ) {
                                $conds[] = 'rc_namespace = ' . $dbr->addQuotes( $opts['namespace'] );
                        } else {
                                $conds[] = 'rc_namespace != ' . $dbr->addQuotes( $opts['namespace'] );
@@ -266,6 +284,7 @@ class SpecialRecentChanges extends SpecialPage {
 
                $tables = array( 'recentchanges' );
                $join_conds = array();
+               $query_options = array( 'USE INDEX' => array('recentchanges' => 'rc_timestamp') );
 
                $uid = $wgUser->getId();
                $dbr = wfGetDB( DB_SLAVE );
@@ -276,17 +295,36 @@ class SpecialRecentChanges extends SpecialPage {
                // JOIN on watchlist for users
                if( $uid ) {
                        $tables[] = 'watchlist';
-                       $join_conds = array( 'watchlist' => array('LEFT JOIN',"wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace") );
+                       $join_conds['watchlist'] = array('LEFT JOIN',
+                               "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace");
                }
+               if ($wgUser->isAllowed("rollback")) {
+                       $tables[] = 'page';
+                       $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
+               }
+               // Tag stuff.
+               $fields = array();
+               // Fields are * in this case, so let the function modify an empty array to keep it happy.
+               ChangeTags::modifyDisplayQuery(
+                       $tables, $fields, $conds, $join_conds, $query_options, $opts['tagfilter']
+               );
 
-               wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
-
-               // Is there either one namespace selected or excluded?
-               // Also, if this is "all" or main namespace, just use timestamp index.
-               if( is_null($namespace) || $invert || $namespace == NS_MAIN ) {
+               if ( !wfRunHooks( 'SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts, &$query_options ) ) )
+                       return false;
+
+               // Don't use the new_namespace_time timestamp index if:
+               // (a) "All namespaces" selected
+               // (b) We want all pages NOT in a certain namespaces (inverted)
+               // (c) There is a tag to filter on (use tag index instead)
+               // (d) UNION + sort/limit is not an option for the DBMS
+               if( is_null($namespace)
+                       || $invert
+                       || $opts['tagfilter'] != ''
+                       || !$dbr->unionSupportsOrderAndLimit() )
+               {
                        $res = $dbr->select( $tables, '*', $conds, __METHOD__,
-                               array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
-                                       'USE INDEX' => array('recentchanges' => 'rc_timestamp') ),
+                               array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) +
+                               $query_options,
                                $join_conds );
                // We have a new_namespace_time index! UNION over new=(0,1) and sort result set!
                } else {
@@ -295,17 +333,18 @@ class SpecialRecentChanges extends SpecialPage {
                                array( 'rc_new' => 1 ) + $conds,
                                __METHOD__,
                                array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
-                                       'USE INDEX' =>  array('recentchanges' => 'new_name_timestamp') ),
+                                       'USE INDEX' =>  array('recentchanges' => 'rc_timestamp') ),
                                $join_conds );
                        // Old pages
                        $sqlOld = $dbr->selectSQLText( $tables, '*',
                                array( 'rc_new' => 0 ) + $conds,
                                __METHOD__,
                                array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
-                                       'USE INDEX' =>  array('recentchanges' => 'new_name_timestamp') ),
+                                       'USE INDEX' =>  array('recentchanges' => 'rc_timestamp') ),
                                $join_conds );
                        # Join the two fast queries, and sort the result set
-                       $sql = "($sqlNew) UNION ($sqlOld) ORDER BY rc_timestamp DESC LIMIT $limit";
+                       $sql = $dbr->unionQueries(array($sqlNew, $sqlOld), false).' ORDER BY rc_timestamp DESC';
+                       $sql = $dbr->limitResult($sql, $limit, false);
                        $res = $dbr->query( $sql, __METHOD__ );
                }
 
@@ -324,68 +363,67 @@ class SpecialRecentChanges extends SpecialPage {
 
                $limit = $opts['limit'];
 
-               if ( !$this->including() ) {
+               if( !$this->including() ) {
                        // Output options box
                        $this->doHeader( $opts );
                }
 
                // And now for the content
-               $wgOut->setSyndicated( true );
-
-               $list = ChangesList::newFromUser( $wgUser );
+               $wgOut->setFeedAppendQuery( $this->getFeedQuery() );
 
-               if ( $wgAllowCategorizedRecentChanges ) {
+               if( $wgAllowCategorizedRecentChanges ) {
                        $this->filterByCategories( $rows, $opts );
                }
 
-               $s = $list->beginRecentChangesList();
-               $counter = 1;
-
                $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
                $watcherCache = array();
 
                $dbr = wfGetDB( DB_SLAVE );
 
-               foreach( $rows as $obj ){
-                       if( $limit == 0) {
-                               break;
-                       }
-
-                       if ( ! ( $opts['hideminor']     && $obj->rc_minor     ) &&
-                            ! ( $opts['hidepatrolled'] && $obj->rc_patrolled ) ) {
-                               $rc = RecentChange::newFromRow( $obj );
-                               $rc->counter = $counter++;
-
-                               if ($wgShowUpdatedMarker
-                                       && !empty( $obj->wl_notificationtimestamp )
-                                       && ($obj->rc_timestamp >= $obj->wl_notificationtimestamp)) {
-                                               $rc->notificationtimestamp = true;
-                               } else {
-                                       $rc->notificationtimestamp = false;
-                               }
+               $counter = 1;
+               $list = ChangesList::newFromUser( $wgUser );
 
-                               $rc->numberofWatchingusers = 0; // Default
-                               if ($showWatcherCount && $obj->rc_namespace >= 0) {
-                                       if (!isset($watcherCache[$obj->rc_namespace][$obj->rc_title])) {
-                                               $watcherCache[$obj->rc_namespace][$obj->rc_title] =
-                                                       $dbr->selectField( 'watchlist',
-                                                               'COUNT(*)',
-                                                               array(
-                                                                       'wl_namespace' => $obj->rc_namespace,
-                                                                       'wl_title' => $obj->rc_title,
-                                                               ),
-                                                               __METHOD__ . '-watchers' );
-                                       }
-                                       $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
+               $s = $list->beginRecentChangesList();
+               foreach( $rows as $obj ) {
+                       if( $limit == 0 ) break;
+                       $rc = RecentChange::newFromRow( $obj );
+                       $rc->counter = $counter++;
+                       # Check if the page has been updated since the last visit
+                       if( $wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) ) {
+                               $rc->notificationtimestamp = ($obj->rc_timestamp >= $obj->wl_notificationtimestamp);
+                       } else {
+                               $rc->notificationtimestamp = false; // Default
+                       }
+                       # Check the number of users watching the page
+                       $rc->numberofWatchingusers = 0; // Default
+                       if( $showWatcherCount && $obj->rc_namespace >= 0 ) {
+                               if( !isset($watcherCache[$obj->rc_namespace][$obj->rc_title]) ) {
+                                       $watcherCache[$obj->rc_namespace][$obj->rc_title] =
+                                                $dbr->selectField( 'watchlist',
+                                                       'COUNT(*)',
+                                                       array(
+                                                               'wl_namespace' => $obj->rc_namespace,
+                                                               'wl_title' => $obj->rc_title,
+                                                       ),
+                                                       __METHOD__ . '-watchers' );
                                }
-                               $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) );
-                               --$limit;
+                               $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
                        }
+                       $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
+                       --$limit;
                }
                $s .= $list->endRecentChangesList();
                $wgOut->addHTML( $s );
        }
 
+       /**
+        * Get the query string to append to feed link URLs.
+        * This is overridden by RCL to add the target parameter
+        */
+       public function getFeedQuery() {
+               return false;
+       }
+
        /**
         * Return the text to be displayed above the changes
         *
@@ -399,29 +437,37 @@ class SpecialRecentChanges extends SpecialPage {
 
                $defaults = $opts->getAllValues();
                $nondefaults = $opts->getChangedValues();
-               $opts->consumeValues( array( 'namespace', 'invert' ) );
+               $opts->consumeValues( array( 'namespace', 'invert', 'tagfilter',
+                       'categories', 'categories_any' ) );
 
                $panel = array();
                $panel[] = $this->optionsPanel( $defaults, $nondefaults );
                $panel[] = '<hr />';
 
                $extraOpts = $this->getExtraOptions( $opts );
+               $extraOptsCount = count( $extraOpts );
+               $count = 0;
+               $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) );
+
+               $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
+               foreach( $extraOpts as $optionRow ) {
+                       # Add submit button to the last row only
+                       ++$count;
+                       $addSubmit = $count === $extraOptsCount ? $submit : '';
 
-               $out = Xml::openElement( 'table' );
-               foreach ( $extraOpts as $optionRow ) {
                        $out .= Xml::openElement( 'tr' );
-                       if ( is_array($optionRow) ) {
-                               $out .= Xml::tags( 'td', null, $optionRow[0] );
-                               $out .= Xml::tags( 'td', null, $optionRow[1] );
+                       if( is_array( $optionRow ) ) {
+                               $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] );
+                               $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit );
                        } else {
-                               $out .= Xml::tags( 'td', array( 'colspan' => 2 ), $optionRow );
+                               $out .= Xml::tags( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ), $optionRow . $addSubmit );
                        }
                        $out .= Xml::closeElement( 'tr' );
                }
                $out .= Xml::closeElement( 'table' );
 
                $unconsumed = $opts->getUnconsumedValues();
-               foreach ( $unconsumed as $key => $value ) {
+               foreach( $unconsumed as $key => $value ) {
                        $out .= Xml::hidden( $key, $value );
                }
 
@@ -432,9 +478,11 @@ class SpecialRecentChanges extends SpecialPage {
                $panelString = implode( "\n", $panel );
 
                $wgOut->addHTML(
-                       Xml::fieldset( wfMsg( strtolower( $this->mName )  ), $panelString, array( 'class' => 'rcoptions' ) )
+                       Xml::fieldset( wfMsg( 'recentchanges-legend' ), $panelString, array( 'class' => 'rcoptions' ) )
                );
 
+               $wgOut->addHTML( ChangesList::flagLegend() );
+
                $this->setBottomText( $wgOut, $opts );
        }
 
@@ -449,12 +497,15 @@ class SpecialRecentChanges extends SpecialPage {
                $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
 
                global $wgAllowCategorizedRecentChanges;
-               if ( $wgAllowCategorizedRecentChanges ) {
+               if( $wgAllowCategorizedRecentChanges ) {
                        $extraOpts['category'] = $this->categoryFilterForm( $opts );
                }
 
+               $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
+               if ( count($tagFilter) )
+                       $extraOpts['tagfilter'] = $tagFilter;
+
                wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
-               $extraOpts['submit'] = Xml::submitbutton( wfMsg('allpagessubmit') );
                return $extraOpts;
        }
 
@@ -484,7 +535,7 @@ class SpecialRecentChanges extends SpecialPage {
         * @return string
         */
        protected function namespaceFilterForm( FormOptions $opts ) {
-               $nsSelect = HTMLnamespaceselector( $opts['namespace'], '' );
+               $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' );
                $nsLabel = Xml::label( wfMsg('namespace'), 'namespace' );
                $invert = Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $opts['invert'] );
                return array( $nsLabel, "$nsSelect $invert" );
@@ -513,51 +564,53 @@ class SpecialRecentChanges extends SpecialPage {
         * @param $opts FormOptions
         */
        function filterByCategories( &$rows, FormOptions $opts ) {
-               $categories = array_map( 'trim', explode( "|" , $opts['categories'] ) );
+               $categories = array_map( 'trim', explode( '|' , $opts['categories'] ) );
 
-               if( empty($categories) ) {
+               if( !count( $categories ) ) {
                        return;
                }
 
                # Filter categories
                $cats = array();
-               foreach ( $categories as $cat ) {
+               foreach( $categories as $cat ) {
                        $cat = trim( $cat );
-                       if ( $cat == "" ) continue;
+                       if( $cat == '' ) continue;
                        $cats[] = $cat;
                }
 
                # Filter articles
                $articles = array();
                $a2r = array();
-               foreach ( $rows AS $k => $r ) {
+               $rowsarr = array();
+               foreach( $rows AS $k => $r ) {
                        $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
                        $id = $nt->getArticleID();
-                       if ( $id == 0 ) continue; # Page might have been deleted...
-                       if ( !in_array($id, $articles) ) {
+                       if( $id == 0 ) continue; # Page might have been deleted...
+                       if( !in_array( $id, $articles ) ) {
                                $articles[] = $id;
                        }
-                       if ( !isset($a2r[$id]) ) {
+                       if( !isset( $a2r[$id] ) ) {
                                $a2r[$id] = array();
                        }
                        $a2r[$id][] = $k;
+                       $rowsarr[$k] = $r;
                }
 
                # Shortcut?
-               if ( !count($articles) || !count($cats) )
+               if( !count( $articles ) || !count( $cats ) )
                        return ;
 
                # Look up
-               $c = new Categoryfinder ;
+               $c = new Categoryfinder;
                $c->seed( $articles, $cats, $opts['categories_any'] ? "OR" : "AND" ) ;
                $match = $c->run();
 
                # Filter
                $newrows = array();
-               foreach ( $match AS $id ) {
-                       foreach ( $a2r[$id] AS $rev ) {
+               foreach( $match AS $id ) {
+                       foreach( $a2r[$id] AS $rev ) {
                                $k = $rev;
-                               $newrows[$k] = $rows[$k];
+                               $newrows[$k] = $rowsarr[$k];
                        }
                }
                $rows = $newrows;
@@ -572,9 +625,13 @@ class SpecialRecentChanges extends SpecialPage {
        function makeOptionsLink( $title, $override, $options, $active = false ) {
                global $wgUser;
                $sk = $wgUser->getSkin();
-               $params = wfArrayMerge( $options, $override );
-               return $sk->link( $this->getTitle(), htmlspecialchars( $title ),
-                       ( $active ? array( 'style'=>'font-weight: bold;' ) : array() ), $params, array( 'known' ) );
+               $params = $override + $options;
+               if ( $active ) {
+                       return $sk->link( $this->getTitle(), '<strong>' . htmlspecialchars( $title ) . '</strong>',
+                                                         array(), $params, array( 'known' ) );
+               } else {
+                       return $sk->link( $this->getTitle(), htmlspecialchars( $title ), array() , $params, array( 'known' ) );
+               }
        }
 
        /**
@@ -587,17 +644,17 @@ class SpecialRecentChanges extends SpecialPage {
 
                $options = $nondefaults + $defaults;
 
-               if( $options['from'] )
-                       $note = wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
-                               $wgLang->formatNum( $options['limit'] ),
-                               $wgLang->timeanddate( $options['from'], true ) );
-               else
-                       $note = wfMsgExt( 'rcnote', array( 'parseinline' ),
+               $note = '';
+               if( !wfEmptyMsg( 'rclegend', wfMsg('rclegend') ) ) {
+                       $note .= '<div class="mw-rclegend">' . wfMsgExt( 'rclegend', array('parseinline') ) . "</div>\n";
+               }
+               if( $options['from'] ) {
+                       $note .= wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
                                $wgLang->formatNum( $options['limit'] ),
-                               $wgLang->formatNum( $options['days'] ),
-                               $wgLang->timeAndDate( wfTimestampNow(), true ),
-                               $wgLang->date( wfTimestampNow(), true ),
-                               $wgLang->time( wfTimestampNow(), true ) );
+                               $wgLang->timeanddate( $options['from'], true ),
+                               $wgLang->date( $options['from'], true ),
+                               $wgLang->time( $options['from'], true ) ) . '<br />';
+               }
 
                # Sort data for display and make sure it's unique after we've added user data.
                $wgRCLinkLimits[] = $options['limit'];
@@ -612,14 +669,14 @@ class SpecialRecentChanges extends SpecialPage {
                        $cl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
                                array( 'limit' => $value ), $nondefaults, $value == $options['limit'] ) ;
                }
-               $cl = implode( ' | ', $cl );
+               $cl = $wgLang->pipeList( $cl );
 
                // day links, reset 'from' to none
                foreach( $wgRCLinkDays as $value ) {
                        $dl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
                                array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] ) ;
                }
-               $dl = implode( ' | ', $dl );
+               $dl = $wgLang->pipeList( $dl );
 
 
                // show/hide links
@@ -644,7 +701,7 @@ class SpecialRecentChanges extends SpecialPage {
                if( $wgUser->useRCPatrol() )
                        $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
                $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
-               $hl = implode( ' | ', $links );
+               $hl = $wgLang->pipeList( $links );
 
                // show from this onward link
                $now = $wgLang->timeanddate( wfTimestampNow(), true );
@@ -653,6 +710,6 @@ class SpecialRecentChanges extends SpecialPage {
                $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ),
                        $cl, $dl, $hl );
                $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl );
-               return "$note<br />$rclinks<br />$rclistfrom";
+               return "{$note}$rclinks<br />$rclistfrom";
        }
 }