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';
37 private $watchlistFilterGroupDefinition;
39 // @codingStandardsIgnoreStart Needed "useless" override to change parameters.
40 public function __construct( $name = 'Recentchanges', $restriction = '' ) {
41 parent
::__construct( $name, $restriction );
43 $this->watchlistFilterGroupDefinition
= [
44 'name' => 'watchlist',
45 'title' => 'rcfilters-filtergroup-watchlist',
46 'class' => ChangesListStringOptionsFilterGroup
::class,
48 'isFullCoverage' => true,
52 'label' => 'rcfilters-filter-watchlist-watched-label',
53 'description' => 'rcfilters-filter-watchlist-watched-description',
54 'cssClassSuffix' => 'watched',
55 'isRowApplicableCallable' => function ( $ctx, $rc ) {
56 return $rc->getAttribute( 'wl_user' );
60 'name' => 'watchednew',
61 'label' => 'rcfilters-filter-watchlist-watchednew-label',
62 'description' => 'rcfilters-filter-watchlist-watchednew-description',
63 'cssClassSuffix' => 'watchednew',
64 'isRowApplicableCallable' => function ( $ctx, $rc ) {
65 return $rc->getAttribute( 'wl_user' ) &&
66 $rc->getAttribute( 'rc_timestamp' ) &&
67 $rc->getAttribute( 'wl_notificationtimestamp' ) &&
68 $rc->getAttribute( 'rc_timestamp' ) >= $rc->getAttribute( 'wl_notificationtimestamp' );
72 'name' => 'notwatched',
73 'label' => 'rcfilters-filter-watchlist-notwatched-label',
74 'description' => 'rcfilters-filter-watchlist-notwatched-description',
75 'cssClassSuffix' => 'notwatched',
76 'isRowApplicableCallable' => function ( $ctx, $rc ) {
77 return $rc->getAttribute( 'wl_user' ) === null;
81 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
82 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
83 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
84 sort( $selectedValues );
85 $notwatchedCond = 'wl_user IS NULL';
86 $watchedCond = 'wl_user IS NOT NULL';
87 $newCond = 'rc_timestamp >= wl_notificationtimestamp';
89 if ( $selectedValues === [ 'notwatched' ] ) {
90 $conds[] = $notwatchedCond;
94 if ( $selectedValues === [ 'watched' ] ) {
95 $conds[] = $watchedCond;
99 if ( $selectedValues === [ 'watchednew' ] ) {
100 $conds[] = $dbr->makeList( [
107 if ( $selectedValues === [ 'notwatched', 'watched' ] ) {
112 if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) {
113 $conds[] = $dbr->makeList( [
123 if ( $selectedValues === [ 'watched', 'watchednew' ] ) {
124 $conds[] = $watchedCond;
128 if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) {
135 // @codingStandardsIgnoreEnd
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 $tables[] = 'recentchanges';
292 $fields = array_merge( RecentChange
::selectFields(), $fields );
294 // JOIN on watchlist for users
295 if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
296 $tables[] = 'watchlist';
297 $fields[] = 'wl_user';
298 $fields[] = 'wl_notificationtimestamp';
299 $join_conds['watchlist'] = [ 'LEFT JOIN', [
300 'wl_user' => $user->getId(),
302 'wl_namespace=rc_namespace'
306 // JOIN on page, used for 'last revision' filter highlight
308 $fields[] = 'page_latest';
309 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
311 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
312 ChangeTags
::modifyDisplayQuery(
321 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
327 if ( $this->areFiltersInConflict() ) {
332 'ORDER BY' => 'rc_timestamp DESC',
333 'LIMIT' => $opts['limit']
335 if ( in_array( 'DISTINCT', $query_options ) ) {
336 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
337 // In order to prevent DISTINCT from causing query performance problems,
338 // we have to GROUP BY the primary key. This in turn requires us to add
339 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
340 // start of the GROUP BY
341 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
342 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
344 // array_merge() is used intentionally here so that hooks can, should
345 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
346 // MediaWiki 1.26 this used to use the plus operator instead, which meant
347 // that extensions weren't able to change these conditions
348 $query_options = array_merge( $orderByAndLimit, $query_options );
349 $rows = $dbr->select(
352 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
353 // knowledge to use an index merge if it wants (it may use some other index though).
354 $conds +
[ 'rc_new' => [ 0, 1 ] ],
360 // Build the final data
361 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
362 $this->filterByCategories( $rows, $opts );
368 protected function runMainQueryHook( &$tables, &$fields, &$conds,
369 &$query_options, &$join_conds, $opts
371 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
373 'SpecialRecentChangesQuery',
374 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
379 protected function getDB() {
380 return wfGetDB( DB_REPLICA
, 'recentchanges' );
383 public function outputFeedLinks() {
384 $this->addFeedLinks( $this->getFeedQuery() );
388 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
392 protected function getFeedQuery() {
393 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
394 // API handles empty parameters in a different way
395 return $value !== '';
397 $query['action'] = 'feedrecentchanges';
398 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
399 if ( $query['limit'] > $feedLimit ) {
400 $query['limit'] = $feedLimit;
407 * Build and output the actual changes list.
409 * @param ResultWrapper $rows Database rows
410 * @param FormOptions $opts
412 public function outputChangesList( $rows, $opts ) {
413 $limit = $opts['limit'];
415 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
416 && $this->getUser()->getOption( 'shownumberswatching' );
420 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
421 $list->initChangesListRows( $rows );
423 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
424 $rclistOutput = $list->beginRecentChangesList();
425 if ( $this->isStructuredFilterUiEnabled() ) {
426 $rclistOutput .= $this->makeLegend();
429 foreach ( $rows as $obj ) {
433 $rc = RecentChange
::newFromRow( $obj );
435 # Skip CatWatch entries for hidden cats based on user preference
437 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
438 !$userShowHiddenCats &&
439 $rc->getParam( 'hidden-cat' )
444 $rc->counter
= $counter++
;
445 # Check if the page has been updated since the last visit
446 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
447 && !empty( $obj->wl_notificationtimestamp
)
449 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
451 $rc->notificationtimestamp
= false; // Default
453 # Check the number of users watching the page
454 $rc->numberofWatchingusers
= 0; // Default
455 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
456 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
457 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
458 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
459 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
462 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
465 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
466 if ( $changeLine !== false ) {
467 $rclistOutput .= $changeLine;
471 $rclistOutput .= $list->endRecentChangesList();
473 if ( $rows->numRows() === 0 ) {
474 $this->outputNoResults();
475 if ( !$this->including() ) {
476 $this->getOutput()->setStatusCode( 404 );
479 $this->getOutput()->addHTML( $rclistOutput );
484 * Set the text to be displayed above the changes
486 * @param FormOptions $opts
487 * @param int $numRows Number of rows in the result to show after this header
489 public function doHeader( $opts, $numRows ) {
490 $this->setTopText( $opts );
492 $defaults = $opts->getAllValues();
493 $nondefaults = $opts->getChangedValues();
496 if ( !$this->isStructuredFilterUiEnabled() ) {
497 $panel[] = $this->makeLegend();
499 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
502 $extraOpts = $this->getExtraOptions( $opts );
503 $extraOptsCount = count( $extraOpts );
505 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
507 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
508 foreach ( $extraOpts as $name => $optionRow ) {
509 # Add submit button to the last row only
511 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
513 $out .= Xml
::openElement( 'tr', [ 'class' => $name . 'Form' ] );
514 if ( is_array( $optionRow ) ) {
517 [ 'class' => 'mw-label mw-' . $name . '-label' ],
522 [ 'class' => 'mw-input' ],
523 $optionRow[1] . $addSubmit
528 [ 'class' => 'mw-input', 'colspan' => 2 ],
529 $optionRow . $addSubmit
532 $out .= Xml
::closeElement( 'tr' );
534 $out .= Xml
::closeElement( 'table' );
536 $unconsumed = $opts->getUnconsumedValues();
537 foreach ( $unconsumed as $key => $value ) {
538 $out .= Html
::hidden( $key, $value );
541 $t = $this->getPageTitle();
542 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
543 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
545 $panelString = implode( "\n", $panel );
547 $rcoptions = Xml
::fieldset(
548 $this->msg( 'recentchanges-legend' )->text(),
550 [ 'class' => 'rcoptions cloptions' ]
553 // Insert a placeholder for RCFilters
554 if ( $this->isStructuredFilterUiEnabled() ) {
555 $rcfilterContainer = Html
::element(
557 [ 'class' => 'rcfilters-container' ]
560 $loadingContainer = Html
::rawElement(
562 [ 'class' => 'rcfilters-spinner' ],
565 [ 'class' => 'rcfilters-spinner-bounce' ]
569 // Wrap both with rcfilters-head
570 $this->getOutput()->addHTML(
573 [ 'class' => 'rcfilters-head' ],
574 $rcfilterContainer . $rcoptions
579 $this->getOutput()->addHTML( $loadingContainer );
581 $this->getOutput()->addHTML( $rcoptions );
584 $this->setBottomText( $opts );
588 * Send the text to be displayed above the options
590 * @param FormOptions $opts Unused
592 function setTopText( FormOptions
$opts ) {
595 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
596 if ( !$message->isDisabled() ) {
597 // Parse the message in this weird ugly way to preserve the ability to include interlanguage
598 // links in it (T172461). In the future when T66969 is resolved, perhaps we can just use
599 // $message->parse() instead. This code is copied from Message::parseText().
600 $parserOutput = MessageCache
::singleton()->parse(
602 $this->getPageTitle(),
604 // Message class sets the interface flag to false when parsing in a language different than
605 // user language, and this is wiki content language
609 $content = $parserOutput->getText();
610 // Add only metadata here (including the language links), text is added below
611 $this->getOutput()->addParserOutputMetadata( $parserOutput );
614 'lang' => $wgContLang->getHtmlCode(),
615 'dir' => $wgContLang->getDir(),
618 $topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
620 if ( $this->isStructuredFilterUiEnabled() ) {
621 // Check whether the widget is already collapsed or expanded
622 $collapsedState = $this->getRequest()->getCookie( 'rcfilters-toplinks-collapsed-state' );
623 // Note that an empty/unset cookie means collapsed, so check for !== 'expanded'
624 $topLinksAttributes[ 'class' ] .= $collapsedState !== 'expanded' ?
625 ' mw-recentchanges-toplinks-collapsed' : '';
627 $this->getOutput()->enableOOUI();
628 $contentTitle = new OOUI\
ButtonWidget( [
629 'classes' => [ 'mw-recentchanges-toplinks-title' ],
630 'label' => new OOUI\
HtmlSnippet( $this->msg( 'rcfilters-other-review-tools' )->parse() ),
632 'indicator' => $collapsedState !== 'expanded' ?
'down' : 'up',
633 'flags' => [ 'progressive' ],
636 $contentWrapper = Html
::rawElement( 'div',
638 [ 'class' => 'mw-recentchanges-toplinks-content mw-collapsible-content' ],
643 $content = $contentTitle . $contentWrapper;
645 // Language direction should be on the top div only
646 // if the title is not there. If it is there, it's
647 // interface direction, and the language/dir attributes
648 // should be on the content itself
649 $topLinksAttributes = array_merge( $topLinksAttributes, $langAttributes );
652 $this->getOutput()->addHTML(
653 Html
::rawElement( 'div', $topLinksAttributes, $content )
659 * Get options to be displayed in a form
661 * @param FormOptions $opts
664 function getExtraOptions( $opts ) {
665 $opts->consumeValues( [
666 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
670 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
672 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
673 $extraOpts['category'] = $this->categoryFilterForm( $opts );
676 $tagFilter = ChangeTags
::buildTagFilterSelector(
677 $opts['tagfilter'], false, $this->getContext() );
678 if ( count( $tagFilter ) ) {
679 $extraOpts['tagfilter'] = $tagFilter;
682 // Don't fire the hook for subclasses. (Or should we?)
683 if ( $this->getName() === 'Recentchanges' ) {
684 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
691 * Add page-specific modules.
693 protected function addModules() {
694 parent
::addModules();
695 $out = $this->getOutput();
696 $out->addModules( 'mediawiki.special.recentchanges' );
700 * Get last modified date, for client caching
701 * Don't use this if we are using the patrol feature, patrol changes don't
702 * update the timestamp
704 * @return string|bool
706 public function checkLastModified() {
707 $dbr = $this->getDB();
708 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
714 * Creates the choose namespace selection
716 * @param FormOptions $opts
719 protected function namespaceFilterForm( FormOptions
$opts ) {
720 $nsSelect = Html
::namespaceSelector(
721 [ 'selected' => $opts['namespace'], 'all' => '' ],
722 [ 'name' => 'namespace', 'id' => 'namespace' ]
724 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
725 $invert = Xml
::checkLabel(
726 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
728 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
730 $associated = Xml
::checkLabel(
731 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
733 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
736 return [ $nsLabel, "$nsSelect $invert $associated" ];
740 * Create an input to filter changes by categories
742 * @param FormOptions $opts
745 protected function categoryFilterForm( FormOptions
$opts ) {
746 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
747 'categories', 'mw-categories', false, $opts['categories'] );
749 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
750 'categories_any', 'mw-categories_any', $opts['categories_any'] );
752 return [ $label, $input ];
756 * Filter $rows by categories set in $opts
758 * @param ResultWrapper &$rows Database rows
759 * @param FormOptions $opts
761 function filterByCategories( &$rows, FormOptions
$opts ) {
762 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
764 if ( !count( $categories ) ) {
770 foreach ( $categories as $cat ) {
782 foreach ( $rows as $k => $r ) {
783 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
784 $id = $nt->getArticleID();
786 continue; # Page might have been deleted...
788 if ( !in_array( $id, $articles ) ) {
791 if ( !isset( $a2r[$id] ) ) {
799 if ( !count( $articles ) ||
!count( $cats ) ) {
804 $catFind = new CategoryFinder
;
805 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
806 $match = $catFind->run();
810 foreach ( $match as $id ) {
811 foreach ( $a2r[$id] as $rev ) {
813 $newrows[$k] = $rowsarr[$k];
816 $rows = new FakeResultWrapper( array_values( $newrows ) );
820 * Makes change an option link which carries all the other options
822 * @param string $title Title
823 * @param array $override Options to override
824 * @param array $options Current options
825 * @param bool $active Whether to show the link in bold
828 function makeOptionsLink( $title, $override, $options, $active = false ) {
829 $params = $this->convertParamsForLink( $override +
$options );
832 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
835 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
836 'data-params' => json_encode( $override ),
837 'data-keys' => implode( ',', array_keys( $override ) ),
842 * Creates the options panel.
844 * @param array $defaults
845 * @param array $nondefaults
846 * @param int $numRows Number of rows in the result to show after this header
849 function optionsPanel( $defaults, $nondefaults, $numRows ) {
850 $options = $nondefaults +
$defaults;
853 $msg = $this->msg( 'rclegend' );
854 if ( !$msg->isDisabled() ) {
855 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
858 $lang = $this->getLanguage();
859 $user = $this->getUser();
860 $config = $this->getConfig();
861 if ( $options['from'] ) {
862 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
863 [ 'from' => '' ], $nondefaults );
865 $noteFromMsg = $this->msg( 'rcnotefrom' )
866 ->numParams( $options['limit'] )
868 $lang->userTimeAndDate( $options['from'], $user ),
869 $lang->userDate( $options['from'], $user ),
870 $lang->userTime( $options['from'], $user )
872 ->numParams( $numRows );
873 $note .= Html
::rawElement(
875 [ 'class' => 'rcnotefrom' ],
876 $noteFromMsg->parse()
881 [ 'class' => 'rcoptions-listfromreset' ],
882 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
887 # Sort data for display and make sure it's unique after we've added user data.
888 $linkLimits = $config->get( 'RCLinkLimits' );
889 $linkLimits[] = $options['limit'];
891 $linkLimits = array_unique( $linkLimits );
893 $linkDays = $config->get( 'RCLinkDays' );
894 $linkDays[] = $options['days'];
896 $linkDays = array_unique( $linkDays );
900 foreach ( $linkLimits as $value ) {
901 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
902 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
904 $cl = $lang->pipeList( $cl );
906 // day links, reset 'from' to none
908 foreach ( $linkDays as $value ) {
909 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
910 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
912 $dl = $lang->pipeList( $dl );
914 $showhide = [ 'show', 'hide' ];
918 foreach ( $this->getLegacyShowHideFilters() as $key => $filter ) {
919 $msg = $filter->getShowHide();
920 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
921 // Extensions can define additional filters, but don't need to define the corresponding
922 // messages. If they don't exist, just fall back to 'show' and 'hide'.
923 if ( !$linkMessage->exists() ) {
924 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
927 $link = $this->makeOptionsLink( $linkMessage->text(),
928 [ $key => 1 - $options[$key] ], $nondefaults );
931 'class' => "$msg rcshowhideoption clshowhideoption",
932 'data-filter-name' => $filter->getName(),
935 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
936 $attribs['data-feature-in-structured-ui'] = true;
939 $links[] = Html
::rawElement(
942 $this->msg( $msg )->rawParams( $link )->escaped()
946 // show from this onward link
947 $timestamp = wfTimestampNow();
948 $now = $lang->userTimeAndDate( $timestamp, $user );
949 $timenow = $lang->userTime( $timestamp, $user );
950 $datenow = $lang->userDate( $timestamp, $user );
951 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
953 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
954 ->parse() . '</span>';
956 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
957 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
958 [ 'from' => $timestamp ],
962 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
965 public function isIncludable() {
969 protected function getCacheTTL() {
973 function getDefaultLimit() {
974 return $this->getUser()->getIntOption( 'rclimit' );
977 function getDefaultDays() {
978 return floatval( $this->getUser()->getOption( 'rcdays' ) );