Merge "Initial Tests for TitleArrayFromResult"
[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 ChangesListSpecialPage {
30
31 public function __construct( $name = 'Recentchanges', $restriction = '' ) {
32 parent::__construct( $name, $restriction );
33 }
34
35 /**
36 * Main execution point
37 *
38 * @param string $subpage
39 */
40 public function execute( $subpage ) {
41 // 10 seconds server-side caching max
42 $this->getOutput()->setSquidMaxage( 10 );
43 // Check if the client has a cached version
44 $lastmod = $this->checkLastModified( $this->feedFormat );
45 if ( $lastmod === false ) {
46 return;
47 }
48
49 parent::execute( $subpage );
50 }
51
52 /**
53 * Get a FormOptions object containing the default options
54 *
55 * @return FormOptions
56 */
57 public function getDefaultOptions() {
58 $opts = parent::getDefaultOptions();
59 $user = $this->getUser();
60
61 $opts->add( 'days', $user->getIntOption( 'rcdays' ) );
62 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
63 $opts->add( 'from', '' );
64
65 $opts->add( 'hideminor', $user->getBoolOption( 'hideminor' ) );
66 $opts->add( 'hidebots', true );
67 $opts->add( 'hideanons', false );
68 $opts->add( 'hideliu', false );
69 $opts->add( 'hidepatrolled', $user->getBoolOption( 'hidepatrolled' ) );
70 $opts->add( 'hidemyself', false );
71
72 $opts->add( 'categories', '' );
73 $opts->add( 'categories_any', false );
74 $opts->add( 'tagfilter', '' );
75
76 return $opts;
77 }
78
79 /**
80 * Get custom show/hide filters
81 *
82 * @return array Map of filter URL param names to properties (msg/default)
83 */
84 protected function getCustomFilters() {
85 if ( $this->customFilters === null ) {
86 $this->customFilters = array();
87 wfRunHooks( 'SpecialRecentChangesFilters', array( $this, &$this->customFilters ) );
88 }
89
90 return $this->customFilters;
91 }
92
93 /**
94 * Process $par and put options found in $opts. Used when including the page.
95 *
96 * @param string $par
97 * @param FormOptions $opts
98 */
99 public function parseParameters( $par, FormOptions $opts ) {
100 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
101 foreach ( $bits as $bit ) {
102 if ( 'hidebots' === $bit ) {
103 $opts['hidebots'] = true;
104 }
105 if ( 'bots' === $bit ) {
106 $opts['hidebots'] = false;
107 }
108 if ( 'hideminor' === $bit ) {
109 $opts['hideminor'] = true;
110 }
111 if ( 'minor' === $bit ) {
112 $opts['hideminor'] = false;
113 }
114 if ( 'hideliu' === $bit ) {
115 $opts['hideliu'] = true;
116 }
117 if ( 'hidepatrolled' === $bit ) {
118 $opts['hidepatrolled'] = true;
119 }
120 if ( 'hideanons' === $bit ) {
121 $opts['hideanons'] = true;
122 }
123 if ( 'hidemyself' === $bit ) {
124 $opts['hidemyself'] = true;
125 }
126
127 if ( is_numeric( $bit ) ) {
128 $opts['limit'] = $bit;
129 }
130
131 $m = array();
132 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
133 $opts['limit'] = $m[1];
134 }
135 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
136 $opts['days'] = $m[1];
137 }
138 if ( preg_match( '/^namespace=(\d+)$/', $bit, $m ) ) {
139 $opts['namespace'] = $m[1];
140 }
141 }
142 }
143
144 public function validateOptions( FormOptions $opts ) {
145 global $wgFeedLimit;
146 $opts->validateIntBounds( 'limit', 0, $this->feedFormat ? $wgFeedLimit : 5000 );
147 }
148
149 /**
150 * Return an array of conditions depending of options set in $opts
151 *
152 * @param FormOptions $opts
153 * @return array
154 */
155 public function buildMainQueryConds( FormOptions $opts ) {
156 $dbr = wfGetDB( DB_SLAVE );
157 $conds = array();
158
159 # It makes no sense to hide both anons and logged-in users
160 # Where this occurs, force anons to be shown
161 $forcebot = false;
162 if ( $opts['hideanons'] && $opts['hideliu'] ) {
163 # Check if the user wants to show bots only
164 if ( $opts['hidebots'] ) {
165 $opts['hideanons'] = false;
166 } else {
167 $forcebot = true;
168 $opts['hidebots'] = false;
169 }
170 }
171
172 // Calculate cutoff
173 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
174 $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime % 86400 );
175 $cutoff = $dbr->timestamp( $cutoff_unixtime );
176
177 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
178 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) {
179 $cutoff = $dbr->timestamp( $opts['from'] );
180 } else {
181 $opts->reset( 'from' );
182 }
183
184 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
185
186 $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled'];
187 $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
188 $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
189
190 if ( $opts['hideminor'] ) {
191 $conds['rc_minor'] = 0;
192 }
193 if ( $opts['hidebots'] ) {
194 $conds['rc_bot'] = 0;
195 }
196 if ( $hidePatrol ) {
197 $conds['rc_patrolled'] = 0;
198 }
199 if ( $forcebot ) {
200 $conds['rc_bot'] = 1;
201 }
202 if ( $hideLoggedInUsers ) {
203 $conds[] = 'rc_user = 0';
204 }
205 if ( $hideAnonymousUsers ) {
206 $conds[] = 'rc_user != 0';
207 }
208
209 if ( $opts['hidemyself'] ) {
210 if ( $this->getUser()->getId() ) {
211 $conds[] = 'rc_user != ' . $dbr->addQuotes( $this->getUser()->getId() );
212 } else {
213 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $this->getUser()->getName() );
214 }
215 }
216
217 # Namespace filtering
218 if ( $opts['namespace'] !== '' ) {
219 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
220 $operator = $opts['invert'] ? '!=' : '=';
221 $boolean = $opts['invert'] ? 'AND' : 'OR';
222
223 # namespace association (bug 2429)
224 if ( !$opts['associated'] ) {
225 $condition = "rc_namespace $operator $selectedNS";
226 } else {
227 # Also add the associated namespace
228 $associatedNS = $dbr->addQuotes(
229 MWNamespace::getAssociated( $opts['namespace'] )
230 );
231 $condition = "(rc_namespace $operator $selectedNS "
232 . $boolean
233 . " rc_namespace $operator $associatedNS)";
234 }
235
236 $conds[] = $condition;
237 }
238
239 return $conds;
240 }
241
242 /**
243 * Process the query
244 *
245 * @param array $conds
246 * @param FormOptions $opts
247 * @return bool|ResultWrapper Result or false (for Recentchangeslinked only)
248 */
249 public function doMainQuery( $conds, $opts ) {
250 $tables = array( 'recentchanges' );
251 $join_conds = array();
252 $query_options = array();
253
254 $uid = $this->getUser()->getId();
255 $dbr = wfGetDB( DB_SLAVE );
256 $limit = $opts['limit'];
257 $namespace = $opts['namespace'];
258 $invert = $opts['invert'];
259 $associated = $opts['associated'];
260
261 $fields = RecentChange::selectFields();
262 // JOIN on watchlist for users
263 if ( $uid && $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
264 $tables[] = 'watchlist';
265 $fields[] = 'wl_user';
266 $fields[] = 'wl_notificationtimestamp';
267 $join_conds['watchlist'] = array( 'LEFT JOIN', array(
268 'wl_user' => $uid,
269 'wl_title=rc_title',
270 'wl_namespace=rc_namespace'
271 ) );
272 }
273 if ( $this->getUser()->isAllowed( 'rollback' ) ) {
274 $tables[] = 'page';
275 $fields[] = 'page_latest';
276 $join_conds['page'] = array( 'LEFT JOIN', 'rc_cur_id=page_id' );
277 }
278 // Tag stuff.
279 ChangeTags::modifyDisplayQuery(
280 $tables,
281 $fields,
282 $conds,
283 $join_conds,
284 $query_options,
285 $opts['tagfilter']
286 );
287
288 if ( !wfRunHooks( 'SpecialRecentChangesQuery',
289 array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ) )
290 ) {
291 return false;
292 }
293
294 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
295 // knowledge to use an index merge if it wants (it may use some other index though).
296 return $dbr->select(
297 $tables,
298 $fields,
299 $conds + array( 'rc_new' => array( 0, 1 ) ),
300 __METHOD__,
301 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) + $query_options,
302 $join_conds
303 );
304 }
305
306 /**
307 * Send output to the OutputPage object, only called if not used feeds
308 *
309 * @param array $rows Database rows
310 * @param FormOptions $opts
311 */
312 public function webOutput( $rows, $opts ) {
313 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker, $wgAllowCategorizedRecentChanges;
314
315 // Build the final data
316
317 if ( $wgAllowCategorizedRecentChanges ) {
318 $this->filterByCategories( $rows, $opts );
319 }
320
321 $limit = $opts['limit'];
322
323 $showWatcherCount = $wgRCShowWatchingUsers && $this->getUser()->getOption( 'shownumberswatching' );
324 $watcherCache = array();
325
326 $dbr = wfGetDB( DB_SLAVE );
327
328 $counter = 1;
329 $list = ChangesList::newFromContext( $this->getContext() );
330
331 $rclistOutput = $list->beginRecentChangesList();
332 foreach ( $rows as $obj ) {
333 if ( $limit == 0 ) {
334 break;
335 }
336 $rc = RecentChange::newFromRow( $obj );
337 $rc->counter = $counter++;
338 # Check if the page has been updated since the last visit
339 if ( $wgShowUpdatedMarker && !empty( $obj->wl_notificationtimestamp ) ) {
340 $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
341 } else {
342 $rc->notificationtimestamp = false; // Default
343 }
344 # Check the number of users watching the page
345 $rc->numberofWatchingusers = 0; // Default
346 if ( $showWatcherCount && $obj->rc_namespace >= 0 ) {
347 if ( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
348 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
349 $dbr->selectField(
350 'watchlist',
351 'COUNT(*)',
352 array(
353 'wl_namespace' => $obj->rc_namespace,
354 'wl_title' => $obj->rc_title,
355 ),
356 __METHOD__ . '-watchers'
357 );
358 }
359 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
360 }
361
362 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
363 if ( $changeLine !== false ) {
364 $rclistOutput .= $changeLine;
365 --$limit;
366 }
367 }
368 $rclistOutput .= $list->endRecentChangesList();
369
370 // Print things out
371
372 if ( !$this->including() ) {
373 // Output options box
374 $this->doHeader( $opts );
375 }
376
377 // And now for the content
378 $feedQuery = $this->getFeedQuery();
379 if ( $feedQuery !== '' ) {
380 $this->getOutput()->setFeedAppendQuery( $feedQuery );
381 } else {
382 $this->getOutput()->setFeedAppendQuery( false );
383 }
384
385 if ( $rows->numRows() === 0 ) {
386 $this->getOutput()->addHtml(
387 '<div class="mw-changeslist-empty">' . $this->msg( 'recentchanges-noresult' )->parse() . '</div>'
388 );
389 } else {
390 $this->getOutput()->addHTML( $rclistOutput );
391 }
392 }
393
394 /**
395 * Return the text to be displayed above the changes
396 *
397 * @param FormOptions $opts
398 * @return string XHTML
399 */
400 public function doHeader( $opts ) {
401 global $wgScript;
402
403 $this->setTopText( $opts );
404
405 $defaults = $opts->getAllValues();
406 $nondefaults = $opts->getChangedValues();
407
408 $panel = array();
409 $panel[] = self::makeLegend( $this->getContext() );
410 $panel[] = $this->optionsPanel( $defaults, $nondefaults );
411 $panel[] = '<hr />';
412
413 $extraOpts = $this->getExtraOptions( $opts );
414 $extraOptsCount = count( $extraOpts );
415 $count = 0;
416 $submit = ' ' . Xml::submitbutton( $this->msg( 'allpagessubmit' )->text() );
417
418 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
419 foreach ( $extraOpts as $name => $optionRow ) {
420 # Add submit button to the last row only
421 ++$count;
422 $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
423
424 $out .= Xml::openElement( 'tr' );
425 if ( is_array( $optionRow ) ) {
426 $out .= Xml::tags(
427 'td',
428 array( 'class' => 'mw-label mw-' . $name . '-label' ),
429 $optionRow[0]
430 );
431 $out .= Xml::tags(
432 'td',
433 array( 'class' => 'mw-input' ),
434 $optionRow[1] . $addSubmit
435 );
436 } else {
437 $out .= Xml::tags(
438 'td',
439 array( 'class' => 'mw-input', 'colspan' => 2 ),
440 $optionRow . $addSubmit
441 );
442 }
443 $out .= Xml::closeElement( 'tr' );
444 }
445 $out .= Xml::closeElement( 'table' );
446
447 $unconsumed = $opts->getUnconsumedValues();
448 foreach ( $unconsumed as $key => $value ) {
449 $out .= Html::hidden( $key, $value );
450 }
451
452 $t = $this->getPageTitle();
453 $out .= Html::hidden( 'title', $t->getPrefixedText() );
454 $form = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
455 $panel[] = $form;
456 $panelString = implode( "\n", $panel );
457
458 $this->getOutput()->addHTML(
459 Xml::fieldset(
460 $this->msg( 'recentchanges-legend' )->text(),
461 $panelString,
462 array( 'class' => 'rcoptions' )
463 )
464 );
465
466 $this->setBottomText( $opts );
467 }
468
469 /**
470 * Send the text to be displayed above the options
471 *
472 * @param FormOptions $opts Unused
473 */
474 function setTopText( FormOptions $opts ) {
475 global $wgContLang;
476
477 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
478 if ( !$message->isDisabled() ) {
479 $this->getOutput()->addWikiText(
480 Html::rawElement( 'p',
481 array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
482 "\n" . $message->plain() . "\n"
483 ),
484 /* $lineStart */ false,
485 /* $interface */ false
486 );
487 }
488 }
489
490 /**
491 * Get options to be displayed in a form
492 *
493 * @param FormOptions $opts
494 * @return array
495 */
496 function getExtraOptions( $opts ) {
497 $opts->consumeValues( array(
498 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
499 ) );
500
501 $extraOpts = array();
502 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
503
504 global $wgAllowCategorizedRecentChanges;
505 if ( $wgAllowCategorizedRecentChanges ) {
506 $extraOpts['category'] = $this->categoryFilterForm( $opts );
507 }
508
509 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
510 if ( count( $tagFilter ) ) {
511 $extraOpts['tagfilter'] = $tagFilter;
512 }
513
514 // Don't fire the hook for subclasses. (Or should we?)
515 if ( $this->getName() === 'Recentchanges' ) {
516 wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
517 }
518
519 return $extraOpts;
520 }
521
522 /**
523 * Add page-specific modules.
524 */
525 protected function addModules() {
526 parent::addModules();
527 $out = $this->getOutput();
528 $out->addModules( 'mediawiki.special.recentchanges' );
529 }
530
531 /**
532 * Get last modified date, for client caching
533 * Don't use this if we are using the patrol feature, patrol changes don't
534 * update the timestamp
535 *
536 * @param string $feedFormat
537 * @return string|bool
538 */
539 public function checkLastModified( $feedFormat ) {
540 $dbr = wfGetDB( DB_SLAVE );
541 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
542 if ( $feedFormat || !$this->getUser()->useRCPatrol() ) {
543 if ( $lastmod && $this->getOutput()->checkLastModified( $lastmod ) ) {
544 # Client cache fresh and headers sent, nothing more to do.
545 return false;
546 }
547 }
548
549 return $lastmod;
550 }
551
552 /**
553 * Return an array with a ChangesFeed object and ChannelFeed object.
554 *
555 * @param string $feedFormat Feed's format (either 'rss' or 'atom')
556 * @return array
557 */
558 public function getFeedObject( $feedFormat ) {
559 $changesFeed = new ChangesFeed( $feedFormat, 'rcfeed' );
560 $formatter = $changesFeed->getFeedObject(
561 $this->msg( 'recentchanges' )->inContentLanguage()->text(),
562 $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
563 $this->getPageTitle()->getFullURL()
564 );
565
566 return array( $changesFeed, $formatter );
567 }
568
569 /**
570 * Get the query string to append to feed link URLs.
571 *
572 * @return string
573 */
574 public function getFeedQuery() {
575 global $wgFeedLimit;
576
577 $this->getOptions()->validateIntBounds( 'limit', 0, $wgFeedLimit );
578 $options = $this->getOptions()->getChangedValues();
579
580 // wfArrayToCgi() omits options set to null or false
581 foreach ( $options as &$value ) {
582 if ( $value === false ) {
583 $value = '0';
584 }
585 }
586 unset( $value );
587
588 return wfArrayToCgi( $options );
589 }
590
591 /**
592 * Creates the choose namespace selection
593 *
594 * @param FormOptions $opts
595 * @return string
596 */
597 protected function namespaceFilterForm( FormOptions $opts ) {
598 $nsSelect = Html::namespaceSelector(
599 array( 'selected' => $opts['namespace'], 'all' => '' ),
600 array( 'name' => 'namespace', 'id' => 'namespace' )
601 );
602 $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
603 $invert = Xml::checkLabel(
604 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
605 $opts['invert'],
606 array( 'title' => $this->msg( 'tooltip-invert' )->text() )
607 );
608 $associated = Xml::checkLabel(
609 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
610 $opts['associated'],
611 array( 'title' => $this->msg( 'tooltip-namespace_association' )->text() )
612 );
613
614 return array( $nsLabel, "$nsSelect $invert $associated" );
615 }
616
617 /**
618 * Create a input to filter changes by categories
619 *
620 * @param FormOptions $opts
621 * @return array
622 */
623 protected function categoryFilterForm( FormOptions $opts ) {
624 list( $label, $input ) = Xml::inputLabelSep( $this->msg( 'rc_categories' )->text(),
625 'categories', 'mw-categories', false, $opts['categories'] );
626
627 $input .= ' ' . Xml::checkLabel( $this->msg( 'rc_categories_any' )->text(),
628 'categories_any', 'mw-categories_any', $opts['categories_any'] );
629
630 return array( $label, $input );
631 }
632
633 /**
634 * Filter $rows by categories set in $opts
635 *
636 * @param ResultWrapper $rows Database rows
637 * @param FormOptions $opts
638 */
639 function filterByCategories( &$rows, FormOptions $opts ) {
640 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
641
642 if ( !count( $categories ) ) {
643 return;
644 }
645
646 # Filter categories
647 $cats = array();
648 foreach ( $categories as $cat ) {
649 $cat = trim( $cat );
650 if ( $cat == '' ) {
651 continue;
652 }
653 $cats[] = $cat;
654 }
655
656 # Filter articles
657 $articles = array();
658 $a2r = array();
659 $rowsarr = array();
660 foreach ( $rows as $k => $r ) {
661 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
662 $id = $nt->getArticleID();
663 if ( $id == 0 ) {
664 continue; # Page might have been deleted...
665 }
666 if ( !in_array( $id, $articles ) ) {
667 $articles[] = $id;
668 }
669 if ( !isset( $a2r[$id] ) ) {
670 $a2r[$id] = array();
671 }
672 $a2r[$id][] = $k;
673 $rowsarr[$k] = $r;
674 }
675
676 # Shortcut?
677 if ( !count( $articles ) || !count( $cats ) ) {
678 return;
679 }
680
681 # Look up
682 $c = new Categoryfinder;
683 $c->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
684 $match = $c->run();
685
686 # Filter
687 $newrows = array();
688 foreach ( $match as $id ) {
689 foreach ( $a2r[$id] as $rev ) {
690 $k = $rev;
691 $newrows[$k] = $rowsarr[$k];
692 }
693 }
694 $rows = $newrows;
695 }
696
697 /**
698 * Makes change an option link which carries all the other options
699 *
700 * @param string $title Title
701 * @param array $override Options to override
702 * @param array $options Current options
703 * @param bool $active Whether to show the link in bold
704 * @return string
705 */
706 function makeOptionsLink( $title, $override, $options, $active = false ) {
707 $params = $override + $options;
708
709 // Bug 36524: false values have be converted to "0" otherwise
710 // wfArrayToCgi() will omit it them.
711 foreach ( $params as &$value ) {
712 if ( $value === false ) {
713 $value = '0';
714 }
715 }
716 unset( $value );
717
718 $text = htmlspecialchars( $title );
719 if ( $active ) {
720 $text = '<strong>' . $text . '</strong>';
721 }
722
723 return Linker::linkKnown( $this->getPageTitle(), $text, array(), $params );
724 }
725
726 /**
727 * Creates the options panel.
728 *
729 * @param array $defaults
730 * @param array $nondefaults
731 * @return string
732 */
733 function optionsPanel( $defaults, $nondefaults ) {
734 global $wgRCLinkLimits, $wgRCLinkDays;
735
736 $options = $nondefaults + $defaults;
737
738 $note = '';
739 $msg = $this->msg( 'rclegend' );
740 if ( !$msg->isDisabled() ) {
741 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
742 }
743
744 $lang = $this->getLanguage();
745 $user = $this->getUser();
746 if ( $options['from'] ) {
747 $note .= $this->msg( 'rcnotefrom' )->numParams( $options['limit'] )->params(
748 $lang->userTimeAndDate( $options['from'], $user ),
749 $lang->userDate( $options['from'], $user ),
750 $lang->userTime( $options['from'], $user ) )->parse() . '<br />';
751 }
752
753 # Sort data for display and make sure it's unique after we've added user data.
754 $linkLimits = $wgRCLinkLimits;
755 $linkLimits[] = $options['limit'];
756 sort( $linkLimits );
757 $linkLimits = array_unique( $linkLimits );
758
759 $linkDays = $wgRCLinkDays;
760 $linkDays[] = $options['days'];
761 sort( $linkDays );
762 $linkDays = array_unique( $linkDays );
763
764 // limit links
765 $cl = array();
766 foreach ( $linkLimits as $value ) {
767 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
768 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] );
769 }
770 $cl = $lang->pipeList( $cl );
771
772 // day links, reset 'from' to none
773 $dl = array();
774 foreach ( $linkDays as $value ) {
775 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
776 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] );
777 }
778 $dl = $lang->pipeList( $dl );
779
780 // show/hide links
781 $showhide = array( $this->msg( 'show' )->text(), $this->msg( 'hide' )->text() );
782 $filters = array(
783 'hideminor' => 'rcshowhideminor',
784 'hidebots' => 'rcshowhidebots',
785 'hideanons' => 'rcshowhideanons',
786 'hideliu' => 'rcshowhideliu',
787 'hidepatrolled' => 'rcshowhidepatr',
788 'hidemyself' => 'rcshowhidemine'
789 );
790 foreach ( $this->getCustomFilters() as $key => $params ) {
791 $filters[$key] = $params['msg'];
792 }
793 // Disable some if needed
794 if ( !$user->useRCPatrol() ) {
795 unset( $filters['hidepatrolled'] );
796 }
797
798 $links = array();
799 foreach ( $filters as $key => $msg ) {
800 $link = $this->makeOptionsLink( $showhide[1 - $options[$key]],
801 array( $key => 1 - $options[$key] ), $nondefaults );
802 $links[] = $this->msg( $msg )->rawParams( $link )->escaped();
803 }
804
805 // show from this onward link
806 $timestamp = wfTimestampNow();
807 $now = $lang->userTimeAndDate( $timestamp, $user );
808 $tl = $this->makeOptionsLink(
809 $now, array( 'from' => $timestamp ), $nondefaults
810 );
811
812 $rclinks = $this->msg( 'rclinks' )->rawParams( $cl, $dl, $lang->pipeList( $links ) )
813 ->parse();
814 $rclistfrom = $this->msg( 'rclistfrom' )->rawParams( $tl )->parse();
815
816 return "{$note}$rclinks<br />$rclistfrom";
817 }
818
819 public function isIncludable() {
820 return true;
821 }
822 }