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\IResultWrapper
;
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
38 protected static $collapsedPreferenceName = 'rcfilters-rc-collapsed';
40 private $watchlistFilterGroupDefinition;
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' ] ) {
139 * @param string|null $subpage
141 public function execute( $subpage ) {
142 // Backwards-compatibility: redirect to new feed URLs
143 $feedFormat = $this->getRequest()->getVal( 'feed' );
144 if ( !$this->including() && $feedFormat ) {
145 $query = $this->getFeedQuery();
146 $query['feedformat'] = $feedFormat === 'atom' ?
'atom' : 'rss';
147 $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
152 // 10 seconds server-side caching max
153 $out = $this->getOutput();
154 $out->setCdnMaxage( 10 );
155 // Check if the client has a cached version
156 $lastmod = $this->checkLastModified();
157 if ( $lastmod === false ) {
162 'https://meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
165 parent
::execute( $subpage );
171 protected function transformFilterDefinition( array $filterDefinition ) {
172 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
173 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
176 return $filterDefinition;
182 protected function registerFilters() {
183 parent
::registerFilters();
186 !$this->including() &&
187 $this->getUser()->isLoggedIn() &&
188 MediaWikiServices
::getInstance()
189 ->getPermissionManager()
190 ->userHasRight( $this->getUser(), 'viewmywatchlist' )
192 $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition
] );
193 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
194 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
195 $watchlistGroup->getFilter( 'watchednew' )
199 $user = $this->getUser();
201 $significance = $this->getFilterGroup( 'significance' );
202 /** @var ChangesListBooleanFilter $hideMinor */
203 $hideMinor = $significance->getFilter( 'hideminor' );
204 '@phan-var ChangesListBooleanFilter $hideMinor';
205 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
207 $automated = $this->getFilterGroup( 'automated' );
208 /** @var ChangesListBooleanFilter $hideBots */
209 $hideBots = $automated->getFilter( 'hidebots' );
210 '@phan-var ChangesListBooleanFilter $hideBots';
211 $hideBots->setDefault( true );
213 /** @var ChangesListStringOptionsFilterGroup|null $reviewStatus */
214 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
215 '@phan-var ChangesListStringOptionsFilterGroup|null $reviewStatus';
216 if ( $reviewStatus !== null ) {
217 // Conditional on feature being available and rights
218 if ( $user->getBoolOption( 'hidepatrolled' ) ) {
219 $reviewStatus->setDefault( 'unpatrolled' );
220 $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
221 /** @var ChangesListBooleanFilter $legacyHidePatrolled */
222 $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
223 '@phan-var ChangesListBooleanFilter $legacyHidePatrolled';
224 $legacyHidePatrolled->setDefault( true );
228 $changeType = $this->getFilterGroup( 'changeType' );
229 /** @var ChangesListBooleanFilter $hideCategorization */
230 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
231 '@phan-var ChangesListBooleanFilter $hideCategorization';
232 if ( $hideCategorization !== null ) {
233 // Conditional on feature being available
234 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
239 * Process $par and put options found in $opts. Used when including the page.
242 * @param FormOptions $opts
244 public function parseParameters( $par, FormOptions
$opts ) {
245 parent
::parseParameters( $par, $opts );
247 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
248 foreach ( $bits as $bit ) {
249 if ( is_numeric( $bit ) ) {
250 $opts['limit'] = $bit;
254 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
255 $opts['limit'] = $m[1];
257 if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
258 $opts['days'] = $m[1];
260 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
261 $opts['namespace'] = $m[1];
263 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
264 $opts['tagfilter'] = $m[1];
272 protected function doMainQuery( $tables, $fields, $conds, $query_options,
273 $join_conds, FormOptions
$opts
275 $dbr = $this->getDB();
276 $user = $this->getUser();
278 $rcQuery = RecentChange
::getQueryInfo();
279 $tables = array_merge( $tables, $rcQuery['tables'] );
280 $fields = array_merge( $rcQuery['fields'], $fields );
281 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
283 // JOIN on watchlist for users
284 if ( $user->isLoggedIn() && MediaWikiServices
::getInstance()
285 ->getPermissionManager()
286 ->userHasRight( $user, 'viewmywatchlist' )
288 $tables[] = 'watchlist';
289 $fields[] = 'wl_user';
290 $fields[] = 'wl_notificationtimestamp';
291 $join_conds['watchlist'] = [ 'LEFT JOIN', [
292 'wl_user' => $user->getId(),
294 'wl_namespace=rc_namespace'
298 // JOIN on page, used for 'last revision' filter highlight
300 $fields[] = 'page_latest';
301 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
303 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
304 ChangeTags
::modifyDisplayQuery(
313 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
319 if ( $this->areFiltersInConflict() ) {
324 'ORDER BY' => 'rc_timestamp DESC',
325 'LIMIT' => $opts['limit']
327 if ( in_array( 'DISTINCT', $query_options ) ) {
328 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
329 // In order to prevent DISTINCT from causing query performance problems,
330 // we have to GROUP BY the primary key. This in turn requires us to add
331 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
332 // start of the GROUP BY
333 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
334 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
336 // array_merge() is used intentionally here so that hooks can, should
337 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
338 // MediaWiki 1.26 this used to use the plus operator instead, which meant
339 // that extensions weren't able to change these conditions
340 $query_options = array_merge( $orderByAndLimit, $query_options );
341 $rows = $dbr->select(
344 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
345 // knowledge to use an index merge if it wants (it may use some other index though).
346 $conds +
[ 'rc_new' => [ 0, 1 ] ],
355 protected function getDB() {
356 return wfGetDB( DB_REPLICA
, 'recentchanges' );
359 public function outputFeedLinks() {
360 $this->addFeedLinks( $this->getFeedQuery() );
364 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
368 protected function getFeedQuery() {
369 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
370 // API handles empty parameters in a different way
371 return $value !== '';
373 $query['action'] = 'feedrecentchanges';
374 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
375 if ( $query['limit'] > $feedLimit ) {
376 $query['limit'] = $feedLimit;
383 * Build and output the actual changes list.
385 * @param IResultWrapper $rows Database rows
386 * @param FormOptions $opts
388 public function outputChangesList( $rows, $opts ) {
389 $limit = $opts['limit'];
391 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
392 && $this->getUser()->getOption( 'shownumberswatching' );
396 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
397 $list->initChangesListRows( $rows );
399 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
400 $rclistOutput = $list->beginRecentChangesList();
401 if ( $this->isStructuredFilterUiEnabled() ) {
402 $rclistOutput .= $this->makeLegend();
405 foreach ( $rows as $obj ) {
409 $rc = RecentChange
::newFromRow( $obj );
411 # Skip CatWatch entries for hidden cats based on user preference
413 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
414 !$userShowHiddenCats &&
415 $rc->getParam( 'hidden-cat' )
420 $rc->counter
= $counter++
;
421 # Check if the page has been updated since the last visit
422 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
423 && !empty( $obj->wl_notificationtimestamp
)
425 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
427 $rc->notificationtimestamp
= false; // Default
429 # Check the number of users watching the page
430 $rc->numberofWatchingusers
= 0; // Default
431 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
432 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
433 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
434 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
435 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
438 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
441 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
442 if ( $changeLine !== false ) {
443 $rclistOutput .= $changeLine;
447 $rclistOutput .= $list->endRecentChangesList();
449 if ( $rows->numRows() === 0 ) {
450 $this->outputNoResults();
451 if ( !$this->including() ) {
452 $this->getOutput()->setStatusCode( 404 );
455 $this->getOutput()->addHTML( $rclistOutput );
460 * Set the text to be displayed above the changes
462 * @param FormOptions $opts
463 * @param int $numRows Number of rows in the result to show after this header
465 public function doHeader( $opts, $numRows ) {
466 $this->setTopText( $opts );
468 $defaults = $opts->getAllValues();
469 $nondefaults = $opts->getChangedValues();
472 if ( !$this->isStructuredFilterUiEnabled() ) {
473 $panel[] = $this->makeLegend();
475 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
478 $extraOpts = $this->getExtraOptions( $opts );
479 $extraOptsCount = count( $extraOpts );
481 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
483 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
484 foreach ( $extraOpts as $name => $optionRow ) {
485 # Add submit button to the last row only
487 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
489 $out .= Xml
::openElement( 'tr', [ 'class' => $name . 'Form' ] );
490 if ( is_array( $optionRow ) ) {
493 [ 'class' => 'mw-label mw-' . $name . '-label' ],
498 [ 'class' => 'mw-input' ],
499 $optionRow[1] . $addSubmit
504 [ 'class' => 'mw-input', 'colspan' => 2 ],
505 $optionRow . $addSubmit
508 $out .= Xml
::closeElement( 'tr' );
510 $out .= Xml
::closeElement( 'table' );
512 $unconsumed = $opts->getUnconsumedValues();
513 foreach ( $unconsumed as $key => $value ) {
514 $out .= Html
::hidden( $key, $value );
517 $t = $this->getPageTitle();
518 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
519 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
521 $panelString = implode( "\n", $panel );
523 $rcoptions = Xml
::fieldset(
524 $this->msg( 'recentchanges-legend' )->text(),
526 [ 'class' => 'rcoptions cloptions' ]
529 // Insert a placeholder for RCFilters
530 if ( $this->isStructuredFilterUiEnabled() ) {
531 $rcfilterContainer = Html
::element(
533 // TODO: Remove deprecated rcfilters-container class
534 [ 'class' => 'rcfilters-container mw-rcfilters-container' ]
537 $loadingContainer = Html
::rawElement(
539 [ 'class' => 'mw-rcfilters-spinner' ],
542 [ 'class' => 'mw-rcfilters-spinner-bounce' ]
546 // Wrap both with rcfilters-head
547 $this->getOutput()->addHTML(
550 // TODO: Remove deprecated rcfilters-head class
551 [ 'class' => 'rcfilters-head mw-rcfilters-head' ],
552 $rcfilterContainer . $rcoptions
557 $this->getOutput()->addHTML( $loadingContainer );
559 $this->getOutput()->addHTML( $rcoptions );
562 $this->setBottomText( $opts );
566 * Send the text to be displayed above the options
568 * @param FormOptions $opts Unused
570 function setTopText( FormOptions
$opts ) {
571 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
572 if ( !$message->isDisabled() ) {
573 $contLang = MediaWikiServices
::getInstance()->getContentLanguage();
574 // Parse the message in this weird ugly way to preserve the ability to include interlanguage
575 // links in it (T172461). In the future when T66969 is resolved, perhaps we can just use
576 // $message->parse() instead. This code is copied from Message::parseText().
577 $parserOutput = MessageCache
::singleton()->parse(
579 $this->getPageTitle(),
581 // Message class sets the interface flag to false when parsing in a language different than
582 // user language, and this is wiki content language
586 $content = $parserOutput->getText( [
587 'enableSectionEditLinks' => false,
589 // Add only metadata here (including the language links), text is added below
590 $this->getOutput()->addParserOutputMetadata( $parserOutput );
593 'lang' => $contLang->getHtmlCode(),
594 'dir' => $contLang->getDir(),
597 $topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
599 if ( $this->isStructuredFilterUiEnabled() ) {
600 // Check whether the widget is already collapsed or expanded
601 $collapsedState = $this->getRequest()->getCookie( 'rcfilters-toplinks-collapsed-state' );
602 // Note that an empty/unset cookie means collapsed, so check for !== 'expanded'
603 $topLinksAttributes[ 'class' ] .= $collapsedState !== 'expanded' ?
604 ' mw-recentchanges-toplinks-collapsed' : '';
606 $this->getOutput()->enableOOUI();
607 $contentTitle = new OOUI\
ButtonWidget( [
608 'classes' => [ 'mw-recentchanges-toplinks-title' ],
609 'label' => new OOUI\
HtmlSnippet( $this->msg( 'rcfilters-other-review-tools' )->parse() ),
611 'indicator' => $collapsedState !== 'expanded' ?
'down' : 'up',
612 'flags' => [ 'progressive' ],
615 $contentWrapper = Html
::rawElement( 'div',
617 [ 'class' => 'mw-recentchanges-toplinks-content mw-collapsible-content' ],
622 $content = $contentTitle . $contentWrapper;
624 // Language direction should be on the top div only
625 // if the title is not there. If it is there, it's
626 // interface direction, and the language/dir attributes
627 // should be on the content itself
628 $topLinksAttributes = array_merge( $topLinksAttributes, $langAttributes );
631 $this->getOutput()->addHTML(
632 Html
::rawElement( 'div', $topLinksAttributes, $content )
638 * Get options to be displayed in a form
640 * @param FormOptions $opts
643 function getExtraOptions( $opts ) {
644 $opts->consumeValues( [
645 'namespace', 'invert', 'associated', 'tagfilter'
649 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
651 $tagFilter = ChangeTags
::buildTagFilterSelector(
652 $opts['tagfilter'], false, $this->getContext() );
653 if ( count( $tagFilter ) ) {
654 $extraOpts['tagfilter'] = $tagFilter;
657 // Don't fire the hook for subclasses. (Or should we?)
658 if ( $this->getName() === 'Recentchanges' ) {
659 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
666 * Add page-specific modules.
668 protected function addModules() {
669 parent
::addModules();
670 $out = $this->getOutput();
671 $out->addModules( 'mediawiki.special.recentchanges' );
675 * Get last modified date, for client caching
676 * Don't use this if we are using the patrol feature, patrol changes don't
677 * update the timestamp
679 * @return string|bool
681 public function checkLastModified() {
682 $dbr = $this->getDB();
683 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__
);
689 * Creates the choose namespace selection
691 * @param FormOptions $opts
694 protected function namespaceFilterForm( FormOptions
$opts ) {
695 $nsSelect = Html
::namespaceSelector(
696 [ 'selected' => $opts['namespace'], 'all' => '', 'in-user-lang' => true ],
697 [ 'name' => 'namespace', 'id' => 'namespace' ]
699 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
700 $attribs = [ 'class' => [ 'mw-input-with-label' ] ];
701 // Hide the checkboxes when the namespace filter is set to 'all'.
702 if ( $opts['namespace'] === '' ) {
703 $attribs['class'][] = 'mw-input-hidden';
705 $invert = Html
::rawElement( 'span', $attribs, Xml
::checkLabel(
706 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
708 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
710 $associated = Html
::rawElement( 'span', $attribs, Xml
::checkLabel(
711 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
713 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
716 return [ $nsLabel, "$nsSelect $invert $associated" ];
720 * Filter $rows by categories set in $opts
722 * @deprecated since 1.31
724 * @param IResultWrapper &$rows Database rows
725 * @param FormOptions $opts
727 function filterByCategories( &$rows, FormOptions
$opts ) {
728 wfDeprecated( __METHOD__
, '1.31' );
730 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
732 if ( $categories === [] ) {
738 foreach ( $categories as $cat ) {
750 foreach ( $rows as $k => $r ) {
751 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
752 $id = $nt->getArticleID();
754 continue; # Page might have been deleted...
756 if ( !in_array( $id, $articles ) ) {
759 if ( !isset( $a2r[$id] ) ) {
767 if ( $articles === [] ||
$cats === [] ) {
772 $catFind = new CategoryFinder
;
773 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
774 $match = $catFind->run();
778 foreach ( $match as $id ) {
779 foreach ( $a2r[$id] as $rev ) {
781 $newrows[$k] = $rowsarr[$k];
784 $rows = new FakeResultWrapper( array_values( $newrows ) );
788 * Makes change an option link which carries all the other options
790 * @param string $title
791 * @param array $override Options to override
792 * @param array $options Current options
793 * @param bool $active Whether to show the link in bold
796 function makeOptionsLink( $title, $override, $options, $active = false ) {
797 $params = $this->convertParamsForLink( $override +
$options );
800 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
803 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
804 'data-params' => json_encode( $override ),
805 'data-keys' => implode( ',', array_keys( $override ) ),
810 * Creates the options panel.
812 * @param array $defaults
813 * @param array $nondefaults
814 * @param int $numRows Number of rows in the result to show after this header
817 function optionsPanel( $defaults, $nondefaults, $numRows ) {
818 $options = $nondefaults +
$defaults;
821 $msg = $this->msg( 'rclegend' );
822 if ( !$msg->isDisabled() ) {
823 $note .= Html
::rawElement(
825 [ 'class' => 'mw-rclegend' ],
830 $lang = $this->getLanguage();
831 $user = $this->getUser();
832 $config = $this->getConfig();
833 if ( $options['from'] ) {
834 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
835 [ 'from' => '' ], $nondefaults );
837 $noteFromMsg = $this->msg( 'rcnotefrom' )
838 ->numParams( $options['limit'] )
840 $lang->userTimeAndDate( $options['from'], $user ),
841 $lang->userDate( $options['from'], $user ),
842 $lang->userTime( $options['from'], $user )
844 ->numParams( $numRows );
845 $note .= Html
::rawElement(
847 [ 'class' => 'rcnotefrom' ],
848 $noteFromMsg->parse()
853 [ 'class' => 'rcoptions-listfromreset' ],
854 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
859 # Sort data for display and make sure it's unique after we've added user data.
860 $linkLimits = $config->get( 'RCLinkLimits' );
861 $linkLimits[] = $options['limit'];
863 $linkLimits = array_unique( $linkLimits );
865 $linkDays = $this->getLinkDays();
866 $linkDays[] = $options['days'];
868 $linkDays = array_unique( $linkDays );
872 foreach ( $linkLimits as $value ) {
873 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
874 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
876 $cl = $lang->pipeList( $cl );
878 // day links, reset 'from' to none
880 foreach ( $linkDays as $value ) {
881 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
882 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
884 $dl = $lang->pipeList( $dl );
886 $showhide = [ 'show', 'hide' ];
890 foreach ( $this->getLegacyShowHideFilters() as $key => $filter ) {
891 $msg = $filter->getShowHide();
892 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
893 // Extensions can define additional filters, but don't need to define the corresponding
894 // messages. If they don't exist, just fall back to 'show' and 'hide'.
895 if ( !$linkMessage->exists() ) {
896 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
899 $link = $this->makeOptionsLink( $linkMessage->text(),
900 [ $key => 1 - $options[$key] ], $nondefaults );
903 'class' => "$msg rcshowhideoption clshowhideoption",
904 'data-filter-name' => $filter->getName(),
907 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
908 $attribs['data-feature-in-structured-ui'] = true;
911 $links[] = Html
::rawElement(
914 $this->msg( $msg )->rawParams( $link )->parse()
918 // show from this onward link
919 $timestamp = wfTimestampNow();
920 $now = $lang->userTimeAndDate( $timestamp, $user );
921 $timenow = $lang->userTime( $timestamp, $user );
922 $datenow = $lang->userDate( $timestamp, $user );
923 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
925 $rclinks = Html
::rawElement(
927 [ 'class' => 'rclinks' ],
928 $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )->parse()
931 $rclistfrom = Html
::rawElement(
933 [ 'class' => 'rclistfrom' ],
934 $this->makeOptionsLink(
935 $this->msg( 'rclistfrom' )->plaintextParams( $now, $timenow, $datenow )->parse(),
936 [ 'from' => $timestamp, 'fromFormatted' => $now ],
941 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
944 public function isIncludable() {
948 protected function getCacheTTL() {
952 public function getDefaultLimit() {
953 $systemPrefValue = $this->getUser()->getIntOption( 'rclimit' );
954 // Prefer the RCFilters-specific preference if RCFilters is enabled
955 if ( $this->isStructuredFilterUiEnabled() ) {
956 return $this->getUser()->getIntOption( static::$limitPreferenceName, $systemPrefValue );
959 // Otherwise, use the system rclimit preference value
960 return $systemPrefValue;