Merge "Remove links list from the 'rclinks' message"
[mediawiki.git] / includes / specials / SpecialRecentchanges.php
blobaaa99b60f16f3052a7c92463f738a9f42e238b38
1 <?php
2 /**
3 * Implements Special:Recentchanges
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.
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.
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
20 * @file
21 * @ingroup SpecialPage
24 use MediaWiki\MediaWikiServices;
25 use Wikimedia\Rdbms\ResultWrapper;
26 use Wikimedia\Rdbms\FakeResultWrapper;
28 /**
29 * A special page that lists last changes made to the wiki
31 * @ingroup SpecialPage
33 class SpecialRecentChanges extends ChangesListSpecialPage {
34 // @codingStandardsIgnoreStart Needed "useless" override to change parameters.
35 public function __construct( $name = 'Recentchanges', $restriction = '' ) {
36 parent::__construct( $name, $restriction );
38 // @codingStandardsIgnoreEnd
40 /**
41 * Main execution point
43 * @param string $subpage
45 public function execute( $subpage ) {
46 // Backwards-compatibility: redirect to new feed URLs
47 $feedFormat = $this->getRequest()->getVal( 'feed' );
48 if ( !$this->including() && $feedFormat ) {
49 $query = $this->getFeedQuery();
50 $query['feedformat'] = $feedFormat === 'atom' ? 'atom' : 'rss';
51 $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
53 return;
56 // 10 seconds server-side caching max
57 $out = $this->getOutput();
58 $out->setCdnMaxage( 10 );
59 // Check if the client has a cached version
60 $lastmod = $this->checkLastModified();
61 if ( $lastmod === false ) {
62 return;
65 $this->addHelpLink(
66 '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
67 true
69 parent::execute( $subpage );
71 if ( $this->isStructuredFilterUiEnabled() ) {
72 $jsData = $this->getStructuredFilterJsData();
74 $messages = [];
75 foreach ( $jsData['messageKeys'] as $key ){
76 $messages[$key] = $this->msg( $key )->plain();
79 $out->addHTML(
80 ResourceLoader::makeInlineScript(
81 ResourceLoader::makeMessageSetScript( $messages )
85 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
89 /**
90 * @inheritdoc
92 protected function transformFilterDefinition( array $filterDefinition ) {
93 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
94 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
97 return $filterDefinition;
101 * @inheritdoc
103 protected function registerFilters() {
104 parent::registerFilters();
106 $user = $this->getUser();
108 $significance = $this->getFilterGroup( 'significance' );
109 $hideMinor = $significance->getFilter( 'hideminor' );
110 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
112 $automated = $this->getFilterGroup( 'automated' );
113 $hideBots = $automated->getFilter( 'hidebots' );
114 $hideBots->setDefault( true );
116 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
117 if ( $reviewStatus !== null ) {
118 // Conditional on feature being available and rights
119 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
120 $hidePatrolled->setDefault( $user->getBoolOption( 'hidepatrolled' ) );
123 $changeType = $this->getFilterGroup( 'changeType' );
124 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
125 if ( $hideCategorization !== null ) {
126 // Conditional on feature being available
127 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
132 * Get a FormOptions object containing the default options
134 * @return FormOptions
136 public function getDefaultOptions() {
137 $opts = parent::getDefaultOptions();
138 $user = $this->getUser();
140 $opts->add( 'days', $user->getIntOption( 'rcdays' ) );
141 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
142 $opts->add( 'from', '' );
144 $opts->add( 'categories', '' );
145 $opts->add( 'categories_any', false );
146 $opts->add( 'tagfilter', '' );
148 return $opts;
152 * Get all custom filters
154 * @return array Map of filter URL param names to properties (msg/default)
156 protected function getCustomFilters() {
157 if ( $this->customFilters === null ) {
158 $this->customFilters = parent::getCustomFilters();
159 Hooks::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters ], '1.23' );
162 return $this->customFilters;
166 * Process $par and put options found in $opts. Used when including the page.
168 * @param string $par
169 * @param FormOptions $opts
171 public function parseParameters( $par, FormOptions $opts ) {
172 parent::parseParameters( $par, $opts );
174 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
175 foreach ( $bits as $bit ) {
176 if ( is_numeric( $bit ) ) {
177 $opts['limit'] = $bit;
180 $m = [];
181 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
182 $opts['limit'] = $m[1];
184 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
185 $opts['days'] = $m[1];
187 if ( preg_match( '/^namespace=(\d+)$/', $bit, $m ) ) {
188 $opts['namespace'] = $m[1];
190 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
191 $opts['tagfilter'] = $m[1];
196 public function validateOptions( FormOptions $opts ) {
197 $opts->validateIntBounds( 'limit', 0, 5000 );
198 parent::validateOptions( $opts );
202 * @inheritdoc
204 protected function buildQuery( &$tables, &$fields, &$conds,
205 &$query_options, &$join_conds, FormOptions $opts ) {
207 $dbr = $this->getDB();
208 parent::buildQuery( $tables, $fields, $conds,
209 $query_options, $join_conds, $opts );
211 // Calculate cutoff
212 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
213 $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime % 86400 );
214 $cutoff = $dbr->timestamp( $cutoff_unixtime );
216 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
217 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) {
218 $cutoff = $dbr->timestamp( $opts['from'] );
219 } else {
220 $opts->reset( 'from' );
223 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
227 * @inheritdoc
229 protected function doMainQuery( $tables, $fields, $conds, $query_options,
230 $join_conds, FormOptions $opts ) {
232 $dbr = $this->getDB();
233 $user = $this->getUser();
235 $tables[] = 'recentchanges';
236 $fields = array_merge( RecentChange::selectFields(), $fields );
238 // JOIN on watchlist for users
239 if ( $user->getId() && $user->isAllowed( 'viewmywatchlist' ) ) {
240 $tables[] = 'watchlist';
241 $fields[] = 'wl_user';
242 $fields[] = 'wl_notificationtimestamp';
243 $join_conds['watchlist'] = [ 'LEFT JOIN', [
244 'wl_user' => $user->getId(),
245 'wl_title=rc_title',
246 'wl_namespace=rc_namespace'
247 ] ];
250 if ( $user->isAllowed( 'rollback' ) ) {
251 $tables[] = 'page';
252 $fields[] = 'page_latest';
253 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
256 ChangeTags::modifyDisplayQuery(
257 $tables,
258 $fields,
259 $conds,
260 $join_conds,
261 $query_options,
262 $opts['tagfilter']
265 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
266 $opts )
268 return false;
271 if ( $this->areFiltersInConflict() ) {
272 return false;
275 // array_merge() is used intentionally here so that hooks can, should
276 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
277 // MediaWiki 1.26 this used to use the plus operator instead, which meant
278 // that extensions weren't able to change these conditions
279 $query_options = array_merge( [
280 'ORDER BY' => 'rc_timestamp DESC',
281 'LIMIT' => $opts['limit'] ], $query_options );
282 $rows = $dbr->select(
283 $tables,
284 $fields,
285 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
286 // knowledge to use an index merge if it wants (it may use some other index though).
287 $conds + [ 'rc_new' => [ 0, 1 ] ],
288 __METHOD__,
289 $query_options,
290 $join_conds
293 // Build the final data
294 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
295 $this->filterByCategories( $rows, $opts );
298 return $rows;
301 protected function runMainQueryHook( &$tables, &$fields, &$conds,
302 &$query_options, &$join_conds, $opts
304 return parent::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
305 && Hooks::run(
306 'SpecialRecentChangesQuery',
307 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
308 '1.23'
312 protected function getDB() {
313 return wfGetDB( DB_REPLICA, 'recentchanges' );
316 public function outputFeedLinks() {
317 $this->addFeedLinks( $this->getFeedQuery() );
321 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
323 * @return array
325 protected function getFeedQuery() {
326 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
327 // API handles empty parameters in a different way
328 return $value !== '';
329 } );
330 $query['action'] = 'feedrecentchanges';
331 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
332 if ( $query['limit'] > $feedLimit ) {
333 $query['limit'] = $feedLimit;
336 return $query;
340 * Build and output the actual changes list.
342 * @param ResultWrapper $rows Database rows
343 * @param FormOptions $opts
345 public function outputChangesList( $rows, $opts ) {
346 $limit = $opts['limit'];
348 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
349 && $this->getUser()->getOption( 'shownumberswatching' );
350 $watcherCache = [];
352 $dbr = $this->getDB();
354 $counter = 1;
355 $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
356 $list->initChangesListRows( $rows );
358 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
359 $rclistOutput = $list->beginRecentChangesList();
360 foreach ( $rows as $obj ) {
361 if ( $limit == 0 ) {
362 break;
364 $rc = RecentChange::newFromRow( $obj );
366 # Skip CatWatch entries for hidden cats based on user preference
367 if (
368 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
369 !$userShowHiddenCats &&
370 $rc->getParam( 'hidden-cat' )
372 continue;
375 $rc->counter = $counter++;
376 # Check if the page has been updated since the last visit
377 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
378 && !empty( $obj->wl_notificationtimestamp )
380 $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
381 } else {
382 $rc->notificationtimestamp = false; // Default
384 # Check the number of users watching the page
385 $rc->numberofWatchingusers = 0; // Default
386 if ( $showWatcherCount && $obj->rc_namespace >= 0 ) {
387 if ( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
388 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
389 MediaWikiServices::getInstance()->getWatchedItemStore()->countWatchers(
390 new TitleValue( (int)$obj->rc_namespace, $obj->rc_title )
393 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
396 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
397 if ( $changeLine !== false ) {
398 $rclistOutput .= $changeLine;
399 --$limit;
402 $rclistOutput .= $list->endRecentChangesList();
404 if ( $rows->numRows() === 0 ) {
405 $this->outputNoResults();
406 if ( !$this->including() ) {
407 $this->getOutput()->setStatusCode( 404 );
409 } else {
410 $this->getOutput()->addHTML( $rclistOutput );
415 * Set the text to be displayed above the changes
417 * @param FormOptions $opts
418 * @param int $numRows Number of rows in the result to show after this header
420 public function doHeader( $opts, $numRows ) {
421 $this->setTopText( $opts );
423 $defaults = $opts->getAllValues();
424 $nondefaults = $opts->getChangedValues();
426 $panel = [];
427 $panel[] = $this->makeLegend();
428 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
429 $panel[] = '<hr />';
431 $extraOpts = $this->getExtraOptions( $opts );
432 $extraOptsCount = count( $extraOpts );
433 $count = 0;
434 $submit = ' ' . Xml::submitButton( $this->msg( 'recentchanges-submit' )->text() );
436 $out = Xml::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
437 foreach ( $extraOpts as $name => $optionRow ) {
438 # Add submit button to the last row only
439 ++$count;
440 $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
442 $out .= Xml::openElement( 'tr' );
443 if ( is_array( $optionRow ) ) {
444 $out .= Xml::tags(
445 'td',
446 [ 'class' => 'mw-label mw-' . $name . '-label' ],
447 $optionRow[0]
449 $out .= Xml::tags(
450 'td',
451 [ 'class' => 'mw-input' ],
452 $optionRow[1] . $addSubmit
454 } else {
455 $out .= Xml::tags(
456 'td',
457 [ 'class' => 'mw-input', 'colspan' => 2 ],
458 $optionRow . $addSubmit
461 $out .= Xml::closeElement( 'tr' );
463 $out .= Xml::closeElement( 'table' );
465 $unconsumed = $opts->getUnconsumedValues();
466 foreach ( $unconsumed as $key => $value ) {
467 $out .= Html::hidden( $key, $value );
470 $t = $this->getPageTitle();
471 $out .= Html::hidden( 'title', $t->getPrefixedText() );
472 $form = Xml::tags( 'form', [ 'action' => wfScript() ], $out );
473 $panel[] = $form;
474 $panelString = implode( "\n", $panel );
476 $rcoptions = Xml::fieldset(
477 $this->msg( 'recentchanges-legend' )->text(),
478 $panelString,
479 [ 'class' => 'rcoptions' ]
482 // Insert a placeholder for RCFilters
483 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
484 $rcfilterContainer = Html::element(
485 'div',
486 [ 'class' => 'rcfilters-container' ]
489 // Wrap both with rcfilters-head
490 $this->getOutput()->addHTML(
491 Html::rawElement(
492 'div',
493 [ 'class' => 'rcfilters-head' ],
494 $rcfilterContainer . $rcoptions
497 } else {
498 $this->getOutput()->addHTML( $rcoptions );
501 $this->setBottomText( $opts );
505 * Send the text to be displayed above the options
507 * @param FormOptions $opts Unused
509 function setTopText( FormOptions $opts ) {
510 global $wgContLang;
512 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
513 if ( !$message->isDisabled() ) {
514 $this->getOutput()->addWikiText(
515 Html::rawElement( 'div',
516 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
517 "\n" . $message->plain() . "\n"
519 /* $lineStart */ true,
520 /* $interface */ false
526 * Get options to be displayed in a form
528 * @param FormOptions $opts
529 * @return array
531 function getExtraOptions( $opts ) {
532 $opts->consumeValues( [
533 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
534 ] );
536 $extraOpts = [];
537 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
539 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
540 $extraOpts['category'] = $this->categoryFilterForm( $opts );
543 $tagFilter = ChangeTags::buildTagFilterSelector(
544 $opts['tagfilter'], false, $this->getContext() );
545 if ( count( $tagFilter ) ) {
546 $extraOpts['tagfilter'] = $tagFilter;
549 // Don't fire the hook for subclasses. (Or should we?)
550 if ( $this->getName() === 'Recentchanges' ) {
551 Hooks::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
554 return $extraOpts;
558 * Check whether the structured filter UI is enabled
560 * @return bool
562 protected function isStructuredFilterUiEnabled() {
563 return $this->getUser()->getOption(
564 'rcenhancedfilters'
569 * Add page-specific modules.
571 protected function addModules() {
572 parent::addModules();
573 $out = $this->getOutput();
574 $out->addModules( 'mediawiki.special.recentchanges' );
575 if ( $this->isStructuredFilterUiEnabled() ) {
576 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
577 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
582 * Get last modified date, for client caching
583 * Don't use this if we are using the patrol feature, patrol changes don't
584 * update the timestamp
586 * @return string|bool
588 public function checkLastModified() {
589 $dbr = $this->getDB();
590 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
592 return $lastmod;
596 * Creates the choose namespace selection
598 * @param FormOptions $opts
599 * @return string
601 protected function namespaceFilterForm( FormOptions $opts ) {
602 $nsSelect = Html::namespaceSelector(
603 [ 'selected' => $opts['namespace'], 'all' => '' ],
604 [ 'name' => 'namespace', 'id' => 'namespace' ]
606 $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
607 $invert = Xml::checkLabel(
608 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
609 $opts['invert'],
610 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
612 $associated = Xml::checkLabel(
613 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
614 $opts['associated'],
615 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
618 return [ $nsLabel, "$nsSelect $invert $associated" ];
622 * Create an input to filter changes by categories
624 * @param FormOptions $opts
625 * @return array
627 protected function categoryFilterForm( FormOptions $opts ) {
628 list( $label, $input ) = Xml::inputLabelSep( $this->msg( 'rc_categories' )->text(),
629 'categories', 'mw-categories', false, $opts['categories'] );
631 $input .= ' ' . Xml::checkLabel( $this->msg( 'rc_categories_any' )->text(),
632 'categories_any', 'mw-categories_any', $opts['categories_any'] );
634 return [ $label, $input ];
638 * Filter $rows by categories set in $opts
640 * @param ResultWrapper $rows Database rows
641 * @param FormOptions $opts
643 function filterByCategories( &$rows, FormOptions $opts ) {
644 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
646 if ( !count( $categories ) ) {
647 return;
650 # Filter categories
651 $cats = [];
652 foreach ( $categories as $cat ) {
653 $cat = trim( $cat );
654 if ( $cat == '' ) {
655 continue;
657 $cats[] = $cat;
660 # Filter articles
661 $articles = [];
662 $a2r = [];
663 $rowsarr = [];
664 foreach ( $rows as $k => $r ) {
665 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
666 $id = $nt->getArticleID();
667 if ( $id == 0 ) {
668 continue; # Page might have been deleted...
670 if ( !in_array( $id, $articles ) ) {
671 $articles[] = $id;
673 if ( !isset( $a2r[$id] ) ) {
674 $a2r[$id] = [];
676 $a2r[$id][] = $k;
677 $rowsarr[$k] = $r;
680 # Shortcut?
681 if ( !count( $articles ) || !count( $cats ) ) {
682 return;
685 # Look up
686 $catFind = new CategoryFinder;
687 $catFind->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
688 $match = $catFind->run();
690 # Filter
691 $newrows = [];
692 foreach ( $match as $id ) {
693 foreach ( $a2r[$id] as $rev ) {
694 $k = $rev;
695 $newrows[$k] = $rowsarr[$k];
698 $rows = new FakeResultWrapper( array_values( $newrows ) );
702 * Makes change an option link which carries all the other options
704 * @param string $title Title
705 * @param array $override Options to override
706 * @param array $options Current options
707 * @param bool $active Whether to show the link in bold
708 * @return string
710 function makeOptionsLink( $title, $override, $options, $active = false ) {
711 $params = $override + $options;
713 // T38524: false values have be converted to "0" otherwise
714 // wfArrayToCgi() will omit it them.
715 foreach ( $params as &$value ) {
716 if ( $value === false ) {
717 $value = '0';
720 unset( $value );
722 if ( $active ) {
723 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
726 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
727 'data-params' => json_encode( $override ),
728 'data-keys' => implode( ',', array_keys( $override ) ),
729 ], $params );
733 * Creates the options panel.
735 * @param array $defaults
736 * @param array $nondefaults
737 * @param int $numRows Number of rows in the result to show after this header
738 * @return string
740 function optionsPanel( $defaults, $nondefaults, $numRows ) {
741 $options = $nondefaults + $defaults;
743 $note = '';
744 $msg = $this->msg( 'rclegend' );
745 if ( !$msg->isDisabled() ) {
746 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
749 $lang = $this->getLanguage();
750 $user = $this->getUser();
751 $config = $this->getConfig();
752 if ( $options['from'] ) {
753 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
754 [ 'from' => '' ], $nondefaults );
756 $note .= $this->msg( 'rcnotefrom' )
757 ->numParams( $options['limit'] )
758 ->params(
759 $lang->userTimeAndDate( $options['from'], $user ),
760 $lang->userDate( $options['from'], $user ),
761 $lang->userTime( $options['from'], $user )
763 ->numParams( $numRows )
764 ->parse() . ' ' .
765 Html::rawElement(
766 'span',
767 [ 'class' => 'rcoptions-listfromreset' ],
768 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
770 '<br />';
773 # Sort data for display and make sure it's unique after we've added user data.
774 $linkLimits = $config->get( 'RCLinkLimits' );
775 $linkLimits[] = $options['limit'];
776 sort( $linkLimits );
777 $linkLimits = array_unique( $linkLimits );
779 $linkDays = $config->get( 'RCLinkDays' );
780 $linkDays[] = $options['days'];
781 sort( $linkDays );
782 $linkDays = array_unique( $linkDays );
784 // limit links
785 $cl = [];
786 foreach ( $linkLimits as $value ) {
787 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
788 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
790 $cl = $lang->pipeList( $cl );
792 // day links, reset 'from' to none
793 $dl = [];
794 foreach ( $linkDays as $value ) {
795 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
796 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
798 $dl = $lang->pipeList( $dl );
800 $showhide = [ 'show', 'hide' ];
802 $links = [];
804 $filterGroups = $this->getFilterGroups();
806 $context = $this->getContext();
807 foreach ( $filterGroups as $groupName => $group ) {
808 if ( !$group->isPerGroupRequestParameter() ) {
809 foreach ( $group->getFilters() as $key => $filter ) {
810 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
811 $msg = $filter->getShowHide();
812 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
813 // Extensions can define additional filters, but don't need to define the corresponding
814 // messages. If they don't exist, just fall back to 'show' and 'hide'.
815 if ( !$linkMessage->exists() ) {
816 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
819 $link = $this->makeOptionsLink( $linkMessage->text(),
820 [ $key => 1 - $options[$key] ], $nondefaults );
822 $attribs = [
823 'class' => "$msg rcshowhideoption",
824 'data-filter-name' => $filter->getName(),
827 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
828 $attribs['data-feature-in-structured-ui'] = true;
831 $links[] = Html::rawElement(
832 'span',
833 $attribs,
834 $this->msg( $msg )->rawParams( $link )->escaped()
841 // show from this onward link
842 $timestamp = wfTimestampNow();
843 $now = $lang->userTimeAndDate( $timestamp, $user );
844 $timenow = $lang->userTime( $timestamp, $user );
845 $datenow = $lang->userDate( $timestamp, $user );
846 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
848 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
849 ->parse() . '</span>';
851 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
852 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
853 [ 'from' => $timestamp ],
854 $nondefaults
855 ) . '</span>';
857 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
860 public function isIncludable() {
861 return true;
864 protected function getCacheTTL() {
865 return 60 * 5;