]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/specials/SpecialRecentchanges.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / includes / specials / SpecialRecentchanges.php
1 <?php
2 /**
3  * Implements Special:Recentchanges
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  * http://www.gnu.org/copyleft/gpl.html
19  *
20  * @file
21  * @ingroup SpecialPage
22  */
23
24 /**
25  * A special page that lists last changes made to the wiki
26  *
27  * @ingroup SpecialPage
28  */
29 class SpecialRecentChanges extends IncludableSpecialPage {
30         var $rcOptions, $rcSubpage;
31
32         public function __construct( $name = 'Recentchanges' ) {
33                 parent::__construct( $name );
34         }
35
36         /**
37          * Get a FormOptions object containing the default options
38          *
39          * @return FormOptions
40          */
41         public function getDefaultOptions() {
42                 global $wgUser;
43                 $opts = new FormOptions();
44
45                 $opts->add( 'days',  (int)$wgUser->getOption( 'rcdays' ) );
46                 $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
47                 $opts->add( 'from', '' );
48
49                 $opts->add( 'hideminor',     $wgUser->getBoolOption( 'hideminor' ) );
50                 $opts->add( 'hidebots',      true  );
51                 $opts->add( 'hideanons',     false );
52                 $opts->add( 'hideliu',       false );
53                 $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'hidepatrolled' ) );
54                 $opts->add( 'hidemyself',    false );
55
56                 $opts->add( 'namespace', '', FormOptions::INTNULL );
57                 $opts->add( 'invert', false );
58
59                 $opts->add( 'categories', '' );
60                 $opts->add( 'categories_any', false );
61                 $opts->add( 'tagfilter', '' );
62                 return $opts;
63         }
64
65         /**
66          * Create a FormOptions object with options as specified by the user
67          *
68          * @return FormOptions
69          */
70         public function setup( $parameters ) {
71                 global $wgRequest;
72
73                 $opts = $this->getDefaultOptions();
74                 $opts->fetchValuesFromRequest( $wgRequest );
75
76                 // Give precedence to subpage syntax
77                 if( $parameters !== null ) {
78                         $this->parseParameters( $parameters, $opts );
79                 }
80
81                 $opts->validateIntBounds( 'limit', 0, 5000 );
82                 return $opts;
83         }
84
85         /**
86          * Create a FormOptions object specific for feed requests and return it
87          *
88          * @return FormOptions
89          */
90         public function feedSetup() {
91                 global $wgFeedLimit, $wgRequest;
92                 $opts = $this->getDefaultOptions();
93                 # Feed is cached on limit,hideminor,namespace; other params would randomly not work
94                 $opts->fetchValuesFromRequest( $wgRequest, array( 'limit', 'hideminor', 'namespace' ) );
95                 $opts->validateIntBounds( 'limit', 0, $wgFeedLimit );
96                 return $opts;
97         }
98
99         /**
100          * Get the current FormOptions for this request
101          */
102         public function getOptions() {
103                 if ( $this->rcOptions === null ) {
104                         global $wgRequest;
105                         $feedFormat = $wgRequest->getVal( 'feed' );
106                         $this->rcOptions = $feedFormat ? $this->feedSetup() : $this->setup( $this->rcSubpage );
107                 }
108                 return $this->rcOptions;
109         }
110
111
112         /**
113          * Main execution point
114          *
115          * @param $subpage String
116          */
117         public function execute( $subpage ) {
118                 global $wgRequest, $wgOut;
119                 $this->rcSubpage = $subpage;
120                 $feedFormat = $wgRequest->getVal( 'feed' );
121
122                 # 10 seconds server-side caching max
123                 $wgOut->setSquidMaxage( 10 );
124                 # Check if the client has a cached version
125                 $lastmod = $this->checkLastModified( $feedFormat );
126                 if( $lastmod === false ) {
127                         return;
128                 }
129
130                 $opts = $this->getOptions();
131                 $this->setHeaders();
132                 $this->outputHeader();
133
134                 // Fetch results, prepare a batch link existence check query
135                 $conds = $this->buildMainQueryConds( $opts );
136                 $rows = $this->doMainQuery( $conds, $opts );
137                 if( $rows === false ){
138                         if( !$this->including() ) {
139                                 $this->doHeader( $opts );
140                         }
141                         return;
142                 }
143
144                 if( !$feedFormat ) {
145                         $batch = new LinkBatch;
146                         foreach( $rows as $row ) {
147                                 $batch->add( NS_USER, $row->rc_user_text  );
148                                 $batch->add( NS_USER_TALK, $row->rc_user_text  );
149                                 $batch->add( $row->rc_namespace, $row->rc_title );
150                         }
151                         $batch->execute();
152                 }
153                 if( $feedFormat ) {
154                         list( $changesFeed, $formatter ) = $this->getFeedObject( $feedFormat );
155                         $changesFeed->execute( $formatter, $rows, $lastmod, $opts );
156                 } else {
157                         $this->webOutput( $rows, $opts );
158                 }
159
160                 $rows->free();
161         }
162
163         /**
164          * Return an array with a ChangesFeed object and ChannelFeed object
165          *
166          * @return Array
167          */
168         public function getFeedObject( $feedFormat ){
169                 $changesFeed = new ChangesFeed( $feedFormat, 'rcfeed' );
170                 $formatter = $changesFeed->getFeedObject(
171                         wfMsgForContent( 'recentchanges' ),
172                         wfMsgForContent( 'recentchanges-feed-description' )
173                 );
174                 return array( $changesFeed, $formatter );
175         }
176
177         /**
178          * Process $par and put options found if $opts
179          * Mainly used when including the page
180          *
181          * @param $par String
182          * @param $opts FormOptions
183          */
184         public function parseParameters( $par, FormOptions $opts ) {
185                 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
186                 foreach( $bits as $bit ) {
187                         if( 'hidebots' === $bit ) $opts['hidebots'] = true;
188                         if( 'bots' === $bit ) $opts['hidebots'] = false;
189                         if( 'hideminor' === $bit ) $opts['hideminor'] = true;
190                         if( 'minor' === $bit ) $opts['hideminor'] = false;
191                         if( 'hideliu' === $bit ) $opts['hideliu'] = true;
192                         if( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true;
193                         if( 'hideanons' === $bit ) $opts['hideanons'] = true;
194                         if( 'hidemyself' === $bit ) $opts['hidemyself'] = true;
195
196                         if( is_numeric( $bit ) ) $opts['limit'] =  $bit;
197
198                         $m = array();
199                         if( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1];
200                         if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1];
201                 }
202         }
203
204         /**
205          * Get last modified date, for client caching
206          * Don't use this if we are using the patrol feature, patrol changes don't
207          * update the timestamp
208          *
209          * @param $feedFormat String
210          * @return String or false
211          */
212         public function checkLastModified( $feedFormat ) {
213                 global $wgUseRCPatrol, $wgOut;
214                 $dbr = wfGetDB( DB_SLAVE );
215                 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
216                 if( $feedFormat || !$wgUseRCPatrol ) {
217                         if( $lastmod && $wgOut->checkLastModified( $lastmod ) ) {
218                                 # Client cache fresh and headers sent, nothing more to do.
219                                 return false;
220                         }
221                 }
222                 return $lastmod;
223         }
224
225         /**
226          * Return an array of conditions depending of options set in $opts
227          *
228          * @param $opts FormOptions
229          * @return array
230          */
231         public function buildMainQueryConds( FormOptions $opts ) {
232                 global $wgUser;
233
234                 $dbr = wfGetDB( DB_SLAVE );
235                 $conds = array();
236
237                 # It makes no sense to hide both anons and logged-in users
238                 # Where this occurs, force anons to be shown
239                 $forcebot = false;
240                 if( $opts['hideanons'] && $opts['hideliu'] ){
241                         # Check if the user wants to show bots only
242                         if( $opts['hidebots'] ){
243                                 $opts['hideanons'] = false;
244                         } else {
245                                 $forcebot = true;
246                                 $opts['hidebots'] = false;
247                         }
248                 }
249
250                 // Calculate cutoff
251                 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
252                 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
253                 $cutoff = $dbr->timestamp( $cutoff_unixtime );
254
255                 $fromValid = preg_match('/^[0-9]{14}$/', $opts['from']);
256                 if( $fromValid && $opts['from'] > wfTimestamp(TS_MW,$cutoff) ) {
257                         $cutoff = $dbr->timestamp($opts['from']);
258                 } else {
259                         $opts->reset( 'from' );
260                 }
261
262                 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
263
264
265                 $hidePatrol = $wgUser->useRCPatrol() && $opts['hidepatrolled'];
266                 $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
267                 $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
268
269                 if( $opts['hideminor'] )  $conds['rc_minor'] = 0;
270                 if( $opts['hidebots'] )   $conds['rc_bot'] = 0;
271                 if( $hidePatrol )         $conds['rc_patrolled'] = 0;
272                 if( $forcebot )           $conds['rc_bot'] = 1;
273                 if( $hideLoggedInUsers )  $conds[] = 'rc_user = 0';
274                 if( $hideAnonymousUsers ) $conds[] = 'rc_user != 0';
275
276                 if( $opts['hidemyself'] ) {
277                         if( $wgUser->getId() ) {
278                                 $conds[] = 'rc_user != ' . $dbr->addQuotes( $wgUser->getId() );
279                         } else {
280                                 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
281                         }
282                 }
283
284                 # Namespace filtering
285                 if( $opts['namespace'] !== '' ) {
286                         if( !$opts['invert'] ) {
287                                 $conds[] = 'rc_namespace = ' . $dbr->addQuotes( $opts['namespace'] );
288                         } else {
289                                 $conds[] = 'rc_namespace != ' . $dbr->addQuotes( $opts['namespace'] );
290                         }
291                 }
292
293                 return $conds;
294         }
295
296         /**
297          * Process the query
298          *
299          * @param $conds Array
300          * @param $opts FormOptions
301          * @return database result or false (for Recentchangeslinked only)
302          */
303         public function doMainQuery( $conds, $opts ) {
304                 global $wgUser;
305
306                 $tables = array( 'recentchanges' );
307                 $join_conds = array();
308                 $query_options = array( 'USE INDEX' => array('recentchanges' => 'rc_timestamp') );
309
310                 $uid = $wgUser->getId();
311                 $dbr = wfGetDB( DB_SLAVE );
312                 $limit = $opts['limit'];
313                 $namespace = $opts['namespace'];
314                 $select = '*';
315                 $invert = $opts['invert'];
316
317                 // JOIN on watchlist for users
318                 if( $uid ) {
319                         $tables[] = 'watchlist';
320                         $join_conds['watchlist'] = array('LEFT JOIN',
321                                 "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace");
322                 }
323                 if ($wgUser->isAllowed("rollback")) {
324                         $tables[] = 'page';
325                         $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
326                 }
327                 if ( !$this->including() ) {
328                         // Tag stuff.
329                         // Doesn't work when transcluding. See bug 23293
330                         $fields = array();
331                         // Fields are * in this case, so let the function modify an empty array to keep it happy.
332                         ChangeTags::modifyDisplayQuery(
333                                 $tables, $fields, $conds, $join_conds, $query_options, $opts['tagfilter']
334                         );
335                 }
336
337                 if ( !wfRunHooks( 'SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ) ) )
338                         return false;
339
340                 // Don't use the new_namespace_time timestamp index if:
341                 // (a) "All namespaces" selected
342                 // (b) We want all pages NOT in a certain namespaces (inverted)
343                 // (c) There is a tag to filter on (use tag index instead)
344                 // (d) UNION + sort/limit is not an option for the DBMS
345                 if( is_null( $namespace )
346                         || ( $invert && !is_null( $namespace ) )
347                         || $opts['tagfilter'] != ''
348                         || !$dbr->unionSupportsOrderAndLimit() )
349                 {
350                         $res = $dbr->select( $tables, '*', $conds, __METHOD__,
351                                 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) +
352                                 $query_options,
353                                 $join_conds );
354                 // We have a new_namespace_time index! UNION over new=(0,1) and sort result set!
355                 } else {
356                         // New pages
357                         $sqlNew = $dbr->selectSQLText( $tables, $select,
358                                 array( 'rc_new' => 1 ) + $conds,
359                                 __METHOD__,
360                                 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
361                                         'USE INDEX' =>  array('recentchanges' => 'rc_timestamp') ),
362                                 $join_conds );
363                         // Old pages
364                         $sqlOld = $dbr->selectSQLText( $tables, '*',
365                                 array( 'rc_new' => 0 ) + $conds,
366                                 __METHOD__,
367                                 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
368                                         'USE INDEX' =>  array('recentchanges' => 'rc_timestamp') ),
369                                 $join_conds );
370                         # Join the two fast queries, and sort the result set
371                         $sql = $dbr->unionQueries(array($sqlNew, $sqlOld), false).' ORDER BY rc_timestamp DESC';
372                         $sql = $dbr->limitResult($sql, $limit, false);
373                         $res = $dbr->query( $sql, __METHOD__ );
374                 }
375
376                 return $res;
377         }
378
379         /**
380          * Send output to $wgOut, only called if not used feeds
381          *
382          * @param $rows Array of database rows
383          * @param $opts FormOptions
384          */
385         public function webOutput( $rows, $opts ) {
386                 global $wgOut, $wgUser, $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
387                 global $wgAllowCategorizedRecentChanges;
388
389                 $limit = $opts['limit'];
390
391                 if( !$this->including() ) {
392                         // Output options box
393                         $this->doHeader( $opts );
394                 }
395
396                 // And now for the content
397                 $wgOut->setFeedAppendQuery( $this->getFeedQuery() );
398
399                 if( $wgAllowCategorizedRecentChanges ) {
400                         $this->filterByCategories( $rows, $opts );
401                 }
402
403                 $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
404                 $watcherCache = array();
405
406                 $dbr = wfGetDB( DB_SLAVE );
407
408                 $counter = 1;
409                 $list = ChangesList::newFromUser( $wgUser );
410
411                 $s = $list->beginRecentChangesList();
412                 foreach( $rows as $obj ) {
413                         if( $limit == 0 ) break;
414                         $rc = RecentChange::newFromRow( $obj );
415                         $rc->counter = $counter++;
416                         # Check if the page has been updated since the last visit
417                         if( $wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) ) {
418                                 $rc->notificationtimestamp = ($obj->rc_timestamp >= $obj->wl_notificationtimestamp);
419                         } else {
420                                 $rc->notificationtimestamp = false; // Default
421                         }
422                         # Check the number of users watching the page
423                         $rc->numberofWatchingusers = 0; // Default
424                         if( $showWatcherCount && $obj->rc_namespace >= 0 ) {
425                                 if( !isset($watcherCache[$obj->rc_namespace][$obj->rc_title]) ) {
426                                         $watcherCache[$obj->rc_namespace][$obj->rc_title] =
427                                                  $dbr->selectField( 'watchlist',
428                                                         'COUNT(*)',
429                                                         array(
430                                                                 'wl_namespace' => $obj->rc_namespace,
431                                                                 'wl_title' => $obj->rc_title,
432                                                         ),
433                                                         __METHOD__ . '-watchers' );
434                                 }
435                                 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
436                         }
437                         $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
438                         --$limit;
439                 }
440                 $s .= $list->endRecentChangesList();
441                 $wgOut->addHTML( $s );
442         }
443
444         /**
445          * Get the query string to append to feed link URLs.
446          * This is overridden by RCL to add the target parameter
447          */
448         public function getFeedQuery() {
449                 return false;
450         }
451
452         /**
453          * Return the text to be displayed above the changes
454          *
455          * @param $opts FormOptions
456          * @return String: XHTML
457          */
458         public function doHeader( $opts ) {
459                 global $wgScript, $wgOut;
460
461                 $this->setTopText( $wgOut, $opts );
462
463                 $defaults = $opts->getAllValues();
464                 $nondefaults = $opts->getChangedValues();
465                 $opts->consumeValues( array( 'namespace', 'invert', 'tagfilter',
466                         'categories', 'categories_any' ) );
467
468                 $panel = array();
469                 $panel[] = $this->optionsPanel( $defaults, $nondefaults );
470                 $panel[] = '<hr />';
471
472                 $extraOpts = $this->getExtraOptions( $opts );
473                 $extraOptsCount = count( $extraOpts );
474                 $count = 0;
475                 $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) );
476
477                 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
478                 foreach( $extraOpts as $optionRow ) {
479                         # Add submit button to the last row only
480                         ++$count;
481                         $addSubmit = $count === $extraOptsCount ? $submit : '';
482
483                         $out .= Xml::openElement( 'tr' );
484                         if( is_array( $optionRow ) ) {
485                                 $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] );
486                                 $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit );
487                         } else {
488                                 $out .= Xml::tags( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ), $optionRow . $addSubmit );
489                         }
490                         $out .= Xml::closeElement( 'tr' );
491                 }
492                 $out .= Xml::closeElement( 'table' );
493
494                 $unconsumed = $opts->getUnconsumedValues();
495                 foreach( $unconsumed as $key => $value ) {
496                         $out .= Html::hidden( $key, $value );
497                 }
498
499                 $t = $this->getTitle();
500                 $out .= Html::hidden( 'title', $t->getPrefixedText() );
501                 $form = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
502                 $panel[] = $form;
503                 $panelString = implode( "\n", $panel );
504
505                 $wgOut->addHTML(
506                         Xml::fieldset( wfMsg( 'recentchanges-legend' ), $panelString, array( 'class' => 'rcoptions' ) )
507                 );
508
509                 $this->setBottomText( $wgOut, $opts );
510         }
511
512         /**
513          * Get options to be displayed in a form
514          *
515          * @param $opts FormOptions
516          * @return Array
517          */
518         function getExtraOptions( $opts ){
519                 $extraOpts = array();
520                 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
521
522                 global $wgAllowCategorizedRecentChanges;
523                 if( $wgAllowCategorizedRecentChanges ) {
524                         $extraOpts['category'] = $this->categoryFilterForm( $opts );
525                 }
526
527                 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
528                 if ( count($tagFilter) )
529                         $extraOpts['tagfilter'] = $tagFilter;
530
531                 wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
532                 return $extraOpts;
533         }
534
535         /**
536          * Send the text to be displayed above the options
537          *
538          * @param $out OutputPage
539          * @param $opts FormOptions
540          */
541         function setTopText( OutputPage $out, FormOptions $opts ){
542                 $out->addWikiText( wfMsgForContentNoTrans( 'recentchangestext' ) );
543         }
544
545         /**
546          * Send the text to be displayed after the options, for use in
547          * Recentchangeslinked
548          *
549          * @param $out OutputPage
550          * @param $opts FormOptions
551          */
552         function setBottomText( OutputPage $out, FormOptions $opts ){}
553
554         /**
555          * Creates the choose namespace selection
556          *
557          * @param $opts FormOptions
558          * @return String
559          */
560         protected function namespaceFilterForm( FormOptions $opts ) {
561                 $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' );
562                 $nsLabel = Xml::label( wfMsg('namespace'), 'namespace' );
563                 $invert = Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $opts['invert'] );
564                 return array( $nsLabel, "$nsSelect $invert" );
565         }
566
567         /**
568          * Create a input to filter changes by categories
569          *
570          * @param $opts FormOptions
571          * @return Array
572          */
573         protected function categoryFilterForm( FormOptions $opts ) {
574                 list( $label, $input ) = Xml::inputLabelSep( wfMsg('rc_categories'),
575                         'categories', 'mw-categories', false, $opts['categories'] );
576
577                 $input .= ' ' . Xml::checkLabel( wfMsg('rc_categories_any'),
578                         'categories_any', 'mw-categories_any', $opts['categories_any'] );
579
580                 return array( $label, $input );
581         }
582
583         /**
584          * Filter $rows by categories set in $opts
585          *
586          * @param $rows Array of database rows
587          * @param $opts FormOptions
588          */
589         function filterByCategories( &$rows, FormOptions $opts ) {
590                 $categories = array_map( 'trim', explode( '|' , $opts['categories'] ) );
591
592                 if( !count( $categories ) ) {
593                         return;
594                 }
595
596                 # Filter categories
597                 $cats = array();
598                 foreach( $categories as $cat ) {
599                         $cat = trim( $cat );
600                         if( $cat == '' ) continue;
601                         $cats[] = $cat;
602                 }
603
604                 # Filter articles
605                 $articles = array();
606                 $a2r = array();
607                 $rowsarr = array();
608                 foreach( $rows AS $k => $r ) {
609                         $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
610                         $id = $nt->getArticleID();
611                         if( $id == 0 ) continue; # Page might have been deleted...
612                         if( !in_array( $id, $articles ) ) {
613                                 $articles[] = $id;
614                         }
615                         if( !isset( $a2r[$id] ) ) {
616                                 $a2r[$id] = array();
617                         }
618                         $a2r[$id][] = $k;
619                         $rowsarr[$k] = $r;
620                 }
621
622                 # Shortcut?
623                 if( !count( $articles ) || !count( $cats ) )
624                         return ;
625
626                 # Look up
627                 $c = new Categoryfinder;
628                 $c->seed( $articles, $cats, $opts['categories_any'] ? "OR" : "AND" ) ;
629                 $match = $c->run();
630
631                 # Filter
632                 $newrows = array();
633                 foreach( $match AS $id ) {
634                         foreach( $a2r[$id] AS $rev ) {
635                                 $k = $rev;
636                                 $newrows[$k] = $rowsarr[$k];
637                         }
638                 }
639                 $rows = $newrows;
640         }
641
642         /**
643          * Makes change an option link which carries all the other options
644          *
645          * @param $title Title
646          * @param $override Array: options to override
647          * @param $options Array: current options
648          * @param $active Boolean: whether to show the link in bold
649          */
650         function makeOptionsLink( $title, $override, $options, $active = false ) {
651                 global $wgUser;
652                 $sk = $wgUser->getSkin();
653                 $params = $override + $options;
654                 if ( $active ) {
655                         return $sk->link( $this->getTitle(), '<strong>' . htmlspecialchars( $title ) . '</strong>',
656                                                           array(), $params, array( 'known' ) );
657                 } else {
658                         return $sk->link( $this->getTitle(), htmlspecialchars( $title ), array() , $params, array( 'known' ) );
659                 }
660         }
661
662         /**
663          * Creates the options panel.
664          *
665          * @param $defaults Array
666          * @param $nondefaults Array
667          */
668         function optionsPanel( $defaults, $nondefaults ) {
669                 global $wgLang, $wgUser, $wgRCLinkLimits, $wgRCLinkDays;
670
671                 $options = $nondefaults + $defaults;
672
673                 $note = '';
674                 if( !wfEmptyMsg( 'rclegend', wfMsg('rclegend') ) ) {
675                         $note .= '<div class="mw-rclegend">' . wfMsgExt( 'rclegend', array('parseinline') ) . "</div>\n";
676                 }
677                 if( $options['from'] ) {
678                         $note .= wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
679                                 $wgLang->formatNum( $options['limit'] ),
680                                 $wgLang->timeanddate( $options['from'], true ),
681                                 $wgLang->date( $options['from'], true ),
682                                 $wgLang->time( $options['from'], true ) ) . '<br />';
683                 }
684
685                 # Sort data for display and make sure it's unique after we've added user data.
686                 $wgRCLinkLimits[] = $options['limit'];
687                 $wgRCLinkDays[] = $options['days'];
688                 sort( $wgRCLinkLimits );
689                 sort( $wgRCLinkDays );
690                 $wgRCLinkLimits = array_unique( $wgRCLinkLimits );
691                 $wgRCLinkDays = array_unique( $wgRCLinkDays );
692
693                 // limit links
694                 foreach( $wgRCLinkLimits as $value ) {
695                         $cl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
696                                 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] ) ;
697                 }
698                 $cl = $wgLang->pipeList( $cl );
699
700                 // day links, reset 'from' to none
701                 foreach( $wgRCLinkDays as $value ) {
702                         $dl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
703                                 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] ) ;
704                 }
705                 $dl = $wgLang->pipeList( $dl );
706
707
708                 // show/hide links
709                 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ) );
710                 $minorLink = $this->makeOptionsLink( $showhide[1-$options['hideminor']],
711                         array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
712                 $botLink = $this->makeOptionsLink( $showhide[1-$options['hidebots']],
713                         array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
714                 $anonsLink = $this->makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
715                         array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
716                 $liuLink   = $this->makeOptionsLink( $showhide[1-$options['hideliu']],
717                         array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
718                 $patrLink  = $this->makeOptionsLink( $showhide[1-$options['hidepatrolled']],
719                         array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
720                 $myselfLink = $this->makeOptionsLink( $showhide[1-$options['hidemyself']],
721                         array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
722
723                 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
724                 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
725                 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
726                 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
727                 if( $wgUser->useRCPatrol() )
728                         $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
729                 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
730                 $hl = $wgLang->pipeList( $links );
731
732                 // show from this onward link
733                 $now = $wgLang->timeanddate( wfTimestampNow(), true );
734                 $tl =  $this->makeOptionsLink( $now, array( 'from' => wfTimestampNow() ), $nondefaults );
735
736                 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ),
737                         $cl, $dl, $hl );
738                 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl );
739                 return "{$note}$rclinks<br />$rclistfrom";
740         }
741 }