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