3 * Special page which uses a ChangesList to show query results.
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
23 use MediaWiki\Logger\LoggerFactory
;
24 use Wikimedia\Rdbms\DBQueryTimeoutError
;
25 use Wikimedia\Rdbms\ResultWrapper
;
26 use Wikimedia\Rdbms\FakeResultWrapper
;
27 use Wikimedia\Rdbms\IDatabase
;
30 * Special page which uses a ChangesList to show query results.
31 * @todo Way too many public functions, most of them should be protected
33 * @ingroup SpecialPage
35 abstract class ChangesListSpecialPage
extends SpecialPage
{
37 * Preference name for saved queries. Subclasses that use saved queries should override this.
40 protected static $savedQueriesPreferenceName;
43 * Preference name for 'days'. Subclasses should override this.
46 protected static $daysPreferenceName;
49 * Preference name for 'limit'. Subclasses should override this.
52 protected static $limitPreferenceName;
57 /** @var FormOptions */
61 protected $customFilters;
63 // Order of both groups and filters is significant; first is top-most priority,
64 // descending from there.
65 // 'showHideSuffix' is a shortcut to and avoid spelling out
66 // details specific to subclasses here.
68 * Definition information for the filters and their groups
70 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
71 * However, priority is dynamically added for the core groups, to ease maintenance.
73 * Groups are displayed to the user in the structured UI. However, if necessary,
74 * all of the filters in a group can be configured to only display on the
75 * unstuctured UI, in which case you don't need a group title. This is done in
76 * getFilterGroupDefinitionFromLegacyCustomFilters, for example.
78 * @var array $filterGroupDefinitions
80 private $filterGroupDefinitions;
82 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
83 // that is registered conditionally.
84 private $reviewStatusFilterGroupDefinition;
86 // Single filter registered conditionally
87 private $hideCategorizationFilterDefinition;
90 * Filter groups, and their contained filters
91 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
93 * @var array $filterGroups
95 protected $filterGroups = [];
97 public function __construct( $name, $restriction ) {
98 parent
::__construct( $name, $restriction );
100 $nonRevisionTypes = [ RC_LOG
];
101 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
103 $this->filterGroupDefinitions
= [
105 'name' => 'registration',
106 'title' => 'rcfilters-filtergroup-registration',
107 'class' => ChangesListBooleanFilterGroup
::class,
111 // rcshowhideliu-show, rcshowhideliu-hide,
113 'showHideSuffix' => 'showhideliu',
115 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
116 &$query_options, &$join_conds
118 $conds[] = 'rc_user = 0';
120 'isReplacedInStructuredUi' => true,
124 'name' => 'hideanons',
125 // rcshowhideanons-show, rcshowhideanons-hide,
127 'showHideSuffix' => 'showhideanons',
129 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
130 &$query_options, &$join_conds
132 $conds[] = 'rc_user != 0';
134 'isReplacedInStructuredUi' => true,
140 'name' => 'userExpLevel',
141 'title' => 'rcfilters-filtergroup-userExpLevel',
142 'class' => ChangesListStringOptionsFilterGroup
::class,
143 'isFullCoverage' => true,
146 'name' => 'unregistered',
147 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
148 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
149 'cssClassSuffix' => 'user-unregistered',
150 'isRowApplicableCallable' => function ( $ctx, $rc ) {
151 return !$rc->getAttribute( 'rc_user' );
155 'name' => 'registered',
156 'label' => 'rcfilters-filter-user-experience-level-registered-label',
157 'description' => 'rcfilters-filter-user-experience-level-registered-description',
158 'cssClassSuffix' => 'user-registered',
159 'isRowApplicableCallable' => function ( $ctx, $rc ) {
160 return $rc->getAttribute( 'rc_user' );
164 'name' => 'newcomer',
165 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
166 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
167 'cssClassSuffix' => 'user-newcomer',
168 'isRowApplicableCallable' => function ( $ctx, $rc ) {
169 $performer = $rc->getPerformer();
170 return $performer && $performer->isLoggedIn() &&
171 $performer->getExperienceLevel() === 'newcomer';
176 'label' => 'rcfilters-filter-user-experience-level-learner-label',
177 'description' => 'rcfilters-filter-user-experience-level-learner-description',
178 'cssClassSuffix' => 'user-learner',
179 'isRowApplicableCallable' => function ( $ctx, $rc ) {
180 $performer = $rc->getPerformer();
181 return $performer && $performer->isLoggedIn() &&
182 $performer->getExperienceLevel() === 'learner';
186 'name' => 'experienced',
187 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
188 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
189 'cssClassSuffix' => 'user-experienced',
190 'isRowApplicableCallable' => function ( $ctx, $rc ) {
191 $performer = $rc->getPerformer();
192 return $performer && $performer->isLoggedIn() &&
193 $performer->getExperienceLevel() === 'experienced';
197 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
198 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
202 'name' => 'authorship',
203 'title' => 'rcfilters-filtergroup-authorship',
204 'class' => ChangesListBooleanFilterGroup
::class,
207 'name' => 'hidemyself',
208 'label' => 'rcfilters-filter-editsbyself-label',
209 'description' => 'rcfilters-filter-editsbyself-description',
210 // rcshowhidemine-show, rcshowhidemine-hide,
212 'showHideSuffix' => 'showhidemine',
214 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
215 &$query_options, &$join_conds
217 $user = $ctx->getUser();
218 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
220 'cssClassSuffix' => 'self',
221 'isRowApplicableCallable' => function ( $ctx, $rc ) {
222 return $ctx->getUser()->equals( $rc->getPerformer() );
226 'name' => 'hidebyothers',
227 'label' => 'rcfilters-filter-editsbyother-label',
228 'description' => 'rcfilters-filter-editsbyother-description',
230 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
231 &$query_options, &$join_conds
233 $user = $ctx->getUser();
234 $conds[] = 'rc_user_text = ' . $dbr->addQuotes( $user->getName() );
236 'cssClassSuffix' => 'others',
237 'isRowApplicableCallable' => function ( $ctx, $rc ) {
238 return !$ctx->getUser()->equals( $rc->getPerformer() );
245 'name' => 'automated',
246 'title' => 'rcfilters-filtergroup-automated',
247 'class' => ChangesListBooleanFilterGroup
::class,
250 'name' => 'hidebots',
251 'label' => 'rcfilters-filter-bots-label',
252 'description' => 'rcfilters-filter-bots-description',
253 // rcshowhidebots-show, rcshowhidebots-hide,
255 'showHideSuffix' => 'showhidebots',
257 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
258 &$query_options, &$join_conds
260 $conds[] = 'rc_bot = 0';
262 'cssClassSuffix' => 'bot',
263 'isRowApplicableCallable' => function ( $ctx, $rc ) {
264 return $rc->getAttribute( 'rc_bot' );
268 'name' => 'hidehumans',
269 'label' => 'rcfilters-filter-humans-label',
270 'description' => 'rcfilters-filter-humans-description',
272 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
273 &$query_options, &$join_conds
275 $conds[] = 'rc_bot = 1';
277 'cssClassSuffix' => 'human',
278 'isRowApplicableCallable' => function ( $ctx, $rc ) {
279 return !$rc->getAttribute( 'rc_bot' );
285 // reviewStatus (conditional)
288 'name' => 'significance',
289 'title' => 'rcfilters-filtergroup-significance',
290 'class' => ChangesListBooleanFilterGroup
::class,
294 'name' => 'hideminor',
295 'label' => 'rcfilters-filter-minor-label',
296 'description' => 'rcfilters-filter-minor-description',
297 // rcshowhideminor-show, rcshowhideminor-hide,
299 'showHideSuffix' => 'showhideminor',
301 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
302 &$query_options, &$join_conds
304 $conds[] = 'rc_minor = 0';
306 'cssClassSuffix' => 'minor',
307 'isRowApplicableCallable' => function ( $ctx, $rc ) {
308 return $rc->getAttribute( 'rc_minor' );
312 'name' => 'hidemajor',
313 'label' => 'rcfilters-filter-major-label',
314 'description' => 'rcfilters-filter-major-description',
316 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
317 &$query_options, &$join_conds
319 $conds[] = 'rc_minor = 1';
321 'cssClassSuffix' => 'major',
322 'isRowApplicableCallable' => function ( $ctx, $rc ) {
323 return !$rc->getAttribute( 'rc_minor' );
330 'name' => 'lastRevision',
331 'title' => 'rcfilters-filtergroup-lastRevision',
332 'class' => ChangesListBooleanFilterGroup
::class,
336 'name' => 'hidelastrevision',
337 'label' => 'rcfilters-filter-lastrevision-label',
338 'description' => 'rcfilters-filter-lastrevision-description',
340 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
341 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
342 $conds[] = $dbr->makeList(
344 'rc_this_oldid <> page_latest',
345 'rc_type' => $nonRevisionTypes,
350 'cssClassSuffix' => 'last',
351 'isRowApplicableCallable' => function ( $ctx, $rc ) {
352 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
356 'name' => 'hidepreviousrevisions',
357 'label' => 'rcfilters-filter-previousrevision-label',
358 'description' => 'rcfilters-filter-previousrevision-description',
360 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
361 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
362 $conds[] = $dbr->makeList(
364 'rc_this_oldid = page_latest',
365 'rc_type' => $nonRevisionTypes,
370 'cssClassSuffix' => 'previous',
371 'isRowApplicableCallable' => function ( $ctx, $rc ) {
372 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
378 // With extensions, there can be change types that will not be hidden by any of these.
380 'name' => 'changeType',
381 'title' => 'rcfilters-filtergroup-changetype',
382 'class' => ChangesListBooleanFilterGroup
::class,
386 'name' => 'hidepageedits',
387 'label' => 'rcfilters-filter-pageedits-label',
388 'description' => 'rcfilters-filter-pageedits-description',
391 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
392 &$query_options, &$join_conds
394 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
396 'cssClassSuffix' => 'src-mw-edit',
397 'isRowApplicableCallable' => function ( $ctx, $rc ) {
398 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
402 'name' => 'hidenewpages',
403 'label' => 'rcfilters-filter-newpages-label',
404 'description' => 'rcfilters-filter-newpages-description',
407 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
408 &$query_options, &$join_conds
410 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
412 'cssClassSuffix' => 'src-mw-new',
413 'isRowApplicableCallable' => function ( $ctx, $rc ) {
414 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
418 // hidecategorization
422 'label' => 'rcfilters-filter-logactions-label',
423 'description' => 'rcfilters-filter-logactions-description',
426 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
427 &$query_options, &$join_conds
429 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
431 'cssClassSuffix' => 'src-mw-log',
432 'isRowApplicableCallable' => function ( $ctx, $rc ) {
433 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
441 $this->reviewStatusFilterGroupDefinition
= [
443 'name' => 'reviewStatus',
444 'title' => 'rcfilters-filtergroup-reviewstatus',
445 'class' => ChangesListBooleanFilterGroup
::class,
449 'name' => 'hidepatrolled',
450 'label' => 'rcfilters-filter-patrolled-label',
451 'description' => 'rcfilters-filter-patrolled-description',
452 // rcshowhidepatr-show, rcshowhidepatr-hide
454 'showHideSuffix' => 'showhidepatr',
456 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
457 &$query_options, &$join_conds
459 $conds[] = 'rc_patrolled = 0';
461 'cssClassSuffix' => 'patrolled',
462 'isRowApplicableCallable' => function ( $ctx, $rc ) {
463 return $rc->getAttribute( 'rc_patrolled' );
467 'name' => 'hideunpatrolled',
468 'label' => 'rcfilters-filter-unpatrolled-label',
469 'description' => 'rcfilters-filter-unpatrolled-description',
471 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
472 &$query_options, &$join_conds
474 $conds[] = 'rc_patrolled = 1';
476 'cssClassSuffix' => 'unpatrolled',
477 'isRowApplicableCallable' => function ( $ctx, $rc ) {
478 return !$rc->getAttribute( 'rc_patrolled' );
485 $this->hideCategorizationFilterDefinition
= [
486 'name' => 'hidecategorization',
487 'label' => 'rcfilters-filter-categorization-label',
488 'description' => 'rcfilters-filter-categorization-description',
489 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
490 // wlshowhidecategorization
491 'showHideSuffix' => 'showhidecategorization',
494 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
495 &$query_options, &$join_conds
497 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
499 'cssClassSuffix' => 'src-mw-categorize',
500 'isRowApplicableCallable' => function ( $ctx, $rc ) {
501 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
507 * Check if filters are in conflict and guaranteed to return no results.
511 protected function areFiltersInConflict() {
512 $opts = $this->getOptions();
513 /** @var ChangesListFilterGroup $group */
514 foreach ( $this->getFilterGroups() as $group ) {
515 if ( $group->getConflictingGroups() ) {
518 " specifies conflicts with other groups but these are not supported yet."
522 /** @var ChangesListFilter $conflictingFilter */
523 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
524 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
529 /** @var ChangesListFilter $filter */
530 foreach ( $group->getFilters() as $filter ) {
531 /** @var ChangesListFilter $conflictingFilter */
532 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
534 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
535 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
549 * Main execution point
551 * @param string $subpage
553 public function execute( $subpage ) {
554 $this->rcSubpage
= $subpage;
556 $this->considerActionsForDefaultSavedQuery();
558 $opts = $this->getOptions();
560 $rows = $this->getRows();
561 if ( $rows === false ) {
562 $rows = new FakeResultWrapper( [] );
565 // Used by Structured UI app to get results without MW chrome
566 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
567 $this->getOutput()->setArticleBodyOnly( true );
570 // Used by "live update" and "view newest" to check
571 // if there's new changes with minimal data transfer
572 if ( $this->getRequest()->getBool( 'peek' ) ) {
573 $code = $rows->numRows() > 0 ?
200 : 204;
574 $this->getOutput()->setStatusCode( $code );
578 $batch = new LinkBatch
;
579 foreach ( $rows as $row ) {
580 $batch->add( NS_USER
, $row->rc_user_text
);
581 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
582 $batch->add( $row->rc_namespace
, $row->rc_title
);
583 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
584 $formatter = LogFormatter
::newFromRow( $row );
585 foreach ( $formatter->getPreloadTitles() as $title ) {
586 $batch->addObj( $title );
593 $this->outputHeader();
595 $this->webOutput( $rows, $opts );
598 } catch ( DBQueryTimeoutError
$timeoutException ) {
599 MWExceptionHandler
::logException( $timeoutException );
602 $this->outputHeader();
605 $this->getOutput()->setStatusCode( 500 );
606 $this->webOutputHeader( 0, $opts );
607 $this->outputTimeout();
610 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
611 // Clean up any bad page entries for titles showing up in RC
612 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
614 LoggerFactory
::getInstance( 'objectcache' )
618 $this->includeRcFiltersApp();
622 * Check whether or not the page should load defaults, and if so, whether
623 * a default saved query is relevant to be redirected to. If it is relevant,
624 * redirect properly with all necessary query parameters.
626 protected function considerActionsForDefaultSavedQuery() {
627 if ( !$this->isStructuredFilterUiEnabled() ) {
631 $knownParams = call_user_func_array(
632 [ $this->getRequest(), 'getValues' ],
633 array_keys( $this->getOptions()->getAllValues() )
636 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
637 // we need to exclude several parameters we know should not be counted towards preventing
638 // the loading of defaults.
639 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
640 $knownParams = array_diff_key( $knownParams, $excludedParams );
643 // If there are NO known parameters in the URL request
644 // (that are not excluded) then we need to check into loading
645 // the default saved query
646 count( $knownParams ) === 0
648 // Get the saved queries data and parse it
649 $savedQueries = FormatJson
::decode(
650 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
654 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
655 // Only load queries that are 'version' 2, since those
656 // have parameter representation
657 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
658 $savedQueryDefaultID = $savedQueries[ 'default' ];
659 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
661 // Build the entire parameter list
662 $query = array_merge(
663 $defaultQuery[ 'params' ],
664 $defaultQuery[ 'highlights' ],
669 // Add to the query any parameters that we may have ignored before
670 // but are still valid and requested in the URL
671 $query = array_merge( $this->getRequest()->getValues(), $query );
672 unset( $query[ 'title' ] );
673 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
675 // There's a default, but the version is not 2, and the server can't
676 // actually recognize the query itself. This happens if it is before
677 // the conversion, so we need to tell the UI to reload saved query as
678 // it does the conversion to version 2
679 $this->getOutput()->addJsConfigVars(
680 'wgStructuredChangeFiltersDefaultSavedQueryExists',
684 // Add the class that tells the frontend it is still loading
686 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
693 * Include the modules and configuration for the RCFilters app.
694 * Conditional on the user having the feature enabled.
696 * If it is disabled, add a <body> class marking that
698 protected function includeRcFiltersApp() {
699 $out = $this->getOutput();
700 if ( $this->isStructuredFilterUiEnabled() ) {
701 $jsData = $this->getStructuredFilterJsData();
704 foreach ( $jsData['messageKeys'] as $key ) {
705 $messages[$key] = $this->msg( $key )->plain();
708 $out->addBodyClasses( 'mw-rcfilters-enabled' );
711 ResourceLoader
::makeInlineScript(
712 ResourceLoader
::makeMessageSetScript( $messages )
716 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
718 $out->addJsConfigVars(
719 'wgRCFiltersChangeTags',
720 $this->getChangeTagList()
722 $out->addJsConfigVars(
723 'StructuredChangeFiltersDisplayConfig',
725 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
726 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
727 'limitDefault' => $this->getDefaultLimit(),
728 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
729 'daysDefault' => $this->getDefaultDays(),
733 $out->addJsConfigVars(
734 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
735 static::$savedQueriesPreferenceName
737 $out->addJsConfigVars(
738 'wgStructuredChangeFiltersLimitPreferenceName',
739 static::$limitPreferenceName
741 $out->addJsConfigVars(
742 'wgStructuredChangeFiltersDaysPreferenceName',
743 static::$daysPreferenceName
746 $out->addJsConfigVars(
747 'StructuredChangeFiltersLiveUpdatePollingRate',
748 $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
751 $out->addBodyClasses( 'mw-rcfilters-disabled' );
756 * Fetch the change tags list for the front end
758 * @return Array Tag data
760 protected function getChangeTagList() {
761 $cache = ObjectCache
::getMainWANInstance();
762 $context = $this->getContext();
763 return $cache->getWithSetCallback(
764 $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ),
765 $cache::TTL_MINUTE
* 10,
766 function () use ( $context ) {
767 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
768 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
770 // Hit counts disabled for perf reasons, see T169997
772 $tagStats = ChangeTags::tagUsageStatistics();
773 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
776 arsort( $tagHitCounts );
778 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
780 // Build the list and data
782 foreach ( $tagHitCounts as $tagName => $hits ) {
784 // Only get active tags
785 isset( $explicitlyDefinedTags[ $tagName ] ) ||
786 isset( $softwareActivatedTags[ $tagName ] )
789 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $context );
793 'label' => Sanitizer
::stripAllTags(
794 ChangeTags
::tagDescription( $tagName, $context )
796 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
797 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
803 // Instead of sorting by hit count (disabled, see above), sort by display name
804 usort( $result, function ( $a, $b ) {
805 return strcasecmp( $a['label'], $b['label'] );
817 * Add the "no results" message to the output
819 protected function outputNoResults() {
820 $this->getOutput()->addHTML(
821 '<div class="mw-changeslist-empty">' .
822 $this->msg( 'recentchanges-noresult' )->parse() .
828 * Add the "timeout" message to the output
830 protected function outputTimeout() {
831 $this->getOutput()->addHTML(
832 '<div class="mw-changeslist-timeout">' .
833 $this->msg( 'recentchanges-timeout' )->parse() .
839 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
841 * @return bool|ResultWrapper Result or false
843 public function getRows() {
844 $opts = $this->getOptions();
851 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
853 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
857 * Get the current FormOptions for this request
859 * @return FormOptions
861 public function getOptions() {
862 if ( $this->rcOptions
=== null ) {
863 $this->rcOptions
= $this->setup( $this->rcSubpage
);
866 return $this->rcOptions
;
870 * Register all filters and their groups (including those from hooks), plus handle
871 * conflicts and defaults.
873 * You might want to customize these in the same method, in subclasses. You can
874 * call getFilterGroup to access a group, and (on the group) getFilter to access a
875 * filter, then make necessary modfications to the filter or group (e.g. with
878 protected function registerFilters() {
879 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
881 // Make sure this is not being transcluded (we don't want to show this
882 // information to all users just because the user that saves the edit can
883 // patrol or is logged in)
884 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
885 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
888 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
890 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
891 $transformedHideCategorizationDef = $this->transformFilterDefinition(
892 $this->hideCategorizationFilterDefinition
895 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
897 $hideCategorization = new ChangesListBooleanFilter(
898 $transformedHideCategorizationDef
902 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
904 $unstructuredGroupDefinition =
905 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
906 $this->getCustomFilters()
908 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
910 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
911 $registered = $userExperienceLevel->getFilter( 'registered' );
912 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
913 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
914 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
916 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
917 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
918 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
920 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
921 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
923 // categoryFilter is conditional; see registerFilters
924 if ( $categoryFilter !== null ) {
925 $hideMinorFilter->conflictsWith(
927 'rcfilters-hideminor-conflicts-typeofchange-global',
928 'rcfilters-hideminor-conflicts-typeofchange',
929 'rcfilters-typeofchange-conflicts-hideminor'
932 $hideMinorFilter->conflictsWith(
934 'rcfilters-hideminor-conflicts-typeofchange-global',
935 'rcfilters-hideminor-conflicts-typeofchange',
936 'rcfilters-typeofchange-conflicts-hideminor'
938 $hideMinorFilter->conflictsWith(
940 'rcfilters-hideminor-conflicts-typeofchange-global',
941 'rcfilters-hideminor-conflicts-typeofchange',
942 'rcfilters-typeofchange-conflicts-hideminor'
947 * Transforms filter definition to prepare it for constructor.
949 * See overrides of this method as well.
951 * @param array $filterDefinition Original filter definition
953 * @return array Transformed definition
955 protected function transformFilterDefinition( array $filterDefinition ) {
956 return $filterDefinition;
960 * Register filters from a definition object
962 * Array specifying groups and their filters; see Filter and
963 * ChangesListFilterGroup constructors.
965 * There is light processing to simplify core maintenance.
966 * @param array $definition
968 protected function registerFiltersFromDefinitions( array $definition ) {
969 $autoFillPriority = -1;
970 foreach ( $definition as $groupDefinition ) {
971 if ( !isset( $groupDefinition['priority'] ) ) {
972 $groupDefinition['priority'] = $autoFillPriority;
974 // If it's explicitly specified, start over the auto-fill
975 $autoFillPriority = $groupDefinition['priority'];
980 $className = $groupDefinition['class'];
981 unset( $groupDefinition['class'] );
983 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
984 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
987 $this->registerFilterGroup( new $className( $groupDefinition ) );
992 * Get filter group definition from legacy custom filters
994 * @param array $customFilters Custom filters from legacy hooks
995 * @return array Group definition
997 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
998 // Special internal unstructured group
999 $unstructuredGroupDefinition = [
1000 'name' => 'unstructured',
1001 'class' => ChangesListBooleanFilterGroup
::class,
1002 'priority' => -1, // Won't display in structured
1006 foreach ( $customFilters as $name => $params ) {
1007 $unstructuredGroupDefinition['filters'][] = [
1009 'showHide' => $params['msg'],
1010 'default' => $params['default'],
1014 return $unstructuredGroupDefinition;
1018 * @return array The legacy show/hide toggle filters
1020 protected function getLegacyShowHideFilters() {
1022 foreach ( $this->filterGroups
as $group ) {
1023 if ( $group instanceof ChangesListBooleanFilterGroup
) {
1024 foreach ( $group->getFilters() as $key => $filter ) {
1025 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1026 $filters[ $key ] = $filter;
1035 * Register all the filters, including legacy hook-driven ones.
1036 * Then create a FormOptions object with options as specified by the user
1038 * @param array $parameters
1040 * @return FormOptions
1042 public function setup( $parameters ) {
1043 $this->registerFilters();
1045 $opts = $this->getDefaultOptions();
1047 $opts = $this->fetchOptionsFromRequest( $opts );
1049 // Give precedence to subpage syntax
1050 if ( $parameters !== null ) {
1051 $this->parseParameters( $parameters, $opts );
1054 $this->validateOptions( $opts );
1060 * Get a FormOptions object containing the default options. By default, returns
1061 * some basic options. The filters listed explicitly here are overriden in this
1062 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1063 * and more) are structured. Structured filters are overriden in registerFilters.
1066 * @return FormOptions
1068 public function getDefaultOptions() {
1069 $opts = new FormOptions();
1070 $structuredUI = $this->isStructuredFilterUiEnabled();
1071 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1072 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1074 /** @var ChangesListFilterGroup $filterGroup */
1075 foreach ( $this->filterGroups
as $filterGroup ) {
1076 $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
1079 $opts->add( 'namespace', '', FormOptions
::STRING );
1080 $opts->add( 'invert', false );
1081 $opts->add( 'associated', false );
1082 $opts->add( 'urlversion', 1 );
1083 $opts->add( 'tagfilter', '' );
1085 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
1086 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
1088 $opts->add( 'from', '' );
1094 * Register a structured changes list filter group
1096 * @param ChangesListFilterGroup $group
1098 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
1099 $groupName = $group->getName();
1101 $this->filterGroups
[$groupName] = $group;
1105 * Gets the currently registered filters groups
1107 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1109 protected function getFilterGroups() {
1110 return $this->filterGroups
;
1114 * Gets a specified ChangesListFilterGroup by name
1116 * @param string $groupName Name of group
1118 * @return ChangesListFilterGroup|null Group, or null if not registered
1120 public function getFilterGroup( $groupName ) {
1121 return isset( $this->filterGroups
[$groupName] ) ?
1122 $this->filterGroups
[$groupName] :
1126 // Currently, this intentionally only includes filters that display
1127 // in the structured UI. This can be changed easily, though, if we want
1128 // to include data on filters that use the unstructured UI. messageKeys is a
1129 // special top-level value, with the value being an array of the message keys to
1130 // send to the client.
1132 * Gets structured filter information needed by JS
1134 * @return array Associative array
1135 * * array $return['groups'] Group data
1136 * * array $return['messageKeys'] Array of message keys
1138 public function getStructuredFilterJsData() {
1141 'messageKeys' => [],
1144 usort( $this->filterGroups
, function ( $a, $b ) {
1145 return $b->getPriority() - $a->getPriority();
1148 foreach ( $this->filterGroups
as $groupName => $group ) {
1149 $groupOutput = $group->getJsData( $this );
1150 if ( $groupOutput !== null ) {
1151 $output['messageKeys'] = array_merge(
1152 $output['messageKeys'],
1153 $groupOutput['messageKeys']
1156 unset( $groupOutput['messageKeys'] );
1157 $output['groups'][] = $groupOutput;
1165 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
1168 * @return array Map of filter URL param names to properties (msg/default)
1170 protected function getCustomFilters() {
1171 if ( $this->customFilters
=== null ) {
1172 $this->customFilters
= [];
1173 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
1176 return $this->customFilters
;
1180 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1182 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1184 * @param FormOptions $opts
1185 * @return FormOptions
1187 protected function fetchOptionsFromRequest( $opts ) {
1188 $opts->fetchValuesFromRequest( $this->getRequest() );
1194 * Process $par and put options found in $opts. Used when including the page.
1196 * @param string $par
1197 * @param FormOptions $opts
1199 public function parseParameters( $par, FormOptions
$opts ) {
1200 $stringParameterNameSet = [];
1201 $hideParameterNameSet = [];
1203 // URL parameters can be per-group, like 'userExpLevel',
1204 // or per-filter, like 'hideminor'.
1206 foreach ( $this->filterGroups
as $filterGroup ) {
1207 if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup
) {
1208 $stringParameterNameSet[$filterGroup->getName()] = true;
1209 } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1210 foreach ( $filterGroup->getFilters() as $filter ) {
1211 $hideParameterNameSet[$filter->getName()] = true;
1216 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1217 foreach ( $bits as $bit ) {
1219 if ( isset( $hideParameterNameSet[$bit] ) ) {
1220 // hidefoo => hidefoo=true
1222 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1223 // foo => hidefoo=false
1224 $opts["hide$bit"] = false;
1225 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1226 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1227 $opts[$m[1]] = $m[2];
1234 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1236 * @param FormOptions $opts
1238 public function validateOptions( FormOptions
$opts ) {
1239 $isContradictory = $this->fixContradictoryOptions( $opts );
1240 $isReplaced = $this->replaceOldOptions( $opts );
1242 if ( $isContradictory ||
$isReplaced ) {
1243 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1244 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1247 $opts->validateIntBounds( 'limit', 0, 5000 );
1248 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1252 * Fix invalid options by resetting pairs that should never appear together.
1254 * @param FormOptions $opts
1255 * @return bool True if any option was reset
1257 private function fixContradictoryOptions( FormOptions
$opts ) {
1258 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1260 foreach ( $this->filterGroups
as $filterGroup ) {
1261 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1262 $filters = $filterGroup->getFilters();
1264 if ( count( $filters ) === 1 ) {
1265 // legacy boolean filters should not be considered
1269 $allInGroupEnabled = array_reduce(
1271 function ( $carry, $filter ) use ( $opts ) {
1272 return $carry && $opts[ $filter->getName() ];
1274 /* initialValue */ count( $filters ) > 0
1277 if ( $allInGroupEnabled ) {
1278 foreach ( $filters as $filter ) {
1279 $opts[ $filter->getName() ] = false;
1291 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1294 * This is deprecated and may be removed.
1296 * @param FormOptions $opts
1297 * @return bool True if this change was mode
1299 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1300 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1301 $opts->reset( 'hideanons' );
1302 if ( !$opts['hidebots'] ) {
1303 $opts->reset( 'hideliu' );
1304 $opts['hidehumans'] = 1;
1314 * Replace old options 'hideanons' or 'hideliu' with structured UI equivalent
1316 * @param FormOptions $opts
1317 * @return bool True if the change was made
1319 public function replaceOldOptions( FormOptions
$opts ) {
1320 if ( !$this->isStructuredFilterUiEnabled() ) {
1324 // At this point 'hideanons' and 'hideliu' cannot be both true,
1325 // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
1326 if ( $opts[ 'hideanons' ] ) {
1327 $opts->reset( 'hideanons' );
1328 $opts[ 'userExpLevel' ] = 'registered';
1332 if ( $opts[ 'hideliu' ] ) {
1333 $opts->reset( 'hideliu' );
1334 $opts[ 'userExpLevel' ] = 'unregistered';
1342 * Convert parameters values from true/false to 1/0
1343 * so they are not omitted by wfArrayToCgi()
1346 * @param array $params
1349 protected function convertParamsForLink( $params ) {
1350 foreach ( $params as &$value ) {
1351 if ( $value === false ) {
1360 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1361 * the user requested.
1363 * @param array &$tables Array of tables; see IDatabase::select $table
1364 * @param array &$fields Array of fields; see IDatabase::select $vars
1365 * @param array &$conds Array of conditions; see IDatabase::select $conds
1366 * @param array &$query_options Array of query options; see IDatabase::select $options
1367 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1368 * @param FormOptions $opts
1370 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1371 &$join_conds, FormOptions
$opts
1373 $dbr = $this->getDB();
1374 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1376 /** @var ChangesListFilterGroup $filterGroup */
1377 foreach ( $this->filterGroups
as $filterGroup ) {
1378 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1379 $query_options, $join_conds, $opts, $isStructuredUI );
1382 // Namespace filtering
1383 if ( $opts[ 'namespace' ] !== '' ) {
1384 $namespaces = explode( ';', $opts[ 'namespace' ] );
1386 if ( $opts[ 'associated' ] ) {
1387 $associatedNamespaces = array_map(
1389 return MWNamespace
::getAssociated( $ns );
1393 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1396 if ( count( $namespaces ) === 1 ) {
1397 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1398 $value = $dbr->addQuotes( reset( $namespaces ) );
1400 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1401 sort( $namespaces );
1402 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1404 $conds[] = "rc_namespace $operator $value";
1408 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1409 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1411 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1412 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
1413 $cutoff = $dbr->timestamp( $opts['from'] );
1415 $opts->reset( 'from' );
1418 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1424 * @param array $tables Array of tables; see IDatabase::select $table
1425 * @param array $fields Array of fields; see IDatabase::select $vars
1426 * @param array $conds Array of conditions; see IDatabase::select $conds
1427 * @param array $query_options Array of query options; see IDatabase::select $options
1428 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1429 * @param FormOptions $opts
1430 * @return bool|ResultWrapper Result or false
1432 protected function doMainQuery( $tables, $fields, $conds,
1433 $query_options, $join_conds, FormOptions
$opts
1435 $rcQuery = RecentChange
::getQueryInfo();
1436 $tables = array_merge( $tables, $rcQuery['tables'] );
1437 $fields = array_merge( $rcQuery['fields'], $fields );
1438 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
1440 ChangeTags
::modifyDisplayQuery(
1449 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1455 $dbr = $this->getDB();
1457 return $dbr->select(
1467 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1468 &$query_options, &$join_conds, $opts
1471 'ChangesListSpecialPageQuery',
1472 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1477 * Return a IDatabase object for reading
1481 protected function getDB() {
1482 return wfGetDB( DB_REPLICA
);
1486 * Send header output to the OutputPage object, only called if not using feeds
1488 * @param int $rowCount Number of database rows
1489 * @param FormOptions $opts
1491 private function webOutputHeader( $rowCount, $opts ) {
1492 if ( !$this->including() ) {
1493 $this->outputFeedLinks();
1494 $this->doHeader( $opts, $rowCount );
1499 * Send output to the OutputPage object, only called if not used feeds
1501 * @param ResultWrapper $rows Database rows
1502 * @param FormOptions $opts
1504 public function webOutput( $rows, $opts ) {
1505 $this->webOutputHeader( $rows->numRows(), $opts );
1507 $this->outputChangesList( $rows, $opts );
1511 * Output feed links.
1513 public function outputFeedLinks() {
1514 // nothing by default
1518 * Build and output the actual changes list.
1520 * @param ResultWrapper $rows Database rows
1521 * @param FormOptions $opts
1523 abstract public function outputChangesList( $rows, $opts );
1526 * Set the text to be displayed above the changes
1528 * @param FormOptions $opts
1529 * @param int $numRows Number of rows in the result to show after this header
1531 public function doHeader( $opts, $numRows ) {
1532 $this->setTopText( $opts );
1534 // @todo Lots of stuff should be done here.
1536 $this->setBottomText( $opts );
1540 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1541 * or similar methods to print the text.
1543 * @param FormOptions $opts
1545 public function setTopText( FormOptions
$opts ) {
1546 // nothing by default
1550 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1551 * or similar methods to print the text.
1553 * @param FormOptions $opts
1555 public function setBottomText( FormOptions
$opts ) {
1556 // nothing by default
1560 * Get options to be displayed in a form
1561 * @todo This should handle options returned by getDefaultOptions().
1562 * @todo Not called by anything in this class (but is in subclasses), should be
1563 * called by something… doHeader() maybe?
1565 * @param FormOptions $opts
1568 public function getExtraOptions( $opts ) {
1573 * Return the legend displayed within the fieldset
1577 public function makeLegend() {
1578 $context = $this->getContext();
1579 $user = $context->getUser();
1580 # The legend showing what the letters and stuff mean
1581 $legend = Html
::openElement( 'dl' ) . "\n";
1582 # Iterates through them and gets the messages for both letter and tooltip
1583 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1584 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1585 unset( $legendItems['unpatrolled'] );
1587 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1588 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1589 $letter = $item['letter'];
1590 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1592 $legend .= Html
::element( 'dt',
1593 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1595 Html
::rawElement( 'dd',
1596 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1597 $context->msg( $label )->parse()
1601 $legend .= Html
::rawElement( 'dt',
1602 [ 'class' => 'mw-plusminus-pos' ],
1603 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1605 $legend .= Html
::element(
1607 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1608 $context->msg( 'recentchanges-label-plusminus' )->text()
1610 $legend .= Html
::closeElement( 'dl' ) . "\n";
1612 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1613 $context->msg( 'rcfilters-legend-heading' )->parse() :
1614 $context->msg( 'recentchanges-legend-heading' )->parse();
1617 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1618 $collapsedClass = $collapsedState === 'collapsed' ?
' mw-collapsed' : '';
1620 $enhancedMode = $this->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
1621 $enhancedClass = $enhancedMode ?
' mw-enhanced' : '';
1623 $legendClasses = $collapsedClass . $enhancedClass;
1625 '<div class="mw-changeslist-legend mw-collapsible' . $legendClasses . '">' .
1627 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1634 * Add page-specific modules.
1636 protected function addModules() {
1637 $out = $this->getOutput();
1638 // Styles and behavior for the legend box (see makeLegend())
1639 $out->addModuleStyles( [
1640 'mediawiki.special.changeslist.legend',
1641 'mediawiki.special.changeslist',
1643 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1645 if ( $this->isStructuredFilterUiEnabled() ) {
1646 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1647 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1651 protected function getGroupName() {
1656 * Filter on users' experience levels; this will not be called if nothing is
1659 * @param string $specialPageClassName Class name of current special page
1660 * @param IContextSource $context Context, for e.g. user
1661 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1662 * @param array &$tables Array of tables; see IDatabase::select $table
1663 * @param array &$fields Array of fields; see IDatabase::select $vars
1664 * @param array &$conds Array of conditions; see IDatabase::select $conds
1665 * @param array &$query_options Array of query options; see IDatabase::select $options
1666 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1667 * @param array $selectedExpLevels The allowed active values, sorted
1668 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1671 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1672 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1674 global $wgLearnerEdits,
1675 $wgExperiencedUserEdits,
1676 $wgLearnerMemberSince,
1677 $wgExperiencedUserMemberSince;
1681 // If all levels are selected, don't filter
1682 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1686 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1688 in_array( 'registered', $selectedExpLevels ) &&
1689 in_array( 'unregistered', $selectedExpLevels )
1694 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1696 in_array( 'registered', $selectedExpLevels ) &&
1697 !in_array( 'unregistered', $selectedExpLevels )
1699 $conds[] = 'rc_user != 0';
1703 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1704 $conds[] = 'rc_user = 0';
1709 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1714 $secondsPerDay = 86400;
1715 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1716 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1718 $aboveNewcomer = $dbr->makeList(
1720 'user_editcount >= ' . intval( $wgLearnerEdits ),
1721 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1726 $aboveLearner = $dbr->makeList(
1728 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1729 'user_registration <= ' .
1730 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1737 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1738 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1739 $conditions[] = 'rc_user = 0';
1742 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1743 $conditions[] = "NOT ( $aboveNewcomer )";
1744 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1745 $conditions[] = $dbr->makeList(
1746 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1749 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1750 $conditions[] = $aboveLearner;
1751 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1752 $conditions[] = "NOT ( $aboveLearner )";
1753 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1754 $conditions[] = $dbr->makeList(
1755 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1758 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1759 $conditions[] = $aboveNewcomer;
1760 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1761 $conditions[] = 'rc_user != 0';
1764 if ( count( $conditions ) > 1 ) {
1765 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1766 } elseif ( count( $conditions ) === 1 ) {
1767 $conds[] = reset( $conditions );
1772 * Check whether the structured filter UI is enabled
1776 public function isStructuredFilterUiEnabled() {
1777 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1781 return static::checkStructuredFilterUiEnabled(
1788 * Check whether the structured filter UI is enabled by default (regardless of
1789 * this particular user's setting)
1793 public function isStructuredFilterUiEnabledByDefault() {
1794 if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
1795 return !$this->getUser()->getDefaultOption( 'rcenhancedfilters-disable' );
1797 return $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
1802 * Static method to check whether StructuredFilter UI is enabled for the given user
1805 * @param Config $config
1806 * @param User $user User object
1809 public static function checkStructuredFilterUiEnabled( Config
$config, User
$user ) {
1810 if ( $config->get( 'StructuredChangeFiltersShowPreference' ) ) {
1811 return !$user->getOption( 'rcenhancedfilters-disable' );
1813 return $user->getOption( 'rcenhancedfilters' );
1818 * Get the default value of the number of changes to display when loading
1824 public function getDefaultLimit() {
1825 return $this->getUser()->getIntOption( static::$limitPreferenceName );
1829 * Get the default value of the number of days to display when loading
1831 * Supports fractional values, and should be cast to a float.
1836 public function getDefaultDays() {
1837 return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );