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 $out->addJsConfigVars(
193 'wgRCFiltersChangeTags',
194 $this->buildChangeTagList()
200 * Fetch the change tags list for the front end
202 * @return Array Tag data
204 protected function buildChangeTagList() {
205 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
206 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
208 // Hit counts disabled for perf reasons, see T169997
210 $tagStats = ChangeTags::tagUsageStatistics();
211 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
214 arsort( $tagHitCounts );
216 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
218 // Build the list and data
220 foreach ( $tagHitCounts as $tagName => $hits ) {
222 // Only get active tags
223 isset( $explicitlyDefinedTags[ $tagName ] ) ||
224 isset( $softwareActivatedTags[ $tagName ] )
227 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $this->getContext() );
231 'label' => Sanitizer
::stripAllTags(
232 ChangeTags
::tagDescription( $tagName, $this->getContext() )
234 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
235 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
241 // Instead of sorting by hit count (disabled, see above), sort by display name
242 usort( $result, function ( $a, $b ) {
243 return strcasecmp( $a['label'], $b['label'] );
252 protected function transformFilterDefinition( array $filterDefinition ) {
253 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
254 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
257 return $filterDefinition;
263 protected function registerFilters() {
264 parent
::registerFilters();
267 !$this->including() &&
268 $this->getUser()->isLoggedIn() &&
269 $this->getUser()->isAllowed( 'viewmywatchlist' )
271 $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition
] );
272 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
273 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
274 $watchlistGroup->getFilter( 'watchednew' )
278 $user = $this->getUser();
280 $significance = $this->getFilterGroup( 'significance' );
281 $hideMinor = $significance->getFilter( 'hideminor' );
282 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
284 $automated = $this->getFilterGroup( 'automated' );
285 $hideBots = $automated->getFilter( 'hidebots' );
286 $hideBots->setDefault( true );
288 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
289 if ( $reviewStatus !== null ) {
290 // Conditional on feature being available and rights
291 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
292 $hidePatrolled->setDefault( $user->getBoolOption( 'hidepatrolled' ) );
295 $changeType = $this->getFilterGroup( 'changeType' );
296 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
297 if ( $hideCategorization !== null ) {
298 // Conditional on feature being available
299 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
304 * Get a FormOptions object containing the default options
306 * @return FormOptions
308 public function getDefaultOptions() {
309 $opts = parent
::getDefaultOptions();
310 $user = $this->getUser();
312 $opts->add( 'days', $user->getIntOption( 'rcdays' ), FormOptions
::FLOAT );
313 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
314 $opts->add( 'from', '' );
316 $opts->add( 'categories', '' );
317 $opts->add( 'categories_any', false );
318 $opts->add( 'tagfilter', '' );
324 * Get all custom filters
326 * @return array Map of filter URL param names to properties (msg/default)
328 protected function getCustomFilters() {
329 if ( $this->customFilters
=== null ) {
330 $this->customFilters
= parent
::getCustomFilters();
331 Hooks
::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters
], '1.23' );
334 return $this->customFilters
;
338 * Process $par and put options found in $opts. Used when including the page.
341 * @param FormOptions $opts
343 public function parseParameters( $par, FormOptions
$opts ) {
344 parent
::parseParameters( $par, $opts );
346 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
347 foreach ( $bits as $bit ) {
348 if ( is_numeric( $bit ) ) {
349 $opts['limit'] = $bit;
353 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
354 $opts['limit'] = $m[1];
356 if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
357 $opts['days'] = $m[1];
359 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
360 $opts['namespace'] = $m[1];
362 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
363 $opts['tagfilter'] = $m[1];
368 public function validateOptions( FormOptions
$opts ) {
369 $opts->validateIntBounds( 'limit', 0, 5000 );
370 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
371 parent
::validateOptions( $opts );
377 protected function buildQuery( &$tables, &$fields, &$conds,
378 &$query_options, &$join_conds, FormOptions
$opts
380 $dbr = $this->getDB();
381 parent
::buildQuery( $tables, $fields, $conds,
382 $query_options, $join_conds, $opts );
385 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
386 $cutoff = $dbr->timestamp( $cutoff_unixtime );
388 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
389 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
390 $cutoff = $dbr->timestamp( $opts['from'] );
392 $opts->reset( 'from' );
395 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
401 protected function doMainQuery( $tables, $fields, $conds, $query_options,
402 $join_conds, FormOptions
$opts
404 $dbr = $this->getDB();
405 $user = $this->getUser();
407 $tables[] = 'recentchanges';
408 $fields = array_merge( RecentChange
::selectFields(), $fields );
410 // JOIN on watchlist for users
411 if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
412 $tables[] = 'watchlist';
413 $fields[] = 'wl_user';
414 $fields[] = 'wl_notificationtimestamp';
415 $join_conds['watchlist'] = [ 'LEFT JOIN', [
416 'wl_user' => $user->getId(),
418 'wl_namespace=rc_namespace'
422 // JOIN on page, used for 'last revision' filter highlight
424 $fields[] = 'page_latest';
425 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
427 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
428 ChangeTags
::modifyDisplayQuery(
437 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
443 if ( $this->areFiltersInConflict() ) {
448 'ORDER BY' => 'rc_timestamp DESC',
449 'LIMIT' => $opts['limit']
451 if ( in_array( 'DISTINCT', $query_options ) ) {
452 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
453 // In order to prevent DISTINCT from causing query performance problems,
454 // we have to GROUP BY the primary key. This in turn requires us to add
455 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
456 // start of the GROUP BY
457 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
458 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
460 // array_merge() is used intentionally here so that hooks can, should
461 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
462 // MediaWiki 1.26 this used to use the plus operator instead, which meant
463 // that extensions weren't able to change these conditions
464 $query_options = array_merge( $orderByAndLimit, $query_options );
465 $rows = $dbr->select(
468 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
469 // knowledge to use an index merge if it wants (it may use some other index though).
470 $conds +
[ 'rc_new' => [ 0, 1 ] ],
476 // Build the final data
477 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
478 $this->filterByCategories( $rows, $opts );
484 protected function runMainQueryHook( &$tables, &$fields, &$conds,
485 &$query_options, &$join_conds, $opts
487 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
489 'SpecialRecentChangesQuery',
490 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
495 protected function getDB() {
496 return wfGetDB( DB_REPLICA
, 'recentchanges' );
499 public function outputFeedLinks() {
500 $this->addFeedLinks( $this->getFeedQuery() );
504 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
508 protected function getFeedQuery() {
509 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
510 // API handles empty parameters in a different way
511 return $value !== '';
513 $query['action'] = 'feedrecentchanges';
514 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
515 if ( $query['limit'] > $feedLimit ) {
516 $query['limit'] = $feedLimit;
523 * Build and output the actual changes list.
525 * @param ResultWrapper $rows Database rows
526 * @param FormOptions $opts
528 public function outputChangesList( $rows, $opts ) {
529 $limit = $opts['limit'];
531 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
532 && $this->getUser()->getOption( 'shownumberswatching' );
535 $dbr = $this->getDB();
538 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
539 $list->initChangesListRows( $rows );
541 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
542 $rclistOutput = $list->beginRecentChangesList();
543 if ( $this->isStructuredFilterUiEnabled() ) {
544 $rclistOutput .= $this->makeLegend();
547 foreach ( $rows as $obj ) {
551 $rc = RecentChange
::newFromRow( $obj );
553 # Skip CatWatch entries for hidden cats based on user preference
555 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
556 !$userShowHiddenCats &&
557 $rc->getParam( 'hidden-cat' )
562 $rc->counter
= $counter++
;
563 # Check if the page has been updated since the last visit
564 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
565 && !empty( $obj->wl_notificationtimestamp
)
567 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
569 $rc->notificationtimestamp
= false; // Default
571 # Check the number of users watching the page
572 $rc->numberofWatchingusers
= 0; // Default
573 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
574 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
575 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
576 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
577 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
580 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
583 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
584 if ( $changeLine !== false ) {
585 $rclistOutput .= $changeLine;
589 $rclistOutput .= $list->endRecentChangesList();
591 if ( $rows->numRows() === 0 ) {
592 $this->outputNoResults();
593 if ( !$this->including() ) {
594 $this->getOutput()->setStatusCode( 404 );
597 $this->getOutput()->addHTML( $rclistOutput );
602 * Set the text to be displayed above the changes
604 * @param FormOptions $opts
605 * @param int $numRows Number of rows in the result to show after this header
607 public function doHeader( $opts, $numRows ) {
608 $this->setTopText( $opts );
610 $defaults = $opts->getAllValues();
611 $nondefaults = $opts->getChangedValues();
614 if ( !$this->isStructuredFilterUiEnabled() ) {
615 $panel[] = $this->makeLegend();
617 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
620 $extraOpts = $this->getExtraOptions( $opts );
621 $extraOptsCount = count( $extraOpts );
623 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
625 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
626 foreach ( $extraOpts as $name => $optionRow ) {
627 # Add submit button to the last row only
629 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
631 $out .= Xml
::openElement( 'tr' );
632 if ( is_array( $optionRow ) ) {
635 [ 'class' => 'mw-label mw-' . $name . '-label' ],
640 [ 'class' => 'mw-input' ],
641 $optionRow[1] . $addSubmit
646 [ 'class' => 'mw-input', 'colspan' => 2 ],
647 $optionRow . $addSubmit
650 $out .= Xml
::closeElement( 'tr' );
652 $out .= Xml
::closeElement( 'table' );
654 $unconsumed = $opts->getUnconsumedValues();
655 foreach ( $unconsumed as $key => $value ) {
656 $out .= Html
::hidden( $key, $value );
659 $t = $this->getPageTitle();
660 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
661 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
663 $panelString = implode( "\n", $panel );
665 $rcoptions = Xml
::fieldset(
666 $this->msg( 'recentchanges-legend' )->text(),
668 [ 'class' => 'rcoptions' ]
671 // Insert a placeholder for RCFilters
672 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
673 $rcfilterContainer = Html
::element(
675 [ 'class' => 'rcfilters-container' ]
678 $loadingContainer = Html
::rawElement(
680 [ 'class' => 'rcfilters-spinner' ],
683 [ 'class' => 'rcfilters-spinner-bounce' ]
687 // Wrap both with rcfilters-head
688 $this->getOutput()->addHTML(
691 [ 'class' => 'rcfilters-head' ],
692 $rcfilterContainer . $rcoptions
697 $this->getOutput()->addHTML( $loadingContainer );
699 $this->getOutput()->addHTML( $rcoptions );
702 $this->setBottomText( $opts );
706 * Send the text to be displayed above the options
708 * @param FormOptions $opts Unused
710 function setTopText( FormOptions
$opts ) {
713 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
714 if ( !$message->isDisabled() ) {
715 $content = $message->parse();
718 'lang' => $wgContLang->getHtmlCode(),
719 'dir' => $wgContLang->getDir(),
722 $topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
724 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
725 $contentTitle = Html
::rawElement( 'div',
726 [ 'class' => 'mw-recentchanges-toplinks-title' ],
727 $this->msg( 'rcfilters-other-review-tools' )->parse()
729 $contentWrapper = Html
::rawElement( 'div',
730 array_merge( [ 'class' => 'mw-collapsible-content' ], $langAttributes ),
733 $content = $contentTitle . $contentWrapper;
735 // Language direction should be on the top div only
736 // if the title is not there. If it is there, it's
737 // interface direction, and the language/dir attributes
738 // should be on the content itself
739 $topLinksAttributes = array_merge( $topLinksAttributes, $langAttributes );
742 $this->getOutput()->addHTML(
743 Html
::rawElement( 'div', $topLinksAttributes, $content )
749 * Get options to be displayed in a form
751 * @param FormOptions $opts
754 function getExtraOptions( $opts ) {
755 $opts->consumeValues( [
756 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
760 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
762 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
763 $extraOpts['category'] = $this->categoryFilterForm( $opts );
766 $tagFilter = ChangeTags
::buildTagFilterSelector(
767 $opts['tagfilter'], false, $this->getContext() );
768 if ( count( $tagFilter ) ) {
769 $extraOpts['tagfilter'] = $tagFilter;
772 // Don't fire the hook for subclasses. (Or should we?)
773 if ( $this->getName() === 'Recentchanges' ) {
774 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
781 * Check whether the structured filter UI is enabled
785 protected function isStructuredFilterUiEnabled() {
786 return $this->getUser()->getOption(
792 * Add page-specific modules.
794 protected function addModules() {
795 parent
::addModules();
796 $out = $this->getOutput();
797 $out->addModules( 'mediawiki.special.recentchanges' );
798 if ( $this->isStructuredFilterUiEnabled() ) {
799 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
800 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
805 * Get last modified date, for client caching
806 * Don't use this if we are using the patrol feature, patrol changes don't
807 * update the timestamp
809 * @return string|bool
811 public function checkLastModified() {
812 $dbr = $this->getDB();
813 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
819 * Creates the choose namespace selection
821 * @param FormOptions $opts
824 protected function namespaceFilterForm( FormOptions
$opts ) {
825 $nsSelect = Html
::namespaceSelector(
826 [ 'selected' => $opts['namespace'], 'all' => '' ],
827 [ 'name' => 'namespace', 'id' => 'namespace' ]
829 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
830 $invert = Xml
::checkLabel(
831 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
833 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
835 $associated = Xml
::checkLabel(
836 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
838 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
841 return [ $nsLabel, "$nsSelect $invert $associated" ];
845 * Create an input to filter changes by categories
847 * @param FormOptions $opts
850 protected function categoryFilterForm( FormOptions
$opts ) {
851 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
852 'categories', 'mw-categories', false, $opts['categories'] );
854 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
855 'categories_any', 'mw-categories_any', $opts['categories_any'] );
857 return [ $label, $input ];
861 * Filter $rows by categories set in $opts
863 * @param ResultWrapper $rows Database rows
864 * @param FormOptions $opts
866 function filterByCategories( &$rows, FormOptions
$opts ) {
867 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
869 if ( !count( $categories ) ) {
875 foreach ( $categories as $cat ) {
887 foreach ( $rows as $k => $r ) {
888 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
889 $id = $nt->getArticleID();
891 continue; # Page might have been deleted...
893 if ( !in_array( $id, $articles ) ) {
896 if ( !isset( $a2r[$id] ) ) {
904 if ( !count( $articles ) ||
!count( $cats ) ) {
909 $catFind = new CategoryFinder
;
910 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
911 $match = $catFind->run();
915 foreach ( $match as $id ) {
916 foreach ( $a2r[$id] as $rev ) {
918 $newrows[$k] = $rowsarr[$k];
921 $rows = new FakeResultWrapper( array_values( $newrows ) );
925 * Makes change an option link which carries all the other options
927 * @param string $title Title
928 * @param array $override Options to override
929 * @param array $options Current options
930 * @param bool $active Whether to show the link in bold
933 function makeOptionsLink( $title, $override, $options, $active = false ) {
934 $params = $this->convertParamsForLink( $override +
$options );
937 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
940 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
941 'data-params' => json_encode( $override ),
942 'data-keys' => implode( ',', array_keys( $override ) ),
947 * Creates the options panel.
949 * @param array $defaults
950 * @param array $nondefaults
951 * @param int $numRows Number of rows in the result to show after this header
954 function optionsPanel( $defaults, $nondefaults, $numRows ) {
955 $options = $nondefaults +
$defaults;
958 $msg = $this->msg( 'rclegend' );
959 if ( !$msg->isDisabled() ) {
960 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
963 $lang = $this->getLanguage();
964 $user = $this->getUser();
965 $config = $this->getConfig();
966 if ( $options['from'] ) {
967 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
968 [ 'from' => '' ], $nondefaults );
970 $noteFromMsg = $this->msg( 'rcnotefrom' )
971 ->numParams( $options['limit'] )
973 $lang->userTimeAndDate( $options['from'], $user ),
974 $lang->userDate( $options['from'], $user ),
975 $lang->userTime( $options['from'], $user )
977 ->numParams( $numRows );
978 $note .= Html
::rawElement(
980 [ 'class' => 'rcnotefrom' ],
981 $noteFromMsg->parse()
986 [ 'class' => 'rcoptions-listfromreset' ],
987 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
992 # Sort data for display and make sure it's unique after we've added user data.
993 $linkLimits = $config->get( 'RCLinkLimits' );
994 $linkLimits[] = $options['limit'];
996 $linkLimits = array_unique( $linkLimits );
998 $linkDays = $config->get( 'RCLinkDays' );
999 $linkDays[] = $options['days'];
1001 $linkDays = array_unique( $linkDays );
1005 foreach ( $linkLimits as $value ) {
1006 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
1007 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
1009 $cl = $lang->pipeList( $cl );
1011 // day links, reset 'from' to none
1013 foreach ( $linkDays as $value ) {
1014 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
1015 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
1017 $dl = $lang->pipeList( $dl );
1019 $showhide = [ 'show', 'hide' ];
1023 $filterGroups = $this->getFilterGroups();
1025 $context = $this->getContext();
1026 foreach ( $filterGroups as $groupName => $group ) {
1027 if ( !$group->isPerGroupRequestParameter() ) {
1028 foreach ( $group->getFilters() as $key => $filter ) {
1029 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1030 $msg = $filter->getShowHide();
1031 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
1032 // Extensions can define additional filters, but don't need to define the corresponding
1033 // messages. If they don't exist, just fall back to 'show' and 'hide'.
1034 if ( !$linkMessage->exists() ) {
1035 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
1038 $link = $this->makeOptionsLink( $linkMessage->text(),
1039 [ $key => 1 - $options[$key] ], $nondefaults );
1042 'class' => "$msg rcshowhideoption",
1043 'data-filter-name' => $filter->getName(),
1046 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
1047 $attribs['data-feature-in-structured-ui'] = true;
1050 $links[] = Html
::rawElement(
1053 $this->msg( $msg )->rawParams( $link )->escaped()
1060 // show from this onward link
1061 $timestamp = wfTimestampNow();
1062 $now = $lang->userTimeAndDate( $timestamp, $user );
1063 $timenow = $lang->userTime( $timestamp, $user );
1064 $datenow = $lang->userDate( $timestamp, $user );
1065 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
1067 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
1068 ->parse() . '</span>';
1070 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
1071 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
1072 [ 'from' => $timestamp ],
1076 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
1079 public function isIncludable() {
1083 protected function getCacheTTL() {