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