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 private $watchlistFilterGroupDefinition;
37 // @codingStandardsIgnoreStart Needed "useless" override to change parameters.
38 public function __construct( $name = 'Recentchanges', $restriction = '' ) {
39 parent
::__construct( $name, $restriction );
41 $this->watchlistFilterGroupDefinition
= [
42 'name' => 'watchlist',
43 'title' => 'rcfilters-filtergroup-watchlist',
44 'class' => ChangesListStringOptionsFilterGroup
::class,
46 'isFullCoverage' => true,
50 'label' => 'rcfilters-filter-watchlist-watched-label',
51 'description' => 'rcfilters-filter-watchlist-watched-description',
52 'cssClassSuffix' => 'watched',
53 'isRowApplicableCallable' => function ( $ctx, $rc ) {
54 return $rc->getAttribute( 'wl_user' );
58 'name' => 'watchednew',
59 'label' => 'rcfilters-filter-watchlist-watchednew-label',
60 'description' => 'rcfilters-filter-watchlist-watchednew-description',
61 'cssClassSuffix' => 'watchednew',
62 'isRowApplicableCallable' => function ( $ctx, $rc ) {
63 return $rc->getAttribute( 'wl_user' ) &&
64 $rc->getAttribute( 'rc_timestamp' ) &&
65 $rc->getAttribute( 'wl_notificationtimestamp' ) &&
66 $rc->getAttribute( 'rc_timestamp' ) >= $rc->getAttribute( 'wl_notificationtimestamp' );
70 'name' => 'notwatched',
71 'label' => 'rcfilters-filter-watchlist-notwatched-label',
72 'description' => 'rcfilters-filter-watchlist-notwatched-description',
73 'cssClassSuffix' => 'notwatched',
74 'isRowApplicableCallable' => function ( $ctx, $rc ) {
75 return $rc->getAttribute( 'wl_user' ) === null;
79 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
80 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
81 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
82 sort( $selectedValues );
83 $notwatchedCond = 'wl_user IS NULL';
84 $watchedCond = 'wl_user IS NOT NULL';
85 $newCond = 'rc_timestamp >= wl_notificationtimestamp';
87 if ( $selectedValues === [ 'notwatched' ] ) {
88 $conds[] = $notwatchedCond;
92 if ( $selectedValues === [ 'watched' ] ) {
93 $conds[] = $watchedCond;
97 if ( $selectedValues === [ 'watchednew' ] ) {
98 $conds[] = $dbr->makeList( [
105 if ( $selectedValues === [ 'notwatched', 'watched' ] ) {
110 if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) {
111 $conds[] = $dbr->makeList( [
121 if ( $selectedValues === [ 'watched', 'watchednew' ] ) {
122 $conds[] = $watchedCond;
126 if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) {
133 // @codingStandardsIgnoreEnd
136 * Main execution point
138 * @param string $subpage
140 public function execute( $subpage ) {
141 // Backwards-compatibility: redirect to new feed URLs
142 $feedFormat = $this->getRequest()->getVal( 'feed' );
143 if ( !$this->including() && $feedFormat ) {
144 $query = $this->getFeedQuery();
145 $query['feedformat'] = $feedFormat === 'atom' ?
'atom' : 'rss';
146 $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
151 // 10 seconds server-side caching max
152 $out = $this->getOutput();
153 $out->setCdnMaxage( 10 );
154 // Check if the client has a cached version
155 $lastmod = $this->checkLastModified();
156 if ( $lastmod === false ) {
161 '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
164 parent
::execute( $subpage );
166 if ( $this->isStructuredFilterUiEnabled() ) {
167 $jsData = $this->getStructuredFilterJsData();
170 foreach ( $jsData['messageKeys'] as $key ) {
171 $messages[$key] = $this->msg( $key )->plain();
175 ResourceLoader
::makeInlineScript(
176 ResourceLoader
::makeMessageSetScript( $messages )
180 $experimentalStructuredChangeFilters =
181 $this->getConfig()->get( 'StructuredChangeFiltersEnableExperimentalViews' );
183 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
184 $out->addJsConfigVars(
185 'wgStructuredChangeFiltersEnableExperimentalViews',
186 $experimentalStructuredChangeFilters
188 $out->addJsConfigVars(
189 'wgStructuredChangeFiltersEnableLiveUpdate',
190 $this->getConfig()->get( 'StructuredChangeFiltersEnableLiveUpdate' )
192 if ( $experimentalStructuredChangeFilters ) {
193 $out->addJsConfigVars(
194 'wgRCFiltersChangeTags',
195 $this->buildChangeTagList()
202 * Fetch the change tags list for the front end
204 * @return Array Tag data
206 protected function buildChangeTagList() {
207 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
208 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
210 // Hit counts disabled for perf reasons, see T169997
212 $tagStats = ChangeTags::tagUsageStatistics();
213 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
216 arsort( $tagHitCounts );
218 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
220 // Build the list and data
222 foreach ( $tagHitCounts as $tagName => $hits ) {
224 // Only get active tags
225 isset( $explicitlyDefinedTags[ $tagName ] ) ||
226 isset( $softwareActivatedTags[ $tagName ] )
229 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $this->getContext() );
233 'label' => Sanitizer
::stripAllTags(
234 ChangeTags
::tagDescription( $tagName, $this->getContext() )
236 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
237 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
243 // Instead of sorting by hit count (disabled, see above), sort by display name
244 usort( $result, function ( $a, $b ) {
245 return strcasecmp( $a['label'], $b['label'] );
254 protected function transformFilterDefinition( array $filterDefinition ) {
255 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
256 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
259 return $filterDefinition;
265 protected function registerFilters() {
266 parent
::registerFilters();
269 !$this->including() &&
270 $this->getUser()->isLoggedIn() &&
271 $this->getUser()->isAllowed( 'viewmywatchlist' )
273 $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition
] );
274 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
275 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
276 $watchlistGroup->getFilter( 'watchednew' )
280 $user = $this->getUser();
282 $significance = $this->getFilterGroup( 'significance' );
283 $hideMinor = $significance->getFilter( 'hideminor' );
284 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
286 $automated = $this->getFilterGroup( 'automated' );
287 $hideBots = $automated->getFilter( 'hidebots' );
288 $hideBots->setDefault( true );
290 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
291 if ( $reviewStatus !== null ) {
292 // Conditional on feature being available and rights
293 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
294 $hidePatrolled->setDefault( $user->getBoolOption( 'hidepatrolled' ) );
297 $changeType = $this->getFilterGroup( 'changeType' );
298 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
299 if ( $hideCategorization !== null ) {
300 // Conditional on feature being available
301 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
306 * Get a FormOptions object containing the default options
308 * @return FormOptions
310 public function getDefaultOptions() {
311 $opts = parent
::getDefaultOptions();
312 $user = $this->getUser();
314 $opts->add( 'days', $user->getIntOption( 'rcdays' ), FormOptions
::FLOAT );
315 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
316 $opts->add( 'from', '' );
318 $opts->add( 'categories', '' );
319 $opts->add( 'categories_any', false );
320 $opts->add( 'tagfilter', '' );
326 * Get all custom filters
328 * @return array Map of filter URL param names to properties (msg/default)
330 protected function getCustomFilters() {
331 if ( $this->customFilters
=== null ) {
332 $this->customFilters
= parent
::getCustomFilters();
333 Hooks
::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters
], '1.23' );
336 return $this->customFilters
;
340 * Process $par and put options found in $opts. Used when including the page.
343 * @param FormOptions $opts
345 public function parseParameters( $par, FormOptions
$opts ) {
346 parent
::parseParameters( $par, $opts );
348 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
349 foreach ( $bits as $bit ) {
350 if ( is_numeric( $bit ) ) {
351 $opts['limit'] = $bit;
355 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
356 $opts['limit'] = $m[1];
358 if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
359 $opts['days'] = $m[1];
361 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
362 $opts['namespace'] = $m[1];
364 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
365 $opts['tagfilter'] = $m[1];
370 public function validateOptions( FormOptions
$opts ) {
371 $opts->validateIntBounds( 'limit', 0, 5000 );
372 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
373 parent
::validateOptions( $opts );
379 protected function buildQuery( &$tables, &$fields, &$conds,
380 &$query_options, &$join_conds, FormOptions
$opts
382 $dbr = $this->getDB();
383 parent
::buildQuery( $tables, $fields, $conds,
384 $query_options, $join_conds, $opts );
387 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
388 $cutoff = $dbr->timestamp( $cutoff_unixtime );
390 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
391 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
392 $cutoff = $dbr->timestamp( $opts['from'] );
394 $opts->reset( 'from' );
397 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
403 protected function doMainQuery( $tables, $fields, $conds, $query_options,
404 $join_conds, FormOptions
$opts
406 $dbr = $this->getDB();
407 $user = $this->getUser();
409 $tables[] = 'recentchanges';
410 $fields = array_merge( RecentChange
::selectFields(), $fields );
412 // JOIN on watchlist for users
413 if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
414 $tables[] = 'watchlist';
415 $fields[] = 'wl_user';
416 $fields[] = 'wl_notificationtimestamp';
417 $join_conds['watchlist'] = [ 'LEFT JOIN', [
418 'wl_user' => $user->getId(),
420 'wl_namespace=rc_namespace'
424 // JOIN on page, used for 'last revision' filter highlight
426 $fields[] = 'page_latest';
427 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
429 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
430 ChangeTags
::modifyDisplayQuery(
439 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
445 if ( $this->areFiltersInConflict() ) {
450 'ORDER BY' => 'rc_timestamp DESC',
451 'LIMIT' => $opts['limit']
453 if ( in_array( 'DISTINCT', $query_options ) ) {
454 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
455 // In order to prevent DISTINCT from causing query performance problems,
456 // we have to GROUP BY the primary key. This in turn requires us to add
457 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
458 // start of the GROUP BY
459 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
460 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
462 // array_merge() is used intentionally here so that hooks can, should
463 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
464 // MediaWiki 1.26 this used to use the plus operator instead, which meant
465 // that extensions weren't able to change these conditions
466 $query_options = array_merge( $orderByAndLimit, $query_options );
467 $rows = $dbr->select(
470 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
471 // knowledge to use an index merge if it wants (it may use some other index though).
472 $conds +
[ 'rc_new' => [ 0, 1 ] ],
478 // Build the final data
479 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
480 $this->filterByCategories( $rows, $opts );
486 protected function runMainQueryHook( &$tables, &$fields, &$conds,
487 &$query_options, &$join_conds, $opts
489 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
491 'SpecialRecentChangesQuery',
492 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
497 protected function getDB() {
498 return wfGetDB( DB_REPLICA
, 'recentchanges' );
501 public function outputFeedLinks() {
502 $this->addFeedLinks( $this->getFeedQuery() );
506 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
510 protected function getFeedQuery() {
511 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
512 // API handles empty parameters in a different way
513 return $value !== '';
515 $query['action'] = 'feedrecentchanges';
516 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
517 if ( $query['limit'] > $feedLimit ) {
518 $query['limit'] = $feedLimit;
525 * Build and output the actual changes list.
527 * @param ResultWrapper $rows Database rows
528 * @param FormOptions $opts
530 public function outputChangesList( $rows, $opts ) {
531 $limit = $opts['limit'];
533 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
534 && $this->getUser()->getOption( 'shownumberswatching' );
537 $dbr = $this->getDB();
540 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
541 $list->initChangesListRows( $rows );
543 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
544 $rclistOutput = $list->beginRecentChangesList();
545 if ( $this->isStructuredFilterUiEnabled() ) {
546 $rclistOutput .= $this->makeLegend();
549 foreach ( $rows as $obj ) {
553 $rc = RecentChange
::newFromRow( $obj );
555 # Skip CatWatch entries for hidden cats based on user preference
557 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
558 !$userShowHiddenCats &&
559 $rc->getParam( 'hidden-cat' )
564 $rc->counter
= $counter++
;
565 # Check if the page has been updated since the last visit
566 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
567 && !empty( $obj->wl_notificationtimestamp
)
569 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
571 $rc->notificationtimestamp
= false; // Default
573 # Check the number of users watching the page
574 $rc->numberofWatchingusers
= 0; // Default
575 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
576 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
577 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
578 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
579 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
582 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
585 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
586 if ( $changeLine !== false ) {
587 $rclistOutput .= $changeLine;
591 $rclistOutput .= $list->endRecentChangesList();
593 if ( $rows->numRows() === 0 ) {
594 $this->outputNoResults();
595 if ( !$this->including() ) {
596 $this->getOutput()->setStatusCode( 404 );
599 $this->getOutput()->addHTML( $rclistOutput );
604 * Set the text to be displayed above the changes
606 * @param FormOptions $opts
607 * @param int $numRows Number of rows in the result to show after this header
609 public function doHeader( $opts, $numRows ) {
610 $this->setTopText( $opts );
612 $defaults = $opts->getAllValues();
613 $nondefaults = $opts->getChangedValues();
616 if ( !$this->isStructuredFilterUiEnabled() ) {
617 $panel[] = $this->makeLegend();
619 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
622 $extraOpts = $this->getExtraOptions( $opts );
623 $extraOptsCount = count( $extraOpts );
625 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
627 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
628 foreach ( $extraOpts as $name => $optionRow ) {
629 # Add submit button to the last row only
631 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
633 $out .= Xml
::openElement( 'tr' );
634 if ( is_array( $optionRow ) ) {
637 [ 'class' => 'mw-label mw-' . $name . '-label' ],
642 [ 'class' => 'mw-input' ],
643 $optionRow[1] . $addSubmit
648 [ 'class' => 'mw-input', 'colspan' => 2 ],
649 $optionRow . $addSubmit
652 $out .= Xml
::closeElement( 'tr' );
654 $out .= Xml
::closeElement( 'table' );
656 $unconsumed = $opts->getUnconsumedValues();
657 foreach ( $unconsumed as $key => $value ) {
658 $out .= Html
::hidden( $key, $value );
661 $t = $this->getPageTitle();
662 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
663 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
665 $panelString = implode( "\n", $panel );
667 $rcoptions = Xml
::fieldset(
668 $this->msg( 'recentchanges-legend' )->text(),
670 [ 'class' => 'rcoptions' ]
673 // Insert a placeholder for RCFilters
674 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
675 $rcfilterContainer = Html
::element(
677 [ 'class' => 'rcfilters-container' ]
680 $loadingContainer = Html
::rawElement(
682 [ 'class' => 'rcfilters-spinner' ],
685 [ 'class' => 'rcfilters-spinner-bounce' ]
689 // Wrap both with rcfilters-head
690 $this->getOutput()->addHTML(
693 [ 'class' => 'rcfilters-head' ],
694 $rcfilterContainer . $rcoptions
699 $this->getOutput()->addHTML( $loadingContainer );
701 $this->getOutput()->addHTML( $rcoptions );
704 $this->setBottomText( $opts );
708 * Send the text to be displayed above the options
710 * @param FormOptions $opts Unused
712 function setTopText( FormOptions
$opts ) {
715 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
716 if ( !$message->isDisabled() ) {
717 $content = $message->parse();
720 'lang' => $wgContLang->getHtmlCode(),
721 'dir' => $wgContLang->getDir(),
724 $topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
726 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
727 $contentTitle = Html
::rawElement( 'div',
728 [ 'class' => 'mw-recentchanges-toplinks-title' ],
729 $this->msg( 'rcfilters-other-review-tools' )->parse()
731 $contentWrapper = Html
::rawElement( 'div',
732 array_merge( [ 'class' => 'mw-collapsible-content' ], $langAttributes ),
735 $content = $contentTitle . $contentWrapper;
737 // Language direction should be on the top div only
738 // if the title is not there. If it is there, it's
739 // interface direction, and the language/dir attributes
740 // should be on the content itself
741 $topLinksAttributes = array_merge( $topLinksAttributes, $langAttributes );
744 $this->getOutput()->addHTML(
745 Html
::rawElement( 'div', $topLinksAttributes, $content )
751 * Get options to be displayed in a form
753 * @param FormOptions $opts
756 function getExtraOptions( $opts ) {
757 $opts->consumeValues( [
758 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
762 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
764 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
765 $extraOpts['category'] = $this->categoryFilterForm( $opts );
768 $tagFilter = ChangeTags
::buildTagFilterSelector(
769 $opts['tagfilter'], false, $this->getContext() );
770 if ( count( $tagFilter ) ) {
771 $extraOpts['tagfilter'] = $tagFilter;
774 // Don't fire the hook for subclasses. (Or should we?)
775 if ( $this->getName() === 'Recentchanges' ) {
776 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
783 * Check whether the structured filter UI is enabled
787 protected function isStructuredFilterUiEnabled() {
788 return $this->getUser()->getOption(
794 * Add page-specific modules.
796 protected function addModules() {
797 parent
::addModules();
798 $out = $this->getOutput();
799 $out->addModules( 'mediawiki.special.recentchanges' );
800 if ( $this->isStructuredFilterUiEnabled() ) {
801 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
802 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
807 * Get last modified date, for client caching
808 * Don't use this if we are using the patrol feature, patrol changes don't
809 * update the timestamp
811 * @return string|bool
813 public function checkLastModified() {
814 $dbr = $this->getDB();
815 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
821 * Creates the choose namespace selection
823 * @param FormOptions $opts
826 protected function namespaceFilterForm( FormOptions
$opts ) {
827 $nsSelect = Html
::namespaceSelector(
828 [ 'selected' => $opts['namespace'], 'all' => '' ],
829 [ 'name' => 'namespace', 'id' => 'namespace' ]
831 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
832 $invert = Xml
::checkLabel(
833 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
835 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
837 $associated = Xml
::checkLabel(
838 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
840 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
843 return [ $nsLabel, "$nsSelect $invert $associated" ];
847 * Create an input to filter changes by categories
849 * @param FormOptions $opts
852 protected function categoryFilterForm( FormOptions
$opts ) {
853 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
854 'categories', 'mw-categories', false, $opts['categories'] );
856 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
857 'categories_any', 'mw-categories_any', $opts['categories_any'] );
859 return [ $label, $input ];
863 * Filter $rows by categories set in $opts
865 * @param ResultWrapper $rows Database rows
866 * @param FormOptions $opts
868 function filterByCategories( &$rows, FormOptions
$opts ) {
869 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
871 if ( !count( $categories ) ) {
877 foreach ( $categories as $cat ) {
889 foreach ( $rows as $k => $r ) {
890 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
891 $id = $nt->getArticleID();
893 continue; # Page might have been deleted...
895 if ( !in_array( $id, $articles ) ) {
898 if ( !isset( $a2r[$id] ) ) {
906 if ( !count( $articles ) ||
!count( $cats ) ) {
911 $catFind = new CategoryFinder
;
912 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
913 $match = $catFind->run();
917 foreach ( $match as $id ) {
918 foreach ( $a2r[$id] as $rev ) {
920 $newrows[$k] = $rowsarr[$k];
923 $rows = new FakeResultWrapper( array_values( $newrows ) );
927 * Makes change an option link which carries all the other options
929 * @param string $title Title
930 * @param array $override Options to override
931 * @param array $options Current options
932 * @param bool $active Whether to show the link in bold
935 function makeOptionsLink( $title, $override, $options, $active = false ) {
936 $params = $this->convertParamsForLink( $override +
$options );
939 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
942 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
943 'data-params' => json_encode( $override ),
944 'data-keys' => implode( ',', array_keys( $override ) ),
949 * Creates the options panel.
951 * @param array $defaults
952 * @param array $nondefaults
953 * @param int $numRows Number of rows in the result to show after this header
956 function optionsPanel( $defaults, $nondefaults, $numRows ) {
957 $options = $nondefaults +
$defaults;
960 $msg = $this->msg( 'rclegend' );
961 if ( !$msg->isDisabled() ) {
962 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
965 $lang = $this->getLanguage();
966 $user = $this->getUser();
967 $config = $this->getConfig();
968 if ( $options['from'] ) {
969 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
970 [ 'from' => '' ], $nondefaults );
972 $note .= $this->msg( 'rcnotefrom' )
973 ->numParams( $options['limit'] )
975 $lang->userTimeAndDate( $options['from'], $user ),
976 $lang->userDate( $options['from'], $user ),
977 $lang->userTime( $options['from'], $user )
979 ->numParams( $numRows )
983 [ 'class' => 'rcoptions-listfromreset' ],
984 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
989 # Sort data for display and make sure it's unique after we've added user data.
990 $linkLimits = $config->get( 'RCLinkLimits' );
991 $linkLimits[] = $options['limit'];
993 $linkLimits = array_unique( $linkLimits );
995 $linkDays = $config->get( 'RCLinkDays' );
996 $linkDays[] = $options['days'];
998 $linkDays = array_unique( $linkDays );
1002 foreach ( $linkLimits as $value ) {
1003 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
1004 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
1006 $cl = $lang->pipeList( $cl );
1008 // day links, reset 'from' to none
1010 foreach ( $linkDays as $value ) {
1011 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
1012 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
1014 $dl = $lang->pipeList( $dl );
1016 $showhide = [ 'show', 'hide' ];
1020 $filterGroups = $this->getFilterGroups();
1022 $context = $this->getContext();
1023 foreach ( $filterGroups as $groupName => $group ) {
1024 if ( !$group->isPerGroupRequestParameter() ) {
1025 foreach ( $group->getFilters() as $key => $filter ) {
1026 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1027 $msg = $filter->getShowHide();
1028 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
1029 // Extensions can define additional filters, but don't need to define the corresponding
1030 // messages. If they don't exist, just fall back to 'show' and 'hide'.
1031 if ( !$linkMessage->exists() ) {
1032 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
1035 $link = $this->makeOptionsLink( $linkMessage->text(),
1036 [ $key => 1 - $options[$key] ], $nondefaults );
1039 'class' => "$msg rcshowhideoption",
1040 'data-filter-name' => $filter->getName(),
1043 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
1044 $attribs['data-feature-in-structured-ui'] = true;
1047 $links[] = Html
::rawElement(
1050 $this->msg( $msg )->rawParams( $link )->escaped()
1057 // show from this onward link
1058 $timestamp = wfTimestampNow();
1059 $now = $lang->userTimeAndDate( $timestamp, $user );
1060 $timenow = $lang->userTime( $timestamp, $user );
1061 $datenow = $lang->userDate( $timestamp, $user );
1062 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
1064 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
1065 ->parse() . '</span>';
1067 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
1068 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
1069 [ 'from' => $timestamp ],
1073 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
1076 public function isIncludable() {
1080 protected function getCacheTTL() {