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\ResultWrapper
;
25 use Wikimedia\Rdbms\FakeResultWrapper
;
26 use Wikimedia\Rdbms\IDatabase
;
29 * Special page which uses a ChangesList to show query results.
30 * @todo Way too many public functions, most of them should be protected
32 * @ingroup SpecialPage
34 abstract class ChangesListSpecialPage
extends SpecialPage
{
36 * Preference name for saved queries. Subclasses that use saved queries should override this.
39 protected static $savedQueriesPreferenceName;
44 /** @var FormOptions */
48 protected $customFilters;
50 // Order of both groups and filters is significant; first is top-most priority,
51 // descending from there.
52 // 'showHideSuffix' is a shortcut to and avoid spelling out
53 // details specific to subclasses here.
55 * Definition information for the filters and their groups
57 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
58 * However, priority is dynamically added for the core groups, to ease maintenance.
60 * Groups are displayed to the user in the structured UI. However, if necessary,
61 * all of the filters in a group can be configured to only display on the
62 * unstuctured UI, in which case you don't need a group title. This is done in
63 * getFilterGroupDefinitionFromLegacyCustomFilters, for example.
65 * @var array $filterGroupDefinitions
67 private $filterGroupDefinitions;
69 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
70 // that is registered conditionally.
71 private $reviewStatusFilterGroupDefinition;
73 // Single filter registered conditionally
74 private $hideCategorizationFilterDefinition;
77 * Filter groups, and their contained filters
78 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
80 * @var array $filterGroups
82 protected $filterGroups = [];
84 public function __construct( $name, $restriction ) {
85 parent
::__construct( $name, $restriction );
87 $nonRevisionTypes = [ RC_LOG
];
88 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
90 $this->filterGroupDefinitions
= [
92 'name' => 'registration',
93 'title' => 'rcfilters-filtergroup-registration',
94 'class' => ChangesListBooleanFilterGroup
::class,
98 // rcshowhideliu-show, rcshowhideliu-hide,
100 'showHideSuffix' => 'showhideliu',
102 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
103 &$query_options, &$join_conds
105 $conds[] = 'rc_user = 0';
107 'isReplacedInStructuredUi' => true,
111 'name' => 'hideanons',
112 // rcshowhideanons-show, rcshowhideanons-hide,
114 'showHideSuffix' => 'showhideanons',
116 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
117 &$query_options, &$join_conds
119 $conds[] = 'rc_user != 0';
121 'isReplacedInStructuredUi' => true,
127 'name' => 'userExpLevel',
128 'title' => 'rcfilters-filtergroup-userExpLevel',
129 'class' => ChangesListStringOptionsFilterGroup
::class,
130 'isFullCoverage' => true,
133 'name' => 'unregistered',
134 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
135 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
136 'cssClassSuffix' => 'user-unregistered',
137 'isRowApplicableCallable' => function ( $ctx, $rc ) {
138 return !$rc->getAttribute( 'rc_user' );
142 'name' => 'registered',
143 'label' => 'rcfilters-filter-user-experience-level-registered-label',
144 'description' => 'rcfilters-filter-user-experience-level-registered-description',
145 'cssClassSuffix' => 'user-registered',
146 'isRowApplicableCallable' => function ( $ctx, $rc ) {
147 return $rc->getAttribute( 'rc_user' );
151 'name' => 'newcomer',
152 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
153 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
154 'cssClassSuffix' => 'user-newcomer',
155 'isRowApplicableCallable' => function ( $ctx, $rc ) {
156 $performer = $rc->getPerformer();
157 return $performer && $performer->isLoggedIn() &&
158 $performer->getExperienceLevel() === 'newcomer';
163 'label' => 'rcfilters-filter-user-experience-level-learner-label',
164 'description' => 'rcfilters-filter-user-experience-level-learner-description',
165 'cssClassSuffix' => 'user-learner',
166 'isRowApplicableCallable' => function ( $ctx, $rc ) {
167 $performer = $rc->getPerformer();
168 return $performer && $performer->isLoggedIn() &&
169 $performer->getExperienceLevel() === 'learner';
173 'name' => 'experienced',
174 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
175 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
176 'cssClassSuffix' => 'user-experienced',
177 'isRowApplicableCallable' => function ( $ctx, $rc ) {
178 $performer = $rc->getPerformer();
179 return $performer && $performer->isLoggedIn() &&
180 $performer->getExperienceLevel() === 'experienced';
184 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
185 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
189 'name' => 'authorship',
190 'title' => 'rcfilters-filtergroup-authorship',
191 'class' => ChangesListBooleanFilterGroup
::class,
194 'name' => 'hidemyself',
195 'label' => 'rcfilters-filter-editsbyself-label',
196 'description' => 'rcfilters-filter-editsbyself-description',
197 // rcshowhidemine-show, rcshowhidemine-hide,
199 'showHideSuffix' => 'showhidemine',
201 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
202 &$query_options, &$join_conds
204 $user = $ctx->getUser();
205 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
207 'cssClassSuffix' => 'self',
208 'isRowApplicableCallable' => function ( $ctx, $rc ) {
209 return $ctx->getUser()->equals( $rc->getPerformer() );
213 'name' => 'hidebyothers',
214 'label' => 'rcfilters-filter-editsbyother-label',
215 'description' => 'rcfilters-filter-editsbyother-description',
217 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
218 &$query_options, &$join_conds
220 $user = $ctx->getUser();
221 $conds[] = 'rc_user_text = ' . $dbr->addQuotes( $user->getName() );
223 'cssClassSuffix' => 'others',
224 'isRowApplicableCallable' => function ( $ctx, $rc ) {
225 return !$ctx->getUser()->equals( $rc->getPerformer() );
232 'name' => 'automated',
233 'title' => 'rcfilters-filtergroup-automated',
234 'class' => ChangesListBooleanFilterGroup
::class,
237 'name' => 'hidebots',
238 'label' => 'rcfilters-filter-bots-label',
239 'description' => 'rcfilters-filter-bots-description',
240 // rcshowhidebots-show, rcshowhidebots-hide,
242 'showHideSuffix' => 'showhidebots',
244 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
245 &$query_options, &$join_conds
247 $conds[] = 'rc_bot = 0';
249 'cssClassSuffix' => 'bot',
250 'isRowApplicableCallable' => function ( $ctx, $rc ) {
251 return $rc->getAttribute( 'rc_bot' );
255 'name' => 'hidehumans',
256 'label' => 'rcfilters-filter-humans-label',
257 'description' => 'rcfilters-filter-humans-description',
259 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
260 &$query_options, &$join_conds
262 $conds[] = 'rc_bot = 1';
264 'cssClassSuffix' => 'human',
265 'isRowApplicableCallable' => function ( $ctx, $rc ) {
266 return !$rc->getAttribute( 'rc_bot' );
272 // reviewStatus (conditional)
275 'name' => 'significance',
276 'title' => 'rcfilters-filtergroup-significance',
277 'class' => ChangesListBooleanFilterGroup
::class,
281 'name' => 'hideminor',
282 'label' => 'rcfilters-filter-minor-label',
283 'description' => 'rcfilters-filter-minor-description',
284 // rcshowhideminor-show, rcshowhideminor-hide,
286 'showHideSuffix' => 'showhideminor',
288 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
289 &$query_options, &$join_conds
291 $conds[] = 'rc_minor = 0';
293 'cssClassSuffix' => 'minor',
294 'isRowApplicableCallable' => function ( $ctx, $rc ) {
295 return $rc->getAttribute( 'rc_minor' );
299 'name' => 'hidemajor',
300 'label' => 'rcfilters-filter-major-label',
301 'description' => 'rcfilters-filter-major-description',
303 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
304 &$query_options, &$join_conds
306 $conds[] = 'rc_minor = 1';
308 'cssClassSuffix' => 'major',
309 'isRowApplicableCallable' => function ( $ctx, $rc ) {
310 return !$rc->getAttribute( 'rc_minor' );
317 'name' => 'lastRevision',
318 'title' => 'rcfilters-filtergroup-lastRevision',
319 'class' => ChangesListBooleanFilterGroup
::class,
323 'name' => 'hidelastrevision',
324 'label' => 'rcfilters-filter-lastrevision-label',
325 'description' => 'rcfilters-filter-lastrevision-description',
327 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
328 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
329 $conds[] = $dbr->makeList(
331 'rc_this_oldid <> page_latest',
332 'rc_type' => $nonRevisionTypes,
337 'cssClassSuffix' => 'last',
338 'isRowApplicableCallable' => function ( $ctx, $rc ) {
339 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
343 'name' => 'hidepreviousrevisions',
344 'label' => 'rcfilters-filter-previousrevision-label',
345 'description' => 'rcfilters-filter-previousrevision-description',
347 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
348 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
349 $conds[] = $dbr->makeList(
351 'rc_this_oldid = page_latest',
352 'rc_type' => $nonRevisionTypes,
357 'cssClassSuffix' => 'previous',
358 'isRowApplicableCallable' => function ( $ctx, $rc ) {
359 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
365 // With extensions, there can be change types that will not be hidden by any of these.
367 'name' => 'changeType',
368 'title' => 'rcfilters-filtergroup-changetype',
369 'class' => ChangesListBooleanFilterGroup
::class,
373 'name' => 'hidepageedits',
374 'label' => 'rcfilters-filter-pageedits-label',
375 'description' => 'rcfilters-filter-pageedits-description',
378 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
379 &$query_options, &$join_conds
381 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
383 'cssClassSuffix' => 'src-mw-edit',
384 'isRowApplicableCallable' => function ( $ctx, $rc ) {
385 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
389 'name' => 'hidenewpages',
390 'label' => 'rcfilters-filter-newpages-label',
391 'description' => 'rcfilters-filter-newpages-description',
394 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
395 &$query_options, &$join_conds
397 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
399 'cssClassSuffix' => 'src-mw-new',
400 'isRowApplicableCallable' => function ( $ctx, $rc ) {
401 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
405 // hidecategorization
409 'label' => 'rcfilters-filter-logactions-label',
410 'description' => 'rcfilters-filter-logactions-description',
413 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
414 &$query_options, &$join_conds
416 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
418 'cssClassSuffix' => 'src-mw-log',
419 'isRowApplicableCallable' => function ( $ctx, $rc ) {
420 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
428 $this->reviewStatusFilterGroupDefinition
= [
430 'name' => 'reviewStatus',
431 'title' => 'rcfilters-filtergroup-reviewstatus',
432 'class' => ChangesListBooleanFilterGroup
::class,
436 'name' => 'hidepatrolled',
437 'label' => 'rcfilters-filter-patrolled-label',
438 'description' => 'rcfilters-filter-patrolled-description',
439 // rcshowhidepatr-show, rcshowhidepatr-hide
441 'showHideSuffix' => 'showhidepatr',
443 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
444 &$query_options, &$join_conds
446 $conds[] = 'rc_patrolled = 0';
448 'cssClassSuffix' => 'patrolled',
449 'isRowApplicableCallable' => function ( $ctx, $rc ) {
450 return $rc->getAttribute( 'rc_patrolled' );
454 'name' => 'hideunpatrolled',
455 'label' => 'rcfilters-filter-unpatrolled-label',
456 'description' => 'rcfilters-filter-unpatrolled-description',
458 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
459 &$query_options, &$join_conds
461 $conds[] = 'rc_patrolled = 1';
463 'cssClassSuffix' => 'unpatrolled',
464 'isRowApplicableCallable' => function ( $ctx, $rc ) {
465 return !$rc->getAttribute( 'rc_patrolled' );
472 $this->hideCategorizationFilterDefinition
= [
473 'name' => 'hidecategorization',
474 'label' => 'rcfilters-filter-categorization-label',
475 'description' => 'rcfilters-filter-categorization-description',
476 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
477 // wlshowhidecategorization
478 'showHideSuffix' => 'showhidecategorization',
481 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
482 &$query_options, &$join_conds
484 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
486 'cssClassSuffix' => 'src-mw-categorize',
487 'isRowApplicableCallable' => function ( $ctx, $rc ) {
488 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
494 * Check if filters are in conflict and guaranteed to return no results.
498 protected function areFiltersInConflict() {
499 $opts = $this->getOptions();
500 /** @var ChangesListFilterGroup $group */
501 foreach ( $this->getFilterGroups() as $group ) {
502 if ( $group->getConflictingGroups() ) {
505 " specifies conflicts with other groups but these are not supported yet."
509 /** @var ChangesListFilter $conflictingFilter */
510 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
511 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
516 /** @var ChangesListFilter $filter */
517 foreach ( $group->getFilters() as $filter ) {
518 /** @var ChangesListFilter $conflictingFilter */
519 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
521 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
522 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
536 * Main execution point
538 * @param string $subpage
540 public function execute( $subpage ) {
541 $this->rcSubpage
= $subpage;
543 $this->considerActionsForDefaultSavedQuery();
545 $rows = $this->getRows();
546 $opts = $this->getOptions();
547 if ( $rows === false ) {
548 $rows = new FakeResultWrapper( [] );
551 // Used by Structured UI app to get results without MW chrome
552 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
553 $this->getOutput()->setArticleBodyOnly( true );
556 // Used by "live update" and "view newest" to check
557 // if there's new changes with minimal data transfer
558 if ( $this->getRequest()->getBool( 'peek' ) ) {
559 $code = $rows->numRows() > 0 ?
200 : 204;
560 $this->getOutput()->setStatusCode( $code );
564 $batch = new LinkBatch
;
565 foreach ( $rows as $row ) {
566 $batch->add( NS_USER
, $row->rc_user_text
);
567 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
568 $batch->add( $row->rc_namespace
, $row->rc_title
);
569 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
570 $formatter = LogFormatter
::newFromRow( $row );
571 foreach ( $formatter->getPreloadTitles() as $title ) {
572 $batch->addObj( $title );
579 $this->outputHeader();
581 $this->webOutput( $rows, $opts );
585 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
586 // Clean up any bad page entries for titles showing up in RC
587 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
589 LoggerFactory
::getInstance( 'objectcache' )
593 $this->includeRcFiltersApp();
597 * Check whether or not the page should load defaults, and if so, whether
598 * a default saved query is relevant to be redirected to. If it is relevant,
599 * redirect properly with all necessary query parameters.
601 protected function considerActionsForDefaultSavedQuery() {
602 if ( !$this->isStructuredFilterUiEnabled() ) {
606 $knownParams = call_user_func_array(
607 [ $this->getRequest(), 'getValues' ],
608 array_keys( $this->getOptions()->getAllValues() )
611 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
612 // we need to exclude several parameters we know should not be counted towards preventing
613 // the loading of defaults.
614 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
615 $knownParams = array_diff_key( $knownParams, $excludedParams );
618 // If there are NO known parameters in the URL request
619 // (that are not excluded) then we need to check into loading
620 // the default saved query
621 count( $knownParams ) === 0
623 // Get the saved queries data and parse it
624 $savedQueries = FormatJson
::decode(
625 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
629 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
630 // Only load queries that are 'version' 2, since those
631 // have parameter representation
632 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
633 $savedQueryDefaultID = $savedQueries[ 'default' ];
634 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
636 // Build the entire parameter list
637 $query = array_merge(
638 $defaultQuery[ 'params' ],
639 $defaultQuery[ 'highlights' ],
644 // Add to the query any parameters that we may have ignored before
645 // but are still valid and requested in the URL
646 $query = array_merge( $this->getRequest()->getValues(), $query );
647 unset( $query[ 'title' ] );
648 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
650 // There's a default, but the version is not 2, and the server can't
651 // actually recognize the query itself. This happens if it is before
652 // the conversion, so we need to tell the UI to reload saved query as
653 // it does the conversion to version 2
654 $this->getOutput()->addJsConfigVars(
655 'wgStructuredChangeFiltersDefaultSavedQueryExists',
659 // Add the class that tells the frontend it is still loading
661 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
668 * Include the modules and configuration for the RCFilters app.
669 * Conditional on the user having the feature enabled.
671 * If it is disabled, add a <body> class marking that
673 protected function includeRcFiltersApp() {
674 $out = $this->getOutput();
675 if ( $this->isStructuredFilterUiEnabled() ) {
676 $jsData = $this->getStructuredFilterJsData();
679 foreach ( $jsData['messageKeys'] as $key ) {
680 $messages[$key] = $this->msg( $key )->plain();
683 $out->addBodyClasses( 'mw-rcfilters-enabled' );
686 ResourceLoader
::makeInlineScript(
687 ResourceLoader
::makeMessageSetScript( $messages )
691 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
693 $out->addJsConfigVars(
694 'wgRCFiltersChangeTags',
695 $this->getChangeTagList()
697 $out->addJsConfigVars(
698 'StructuredChangeFiltersDisplayConfig',
700 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
701 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
702 'limitDefault' => $this->getDefaultLimit(),
703 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
704 'daysDefault' => $this->getDefaultDays(),
708 $out->addJsConfigVars(
709 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
710 static::$savedQueriesPreferenceName
713 $out->addJsConfigVars(
714 'StructuredChangeFiltersLiveUpdatePollingRate',
715 $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
718 $out->addBodyClasses( 'mw-rcfilters-disabled' );
723 * Fetch the change tags list for the front end
725 * @return Array Tag data
727 protected function getChangeTagList() {
728 $cache = ObjectCache
::getMainWANInstance();
729 $context = $this->getContext();
730 return $cache->getWithSetCallback(
731 $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ),
732 $cache::TTL_MINUTE
* 10,
733 function () use ( $context ) {
734 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
735 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
737 // Hit counts disabled for perf reasons, see T169997
739 $tagStats = ChangeTags::tagUsageStatistics();
740 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
743 arsort( $tagHitCounts );
745 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
747 // Build the list and data
749 foreach ( $tagHitCounts as $tagName => $hits ) {
751 // Only get active tags
752 isset( $explicitlyDefinedTags[ $tagName ] ) ||
753 isset( $softwareActivatedTags[ $tagName ] )
756 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $context );
760 'label' => Sanitizer
::stripAllTags(
761 ChangeTags
::tagDescription( $tagName, $context )
763 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
764 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
770 // Instead of sorting by hit count (disabled, see above), sort by display name
771 usort( $result, function ( $a, $b ) {
772 return strcasecmp( $a['label'], $b['label'] );
784 * Add the "no results" message to the output
786 protected function outputNoResults() {
787 $this->getOutput()->addHTML(
788 '<div class="mw-changeslist-empty">' .
789 $this->msg( 'recentchanges-noresult' )->parse() .
795 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
797 * @return bool|ResultWrapper Result or false
799 public function getRows() {
800 $opts = $this->getOptions();
807 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
809 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
813 * Get the current FormOptions for this request
815 * @return FormOptions
817 public function getOptions() {
818 if ( $this->rcOptions
=== null ) {
819 $this->rcOptions
= $this->setup( $this->rcSubpage
);
822 return $this->rcOptions
;
826 * Register all filters and their groups (including those from hooks), plus handle
827 * conflicts and defaults.
829 * You might want to customize these in the same method, in subclasses. You can
830 * call getFilterGroup to access a group, and (on the group) getFilter to access a
831 * filter, then make necessary modfications to the filter or group (e.g. with
834 protected function registerFilters() {
835 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
837 // Make sure this is not being transcluded (we don't want to show this
838 // information to all users just because the user that saves the edit can
839 // patrol or is logged in)
840 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
841 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
844 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
846 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
847 $transformedHideCategorizationDef = $this->transformFilterDefinition(
848 $this->hideCategorizationFilterDefinition
851 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
853 $hideCategorization = new ChangesListBooleanFilter(
854 $transformedHideCategorizationDef
858 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
860 $unstructuredGroupDefinition =
861 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
862 $this->getCustomFilters()
864 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
866 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
867 $registered = $userExperienceLevel->getFilter( 'registered' );
868 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
869 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
870 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
872 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
873 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
874 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
876 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
877 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
879 // categoryFilter is conditional; see registerFilters
880 if ( $categoryFilter !== null ) {
881 $hideMinorFilter->conflictsWith(
883 'rcfilters-hideminor-conflicts-typeofchange-global',
884 'rcfilters-hideminor-conflicts-typeofchange',
885 'rcfilters-typeofchange-conflicts-hideminor'
888 $hideMinorFilter->conflictsWith(
890 'rcfilters-hideminor-conflicts-typeofchange-global',
891 'rcfilters-hideminor-conflicts-typeofchange',
892 'rcfilters-typeofchange-conflicts-hideminor'
894 $hideMinorFilter->conflictsWith(
896 'rcfilters-hideminor-conflicts-typeofchange-global',
897 'rcfilters-hideminor-conflicts-typeofchange',
898 'rcfilters-typeofchange-conflicts-hideminor'
903 * Transforms filter definition to prepare it for constructor.
905 * See overrides of this method as well.
907 * @param array $filterDefinition Original filter definition
909 * @return array Transformed definition
911 protected function transformFilterDefinition( array $filterDefinition ) {
912 return $filterDefinition;
916 * Register filters from a definition object
918 * Array specifying groups and their filters; see Filter and
919 * ChangesListFilterGroup constructors.
921 * There is light processing to simplify core maintenance.
922 * @param array $definition
924 protected function registerFiltersFromDefinitions( array $definition ) {
925 $autoFillPriority = -1;
926 foreach ( $definition as $groupDefinition ) {
927 if ( !isset( $groupDefinition['priority'] ) ) {
928 $groupDefinition['priority'] = $autoFillPriority;
930 // If it's explicitly specified, start over the auto-fill
931 $autoFillPriority = $groupDefinition['priority'];
936 $className = $groupDefinition['class'];
937 unset( $groupDefinition['class'] );
939 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
940 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
943 $this->registerFilterGroup( new $className( $groupDefinition ) );
948 * Get filter group definition from legacy custom filters
950 * @param array $customFilters Custom filters from legacy hooks
951 * @return array Group definition
953 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
954 // Special internal unstructured group
955 $unstructuredGroupDefinition = [
956 'name' => 'unstructured',
957 'class' => ChangesListBooleanFilterGroup
::class,
958 'priority' => -1, // Won't display in structured
962 foreach ( $customFilters as $name => $params ) {
963 $unstructuredGroupDefinition['filters'][] = [
965 'showHide' => $params['msg'],
966 'default' => $params['default'],
970 return $unstructuredGroupDefinition;
974 * Register all the filters, including legacy hook-driven ones.
975 * Then create a FormOptions object with options as specified by the user
977 * @param array $parameters
979 * @return FormOptions
981 public function setup( $parameters ) {
982 $this->registerFilters();
984 $opts = $this->getDefaultOptions();
986 $opts = $this->fetchOptionsFromRequest( $opts );
988 // Give precedence to subpage syntax
989 if ( $parameters !== null ) {
990 $this->parseParameters( $parameters, $opts );
993 $this->validateOptions( $opts );
999 * Get a FormOptions object containing the default options. By default, returns
1000 * some basic options. The filters listed explicitly here are overriden in this
1001 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1002 * and more) are structured. Structured filters are overriden in registerFilters.
1005 * @return FormOptions
1007 public function getDefaultOptions() {
1008 $opts = new FormOptions();
1009 $structuredUI = $this->isStructuredFilterUiEnabled();
1010 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1011 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1014 /** @var ChangesListFilterGroup $filterGroup */
1015 foreach ( $this->filterGroups
as $filterGroup ) {
1016 // URL parameters can be per-group, like 'userExpLevel',
1017 // or per-filter, like 'hideminor'.
1018 if ( $filterGroup->isPerGroupRequestParameter() ) {
1019 $opts->add( $filterGroup->getName(), $useDefaults ?
$filterGroup->getDefault() : '' );
1021 /** @var ChangesListBooleanFilter $filter */
1022 foreach ( $filterGroup->getFilters() as $filter ) {
1023 $opts->add( $filter->getName(), $useDefaults ?
$filter->getDefault( $structuredUI ) : false );
1028 $opts->add( 'namespace', '', FormOptions
::STRING );
1029 $opts->add( 'invert', false );
1030 $opts->add( 'associated', false );
1031 $opts->add( 'urlversion', 1 );
1032 $opts->add( 'tagfilter', '' );
1034 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
1035 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
1037 $opts->add( 'from', '' );
1043 * Register a structured changes list filter group
1045 * @param ChangesListFilterGroup $group
1047 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
1048 $groupName = $group->getName();
1050 $this->filterGroups
[$groupName] = $group;
1054 * Gets the currently registered filters groups
1056 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1058 protected function getFilterGroups() {
1059 return $this->filterGroups
;
1063 * Gets a specified ChangesListFilterGroup by name
1065 * @param string $groupName Name of group
1067 * @return ChangesListFilterGroup|null Group, or null if not registered
1069 public function getFilterGroup( $groupName ) {
1070 return isset( $this->filterGroups
[$groupName] ) ?
1071 $this->filterGroups
[$groupName] :
1075 // Currently, this intentionally only includes filters that display
1076 // in the structured UI. This can be changed easily, though, if we want
1077 // to include data on filters that use the unstructured UI. messageKeys is a
1078 // special top-level value, with the value being an array of the message keys to
1079 // send to the client.
1081 * Gets structured filter information needed by JS
1083 * @return array Associative array
1084 * * array $return['groups'] Group data
1085 * * array $return['messageKeys'] Array of message keys
1087 public function getStructuredFilterJsData() {
1090 'messageKeys' => [],
1093 usort( $this->filterGroups
, function ( $a, $b ) {
1094 return $b->getPriority() - $a->getPriority();
1097 foreach ( $this->filterGroups
as $groupName => $group ) {
1098 $groupOutput = $group->getJsData( $this );
1099 if ( $groupOutput !== null ) {
1100 $output['messageKeys'] = array_merge(
1101 $output['messageKeys'],
1102 $groupOutput['messageKeys']
1105 unset( $groupOutput['messageKeys'] );
1106 $output['groups'][] = $groupOutput;
1114 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
1117 * @return array Map of filter URL param names to properties (msg/default)
1119 protected function getCustomFilters() {
1120 if ( $this->customFilters
=== null ) {
1121 $this->customFilters
= [];
1122 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
1125 return $this->customFilters
;
1129 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1131 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1133 * @param FormOptions $opts
1134 * @return FormOptions
1136 protected function fetchOptionsFromRequest( $opts ) {
1137 $opts->fetchValuesFromRequest( $this->getRequest() );
1143 * Process $par and put options found in $opts. Used when including the page.
1145 * @param string $par
1146 * @param FormOptions $opts
1148 public function parseParameters( $par, FormOptions
$opts ) {
1149 $stringParameterNameSet = [];
1150 $hideParameterNameSet = [];
1152 // URL parameters can be per-group, like 'userExpLevel',
1153 // or per-filter, like 'hideminor'.
1155 foreach ( $this->filterGroups
as $filterGroup ) {
1156 if ( $filterGroup->isPerGroupRequestParameter() ) {
1157 $stringParameterNameSet[$filterGroup->getName()] = true;
1158 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup
::TYPE
) {
1159 foreach ( $filterGroup->getFilters() as $filter ) {
1160 $hideParameterNameSet[$filter->getName()] = true;
1165 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1166 foreach ( $bits as $bit ) {
1168 if ( isset( $hideParameterNameSet[$bit] ) ) {
1169 // hidefoo => hidefoo=true
1171 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1172 // foo => hidefoo=false
1173 $opts["hide$bit"] = false;
1174 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1175 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1176 $opts[$m[1]] = $m[2];
1183 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1185 * @param FormOptions $opts
1187 public function validateOptions( FormOptions
$opts ) {
1188 if ( $this->fixContradictoryOptions( $opts ) ) {
1189 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1190 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1193 $opts->validateIntBounds( 'limit', 0, 5000 );
1194 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1198 * Fix invalid options by resetting pairs that should never appear together.
1200 * @param FormOptions $opts
1201 * @return bool True if any option was reset
1203 private function fixContradictoryOptions( FormOptions
$opts ) {
1204 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1206 foreach ( $this->filterGroups
as $filterGroup ) {
1207 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1208 $filters = $filterGroup->getFilters();
1210 if ( count( $filters ) === 1 ) {
1211 // legacy boolean filters should not be considered
1215 $allInGroupEnabled = array_reduce(
1217 function ( $carry, $filter ) use ( $opts ) {
1218 return $carry && $opts[ $filter->getName() ];
1220 /* initialValue */ count( $filters ) > 0
1223 if ( $allInGroupEnabled ) {
1224 foreach ( $filters as $filter ) {
1225 $opts[ $filter->getName() ] = false;
1237 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1240 * This is deprecated and may be removed.
1242 * @param FormOptions $opts
1243 * @return bool True if this change was mode
1245 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1246 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1247 $opts->reset( 'hideanons' );
1248 if ( !$opts['hidebots'] ) {
1249 $opts->reset( 'hideliu' );
1250 $opts['hidehumans'] = 1;
1260 * Convert parameters values from true/false to 1/0
1261 * so they are not omitted by wfArrayToCgi()
1264 * @param array $params
1267 protected function convertParamsForLink( $params ) {
1268 foreach ( $params as &$value ) {
1269 if ( $value === false ) {
1278 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1279 * the user requested.
1281 * @param array &$tables Array of tables; see IDatabase::select $table
1282 * @param array &$fields Array of fields; see IDatabase::select $vars
1283 * @param array &$conds Array of conditions; see IDatabase::select $conds
1284 * @param array &$query_options Array of query options; see IDatabase::select $options
1285 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1286 * @param FormOptions $opts
1288 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1289 &$join_conds, FormOptions
$opts
1291 $dbr = $this->getDB();
1292 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1294 foreach ( $this->filterGroups
as $filterGroup ) {
1295 // URL parameters can be per-group, like 'userExpLevel',
1296 // or per-filter, like 'hideminor'.
1297 if ( $filterGroup->isPerGroupRequestParameter() ) {
1298 if ( $filterGroup->isActive( $isStructuredUI ) ) {
1299 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1300 $query_options, $join_conds, $opts[$filterGroup->getName()] );
1303 foreach ( $filterGroup->getFilters() as $filter ) {
1304 if ( $filter->isActive( $opts, $isStructuredUI ) ) {
1305 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1306 $query_options, $join_conds );
1312 // Namespace filtering
1313 if ( $opts[ 'namespace' ] !== '' ) {
1314 $namespaces = explode( ';', $opts[ 'namespace' ] );
1316 if ( $opts[ 'associated' ] ) {
1317 $associatedNamespaces = array_map(
1319 return MWNamespace
::getAssociated( $ns );
1323 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1326 if ( count( $namespaces ) === 1 ) {
1327 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1328 $value = $dbr->addQuotes( reset( $namespaces ) );
1330 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1331 sort( $namespaces );
1332 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1334 $conds[] = "rc_namespace $operator $value";
1338 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1339 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1341 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1342 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
1343 $cutoff = $dbr->timestamp( $opts['from'] );
1345 $opts->reset( 'from' );
1348 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1354 * @param array $tables Array of tables; see IDatabase::select $table
1355 * @param array $fields Array of fields; see IDatabase::select $vars
1356 * @param array $conds Array of conditions; see IDatabase::select $conds
1357 * @param array $query_options Array of query options; see IDatabase::select $options
1358 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1359 * @param FormOptions $opts
1360 * @return bool|ResultWrapper Result or false
1362 protected function doMainQuery( $tables, $fields, $conds,
1363 $query_options, $join_conds, FormOptions
$opts
1365 $tables[] = 'recentchanges';
1366 $fields = array_merge( RecentChange
::selectFields(), $fields );
1368 ChangeTags
::modifyDisplayQuery(
1377 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1383 $dbr = $this->getDB();
1385 return $dbr->select(
1395 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1396 &$query_options, &$join_conds, $opts
1399 'ChangesListSpecialPageQuery',
1400 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1405 * Return a IDatabase object for reading
1409 protected function getDB() {
1410 return wfGetDB( DB_REPLICA
);
1414 * Send output to the OutputPage object, only called if not used feeds
1416 * @param ResultWrapper $rows Database rows
1417 * @param FormOptions $opts
1419 public function webOutput( $rows, $opts ) {
1420 if ( !$this->including() ) {
1421 $this->outputFeedLinks();
1422 $this->doHeader( $opts, $rows->numRows() );
1425 $this->outputChangesList( $rows, $opts );
1429 * Output feed links.
1431 public function outputFeedLinks() {
1432 // nothing by default
1436 * Build and output the actual changes list.
1438 * @param ResultWrapper $rows Database rows
1439 * @param FormOptions $opts
1441 abstract public function outputChangesList( $rows, $opts );
1444 * Set the text to be displayed above the changes
1446 * @param FormOptions $opts
1447 * @param int $numRows Number of rows in the result to show after this header
1449 public function doHeader( $opts, $numRows ) {
1450 $this->setTopText( $opts );
1452 // @todo Lots of stuff should be done here.
1454 $this->setBottomText( $opts );
1458 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1459 * or similar methods to print the text.
1461 * @param FormOptions $opts
1463 public function setTopText( FormOptions
$opts ) {
1464 // nothing by default
1468 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1469 * or similar methods to print the text.
1471 * @param FormOptions $opts
1473 public function setBottomText( FormOptions
$opts ) {
1474 // nothing by default
1478 * Get options to be displayed in a form
1479 * @todo This should handle options returned by getDefaultOptions().
1480 * @todo Not called by anything in this class (but is in subclasses), should be
1481 * called by something… doHeader() maybe?
1483 * @param FormOptions $opts
1486 public function getExtraOptions( $opts ) {
1491 * Return the legend displayed within the fieldset
1495 public function makeLegend() {
1496 $context = $this->getContext();
1497 $user = $context->getUser();
1498 # The legend showing what the letters and stuff mean
1499 $legend = Html
::openElement( 'dl' ) . "\n";
1500 # Iterates through them and gets the messages for both letter and tooltip
1501 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1502 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1503 unset( $legendItems['unpatrolled'] );
1505 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1506 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1507 $letter = $item['letter'];
1508 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1510 $legend .= Html
::element( 'dt',
1511 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1513 Html
::rawElement( 'dd',
1514 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1515 $context->msg( $label )->parse()
1519 $legend .= Html
::rawElement( 'dt',
1520 [ 'class' => 'mw-plusminus-pos' ],
1521 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1523 $legend .= Html
::element(
1525 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1526 $context->msg( 'recentchanges-label-plusminus' )->text()
1528 $legend .= Html
::closeElement( 'dl' ) . "\n";
1530 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1531 $context->msg( 'rcfilters-legend-heading' )->parse() :
1532 $context->msg( 'recentchanges-legend-heading' )->parse();
1535 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1536 $collapsedClass = $collapsedState === 'collapsed' ?
' mw-collapsed' : '';
1538 '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
1540 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1547 * Add page-specific modules.
1549 protected function addModules() {
1550 $out = $this->getOutput();
1551 // Styles and behavior for the legend box (see makeLegend())
1552 $out->addModuleStyles( [
1553 'mediawiki.special.changeslist.legend',
1554 'mediawiki.special.changeslist',
1556 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1558 if ( $this->isStructuredFilterUiEnabled() ) {
1559 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1560 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1564 protected function getGroupName() {
1569 * Filter on users' experience levels; this will not be called if nothing is
1572 * @param string $specialPageClassName Class name of current special page
1573 * @param IContextSource $context Context, for e.g. user
1574 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1575 * @param array &$tables Array of tables; see IDatabase::select $table
1576 * @param array &$fields Array of fields; see IDatabase::select $vars
1577 * @param array &$conds Array of conditions; see IDatabase::select $conds
1578 * @param array &$query_options Array of query options; see IDatabase::select $options
1579 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1580 * @param array $selectedExpLevels The allowed active values, sorted
1581 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1584 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1585 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1587 global $wgLearnerEdits,
1588 $wgExperiencedUserEdits,
1589 $wgLearnerMemberSince,
1590 $wgExperiencedUserMemberSince;
1594 // If all levels are selected, don't filter
1595 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1599 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1601 in_array( 'registered', $selectedExpLevels ) &&
1602 in_array( 'unregistered', $selectedExpLevels )
1607 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1609 in_array( 'registered', $selectedExpLevels ) &&
1610 !in_array( 'unregistered', $selectedExpLevels )
1612 $conds[] = 'rc_user != 0';
1616 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1617 $conds[] = 'rc_user = 0';
1622 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1627 $secondsPerDay = 86400;
1628 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1629 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1631 $aboveNewcomer = $dbr->makeList(
1633 'user_editcount >= ' . intval( $wgLearnerEdits ),
1634 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1639 $aboveLearner = $dbr->makeList(
1641 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1642 'user_registration <= ' .
1643 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1650 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1651 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1652 $conditions[] = 'rc_user = 0';
1655 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1656 $conditions[] = "NOT ( $aboveNewcomer )";
1657 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1658 $conditions[] = $dbr->makeList(
1659 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1662 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1663 $conditions[] = $aboveLearner;
1664 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1665 $conditions[] = "NOT ( $aboveLearner )";
1666 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1667 $conditions[] = $dbr->makeList(
1668 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1671 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1672 $conditions[] = $aboveNewcomer;
1673 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1674 $conditions[] = 'rc_user != 0';
1677 if ( count( $conditions ) > 1 ) {
1678 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1679 } elseif ( count( $conditions ) === 1 ) {
1680 $conds[] = reset( $conditions );
1685 * Check whether the structured filter UI is enabled
1689 public function isStructuredFilterUiEnabled() {
1690 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1694 if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
1695 return !$this->getUser()->getOption( 'rcenhancedfilters-disable' );
1697 return $this->getUser()->getOption( 'rcenhancedfilters' );
1702 * Check whether the structured filter UI is enabled by default (regardless of
1703 * this particular user's setting)
1707 public function isStructuredFilterUiEnabledByDefault() {
1708 if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
1709 return !$this->getUser()->getDefaultOption( 'rcenhancedfilters-disable' );
1711 return $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
1715 abstract function getDefaultLimit();
1718 * Get the default value of the number of days to display when loading
1720 * Supports fractional values, and should be cast to a float.
1724 abstract function getDefaultDays();