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