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
21 * @ingroup SpecialPage
24 use MediaWiki\MediaWikiServices
;
25 use Wikimedia\Rdbms\ResultWrapper
;
26 use Wikimedia\Rdbms\FakeResultWrapper
;
29 * A special page that lists last changes made to the wiki
31 * @ingroup SpecialPage
33 class SpecialRecentChanges
extends ChangesListSpecialPage
{
35 protected static $savedQueriesPreferenceName = 'rcfilters-saved-queries';
36 protected static $daysPreferenceName = 'rcdays'; // Use general RecentChanges preference
37 protected static $limitPreferenceName = 'rcfilters-limit'; // Use RCFilters-specific preference
39 private $watchlistFilterGroupDefinition;
41 // @codingStandardsIgnoreStart Needed "useless" override to change parameters.
42 public function __construct( $name = 'Recentchanges', $restriction = '' ) {
43 parent
::__construct( $name, $restriction );
45 $this->watchlistFilterGroupDefinition
= [
46 'name' => 'watchlist',
47 'title' => 'rcfilters-filtergroup-watchlist',
48 'class' => ChangesListStringOptionsFilterGroup
::class,
50 'isFullCoverage' => true,
54 'label' => 'rcfilters-filter-watchlist-watched-label',
55 'description' => 'rcfilters-filter-watchlist-watched-description',
56 'cssClassSuffix' => 'watched',
57 'isRowApplicableCallable' => function ( $ctx, $rc ) {
58 return $rc->getAttribute( 'wl_user' );
62 'name' => 'watchednew',
63 'label' => 'rcfilters-filter-watchlist-watchednew-label',
64 'description' => 'rcfilters-filter-watchlist-watchednew-description',
65 'cssClassSuffix' => 'watchednew',
66 'isRowApplicableCallable' => function ( $ctx, $rc ) {
67 return $rc->getAttribute( 'wl_user' ) &&
68 $rc->getAttribute( 'rc_timestamp' ) &&
69 $rc->getAttribute( 'wl_notificationtimestamp' ) &&
70 $rc->getAttribute( 'rc_timestamp' ) >= $rc->getAttribute( 'wl_notificationtimestamp' );
74 'name' => 'notwatched',
75 'label' => 'rcfilters-filter-watchlist-notwatched-label',
76 'description' => 'rcfilters-filter-watchlist-notwatched-description',
77 'cssClassSuffix' => 'notwatched',
78 'isRowApplicableCallable' => function ( $ctx, $rc ) {
79 return $rc->getAttribute( 'wl_user' ) === null;
83 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
84 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
85 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
86 sort( $selectedValues );
87 $notwatchedCond = 'wl_user IS NULL';
88 $watchedCond = 'wl_user IS NOT NULL';
89 $newCond = 'rc_timestamp >= wl_notificationtimestamp';
91 if ( $selectedValues === [ 'notwatched' ] ) {
92 $conds[] = $notwatchedCond;
96 if ( $selectedValues === [ 'watched' ] ) {
97 $conds[] = $watchedCond;
101 if ( $selectedValues === [ 'watchednew' ] ) {
102 $conds[] = $dbr->makeList( [
109 if ( $selectedValues === [ 'notwatched', 'watched' ] ) {
114 if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) {
115 $conds[] = $dbr->makeList( [
125 if ( $selectedValues === [ 'watched', 'watchednew' ] ) {
126 $conds[] = $watchedCond;
130 if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) {
137 // @codingStandardsIgnoreEnd
140 * Main execution point
142 * @param string $subpage
144 public function execute( $subpage ) {
145 // Backwards-compatibility: redirect to new feed URLs
146 $feedFormat = $this->getRequest()->getVal( 'feed' );
147 if ( !$this->including() && $feedFormat ) {
148 $query = $this->getFeedQuery();
149 $query['feedformat'] = $feedFormat === 'atom' ?
'atom' : 'rss';
150 $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
155 // 10 seconds server-side caching max
156 $out = $this->getOutput();
157 $out->setCdnMaxage( 10 );
158 // Check if the client has a cached version
159 $lastmod = $this->checkLastModified();
160 if ( $lastmod === false ) {
165 '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
168 parent
::execute( $subpage );
174 protected function transformFilterDefinition( array $filterDefinition ) {
175 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
176 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
179 return $filterDefinition;
185 protected function registerFilters() {
186 parent
::registerFilters();
189 !$this->including() &&
190 $this->getUser()->isLoggedIn() &&
191 $this->getUser()->isAllowed( 'viewmywatchlist' )
193 $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition
] );
194 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
195 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
196 $watchlistGroup->getFilter( 'watchednew' )
200 $user = $this->getUser();
202 $significance = $this->getFilterGroup( 'significance' );
203 $hideMinor = $significance->getFilter( 'hideminor' );
204 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
206 $automated = $this->getFilterGroup( 'automated' );
207 $hideBots = $automated->getFilter( 'hidebots' );
208 $hideBots->setDefault( true );
210 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
211 if ( $reviewStatus !== null ) {
212 // Conditional on feature being available and rights
213 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
214 $hidePatrolled->setDefault( $user->getBoolOption( 'hidepatrolled' ) );
217 $changeType = $this->getFilterGroup( 'changeType' );
218 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
219 if ( $hideCategorization !== null ) {
220 // Conditional on feature being available
221 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
226 * Get a FormOptions object containing the default options
228 * @return FormOptions
230 public function getDefaultOptions() {
231 $opts = parent
::getDefaultOptions();
233 $opts->add( 'categories', '' );
234 $opts->add( 'categories_any', false );
240 * Get all custom filters
242 * @return array Map of filter URL param names to properties (msg/default)
244 protected function getCustomFilters() {
245 if ( $this->customFilters
=== null ) {
246 $this->customFilters
= parent
::getCustomFilters();
247 Hooks
::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters
], '1.23' );
250 return $this->customFilters
;
254 * Process $par and put options found in $opts. Used when including the page.
257 * @param FormOptions $opts
259 public function parseParameters( $par, FormOptions
$opts ) {
260 parent
::parseParameters( $par, $opts );
262 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
263 foreach ( $bits as $bit ) {
264 if ( is_numeric( $bit ) ) {
265 $opts['limit'] = $bit;
269 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
270 $opts['limit'] = $m[1];
272 if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
273 $opts['days'] = $m[1];
275 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
276 $opts['namespace'] = $m[1];
278 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
279 $opts['tagfilter'] = $m[1];
287 protected function doMainQuery( $tables, $fields, $conds, $query_options,
288 $join_conds, FormOptions
$opts
290 $dbr = $this->getDB();
291 $user = $this->getUser();
293 $rcQuery = RecentChange
::getQueryInfo();
294 $tables = array_merge( $tables, $rcQuery['tables'] );
295 $fields = array_merge( $rcQuery['fields'], $fields );
296 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
298 // JOIN on watchlist for users
299 if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
300 $tables[] = 'watchlist';
301 $fields[] = 'wl_user';
302 $fields[] = 'wl_notificationtimestamp';
303 $join_conds['watchlist'] = [ 'LEFT JOIN', [
304 'wl_user' => $user->getId(),
306 'wl_namespace=rc_namespace'
310 // JOIN on page, used for 'last revision' filter highlight
312 $fields[] = 'page_latest';
313 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
315 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
316 ChangeTags
::modifyDisplayQuery(
325 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
331 if ( $this->areFiltersInConflict() ) {
336 'ORDER BY' => 'rc_timestamp DESC',
337 'LIMIT' => $opts['limit']
339 if ( in_array( 'DISTINCT', $query_options ) ) {
340 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
341 // In order to prevent DISTINCT from causing query performance problems,
342 // we have to GROUP BY the primary key. This in turn requires us to add
343 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
344 // start of the GROUP BY
345 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
346 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
348 // array_merge() is used intentionally here so that hooks can, should
349 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
350 // MediaWiki 1.26 this used to use the plus operator instead, which meant
351 // that extensions weren't able to change these conditions
352 $query_options = array_merge( $orderByAndLimit, $query_options );
353 $rows = $dbr->select(
356 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
357 // knowledge to use an index merge if it wants (it may use some other index though).
358 $conds +
[ 'rc_new' => [ 0, 1 ] ],
364 // Build the final data
365 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
366 $this->filterByCategories( $rows, $opts );
372 protected function runMainQueryHook( &$tables, &$fields, &$conds,
373 &$query_options, &$join_conds, $opts
375 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
377 'SpecialRecentChangesQuery',
378 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
383 protected function getDB() {
384 return wfGetDB( DB_REPLICA
, 'recentchanges' );
387 public function outputFeedLinks() {
388 $this->addFeedLinks( $this->getFeedQuery() );
392 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
396 protected function getFeedQuery() {
397 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
398 // API handles empty parameters in a different way
399 return $value !== '';
401 $query['action'] = 'feedrecentchanges';
402 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
403 if ( $query['limit'] > $feedLimit ) {
404 $query['limit'] = $feedLimit;
411 * Build and output the actual changes list.
413 * @param ResultWrapper $rows Database rows
414 * @param FormOptions $opts
416 public function outputChangesList( $rows, $opts ) {
417 $limit = $opts['limit'];
419 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
420 && $this->getUser()->getOption( 'shownumberswatching' );
424 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
425 $list->initChangesListRows( $rows );
427 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
428 $rclistOutput = $list->beginRecentChangesList();
429 if ( $this->isStructuredFilterUiEnabled() ) {
430 $rclistOutput .= $this->makeLegend();
433 foreach ( $rows as $obj ) {
437 $rc = RecentChange
::newFromRow( $obj );
439 # Skip CatWatch entries for hidden cats based on user preference
441 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
442 !$userShowHiddenCats &&
443 $rc->getParam( 'hidden-cat' )
448 $rc->counter
= $counter++
;
449 # Check if the page has been updated since the last visit
450 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
451 && !empty( $obj->wl_notificationtimestamp
)
453 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
455 $rc->notificationtimestamp
= false; // Default
457 # Check the number of users watching the page
458 $rc->numberofWatchingusers
= 0; // Default
459 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
460 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
461 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
462 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
463 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
466 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
469 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
470 if ( $changeLine !== false ) {
471 $rclistOutput .= $changeLine;
475 $rclistOutput .= $list->endRecentChangesList();
477 if ( $rows->numRows() === 0 ) {
478 $this->outputNoResults();
479 if ( !$this->including() ) {
480 $this->getOutput()->setStatusCode( 404 );
483 $this->getOutput()->addHTML( $rclistOutput );
488 * Set the text to be displayed above the changes
490 * @param FormOptions $opts
491 * @param int $numRows Number of rows in the result to show after this header
493 public function doHeader( $opts, $numRows ) {
494 $this->setTopText( $opts );
496 $defaults = $opts->getAllValues();
497 $nondefaults = $opts->getChangedValues();
500 if ( !$this->isStructuredFilterUiEnabled() ) {
501 $panel[] = $this->makeLegend();
503 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
506 $extraOpts = $this->getExtraOptions( $opts );
507 $extraOptsCount = count( $extraOpts );
509 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
511 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
512 foreach ( $extraOpts as $name => $optionRow ) {
513 # Add submit button to the last row only
515 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
517 $out .= Xml
::openElement( 'tr', [ 'class' => $name . 'Form' ] );
518 if ( is_array( $optionRow ) ) {
521 [ 'class' => 'mw-label mw-' . $name . '-label' ],
526 [ 'class' => 'mw-input' ],
527 $optionRow[1] . $addSubmit
532 [ 'class' => 'mw-input', 'colspan' => 2 ],
533 $optionRow . $addSubmit
536 $out .= Xml
::closeElement( 'tr' );
538 $out .= Xml
::closeElement( 'table' );
540 $unconsumed = $opts->getUnconsumedValues();
541 foreach ( $unconsumed as $key => $value ) {
542 $out .= Html
::hidden( $key, $value );
545 $t = $this->getPageTitle();
546 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
547 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
549 $panelString = implode( "\n", $panel );
551 $rcoptions = Xml
::fieldset(
552 $this->msg( 'recentchanges-legend' )->text(),
554 [ 'class' => 'rcoptions cloptions' ]
557 // Insert a placeholder for RCFilters
558 if ( $this->isStructuredFilterUiEnabled() ) {
559 $rcfilterContainer = Html
::element(
561 [ 'class' => 'rcfilters-container' ]
564 $loadingContainer = Html
::rawElement(
566 [ 'class' => 'rcfilters-spinner' ],
569 [ 'class' => 'rcfilters-spinner-bounce' ]
573 // Wrap both with rcfilters-head
574 $this->getOutput()->addHTML(
577 [ 'class' => 'rcfilters-head' ],
578 $rcfilterContainer . $rcoptions
583 $this->getOutput()->addHTML( $loadingContainer );
585 $this->getOutput()->addHTML( $rcoptions );
588 $this->setBottomText( $opts );
592 * Send the text to be displayed above the options
594 * @param FormOptions $opts Unused
596 function setTopText( FormOptions
$opts ) {
599 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
600 if ( !$message->isDisabled() ) {
601 // Parse the message in this weird ugly way to preserve the ability to include interlanguage
602 // links in it (T172461). In the future when T66969 is resolved, perhaps we can just use
603 // $message->parse() instead. This code is copied from Message::parseText().
604 $parserOutput = MessageCache
::singleton()->parse(
606 $this->getPageTitle(),
608 // Message class sets the interface flag to false when parsing in a language different than
609 // user language, and this is wiki content language
613 $content = $parserOutput->getText( [
614 'enableSectionEditLinks' => false,
616 // Add only metadata here (including the language links), text is added below
617 $this->getOutput()->addParserOutputMetadata( $parserOutput );
620 'lang' => $wgContLang->getHtmlCode(),
621 'dir' => $wgContLang->getDir(),
624 $topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
626 if ( $this->isStructuredFilterUiEnabled() ) {
627 // Check whether the widget is already collapsed or expanded
628 $collapsedState = $this->getRequest()->getCookie( 'rcfilters-toplinks-collapsed-state' );
629 // Note that an empty/unset cookie means collapsed, so check for !== 'expanded'
630 $topLinksAttributes[ 'class' ] .= $collapsedState !== 'expanded' ?
631 ' mw-recentchanges-toplinks-collapsed' : '';
633 $this->getOutput()->enableOOUI();
634 $contentTitle = new OOUI\
ButtonWidget( [
635 'classes' => [ 'mw-recentchanges-toplinks-title' ],
636 'label' => new OOUI\
HtmlSnippet( $this->msg( 'rcfilters-other-review-tools' )->parse() ),
638 'indicator' => $collapsedState !== 'expanded' ?
'down' : 'up',
639 'flags' => [ 'progressive' ],
642 $contentWrapper = Html
::rawElement( 'div',
644 [ 'class' => 'mw-recentchanges-toplinks-content mw-collapsible-content' ],
649 $content = $contentTitle . $contentWrapper;
651 // Language direction should be on the top div only
652 // if the title is not there. If it is there, it's
653 // interface direction, and the language/dir attributes
654 // should be on the content itself
655 $topLinksAttributes = array_merge( $topLinksAttributes, $langAttributes );
658 $this->getOutput()->addHTML(
659 Html
::rawElement( 'div', $topLinksAttributes, $content )
665 * Get options to be displayed in a form
667 * @param FormOptions $opts
670 function getExtraOptions( $opts ) {
671 $opts->consumeValues( [
672 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
676 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
678 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
679 $extraOpts['category'] = $this->categoryFilterForm( $opts );
682 $tagFilter = ChangeTags
::buildTagFilterSelector(
683 $opts['tagfilter'], false, $this->getContext() );
684 if ( count( $tagFilter ) ) {
685 $extraOpts['tagfilter'] = $tagFilter;
688 // Don't fire the hook for subclasses. (Or should we?)
689 if ( $this->getName() === 'Recentchanges' ) {
690 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
697 * Add page-specific modules.
699 protected function addModules() {
700 parent
::addModules();
701 $out = $this->getOutput();
702 $out->addModules( 'mediawiki.special.recentchanges' );
706 * Get last modified date, for client caching
707 * Don't use this if we are using the patrol feature, patrol changes don't
708 * update the timestamp
710 * @return string|bool
712 public function checkLastModified() {
713 $dbr = $this->getDB();
714 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
720 * Creates the choose namespace selection
722 * @param FormOptions $opts
725 protected function namespaceFilterForm( FormOptions
$opts ) {
726 $nsSelect = Html
::namespaceSelector(
727 [ 'selected' => $opts['namespace'], 'all' => '' ],
728 [ 'name' => 'namespace', 'id' => 'namespace' ]
730 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
731 $invert = Xml
::checkLabel(
732 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
734 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
736 $associated = Xml
::checkLabel(
737 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
739 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
742 return [ $nsLabel, "$nsSelect $invert $associated" ];
746 * Create an input to filter changes by categories
748 * @param FormOptions $opts
751 protected function categoryFilterForm( FormOptions
$opts ) {
752 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
753 'categories', 'mw-categories', false, $opts['categories'] );
755 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
756 'categories_any', 'mw-categories_any', $opts['categories_any'] );
758 return [ $label, $input ];
762 * Filter $rows by categories set in $opts
764 * @param ResultWrapper &$rows Database rows
765 * @param FormOptions $opts
767 function filterByCategories( &$rows, FormOptions
$opts ) {
768 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
770 if ( !count( $categories ) ) {
776 foreach ( $categories as $cat ) {
788 foreach ( $rows as $k => $r ) {
789 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
790 $id = $nt->getArticleID();
792 continue; # Page might have been deleted...
794 if ( !in_array( $id, $articles ) ) {
797 if ( !isset( $a2r[$id] ) ) {
805 if ( !count( $articles ) ||
!count( $cats ) ) {
810 $catFind = new CategoryFinder
;
811 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
812 $match = $catFind->run();
816 foreach ( $match as $id ) {
817 foreach ( $a2r[$id] as $rev ) {
819 $newrows[$k] = $rowsarr[$k];
822 $rows = new FakeResultWrapper( array_values( $newrows ) );
826 * Makes change an option link which carries all the other options
828 * @param string $title Title
829 * @param array $override Options to override
830 * @param array $options Current options
831 * @param bool $active Whether to show the link in bold
834 function makeOptionsLink( $title, $override, $options, $active = false ) {
835 $params = $this->convertParamsForLink( $override +
$options );
838 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
841 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
842 'data-params' => json_encode( $override ),
843 'data-keys' => implode( ',', array_keys( $override ) ),
848 * Creates the options panel.
850 * @param array $defaults
851 * @param array $nondefaults
852 * @param int $numRows Number of rows in the result to show after this header
855 function optionsPanel( $defaults, $nondefaults, $numRows ) {
856 $options = $nondefaults +
$defaults;
859 $msg = $this->msg( 'rclegend' );
860 if ( !$msg->isDisabled() ) {
861 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
864 $lang = $this->getLanguage();
865 $user = $this->getUser();
866 $config = $this->getConfig();
867 if ( $options['from'] ) {
868 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
869 [ 'from' => '' ], $nondefaults );
871 $noteFromMsg = $this->msg( 'rcnotefrom' )
872 ->numParams( $options['limit'] )
874 $lang->userTimeAndDate( $options['from'], $user ),
875 $lang->userDate( $options['from'], $user ),
876 $lang->userTime( $options['from'], $user )
878 ->numParams( $numRows );
879 $note .= Html
::rawElement(
881 [ 'class' => 'rcnotefrom' ],
882 $noteFromMsg->parse()
887 [ 'class' => 'rcoptions-listfromreset' ],
888 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
893 # Sort data for display and make sure it's unique after we've added user data.
894 $linkLimits = $config->get( 'RCLinkLimits' );
895 $linkLimits[] = $options['limit'];
897 $linkLimits = array_unique( $linkLimits );
899 $linkDays = $config->get( 'RCLinkDays' );
900 $linkDays[] = $options['days'];
902 $linkDays = array_unique( $linkDays );
906 foreach ( $linkLimits as $value ) {
907 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
908 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
910 $cl = $lang->pipeList( $cl );
912 // day links, reset 'from' to none
914 foreach ( $linkDays as $value ) {
915 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
916 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
918 $dl = $lang->pipeList( $dl );
920 $showhide = [ 'show', 'hide' ];
924 foreach ( $this->getLegacyShowHideFilters() as $key => $filter ) {
925 $msg = $filter->getShowHide();
926 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
927 // Extensions can define additional filters, but don't need to define the corresponding
928 // messages. If they don't exist, just fall back to 'show' and 'hide'.
929 if ( !$linkMessage->exists() ) {
930 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
933 $link = $this->makeOptionsLink( $linkMessage->text(),
934 [ $key => 1 - $options[$key] ], $nondefaults );
937 'class' => "$msg rcshowhideoption clshowhideoption",
938 'data-filter-name' => $filter->getName(),
941 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
942 $attribs['data-feature-in-structured-ui'] = true;
945 $links[] = Html
::rawElement(
948 $this->msg( $msg )->rawParams( $link )->escaped()
952 // show from this onward link
953 $timestamp = wfTimestampNow();
954 $now = $lang->userTimeAndDate( $timestamp, $user );
955 $timenow = $lang->userTime( $timestamp, $user );
956 $datenow = $lang->userDate( $timestamp, $user );
957 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
959 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
960 ->parse() . '</span>';
962 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
963 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
964 [ 'from' => $timestamp ],
968 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
971 public function isIncludable() {
975 protected function getCacheTTL() {
979 public function getDefaultLimit() {
980 $systemPrefValue = $this->getUser()->getIntOption( 'rclimit' );
981 // Prefer the RCFilters-specific preference if RCFilters is enabled
982 if ( $this->isStructuredFilterUiEnabled() ) {
983 return $this->getUser()->getIntOption( static::$limitPreferenceName, $systemPrefValue );
986 // Otherwise, use the system rclimit preference value
987 return $systemPrefValue;