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()
196 $out->addJsConfigVars(
197 'StructuredChangeFiltersDisplayConfig',
199 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
200 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
201 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
208 * Fetch the change tags list for the front end
210 * @return Array Tag data
212 protected function buildChangeTagList() {
213 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
214 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
216 // Hit counts disabled for perf reasons, see T169997
218 $tagStats = ChangeTags::tagUsageStatistics();
219 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
222 arsort( $tagHitCounts );
224 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
226 // Build the list and data
228 foreach ( $tagHitCounts as $tagName => $hits ) {
230 // Only get active tags
231 isset( $explicitlyDefinedTags[ $tagName ] ) ||
232 isset( $softwareActivatedTags[ $tagName ] )
235 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $this->getContext() );
239 'label' => Sanitizer
::stripAllTags(
240 ChangeTags
::tagDescription( $tagName, $this->getContext() )
242 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
243 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
249 // Instead of sorting by hit count (disabled, see above), sort by display name
250 usort( $result, function ( $a, $b ) {
251 return strcasecmp( $a['label'], $b['label'] );
260 protected function transformFilterDefinition( array $filterDefinition ) {
261 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
262 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
265 return $filterDefinition;
271 protected function registerFilters() {
272 parent
::registerFilters();
275 !$this->including() &&
276 $this->getUser()->isLoggedIn() &&
277 $this->getUser()->isAllowed( 'viewmywatchlist' )
279 $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition
] );
280 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
281 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
282 $watchlistGroup->getFilter( 'watchednew' )
286 $user = $this->getUser();
288 $significance = $this->getFilterGroup( 'significance' );
289 $hideMinor = $significance->getFilter( 'hideminor' );
290 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
292 $automated = $this->getFilterGroup( 'automated' );
293 $hideBots = $automated->getFilter( 'hidebots' );
294 $hideBots->setDefault( true );
296 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
297 if ( $reviewStatus !== null ) {
298 // Conditional on feature being available and rights
299 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
300 $hidePatrolled->setDefault( $user->getBoolOption( 'hidepatrolled' ) );
303 $changeType = $this->getFilterGroup( 'changeType' );
304 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
305 if ( $hideCategorization !== null ) {
306 // Conditional on feature being available
307 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
312 * Get a FormOptions object containing the default options
314 * @return FormOptions
316 public function getDefaultOptions() {
317 $opts = parent
::getDefaultOptions();
318 $user = $this->getUser();
320 $opts->add( 'days', $user->getIntOption( 'rcdays' ), FormOptions
::FLOAT );
321 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
322 $opts->add( 'from', '' );
324 $opts->add( 'categories', '' );
325 $opts->add( 'categories_any', false );
326 $opts->add( 'tagfilter', '' );
332 * Get all custom filters
334 * @return array Map of filter URL param names to properties (msg/default)
336 protected function getCustomFilters() {
337 if ( $this->customFilters
=== null ) {
338 $this->customFilters
= parent
::getCustomFilters();
339 Hooks
::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters
], '1.23' );
342 return $this->customFilters
;
346 * Process $par and put options found in $opts. Used when including the page.
349 * @param FormOptions $opts
351 public function parseParameters( $par, FormOptions
$opts ) {
352 parent
::parseParameters( $par, $opts );
354 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
355 foreach ( $bits as $bit ) {
356 if ( is_numeric( $bit ) ) {
357 $opts['limit'] = $bit;
361 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
362 $opts['limit'] = $m[1];
364 if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
365 $opts['days'] = $m[1];
367 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
368 $opts['namespace'] = $m[1];
370 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
371 $opts['tagfilter'] = $m[1];
376 public function validateOptions( FormOptions
$opts ) {
377 $opts->validateIntBounds( 'limit', 0, 5000 );
378 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
379 parent
::validateOptions( $opts );
385 protected function buildQuery( &$tables, &$fields, &$conds,
386 &$query_options, &$join_conds, FormOptions
$opts
388 $dbr = $this->getDB();
389 parent
::buildQuery( $tables, $fields, $conds,
390 $query_options, $join_conds, $opts );
393 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
394 $cutoff = $dbr->timestamp( $cutoff_unixtime );
396 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
397 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
398 $cutoff = $dbr->timestamp( $opts['from'] );
400 $opts->reset( 'from' );
403 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
409 protected function doMainQuery( $tables, $fields, $conds, $query_options,
410 $join_conds, FormOptions
$opts
412 $dbr = $this->getDB();
413 $user = $this->getUser();
415 $tables[] = 'recentchanges';
416 $fields = array_merge( RecentChange
::selectFields(), $fields );
418 // JOIN on watchlist for users
419 if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
420 $tables[] = 'watchlist';
421 $fields[] = 'wl_user';
422 $fields[] = 'wl_notificationtimestamp';
423 $join_conds['watchlist'] = [ 'LEFT JOIN', [
424 'wl_user' => $user->getId(),
426 'wl_namespace=rc_namespace'
430 // JOIN on page, used for 'last revision' filter highlight
432 $fields[] = 'page_latest';
433 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
435 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
436 ChangeTags
::modifyDisplayQuery(
445 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
451 if ( $this->areFiltersInConflict() ) {
456 'ORDER BY' => 'rc_timestamp DESC',
457 'LIMIT' => $opts['limit']
459 if ( in_array( 'DISTINCT', $query_options ) ) {
460 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
461 // In order to prevent DISTINCT from causing query performance problems,
462 // we have to GROUP BY the primary key. This in turn requires us to add
463 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
464 // start of the GROUP BY
465 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
466 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
468 // array_merge() is used intentionally here so that hooks can, should
469 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
470 // MediaWiki 1.26 this used to use the plus operator instead, which meant
471 // that extensions weren't able to change these conditions
472 $query_options = array_merge( $orderByAndLimit, $query_options );
473 $rows = $dbr->select(
476 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
477 // knowledge to use an index merge if it wants (it may use some other index though).
478 $conds +
[ 'rc_new' => [ 0, 1 ] ],
484 // Build the final data
485 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
486 $this->filterByCategories( $rows, $opts );
492 protected function runMainQueryHook( &$tables, &$fields, &$conds,
493 &$query_options, &$join_conds, $opts
495 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
497 'SpecialRecentChangesQuery',
498 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
503 protected function getDB() {
504 return wfGetDB( DB_REPLICA
, 'recentchanges' );
507 public function outputFeedLinks() {
508 $this->addFeedLinks( $this->getFeedQuery() );
512 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
516 protected function getFeedQuery() {
517 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
518 // API handles empty parameters in a different way
519 return $value !== '';
521 $query['action'] = 'feedrecentchanges';
522 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
523 if ( $query['limit'] > $feedLimit ) {
524 $query['limit'] = $feedLimit;
531 * Build and output the actual changes list.
533 * @param ResultWrapper $rows Database rows
534 * @param FormOptions $opts
536 public function outputChangesList( $rows, $opts ) {
537 $limit = $opts['limit'];
539 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
540 && $this->getUser()->getOption( 'shownumberswatching' );
543 $dbr = $this->getDB();
546 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
547 $list->initChangesListRows( $rows );
549 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
550 $rclistOutput = $list->beginRecentChangesList();
551 if ( $this->isStructuredFilterUiEnabled() ) {
552 $rclistOutput .= $this->makeLegend();
555 foreach ( $rows as $obj ) {
559 $rc = RecentChange
::newFromRow( $obj );
561 # Skip CatWatch entries for hidden cats based on user preference
563 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
564 !$userShowHiddenCats &&
565 $rc->getParam( 'hidden-cat' )
570 $rc->counter
= $counter++
;
571 # Check if the page has been updated since the last visit
572 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
573 && !empty( $obj->wl_notificationtimestamp
)
575 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
577 $rc->notificationtimestamp
= false; // Default
579 # Check the number of users watching the page
580 $rc->numberofWatchingusers
= 0; // Default
581 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
582 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
583 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
584 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
585 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
588 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
591 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
592 if ( $changeLine !== false ) {
593 $rclistOutput .= $changeLine;
597 $rclistOutput .= $list->endRecentChangesList();
599 if ( $rows->numRows() === 0 ) {
600 $this->outputNoResults();
601 if ( !$this->including() ) {
602 $this->getOutput()->setStatusCode( 404 );
605 $this->getOutput()->addHTML( $rclistOutput );
610 * Set the text to be displayed above the changes
612 * @param FormOptions $opts
613 * @param int $numRows Number of rows in the result to show after this header
615 public function doHeader( $opts, $numRows ) {
616 $this->setTopText( $opts );
618 $defaults = $opts->getAllValues();
619 $nondefaults = $opts->getChangedValues();
622 if ( !$this->isStructuredFilterUiEnabled() ) {
623 $panel[] = $this->makeLegend();
625 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
628 $extraOpts = $this->getExtraOptions( $opts );
629 $extraOptsCount = count( $extraOpts );
631 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
633 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
634 foreach ( $extraOpts as $name => $optionRow ) {
635 # Add submit button to the last row only
637 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
639 $out .= Xml
::openElement( 'tr' );
640 if ( is_array( $optionRow ) ) {
643 [ 'class' => 'mw-label mw-' . $name . '-label' ],
648 [ 'class' => 'mw-input' ],
649 $optionRow[1] . $addSubmit
654 [ 'class' => 'mw-input', 'colspan' => 2 ],
655 $optionRow . $addSubmit
658 $out .= Xml
::closeElement( 'tr' );
660 $out .= Xml
::closeElement( 'table' );
662 $unconsumed = $opts->getUnconsumedValues();
663 foreach ( $unconsumed as $key => $value ) {
664 $out .= Html
::hidden( $key, $value );
667 $t = $this->getPageTitle();
668 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
669 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
671 $panelString = implode( "\n", $panel );
673 $rcoptions = Xml
::fieldset(
674 $this->msg( 'recentchanges-legend' )->text(),
676 [ 'class' => 'rcoptions' ]
679 // Insert a placeholder for RCFilters
680 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
681 $rcfilterContainer = Html
::element(
683 [ 'class' => 'rcfilters-container' ]
686 $loadingContainer = Html
::rawElement(
688 [ 'class' => 'rcfilters-spinner' ],
691 [ 'class' => 'rcfilters-spinner-bounce' ]
695 // Wrap both with rcfilters-head
696 $this->getOutput()->addHTML(
699 [ 'class' => 'rcfilters-head' ],
700 $rcfilterContainer . $rcoptions
705 $this->getOutput()->addHTML( $loadingContainer );
707 $this->getOutput()->addHTML( $rcoptions );
710 $this->setBottomText( $opts );
714 * Send the text to be displayed above the options
716 * @param FormOptions $opts Unused
718 function setTopText( FormOptions
$opts ) {
721 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
722 if ( !$message->isDisabled() ) {
723 $content = $message->parse();
726 'lang' => $wgContLang->getHtmlCode(),
727 'dir' => $wgContLang->getDir(),
730 $topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
732 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
733 $contentTitle = Html
::rawElement( 'div',
734 [ 'class' => 'mw-recentchanges-toplinks-title' ],
735 $this->msg( 'rcfilters-other-review-tools' )->parse()
737 $contentWrapper = Html
::rawElement( 'div',
738 array_merge( [ 'class' => 'mw-collapsible-content' ], $langAttributes ),
741 $content = $contentTitle . $contentWrapper;
743 // Language direction should be on the top div only
744 // if the title is not there. If it is there, it's
745 // interface direction, and the language/dir attributes
746 // should be on the content itself
747 $topLinksAttributes = array_merge( $topLinksAttributes, $langAttributes );
750 $this->getOutput()->addHTML(
751 Html
::rawElement( 'div', $topLinksAttributes, $content )
757 * Get options to be displayed in a form
759 * @param FormOptions $opts
762 function getExtraOptions( $opts ) {
763 $opts->consumeValues( [
764 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
768 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
770 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
771 $extraOpts['category'] = $this->categoryFilterForm( $opts );
774 $tagFilter = ChangeTags
::buildTagFilterSelector(
775 $opts['tagfilter'], false, $this->getContext() );
776 if ( count( $tagFilter ) ) {
777 $extraOpts['tagfilter'] = $tagFilter;
780 // Don't fire the hook for subclasses. (Or should we?)
781 if ( $this->getName() === 'Recentchanges' ) {
782 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
789 * Check whether the structured filter UI is enabled
793 protected function isStructuredFilterUiEnabled() {
794 return $this->getUser()->getOption(
800 * Add page-specific modules.
802 protected function addModules() {
803 parent
::addModules();
804 $out = $this->getOutput();
805 $out->addModules( 'mediawiki.special.recentchanges' );
806 if ( $this->isStructuredFilterUiEnabled() ) {
807 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
808 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
813 * Get last modified date, for client caching
814 * Don't use this if we are using the patrol feature, patrol changes don't
815 * update the timestamp
817 * @return string|bool
819 public function checkLastModified() {
820 $dbr = $this->getDB();
821 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
827 * Creates the choose namespace selection
829 * @param FormOptions $opts
832 protected function namespaceFilterForm( FormOptions
$opts ) {
833 $nsSelect = Html
::namespaceSelector(
834 [ 'selected' => $opts['namespace'], 'all' => '' ],
835 [ 'name' => 'namespace', 'id' => 'namespace' ]
837 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
838 $invert = Xml
::checkLabel(
839 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
841 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
843 $associated = Xml
::checkLabel(
844 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
846 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
849 return [ $nsLabel, "$nsSelect $invert $associated" ];
853 * Create an input to filter changes by categories
855 * @param FormOptions $opts
858 protected function categoryFilterForm( FormOptions
$opts ) {
859 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
860 'categories', 'mw-categories', false, $opts['categories'] );
862 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
863 'categories_any', 'mw-categories_any', $opts['categories_any'] );
865 return [ $label, $input ];
869 * Filter $rows by categories set in $opts
871 * @param ResultWrapper &$rows Database rows
872 * @param FormOptions $opts
874 function filterByCategories( &$rows, FormOptions
$opts ) {
875 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
877 if ( !count( $categories ) ) {
883 foreach ( $categories as $cat ) {
895 foreach ( $rows as $k => $r ) {
896 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
897 $id = $nt->getArticleID();
899 continue; # Page might have been deleted...
901 if ( !in_array( $id, $articles ) ) {
904 if ( !isset( $a2r[$id] ) ) {
912 if ( !count( $articles ) ||
!count( $cats ) ) {
917 $catFind = new CategoryFinder
;
918 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
919 $match = $catFind->run();
923 foreach ( $match as $id ) {
924 foreach ( $a2r[$id] as $rev ) {
926 $newrows[$k] = $rowsarr[$k];
929 $rows = new FakeResultWrapper( array_values( $newrows ) );
933 * Makes change an option link which carries all the other options
935 * @param string $title Title
936 * @param array $override Options to override
937 * @param array $options Current options
938 * @param bool $active Whether to show the link in bold
941 function makeOptionsLink( $title, $override, $options, $active = false ) {
942 $params = $this->convertParamsForLink( $override +
$options );
945 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
948 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
949 'data-params' => json_encode( $override ),
950 'data-keys' => implode( ',', array_keys( $override ) ),
955 * Creates the options panel.
957 * @param array $defaults
958 * @param array $nondefaults
959 * @param int $numRows Number of rows in the result to show after this header
962 function optionsPanel( $defaults, $nondefaults, $numRows ) {
963 $options = $nondefaults +
$defaults;
966 $msg = $this->msg( 'rclegend' );
967 if ( !$msg->isDisabled() ) {
968 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
971 $lang = $this->getLanguage();
972 $user = $this->getUser();
973 $config = $this->getConfig();
974 if ( $options['from'] ) {
975 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
976 [ 'from' => '' ], $nondefaults );
978 $noteFromMsg = $this->msg( 'rcnotefrom' )
979 ->numParams( $options['limit'] )
981 $lang->userTimeAndDate( $options['from'], $user ),
982 $lang->userDate( $options['from'], $user ),
983 $lang->userTime( $options['from'], $user )
985 ->numParams( $numRows );
986 $note .= Html
::rawElement(
988 [ 'class' => 'rcnotefrom' ],
989 $noteFromMsg->parse()
994 [ 'class' => 'rcoptions-listfromreset' ],
995 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
1000 # Sort data for display and make sure it's unique after we've added user data.
1001 $linkLimits = $config->get( 'RCLinkLimits' );
1002 $linkLimits[] = $options['limit'];
1003 sort( $linkLimits );
1004 $linkLimits = array_unique( $linkLimits );
1006 $linkDays = $config->get( 'RCLinkDays' );
1007 $linkDays[] = $options['days'];
1009 $linkDays = array_unique( $linkDays );
1013 foreach ( $linkLimits as $value ) {
1014 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
1015 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
1017 $cl = $lang->pipeList( $cl );
1019 // day links, reset 'from' to none
1021 foreach ( $linkDays as $value ) {
1022 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
1023 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
1025 $dl = $lang->pipeList( $dl );
1027 $showhide = [ 'show', 'hide' ];
1031 $filterGroups = $this->getFilterGroups();
1033 $context = $this->getContext();
1034 foreach ( $filterGroups as $groupName => $group ) {
1035 if ( !$group->isPerGroupRequestParameter() ) {
1036 foreach ( $group->getFilters() as $key => $filter ) {
1037 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1038 $msg = $filter->getShowHide();
1039 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
1040 // Extensions can define additional filters, but don't need to define the corresponding
1041 // messages. If they don't exist, just fall back to 'show' and 'hide'.
1042 if ( !$linkMessage->exists() ) {
1043 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
1046 $link = $this->makeOptionsLink( $linkMessage->text(),
1047 [ $key => 1 - $options[$key] ], $nondefaults );
1050 'class' => "$msg rcshowhideoption",
1051 'data-filter-name' => $filter->getName(),
1054 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
1055 $attribs['data-feature-in-structured-ui'] = true;
1058 $links[] = Html
::rawElement(
1061 $this->msg( $msg )->rawParams( $link )->escaped()
1068 // show from this onward link
1069 $timestamp = wfTimestampNow();
1070 $now = $lang->userTimeAndDate( $timestamp, $user );
1071 $timenow = $lang->userTime( $timestamp, $user );
1072 $datenow = $lang->userDate( $timestamp, $user );
1073 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
1075 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
1076 ->parse() . '</span>';
1078 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
1079 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
1080 [ 'from' => $timestamp ],
1084 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
1087 public function isIncludable() {
1091 protected function getCacheTTL() {