Pass the url to ChangesFeed::getFeedObject() instead of grabbing it from $wgTitle
[lhc/web/wiklou.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 $this->getTitle()->getFullUrl()
174 );
175 return array( $changesFeed, $formatter );
176 }
177
178 /**
179 * Process $par and put options found if $opts
180 * Mainly used when including the page
181 *
182 * @param $par String
183 * @param $opts FormOptions
184 */
185 public function parseParameters( $par, FormOptions $opts ) {
186 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
187 foreach( $bits as $bit ) {
188 if( 'hidebots' === $bit ) $opts['hidebots'] = true;
189 if( 'bots' === $bit ) $opts['hidebots'] = false;
190 if( 'hideminor' === $bit ) $opts['hideminor'] = true;
191 if( 'minor' === $bit ) $opts['hideminor'] = false;
192 if( 'hideliu' === $bit ) $opts['hideliu'] = true;
193 if( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true;
194 if( 'hideanons' === $bit ) $opts['hideanons'] = true;
195 if( 'hidemyself' === $bit ) $opts['hidemyself'] = true;
196
197 if( is_numeric( $bit ) ) $opts['limit'] = $bit;
198
199 $m = array();
200 if( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1];
201 if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1];
202 }
203 }
204
205 /**
206 * Get last modified date, for client caching
207 * Don't use this if we are using the patrol feature, patrol changes don't
208 * update the timestamp
209 *
210 * @param $feedFormat String
211 * @return String or false
212 */
213 public function checkLastModified( $feedFormat ) {
214 global $wgOut, $wgUser;
215 $dbr = wfGetDB( DB_SLAVE );
216 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
217 if( $feedFormat || !$wgUser->useRCPatrol() ) {
218 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ) {
219 # Client cache fresh and headers sent, nothing more to do.
220 return false;
221 }
222 }
223 return $lastmod;
224 }
225
226 /**
227 * Return an array of conditions depending of options set in $opts
228 *
229 * @param $opts FormOptions
230 * @return array
231 */
232 public function buildMainQueryConds( FormOptions $opts ) {
233 global $wgUser;
234
235 $dbr = wfGetDB( DB_SLAVE );
236 $conds = array();
237
238 # It makes no sense to hide both anons and logged-in users
239 # Where this occurs, force anons to be shown
240 $forcebot = false;
241 if( $opts['hideanons'] && $opts['hideliu'] ){
242 # Check if the user wants to show bots only
243 if( $opts['hidebots'] ){
244 $opts['hideanons'] = false;
245 } else {
246 $forcebot = true;
247 $opts['hidebots'] = false;
248 }
249 }
250
251 // Calculate cutoff
252 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
253 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
254 $cutoff = $dbr->timestamp( $cutoff_unixtime );
255
256 $fromValid = preg_match('/^[0-9]{14}$/', $opts['from']);
257 if( $fromValid && $opts['from'] > wfTimestamp(TS_MW,$cutoff) ) {
258 $cutoff = $dbr->timestamp($opts['from']);
259 } else {
260 $opts->reset( 'from' );
261 }
262
263 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
264
265
266 $hidePatrol = $wgUser->useRCPatrol() && $opts['hidepatrolled'];
267 $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
268 $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
269
270 if( $opts['hideminor'] ) $conds['rc_minor'] = 0;
271 if( $opts['hidebots'] ) $conds['rc_bot'] = 0;
272 if( $hidePatrol ) $conds['rc_patrolled'] = 0;
273 if( $forcebot ) $conds['rc_bot'] = 1;
274 if( $hideLoggedInUsers ) $conds[] = 'rc_user = 0';
275 if( $hideAnonymousUsers ) $conds[] = 'rc_user != 0';
276
277 if( $opts['hidemyself'] ) {
278 if( $wgUser->getId() ) {
279 $conds[] = 'rc_user != ' . $dbr->addQuotes( $wgUser->getId() );
280 } else {
281 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
282 }
283 }
284
285 # Namespace filtering
286 if( $opts['namespace'] !== '' ) {
287 if( !$opts['invert'] ) {
288 $conds[] = 'rc_namespace = ' . $dbr->addQuotes( $opts['namespace'] );
289 } else {
290 $conds[] = 'rc_namespace != ' . $dbr->addQuotes( $opts['namespace'] );
291 }
292 }
293
294 return $conds;
295 }
296
297 /**
298 * Process the query
299 *
300 * @param $conds Array
301 * @param $opts FormOptions
302 * @return database result or false (for Recentchangeslinked only)
303 */
304 public function doMainQuery( $conds, $opts ) {
305 global $wgUser;
306
307 $tables = array( 'recentchanges' );
308 $join_conds = array();
309 $query_options = array( 'USE INDEX' => array('recentchanges' => 'rc_timestamp') );
310
311 $uid = $wgUser->getId();
312 $dbr = wfGetDB( DB_SLAVE );
313 $limit = $opts['limit'];
314 $namespace = $opts['namespace'];
315 $select = '*';
316 $invert = $opts['invert'];
317
318 // JOIN on watchlist for users
319 if( $uid ) {
320 $tables[] = 'watchlist';
321 $join_conds['watchlist'] = array('LEFT JOIN',
322 "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace");
323 }
324 if ($wgUser->isAllowed("rollback")) {
325 $tables[] = 'page';
326 $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
327 }
328 if ( !$this->including() ) {
329 // Tag stuff.
330 // Doesn't work when transcluding. See bug 23293
331 $fields = array();
332 // Fields are * in this case, so let the function modify an empty array to keep it happy.
333 ChangeTags::modifyDisplayQuery(
334 $tables, $fields, $conds, $join_conds, $query_options, $opts['tagfilter']
335 );
336 }
337
338 if ( !wfRunHooks( 'SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ) ) )
339 return false;
340
341 // Don't use the new_namespace_time timestamp index if:
342 // (a) "All namespaces" selected
343 // (b) We want all pages NOT in a certain namespaces (inverted)
344 // (c) There is a tag to filter on (use tag index instead)
345 // (d) UNION + sort/limit is not an option for the DBMS
346 if( is_null( $namespace )
347 || ( $invert && !is_null( $namespace ) )
348 || $opts['tagfilter'] != ''
349 || !$dbr->unionSupportsOrderAndLimit() )
350 {
351 $res = $dbr->select( $tables, '*', $conds, __METHOD__,
352 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) +
353 $query_options,
354 $join_conds );
355 // We have a new_namespace_time index! UNION over new=(0,1) and sort result set!
356 } else {
357 // New pages
358 $sqlNew = $dbr->selectSQLText( $tables, $select,
359 array( 'rc_new' => 1 ) + $conds,
360 __METHOD__,
361 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
362 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ),
363 $join_conds );
364 // Old pages
365 $sqlOld = $dbr->selectSQLText( $tables, '*',
366 array( 'rc_new' => 0 ) + $conds,
367 __METHOD__,
368 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
369 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ),
370 $join_conds );
371 # Join the two fast queries, and sort the result set
372 $sql = $dbr->unionQueries(array($sqlNew, $sqlOld), false).' ORDER BY rc_timestamp DESC';
373 $sql = $dbr->limitResult($sql, $limit, false);
374 $res = $dbr->query( $sql, __METHOD__ );
375 }
376
377 return $res;
378 }
379
380 /**
381 * Send output to $wgOut, only called if not used feeds
382 *
383 * @param $rows Array of database rows
384 * @param $opts FormOptions
385 */
386 public function webOutput( $rows, $opts ) {
387 global $wgOut, $wgUser, $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
388 global $wgAllowCategorizedRecentChanges;
389
390 $limit = $opts['limit'];
391
392 if( !$this->including() ) {
393 // Output options box
394 $this->doHeader( $opts );
395 }
396
397 // And now for the content
398 $wgOut->setFeedAppendQuery( $this->getFeedQuery() );
399
400 if( $wgAllowCategorizedRecentChanges ) {
401 $this->filterByCategories( $rows, $opts );
402 }
403
404 $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
405 $watcherCache = array();
406
407 $dbr = wfGetDB( DB_SLAVE );
408
409 $counter = 1;
410 $list = ChangesList::newFromUser( $wgUser );
411
412 $s = $list->beginRecentChangesList();
413 foreach( $rows as $obj ) {
414 if( $limit == 0 ) break;
415 $rc = RecentChange::newFromRow( $obj );
416 $rc->counter = $counter++;
417 # Check if the page has been updated since the last visit
418 if( $wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) ) {
419 $rc->notificationtimestamp = ($obj->rc_timestamp >= $obj->wl_notificationtimestamp);
420 } else {
421 $rc->notificationtimestamp = false; // Default
422 }
423 # Check the number of users watching the page
424 $rc->numberofWatchingusers = 0; // Default
425 if( $showWatcherCount && $obj->rc_namespace >= 0 ) {
426 if( !isset($watcherCache[$obj->rc_namespace][$obj->rc_title]) ) {
427 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
428 $dbr->selectField( 'watchlist',
429 'COUNT(*)',
430 array(
431 'wl_namespace' => $obj->rc_namespace,
432 'wl_title' => $obj->rc_title,
433 ),
434 __METHOD__ . '-watchers' );
435 }
436 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
437 }
438 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
439 --$limit;
440 }
441 $s .= $list->endRecentChangesList();
442 $wgOut->addHTML( $s );
443 }
444
445 /**
446 * Get the query string to append to feed link URLs.
447 * This is overridden by RCL to add the target parameter
448 */
449 public function getFeedQuery() {
450 return false;
451 }
452
453 /**
454 * Return the text to be displayed above the changes
455 *
456 * @param $opts FormOptions
457 * @return String: XHTML
458 */
459 public function doHeader( $opts ) {
460 global $wgScript, $wgOut;
461
462 $this->setTopText( $wgOut, $opts );
463
464 $defaults = $opts->getAllValues();
465 $nondefaults = $opts->getChangedValues();
466 $opts->consumeValues( array( 'namespace', 'invert', 'tagfilter',
467 'categories', 'categories_any' ) );
468
469 $panel = array();
470 $panel[] = $this->optionsPanel( $defaults, $nondefaults );
471 $panel[] = '<hr />';
472
473 $extraOpts = $this->getExtraOptions( $opts );
474 $extraOptsCount = count( $extraOpts );
475 $count = 0;
476 $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) );
477
478 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
479 foreach( $extraOpts as $optionRow ) {
480 # Add submit button to the last row only
481 ++$count;
482 $addSubmit = $count === $extraOptsCount ? $submit : '';
483
484 $out .= Xml::openElement( 'tr' );
485 if( is_array( $optionRow ) ) {
486 $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] );
487 $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit );
488 } else {
489 $out .= Xml::tags( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ), $optionRow . $addSubmit );
490 }
491 $out .= Xml::closeElement( 'tr' );
492 }
493 $out .= Xml::closeElement( 'table' );
494
495 $unconsumed = $opts->getUnconsumedValues();
496 foreach( $unconsumed as $key => $value ) {
497 $out .= Html::hidden( $key, $value );
498 }
499
500 $t = $this->getTitle();
501 $out .= Html::hidden( 'title', $t->getPrefixedText() );
502 $form = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
503 $panel[] = $form;
504 $panelString = implode( "\n", $panel );
505
506 $wgOut->addHTML(
507 Xml::fieldset( wfMsg( 'recentchanges-legend' ), $panelString, array( 'class' => 'rcoptions' ) )
508 );
509
510 $this->setBottomText( $wgOut, $opts );
511 }
512
513 /**
514 * Get options to be displayed in a form
515 *
516 * @param $opts FormOptions
517 * @return Array
518 */
519 function getExtraOptions( $opts ){
520 $extraOpts = array();
521 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
522
523 global $wgAllowCategorizedRecentChanges;
524 if( $wgAllowCategorizedRecentChanges ) {
525 $extraOpts['category'] = $this->categoryFilterForm( $opts );
526 }
527
528 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
529 if ( count($tagFilter) )
530 $extraOpts['tagfilter'] = $tagFilter;
531
532 wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
533 return $extraOpts;
534 }
535
536 /**
537 * Send the text to be displayed above the options
538 *
539 * @param $out OutputPage
540 * @param $opts FormOptions
541 */
542 function setTopText( OutputPage $out, FormOptions $opts ){
543 $out->addWikiText( wfMsgForContentNoTrans( 'recentchangestext' ) );
544 }
545
546 /**
547 * Send the text to be displayed after the options, for use in
548 * Recentchangeslinked
549 *
550 * @param $out OutputPage
551 * @param $opts FormOptions
552 */
553 function setBottomText( OutputPage $out, FormOptions $opts ){}
554
555 /**
556 * Creates the choose namespace selection
557 *
558 * @param $opts FormOptions
559 * @return String
560 */
561 protected function namespaceFilterForm( FormOptions $opts ) {
562 $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' );
563 $nsLabel = Xml::label( wfMsg('namespace'), 'namespace' );
564 $invert = Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $opts['invert'] );
565 return array( $nsLabel, "$nsSelect $invert" );
566 }
567
568 /**
569 * Create a input to filter changes by categories
570 *
571 * @param $opts FormOptions
572 * @return Array
573 */
574 protected function categoryFilterForm( FormOptions $opts ) {
575 list( $label, $input ) = Xml::inputLabelSep( wfMsg('rc_categories'),
576 'categories', 'mw-categories', false, $opts['categories'] );
577
578 $input .= ' ' . Xml::checkLabel( wfMsg('rc_categories_any'),
579 'categories_any', 'mw-categories_any', $opts['categories_any'] );
580
581 return array( $label, $input );
582 }
583
584 /**
585 * Filter $rows by categories set in $opts
586 *
587 * @param $rows Array of database rows
588 * @param $opts FormOptions
589 */
590 function filterByCategories( &$rows, FormOptions $opts ) {
591 $categories = array_map( 'trim', explode( '|' , $opts['categories'] ) );
592
593 if( !count( $categories ) ) {
594 return;
595 }
596
597 # Filter categories
598 $cats = array();
599 foreach( $categories as $cat ) {
600 $cat = trim( $cat );
601 if( $cat == '' ) continue;
602 $cats[] = $cat;
603 }
604
605 # Filter articles
606 $articles = array();
607 $a2r = array();
608 $rowsarr = array();
609 foreach( $rows AS $k => $r ) {
610 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
611 $id = $nt->getArticleID();
612 if( $id == 0 ) continue; # Page might have been deleted...
613 if( !in_array( $id, $articles ) ) {
614 $articles[] = $id;
615 }
616 if( !isset( $a2r[$id] ) ) {
617 $a2r[$id] = array();
618 }
619 $a2r[$id][] = $k;
620 $rowsarr[$k] = $r;
621 }
622
623 # Shortcut?
624 if( !count( $articles ) || !count( $cats ) )
625 return ;
626
627 # Look up
628 $c = new Categoryfinder;
629 $c->seed( $articles, $cats, $opts['categories_any'] ? "OR" : "AND" ) ;
630 $match = $c->run();
631
632 # Filter
633 $newrows = array();
634 foreach( $match AS $id ) {
635 foreach( $a2r[$id] AS $rev ) {
636 $k = $rev;
637 $newrows[$k] = $rowsarr[$k];
638 }
639 }
640 $rows = $newrows;
641 }
642
643 /**
644 * Makes change an option link which carries all the other options
645 *
646 * @param $title Title
647 * @param $override Array: options to override
648 * @param $options Array: current options
649 * @param $active Boolean: whether to show the link in bold
650 */
651 function makeOptionsLink( $title, $override, $options, $active = false ) {
652 global $wgUser;
653 $sk = $wgUser->getSkin();
654 $params = $override + $options;
655 if ( $active ) {
656 return $sk->link( $this->getTitle(), '<strong>' . htmlspecialchars( $title ) . '</strong>',
657 array(), $params, array( 'known' ) );
658 } else {
659 return $sk->link( $this->getTitle(), htmlspecialchars( $title ), array() , $params, array( 'known' ) );
660 }
661 }
662
663 /**
664 * Creates the options panel.
665 *
666 * @param $defaults Array
667 * @param $nondefaults Array
668 */
669 function optionsPanel( $defaults, $nondefaults ) {
670 global $wgLang, $wgUser, $wgRCLinkLimits, $wgRCLinkDays;
671
672 $options = $nondefaults + $defaults;
673
674 $note = '';
675 if( !wfEmptyMsg( 'rclegend' ) ) {
676 $note .= '<div class="mw-rclegend">' . wfMsgExt( 'rclegend', array('parseinline') ) . "</div>\n";
677 }
678 if( $options['from'] ) {
679 $note .= wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
680 $wgLang->formatNum( $options['limit'] ),
681 $wgLang->timeanddate( $options['from'], true ),
682 $wgLang->date( $options['from'], true ),
683 $wgLang->time( $options['from'], true ) ) . '<br />';
684 }
685
686 # Sort data for display and make sure it's unique after we've added user data.
687 $wgRCLinkLimits[] = $options['limit'];
688 $wgRCLinkDays[] = $options['days'];
689 sort( $wgRCLinkLimits );
690 sort( $wgRCLinkDays );
691 $wgRCLinkLimits = array_unique( $wgRCLinkLimits );
692 $wgRCLinkDays = array_unique( $wgRCLinkDays );
693
694 // limit links
695 foreach( $wgRCLinkLimits as $value ) {
696 $cl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
697 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] ) ;
698 }
699 $cl = $wgLang->pipeList( $cl );
700
701 // day links, reset 'from' to none
702 foreach( $wgRCLinkDays as $value ) {
703 $dl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
704 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] ) ;
705 }
706 $dl = $wgLang->pipeList( $dl );
707
708
709 // show/hide links
710 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ) );
711 $minorLink = $this->makeOptionsLink( $showhide[1-$options['hideminor']],
712 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
713 $botLink = $this->makeOptionsLink( $showhide[1-$options['hidebots']],
714 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
715 $anonsLink = $this->makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
716 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
717 $liuLink = $this->makeOptionsLink( $showhide[1-$options['hideliu']],
718 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
719 $patrLink = $this->makeOptionsLink( $showhide[1-$options['hidepatrolled']],
720 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
721 $myselfLink = $this->makeOptionsLink( $showhide[1-$options['hidemyself']],
722 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
723
724 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
725 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
726 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
727 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
728 if( $wgUser->useRCPatrol() )
729 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
730 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
731 $hl = $wgLang->pipeList( $links );
732
733 // show from this onward link
734 $now = $wgLang->timeanddate( wfTimestampNow(), true );
735 $tl = $this->makeOptionsLink( $now, array( 'from' => wfTimestampNow() ), $nondefaults );
736
737 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ),
738 $cl, $dl, $hl );
739 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl );
740 return "{$note}$rclinks<br />$rclistfrom";
741 }
742 }