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 public function __construct( $name = 'Recentchanges', $restriction = '' ) {
42 parent
::__construct( $name, $restriction );
44 $this->watchlistFilterGroupDefinition
= [
45 'name' => 'watchlist',
46 'title' => 'rcfilters-filtergroup-watchlist',
47 'class' => ChangesListStringOptionsFilterGroup
::class,
49 'isFullCoverage' => true,
53 'label' => 'rcfilters-filter-watchlist-watched-label',
54 'description' => 'rcfilters-filter-watchlist-watched-description',
55 'cssClassSuffix' => 'watched',
56 'isRowApplicableCallable' => function ( $ctx, $rc ) {
57 return $rc->getAttribute( 'wl_user' );
61 'name' => 'watchednew',
62 'label' => 'rcfilters-filter-watchlist-watchednew-label',
63 'description' => 'rcfilters-filter-watchlist-watchednew-description',
64 'cssClassSuffix' => 'watchednew',
65 'isRowApplicableCallable' => function ( $ctx, $rc ) {
66 return $rc->getAttribute( 'wl_user' ) &&
67 $rc->getAttribute( 'rc_timestamp' ) &&
68 $rc->getAttribute( 'wl_notificationtimestamp' ) &&
69 $rc->getAttribute( 'rc_timestamp' ) >= $rc->getAttribute( 'wl_notificationtimestamp' );
73 'name' => 'notwatched',
74 'label' => 'rcfilters-filter-watchlist-notwatched-label',
75 'description' => 'rcfilters-filter-watchlist-notwatched-description',
76 'cssClassSuffix' => 'notwatched',
77 'isRowApplicableCallable' => function ( $ctx, $rc ) {
78 return $rc->getAttribute( 'wl_user' ) === null;
82 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
83 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
84 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
85 sort( $selectedValues );
86 $notwatchedCond = 'wl_user IS NULL';
87 $watchedCond = 'wl_user IS NOT NULL';
88 $newCond = 'rc_timestamp >= wl_notificationtimestamp';
90 if ( $selectedValues === [ 'notwatched' ] ) {
91 $conds[] = $notwatchedCond;
95 if ( $selectedValues === [ 'watched' ] ) {
96 $conds[] = $watchedCond;
100 if ( $selectedValues === [ 'watchednew' ] ) {
101 $conds[] = $dbr->makeList( [
108 if ( $selectedValues === [ 'notwatched', 'watched' ] ) {
113 if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) {
114 $conds[] = $dbr->makeList( [
124 if ( $selectedValues === [ 'watched', 'watchednew' ] ) {
125 $conds[] = $watchedCond;
129 if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) {
138 * Main execution point
140 * @param string $subpage
142 public function execute( $subpage ) {
143 // Backwards-compatibility: redirect to new feed URLs
144 $feedFormat = $this->getRequest()->getVal( 'feed' );
145 if ( !$this->including() && $feedFormat ) {
146 $query = $this->getFeedQuery();
147 $query['feedformat'] = $feedFormat === 'atom' ?
'atom' : 'rss';
148 $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
153 // 10 seconds server-side caching max
154 $out = $this->getOutput();
155 $out->setCdnMaxage( 10 );
156 // Check if the client has a cached version
157 $lastmod = $this->checkLastModified();
158 if ( $lastmod === false ) {
163 '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
166 parent
::execute( $subpage );
172 protected function transformFilterDefinition( array $filterDefinition ) {
173 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
174 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
177 return $filterDefinition;
183 protected function registerFilters() {
184 parent
::registerFilters();
187 !$this->including() &&
188 $this->getUser()->isLoggedIn() &&
189 $this->getUser()->isAllowed( 'viewmywatchlist' )
191 $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition
] );
192 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
193 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
194 $watchlistGroup->getFilter( 'watchednew' )
198 $user = $this->getUser();
200 $significance = $this->getFilterGroup( 'significance' );
201 $hideMinor = $significance->getFilter( 'hideminor' );
202 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
204 $automated = $this->getFilterGroup( 'automated' );
205 $hideBots = $automated->getFilter( 'hidebots' );
206 $hideBots->setDefault( true );
208 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
209 if ( $reviewStatus !== null ) {
210 // Conditional on feature being available and rights
211 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
212 $hidePatrolled->setDefault( $user->getBoolOption( 'hidepatrolled' ) );
215 $changeType = $this->getFilterGroup( 'changeType' );
216 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
217 if ( $hideCategorization !== null ) {
218 // Conditional on feature being available
219 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
224 * Get a FormOptions object containing the default options
226 * @return FormOptions
228 public function getDefaultOptions() {
229 $opts = parent
::getDefaultOptions();
231 $opts->add( 'categories', '' );
232 $opts->add( 'categories_any', false );
238 * Get all custom filters
240 * @return array Map of filter URL param names to properties (msg/default)
242 protected function getCustomFilters() {
243 if ( $this->customFilters
=== null ) {
244 $this->customFilters
= parent
::getCustomFilters();
245 Hooks
::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters
], '1.23' );
248 return $this->customFilters
;
252 * Process $par and put options found in $opts. Used when including the page.
255 * @param FormOptions $opts
257 public function parseParameters( $par, FormOptions
$opts ) {
258 parent
::parseParameters( $par, $opts );
260 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
261 foreach ( $bits as $bit ) {
262 if ( is_numeric( $bit ) ) {
263 $opts['limit'] = $bit;
267 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
268 $opts['limit'] = $m[1];
270 if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
271 $opts['days'] = $m[1];
273 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
274 $opts['namespace'] = $m[1];
276 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
277 $opts['tagfilter'] = $m[1];
285 protected function doMainQuery( $tables, $fields, $conds, $query_options,
286 $join_conds, FormOptions
$opts
288 $dbr = $this->getDB();
289 $user = $this->getUser();
291 $rcQuery = RecentChange
::getQueryInfo();
292 $tables = array_merge( $tables, $rcQuery['tables'] );
293 $fields = array_merge( $rcQuery['fields'], $fields );
294 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
296 // JOIN on watchlist for users
297 if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
298 $tables[] = 'watchlist';
299 $fields[] = 'wl_user';
300 $fields[] = 'wl_notificationtimestamp';
301 $join_conds['watchlist'] = [ 'LEFT JOIN', [
302 'wl_user' => $user->getId(),
304 'wl_namespace=rc_namespace'
308 // JOIN on page, used for 'last revision' filter highlight
310 $fields[] = 'page_latest';
311 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
313 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
314 ChangeTags
::modifyDisplayQuery(
323 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
329 if ( $this->areFiltersInConflict() ) {
334 'ORDER BY' => 'rc_timestamp DESC',
335 'LIMIT' => $opts['limit']
337 if ( in_array( 'DISTINCT', $query_options ) ) {
338 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
339 // In order to prevent DISTINCT from causing query performance problems,
340 // we have to GROUP BY the primary key. This in turn requires us to add
341 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
342 // start of the GROUP BY
343 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
344 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
346 // array_merge() is used intentionally here so that hooks can, should
347 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
348 // MediaWiki 1.26 this used to use the plus operator instead, which meant
349 // that extensions weren't able to change these conditions
350 $query_options = array_merge( $orderByAndLimit, $query_options );
351 $rows = $dbr->select(
354 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
355 // knowledge to use an index merge if it wants (it may use some other index though).
356 $conds +
[ 'rc_new' => [ 0, 1 ] ],
362 // Build the final data
363 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
364 $this->filterByCategories( $rows, $opts );
370 protected function runMainQueryHook( &$tables, &$fields, &$conds,
371 &$query_options, &$join_conds, $opts
373 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
375 'SpecialRecentChangesQuery',
376 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
381 protected function getDB() {
382 return wfGetDB( DB_REPLICA
, 'recentchanges' );
385 public function outputFeedLinks() {
386 $this->addFeedLinks( $this->getFeedQuery() );
390 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
394 protected function getFeedQuery() {
395 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
396 // API handles empty parameters in a different way
397 return $value !== '';
399 $query['action'] = 'feedrecentchanges';
400 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
401 if ( $query['limit'] > $feedLimit ) {
402 $query['limit'] = $feedLimit;
409 * Build and output the actual changes list.
411 * @param ResultWrapper $rows Database rows
412 * @param FormOptions $opts
414 public function outputChangesList( $rows, $opts ) {
415 $limit = $opts['limit'];
417 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
418 && $this->getUser()->getOption( 'shownumberswatching' );
422 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
423 $list->initChangesListRows( $rows );
425 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
426 $rclistOutput = $list->beginRecentChangesList();
427 if ( $this->isStructuredFilterUiEnabled() ) {
428 $rclistOutput .= $this->makeLegend();
431 foreach ( $rows as $obj ) {
435 $rc = RecentChange
::newFromRow( $obj );
437 # Skip CatWatch entries for hidden cats based on user preference
439 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
440 !$userShowHiddenCats &&
441 $rc->getParam( 'hidden-cat' )
446 $rc->counter
= $counter++
;
447 # Check if the page has been updated since the last visit
448 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
449 && !empty( $obj->wl_notificationtimestamp
)
451 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
453 $rc->notificationtimestamp
= false; // Default
455 # Check the number of users watching the page
456 $rc->numberofWatchingusers
= 0; // Default
457 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
458 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
459 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
460 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
461 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
464 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
467 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
468 if ( $changeLine !== false ) {
469 $rclistOutput .= $changeLine;
473 $rclistOutput .= $list->endRecentChangesList();
475 if ( $rows->numRows() === 0 ) {
476 $this->outputNoResults();
477 if ( !$this->including() ) {
478 $this->getOutput()->setStatusCode( 404 );
481 $this->getOutput()->addHTML( $rclistOutput );
486 * Set the text to be displayed above the changes
488 * @param FormOptions $opts
489 * @param int $numRows Number of rows in the result to show after this header
491 public function doHeader( $opts, $numRows ) {
492 $this->setTopText( $opts );
494 $defaults = $opts->getAllValues();
495 $nondefaults = $opts->getChangedValues();
498 if ( !$this->isStructuredFilterUiEnabled() ) {
499 $panel[] = $this->makeLegend();
501 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
504 $extraOpts = $this->getExtraOptions( $opts );
505 $extraOptsCount = count( $extraOpts );
507 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
509 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
510 foreach ( $extraOpts as $name => $optionRow ) {
511 # Add submit button to the last row only
513 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
515 $out .= Xml
::openElement( 'tr', [ 'class' => $name . 'Form' ] );
516 if ( is_array( $optionRow ) ) {
519 [ 'class' => 'mw-label mw-' . $name . '-label' ],
524 [ 'class' => 'mw-input' ],
525 $optionRow[1] . $addSubmit
530 [ 'class' => 'mw-input', 'colspan' => 2 ],
531 $optionRow . $addSubmit
534 $out .= Xml
::closeElement( 'tr' );
536 $out .= Xml
::closeElement( 'table' );
538 $unconsumed = $opts->getUnconsumedValues();
539 foreach ( $unconsumed as $key => $value ) {
540 $out .= Html
::hidden( $key, $value );
543 $t = $this->getPageTitle();
544 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
545 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
547 $panelString = implode( "\n", $panel );
549 $rcoptions = Xml
::fieldset(
550 $this->msg( 'recentchanges-legend' )->text(),
552 [ 'class' => 'rcoptions cloptions' ]
555 // Insert a placeholder for RCFilters
556 if ( $this->isStructuredFilterUiEnabled() ) {
557 $rcfilterContainer = Html
::element(
559 [ 'class' => 'rcfilters-container' ]
562 $loadingContainer = Html
::rawElement(
564 [ 'class' => 'rcfilters-spinner' ],
567 [ 'class' => 'rcfilters-spinner-bounce' ]
571 // Wrap both with rcfilters-head
572 $this->getOutput()->addHTML(
575 [ 'class' => 'rcfilters-head' ],
576 $rcfilterContainer . $rcoptions
581 $this->getOutput()->addHTML( $loadingContainer );
583 $this->getOutput()->addHTML( $rcoptions );
586 $this->setBottomText( $opts );
590 * Send the text to be displayed above the options
592 * @param FormOptions $opts Unused
594 function setTopText( FormOptions
$opts ) {
597 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
598 if ( !$message->isDisabled() ) {
599 // Parse the message in this weird ugly way to preserve the ability to include interlanguage
600 // links in it (T172461). In the future when T66969 is resolved, perhaps we can just use
601 // $message->parse() instead. This code is copied from Message::parseText().
602 $parserOutput = MessageCache
::singleton()->parse(
604 $this->getPageTitle(),
606 // Message class sets the interface flag to false when parsing in a language different than
607 // user language, and this is wiki content language
611 $content = $parserOutput->getText( [
612 'enableSectionEditLinks' => false,
614 // Add only metadata here (including the language links), text is added below
615 $this->getOutput()->addParserOutputMetadata( $parserOutput );
618 'lang' => $wgContLang->getHtmlCode(),
619 'dir' => $wgContLang->getDir(),
622 $topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
624 if ( $this->isStructuredFilterUiEnabled() ) {
625 // Check whether the widget is already collapsed or expanded
626 $collapsedState = $this->getRequest()->getCookie( 'rcfilters-toplinks-collapsed-state' );
627 // Note that an empty/unset cookie means collapsed, so check for !== 'expanded'
628 $topLinksAttributes[ 'class' ] .= $collapsedState !== 'expanded' ?
629 ' mw-recentchanges-toplinks-collapsed' : '';
631 $this->getOutput()->enableOOUI();
632 $contentTitle = new OOUI\
ButtonWidget( [
633 'classes' => [ 'mw-recentchanges-toplinks-title' ],
634 'label' => new OOUI\
HtmlSnippet( $this->msg( 'rcfilters-other-review-tools' )->parse() ),
636 'indicator' => $collapsedState !== 'expanded' ?
'down' : 'up',
637 'flags' => [ 'progressive' ],
640 $contentWrapper = Html
::rawElement( 'div',
642 [ 'class' => 'mw-recentchanges-toplinks-content mw-collapsible-content' ],
647 $content = $contentTitle . $contentWrapper;
649 // Language direction should be on the top div only
650 // if the title is not there. If it is there, it's
651 // interface direction, and the language/dir attributes
652 // should be on the content itself
653 $topLinksAttributes = array_merge( $topLinksAttributes, $langAttributes );
656 $this->getOutput()->addHTML(
657 Html
::rawElement( 'div', $topLinksAttributes, $content )
663 * Get options to be displayed in a form
665 * @param FormOptions $opts
668 function getExtraOptions( $opts ) {
669 $opts->consumeValues( [
670 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
674 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
676 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
677 $extraOpts['category'] = $this->categoryFilterForm( $opts );
680 $tagFilter = ChangeTags
::buildTagFilterSelector(
681 $opts['tagfilter'], false, $this->getContext() );
682 if ( count( $tagFilter ) ) {
683 $extraOpts['tagfilter'] = $tagFilter;
686 // Don't fire the hook for subclasses. (Or should we?)
687 if ( $this->getName() === 'Recentchanges' ) {
688 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
695 * Add page-specific modules.
697 protected function addModules() {
698 parent
::addModules();
699 $out = $this->getOutput();
700 $out->addModules( 'mediawiki.special.recentchanges' );
704 * Get last modified date, for client caching
705 * Don't use this if we are using the patrol feature, patrol changes don't
706 * update the timestamp
708 * @return string|bool
710 public function checkLastModified() {
711 $dbr = $this->getDB();
712 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
718 * Creates the choose namespace selection
720 * @param FormOptions $opts
723 protected function namespaceFilterForm( FormOptions
$opts ) {
724 $nsSelect = Html
::namespaceSelector(
725 [ 'selected' => $opts['namespace'], 'all' => '' ],
726 [ 'name' => 'namespace', 'id' => 'namespace' ]
728 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
729 $invert = Xml
::checkLabel(
730 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
732 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
734 $associated = Xml
::checkLabel(
735 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
737 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
740 return [ $nsLabel, "$nsSelect $invert $associated" ];
744 * Create an input to filter changes by categories
746 * @param FormOptions $opts
749 protected function categoryFilterForm( FormOptions
$opts ) {
750 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
751 'categories', 'mw-categories', false, $opts['categories'] );
753 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
754 'categories_any', 'mw-categories_any', $opts['categories_any'] );
756 return [ $label, $input ];
760 * Filter $rows by categories set in $opts
762 * @param ResultWrapper &$rows Database rows
763 * @param FormOptions $opts
765 function filterByCategories( &$rows, FormOptions
$opts ) {
766 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
768 if ( !count( $categories ) ) {
774 foreach ( $categories as $cat ) {
786 foreach ( $rows as $k => $r ) {
787 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
788 $id = $nt->getArticleID();
790 continue; # Page might have been deleted...
792 if ( !in_array( $id, $articles ) ) {
795 if ( !isset( $a2r[$id] ) ) {
803 if ( !count( $articles ) ||
!count( $cats ) ) {
808 $catFind = new CategoryFinder
;
809 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
810 $match = $catFind->run();
814 foreach ( $match as $id ) {
815 foreach ( $a2r[$id] as $rev ) {
817 $newrows[$k] = $rowsarr[$k];
820 $rows = new FakeResultWrapper( array_values( $newrows ) );
824 * Makes change an option link which carries all the other options
826 * @param string $title Title
827 * @param array $override Options to override
828 * @param array $options Current options
829 * @param bool $active Whether to show the link in bold
832 function makeOptionsLink( $title, $override, $options, $active = false ) {
833 $params = $this->convertParamsForLink( $override +
$options );
836 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
839 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
840 'data-params' => json_encode( $override ),
841 'data-keys' => implode( ',', array_keys( $override ) ),
846 * Creates the options panel.
848 * @param array $defaults
849 * @param array $nondefaults
850 * @param int $numRows Number of rows in the result to show after this header
853 function optionsPanel( $defaults, $nondefaults, $numRows ) {
854 $options = $nondefaults +
$defaults;
857 $msg = $this->msg( 'rclegend' );
858 if ( !$msg->isDisabled() ) {
859 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
862 $lang = $this->getLanguage();
863 $user = $this->getUser();
864 $config = $this->getConfig();
865 if ( $options['from'] ) {
866 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
867 [ 'from' => '' ], $nondefaults );
869 $noteFromMsg = $this->msg( 'rcnotefrom' )
870 ->numParams( $options['limit'] )
872 $lang->userTimeAndDate( $options['from'], $user ),
873 $lang->userDate( $options['from'], $user ),
874 $lang->userTime( $options['from'], $user )
876 ->numParams( $numRows );
877 $note .= Html
::rawElement(
879 [ 'class' => 'rcnotefrom' ],
880 $noteFromMsg->parse()
885 [ 'class' => 'rcoptions-listfromreset' ],
886 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
891 # Sort data for display and make sure it's unique after we've added user data.
892 $linkLimits = $config->get( 'RCLinkLimits' );
893 $linkLimits[] = $options['limit'];
895 $linkLimits = array_unique( $linkLimits );
897 $linkDays = $config->get( 'RCLinkDays' );
898 $linkDays[] = $options['days'];
900 $linkDays = array_unique( $linkDays );
904 foreach ( $linkLimits as $value ) {
905 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
906 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
908 $cl = $lang->pipeList( $cl );
910 // day links, reset 'from' to none
912 foreach ( $linkDays as $value ) {
913 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
914 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
916 $dl = $lang->pipeList( $dl );
918 $showhide = [ 'show', 'hide' ];
922 foreach ( $this->getLegacyShowHideFilters() as $key => $filter ) {
923 $msg = $filter->getShowHide();
924 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
925 // Extensions can define additional filters, but don't need to define the corresponding
926 // messages. If they don't exist, just fall back to 'show' and 'hide'.
927 if ( !$linkMessage->exists() ) {
928 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
931 $link = $this->makeOptionsLink( $linkMessage->text(),
932 [ $key => 1 - $options[$key] ], $nondefaults );
935 'class' => "$msg rcshowhideoption clshowhideoption",
936 'data-filter-name' => $filter->getName(),
939 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
940 $attribs['data-feature-in-structured-ui'] = true;
943 $links[] = Html
::rawElement(
946 $this->msg( $msg )->rawParams( $link )->parse()
950 // show from this onward link
951 $timestamp = wfTimestampNow();
952 $now = $lang->userTimeAndDate( $timestamp, $user );
953 $timenow = $lang->userTime( $timestamp, $user );
954 $datenow = $lang->userDate( $timestamp, $user );
955 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
957 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
958 ->parse() . '</span>';
960 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
961 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
962 [ 'from' => $timestamp ],
966 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
969 public function isIncludable() {
973 protected function getCacheTTL() {
977 public function getDefaultLimit() {
978 $systemPrefValue = $this->getUser()->getIntOption( 'rclimit' );
979 // Prefer the RCFilters-specific preference if RCFilters is enabled
980 if ( $this->isStructuredFilterUiEnabled() ) {
981 return $this->getUser()->getIntOption( static::$limitPreferenceName, $systemPrefValue );
984 // Otherwise, use the system rclimit preference value
985 return $systemPrefValue;