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;
45 /** @var FormOptions */
49 protected $customFilters;
51 // Order of both groups and filters is significant; first is top-most priority,
52 // descending from there.
53 // 'showHideSuffix' is a shortcut to and avoid spelling out
54 // details specific to subclasses here.
56 * Definition information for the filters and their groups
58 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
59 * However, priority is dynamically added for the core groups, to ease maintenance.
61 * Groups are displayed to the user in the structured UI. However, if necessary,
62 * all of the filters in a group can be configured to only display on the
63 * unstuctured UI, in which case you don't need a group title. This is done in
64 * getFilterGroupDefinitionFromLegacyCustomFilters, for example.
66 * @var array $filterGroupDefinitions
68 private $filterGroupDefinitions;
70 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
71 // that is registered conditionally.
72 private $reviewStatusFilterGroupDefinition;
74 // Single filter registered conditionally
75 private $hideCategorizationFilterDefinition;
78 * Filter groups, and their contained filters
79 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
81 * @var array $filterGroups
83 protected $filterGroups = [];
85 public function __construct( $name, $restriction ) {
86 parent
::__construct( $name, $restriction );
88 $nonRevisionTypes = [ RC_LOG
];
89 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
91 $this->filterGroupDefinitions
= [
93 'name' => 'registration',
94 'title' => 'rcfilters-filtergroup-registration',
95 'class' => ChangesListBooleanFilterGroup
::class,
99 // rcshowhideliu-show, rcshowhideliu-hide,
101 'showHideSuffix' => 'showhideliu',
103 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
104 &$query_options, &$join_conds
106 $conds[] = 'rc_user = 0';
108 'isReplacedInStructuredUi' => true,
112 'name' => 'hideanons',
113 // rcshowhideanons-show, rcshowhideanons-hide,
115 'showHideSuffix' => 'showhideanons',
117 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
118 &$query_options, &$join_conds
120 $conds[] = 'rc_user != 0';
122 'isReplacedInStructuredUi' => true,
128 'name' => 'userExpLevel',
129 'title' => 'rcfilters-filtergroup-userExpLevel',
130 'class' => ChangesListStringOptionsFilterGroup
::class,
131 'isFullCoverage' => true,
134 'name' => 'unregistered',
135 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
136 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
137 'cssClassSuffix' => 'user-unregistered',
138 'isRowApplicableCallable' => function ( $ctx, $rc ) {
139 return !$rc->getAttribute( 'rc_user' );
143 'name' => 'registered',
144 'label' => 'rcfilters-filter-user-experience-level-registered-label',
145 'description' => 'rcfilters-filter-user-experience-level-registered-description',
146 'cssClassSuffix' => 'user-registered',
147 'isRowApplicableCallable' => function ( $ctx, $rc ) {
148 return $rc->getAttribute( 'rc_user' );
152 'name' => 'newcomer',
153 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
154 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
155 'cssClassSuffix' => 'user-newcomer',
156 'isRowApplicableCallable' => function ( $ctx, $rc ) {
157 $performer = $rc->getPerformer();
158 return $performer && $performer->isLoggedIn() &&
159 $performer->getExperienceLevel() === 'newcomer';
164 'label' => 'rcfilters-filter-user-experience-level-learner-label',
165 'description' => 'rcfilters-filter-user-experience-level-learner-description',
166 'cssClassSuffix' => 'user-learner',
167 'isRowApplicableCallable' => function ( $ctx, $rc ) {
168 $performer = $rc->getPerformer();
169 return $performer && $performer->isLoggedIn() &&
170 $performer->getExperienceLevel() === 'learner';
174 'name' => 'experienced',
175 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
176 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
177 'cssClassSuffix' => 'user-experienced',
178 'isRowApplicableCallable' => function ( $ctx, $rc ) {
179 $performer = $rc->getPerformer();
180 return $performer && $performer->isLoggedIn() &&
181 $performer->getExperienceLevel() === 'experienced';
185 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
186 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
190 'name' => 'authorship',
191 'title' => 'rcfilters-filtergroup-authorship',
192 'class' => ChangesListBooleanFilterGroup
::class,
195 'name' => 'hidemyself',
196 'label' => 'rcfilters-filter-editsbyself-label',
197 'description' => 'rcfilters-filter-editsbyself-description',
198 // rcshowhidemine-show, rcshowhidemine-hide,
200 'showHideSuffix' => 'showhidemine',
202 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
203 &$query_options, &$join_conds
205 $user = $ctx->getUser();
206 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
208 'cssClassSuffix' => 'self',
209 'isRowApplicableCallable' => function ( $ctx, $rc ) {
210 return $ctx->getUser()->equals( $rc->getPerformer() );
214 'name' => 'hidebyothers',
215 'label' => 'rcfilters-filter-editsbyother-label',
216 'description' => 'rcfilters-filter-editsbyother-description',
218 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
219 &$query_options, &$join_conds
221 $user = $ctx->getUser();
222 $conds[] = 'rc_user_text = ' . $dbr->addQuotes( $user->getName() );
224 'cssClassSuffix' => 'others',
225 'isRowApplicableCallable' => function ( $ctx, $rc ) {
226 return !$ctx->getUser()->equals( $rc->getPerformer() );
233 'name' => 'automated',
234 'title' => 'rcfilters-filtergroup-automated',
235 'class' => ChangesListBooleanFilterGroup
::class,
238 'name' => 'hidebots',
239 'label' => 'rcfilters-filter-bots-label',
240 'description' => 'rcfilters-filter-bots-description',
241 // rcshowhidebots-show, rcshowhidebots-hide,
243 'showHideSuffix' => 'showhidebots',
245 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
246 &$query_options, &$join_conds
248 $conds[] = 'rc_bot = 0';
250 'cssClassSuffix' => 'bot',
251 'isRowApplicableCallable' => function ( $ctx, $rc ) {
252 return $rc->getAttribute( 'rc_bot' );
256 'name' => 'hidehumans',
257 'label' => 'rcfilters-filter-humans-label',
258 'description' => 'rcfilters-filter-humans-description',
260 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
261 &$query_options, &$join_conds
263 $conds[] = 'rc_bot = 1';
265 'cssClassSuffix' => 'human',
266 'isRowApplicableCallable' => function ( $ctx, $rc ) {
267 return !$rc->getAttribute( 'rc_bot' );
273 // reviewStatus (conditional)
276 'name' => 'significance',
277 'title' => 'rcfilters-filtergroup-significance',
278 'class' => ChangesListBooleanFilterGroup
::class,
282 'name' => 'hideminor',
283 'label' => 'rcfilters-filter-minor-label',
284 'description' => 'rcfilters-filter-minor-description',
285 // rcshowhideminor-show, rcshowhideminor-hide,
287 'showHideSuffix' => 'showhideminor',
289 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
290 &$query_options, &$join_conds
292 $conds[] = 'rc_minor = 0';
294 'cssClassSuffix' => 'minor',
295 'isRowApplicableCallable' => function ( $ctx, $rc ) {
296 return $rc->getAttribute( 'rc_minor' );
300 'name' => 'hidemajor',
301 'label' => 'rcfilters-filter-major-label',
302 'description' => 'rcfilters-filter-major-description',
304 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
305 &$query_options, &$join_conds
307 $conds[] = 'rc_minor = 1';
309 'cssClassSuffix' => 'major',
310 'isRowApplicableCallable' => function ( $ctx, $rc ) {
311 return !$rc->getAttribute( 'rc_minor' );
318 'name' => 'lastRevision',
319 'title' => 'rcfilters-filtergroup-lastRevision',
320 'class' => ChangesListBooleanFilterGroup
::class,
324 'name' => 'hidelastrevision',
325 'label' => 'rcfilters-filter-lastrevision-label',
326 'description' => 'rcfilters-filter-lastrevision-description',
328 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
329 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
330 $conds[] = $dbr->makeList(
332 'rc_this_oldid <> page_latest',
333 'rc_type' => $nonRevisionTypes,
338 'cssClassSuffix' => 'last',
339 'isRowApplicableCallable' => function ( $ctx, $rc ) {
340 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
344 'name' => 'hidepreviousrevisions',
345 'label' => 'rcfilters-filter-previousrevision-label',
346 'description' => 'rcfilters-filter-previousrevision-description',
348 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
349 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
350 $conds[] = $dbr->makeList(
352 'rc_this_oldid = page_latest',
353 'rc_type' => $nonRevisionTypes,
358 'cssClassSuffix' => 'previous',
359 'isRowApplicableCallable' => function ( $ctx, $rc ) {
360 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
366 // With extensions, there can be change types that will not be hidden by any of these.
368 'name' => 'changeType',
369 'title' => 'rcfilters-filtergroup-changetype',
370 'class' => ChangesListBooleanFilterGroup
::class,
374 'name' => 'hidepageedits',
375 'label' => 'rcfilters-filter-pageedits-label',
376 'description' => 'rcfilters-filter-pageedits-description',
379 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
380 &$query_options, &$join_conds
382 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
384 'cssClassSuffix' => 'src-mw-edit',
385 'isRowApplicableCallable' => function ( $ctx, $rc ) {
386 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
390 'name' => 'hidenewpages',
391 'label' => 'rcfilters-filter-newpages-label',
392 'description' => 'rcfilters-filter-newpages-description',
395 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
396 &$query_options, &$join_conds
398 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
400 'cssClassSuffix' => 'src-mw-new',
401 'isRowApplicableCallable' => function ( $ctx, $rc ) {
402 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
406 // hidecategorization
410 'label' => 'rcfilters-filter-logactions-label',
411 'description' => 'rcfilters-filter-logactions-description',
414 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
415 &$query_options, &$join_conds
417 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
419 'cssClassSuffix' => 'src-mw-log',
420 'isRowApplicableCallable' => function ( $ctx, $rc ) {
421 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
429 $this->reviewStatusFilterGroupDefinition
= [
431 'name' => 'reviewStatus',
432 'title' => 'rcfilters-filtergroup-reviewstatus',
433 'class' => ChangesListBooleanFilterGroup
::class,
437 'name' => 'hidepatrolled',
438 'label' => 'rcfilters-filter-patrolled-label',
439 'description' => 'rcfilters-filter-patrolled-description',
440 // rcshowhidepatr-show, rcshowhidepatr-hide
442 'showHideSuffix' => 'showhidepatr',
444 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
445 &$query_options, &$join_conds
447 $conds[] = 'rc_patrolled = 0';
449 'cssClassSuffix' => 'patrolled',
450 'isRowApplicableCallable' => function ( $ctx, $rc ) {
451 return $rc->getAttribute( 'rc_patrolled' );
455 'name' => 'hideunpatrolled',
456 'label' => 'rcfilters-filter-unpatrolled-label',
457 'description' => 'rcfilters-filter-unpatrolled-description',
459 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
460 &$query_options, &$join_conds
462 $conds[] = 'rc_patrolled = 1';
464 'cssClassSuffix' => 'unpatrolled',
465 'isRowApplicableCallable' => function ( $ctx, $rc ) {
466 return !$rc->getAttribute( 'rc_patrolled' );
473 $this->hideCategorizationFilterDefinition
= [
474 'name' => 'hidecategorization',
475 'label' => 'rcfilters-filter-categorization-label',
476 'description' => 'rcfilters-filter-categorization-description',
477 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
478 // wlshowhidecategorization
479 'showHideSuffix' => 'showhidecategorization',
482 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
483 &$query_options, &$join_conds
485 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
487 'cssClassSuffix' => 'src-mw-categorize',
488 'isRowApplicableCallable' => function ( $ctx, $rc ) {
489 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
495 * Check if filters are in conflict and guaranteed to return no results.
499 protected function areFiltersInConflict() {
500 $opts = $this->getOptions();
501 /** @var ChangesListFilterGroup $group */
502 foreach ( $this->getFilterGroups() as $group ) {
503 if ( $group->getConflictingGroups() ) {
506 " specifies conflicts with other groups but these are not supported yet."
510 /** @var ChangesListFilter $conflictingFilter */
511 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
512 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
517 /** @var ChangesListFilter $filter */
518 foreach ( $group->getFilters() as $filter ) {
519 /** @var ChangesListFilter $conflictingFilter */
520 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
522 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
523 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
537 * Main execution point
539 * @param string $subpage
541 public function execute( $subpage ) {
542 $this->rcSubpage
= $subpage;
544 $this->considerActionsForDefaultSavedQuery();
546 $opts = $this->getOptions();
548 $rows = $this->getRows();
549 if ( $rows === false ) {
550 $rows = new FakeResultWrapper( [] );
553 // Used by Structured UI app to get results without MW chrome
554 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
555 $this->getOutput()->setArticleBodyOnly( true );
558 // Used by "live update" and "view newest" to check
559 // if there's new changes with minimal data transfer
560 if ( $this->getRequest()->getBool( 'peek' ) ) {
561 $code = $rows->numRows() > 0 ?
200 : 204;
562 $this->getOutput()->setStatusCode( $code );
566 $batch = new LinkBatch
;
567 foreach ( $rows as $row ) {
568 $batch->add( NS_USER
, $row->rc_user_text
);
569 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
570 $batch->add( $row->rc_namespace
, $row->rc_title
);
571 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
572 $formatter = LogFormatter
::newFromRow( $row );
573 foreach ( $formatter->getPreloadTitles() as $title ) {
574 $batch->addObj( $title );
581 $this->outputHeader();
583 $this->webOutput( $rows, $opts );
586 } catch ( DBQueryTimeoutError
$timeoutException ) {
587 MWExceptionHandler
::logException( $timeoutException );
590 $this->outputHeader();
593 $this->getOutput()->setStatusCode( 500 );
594 $this->webOutputHeader( 0, $opts );
595 $this->outputTimeout();
598 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
599 // Clean up any bad page entries for titles showing up in RC
600 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
602 LoggerFactory
::getInstance( 'objectcache' )
606 $this->includeRcFiltersApp();
610 * Check whether or not the page should load defaults, and if so, whether
611 * a default saved query is relevant to be redirected to. If it is relevant,
612 * redirect properly with all necessary query parameters.
614 protected function considerActionsForDefaultSavedQuery() {
615 if ( !$this->isStructuredFilterUiEnabled() ) {
619 $knownParams = call_user_func_array(
620 [ $this->getRequest(), 'getValues' ],
621 array_keys( $this->getOptions()->getAllValues() )
624 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
625 // we need to exclude several parameters we know should not be counted towards preventing
626 // the loading of defaults.
627 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
628 $knownParams = array_diff_key( $knownParams, $excludedParams );
631 // If there are NO known parameters in the URL request
632 // (that are not excluded) then we need to check into loading
633 // the default saved query
634 count( $knownParams ) === 0
636 // Get the saved queries data and parse it
637 $savedQueries = FormatJson
::decode(
638 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
642 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
643 // Only load queries that are 'version' 2, since those
644 // have parameter representation
645 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
646 $savedQueryDefaultID = $savedQueries[ 'default' ];
647 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
649 // Build the entire parameter list
650 $query = array_merge(
651 $defaultQuery[ 'params' ],
652 $defaultQuery[ 'highlights' ],
657 // Add to the query any parameters that we may have ignored before
658 // but are still valid and requested in the URL
659 $query = array_merge( $this->getRequest()->getValues(), $query );
660 unset( $query[ 'title' ] );
661 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
663 // There's a default, but the version is not 2, and the server can't
664 // actually recognize the query itself. This happens if it is before
665 // the conversion, so we need to tell the UI to reload saved query as
666 // it does the conversion to version 2
667 $this->getOutput()->addJsConfigVars(
668 'wgStructuredChangeFiltersDefaultSavedQueryExists',
672 // Add the class that tells the frontend it is still loading
674 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
681 * Include the modules and configuration for the RCFilters app.
682 * Conditional on the user having the feature enabled.
684 * If it is disabled, add a <body> class marking that
686 protected function includeRcFiltersApp() {
687 $out = $this->getOutput();
688 if ( $this->isStructuredFilterUiEnabled() ) {
689 $jsData = $this->getStructuredFilterJsData();
692 foreach ( $jsData['messageKeys'] as $key ) {
693 $messages[$key] = $this->msg( $key )->plain();
696 $out->addBodyClasses( 'mw-rcfilters-enabled' );
699 ResourceLoader
::makeInlineScript(
700 ResourceLoader
::makeMessageSetScript( $messages )
704 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
706 $out->addJsConfigVars(
707 'wgRCFiltersChangeTags',
708 $this->getChangeTagList()
710 $out->addJsConfigVars(
711 'StructuredChangeFiltersDisplayConfig',
713 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
714 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
715 'limitDefault' => $this->getDefaultLimit(),
716 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
717 'daysDefault' => $this->getDefaultDays(),
721 $out->addJsConfigVars(
722 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
723 static::$savedQueriesPreferenceName
726 $out->addJsConfigVars(
727 'StructuredChangeFiltersLiveUpdatePollingRate',
728 $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
731 $out->addBodyClasses( 'mw-rcfilters-disabled' );
736 * Fetch the change tags list for the front end
738 * @return Array Tag data
740 protected function getChangeTagList() {
741 $cache = ObjectCache
::getMainWANInstance();
742 $context = $this->getContext();
743 return $cache->getWithSetCallback(
744 $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ),
745 $cache::TTL_MINUTE
* 10,
746 function () use ( $context ) {
747 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
748 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
750 // Hit counts disabled for perf reasons, see T169997
752 $tagStats = ChangeTags::tagUsageStatistics();
753 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
756 arsort( $tagHitCounts );
758 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
760 // Build the list and data
762 foreach ( $tagHitCounts as $tagName => $hits ) {
764 // Only get active tags
765 isset( $explicitlyDefinedTags[ $tagName ] ) ||
766 isset( $softwareActivatedTags[ $tagName ] )
769 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $context );
773 'label' => Sanitizer
::stripAllTags(
774 ChangeTags
::tagDescription( $tagName, $context )
776 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
777 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
783 // Instead of sorting by hit count (disabled, see above), sort by display name
784 usort( $result, function ( $a, $b ) {
785 return strcasecmp( $a['label'], $b['label'] );
797 * Add the "no results" message to the output
799 protected function outputNoResults() {
800 $this->getOutput()->addHTML(
801 '<div class="mw-changeslist-empty">' .
802 $this->msg( 'recentchanges-noresult' )->parse() .
808 * Add the "timeout" message to the output
810 protected function outputTimeout() {
811 $this->getOutput()->addHTML(
812 '<div class="mw-changeslist-timeout">' .
813 $this->msg( 'recentchanges-timeout' )->parse() .
819 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
821 * @return bool|ResultWrapper Result or false
823 public function getRows() {
824 $opts = $this->getOptions();
831 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
833 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
837 * Get the current FormOptions for this request
839 * @return FormOptions
841 public function getOptions() {
842 if ( $this->rcOptions
=== null ) {
843 $this->rcOptions
= $this->setup( $this->rcSubpage
);
846 return $this->rcOptions
;
850 * Register all filters and their groups (including those from hooks), plus handle
851 * conflicts and defaults.
853 * You might want to customize these in the same method, in subclasses. You can
854 * call getFilterGroup to access a group, and (on the group) getFilter to access a
855 * filter, then make necessary modfications to the filter or group (e.g. with
858 protected function registerFilters() {
859 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
861 // Make sure this is not being transcluded (we don't want to show this
862 // information to all users just because the user that saves the edit can
863 // patrol or is logged in)
864 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
865 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
868 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
870 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
871 $transformedHideCategorizationDef = $this->transformFilterDefinition(
872 $this->hideCategorizationFilterDefinition
875 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
877 $hideCategorization = new ChangesListBooleanFilter(
878 $transformedHideCategorizationDef
882 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
884 $unstructuredGroupDefinition =
885 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
886 $this->getCustomFilters()
888 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
890 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
891 $registered = $userExperienceLevel->getFilter( 'registered' );
892 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
893 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
894 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
896 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
897 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
898 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
900 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
901 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
903 // categoryFilter is conditional; see registerFilters
904 if ( $categoryFilter !== null ) {
905 $hideMinorFilter->conflictsWith(
907 'rcfilters-hideminor-conflicts-typeofchange-global',
908 'rcfilters-hideminor-conflicts-typeofchange',
909 'rcfilters-typeofchange-conflicts-hideminor'
912 $hideMinorFilter->conflictsWith(
914 'rcfilters-hideminor-conflicts-typeofchange-global',
915 'rcfilters-hideminor-conflicts-typeofchange',
916 'rcfilters-typeofchange-conflicts-hideminor'
918 $hideMinorFilter->conflictsWith(
920 'rcfilters-hideminor-conflicts-typeofchange-global',
921 'rcfilters-hideminor-conflicts-typeofchange',
922 'rcfilters-typeofchange-conflicts-hideminor'
927 * Transforms filter definition to prepare it for constructor.
929 * See overrides of this method as well.
931 * @param array $filterDefinition Original filter definition
933 * @return array Transformed definition
935 protected function transformFilterDefinition( array $filterDefinition ) {
936 return $filterDefinition;
940 * Register filters from a definition object
942 * Array specifying groups and their filters; see Filter and
943 * ChangesListFilterGroup constructors.
945 * There is light processing to simplify core maintenance.
946 * @param array $definition
948 protected function registerFiltersFromDefinitions( array $definition ) {
949 $autoFillPriority = -1;
950 foreach ( $definition as $groupDefinition ) {
951 if ( !isset( $groupDefinition['priority'] ) ) {
952 $groupDefinition['priority'] = $autoFillPriority;
954 // If it's explicitly specified, start over the auto-fill
955 $autoFillPriority = $groupDefinition['priority'];
960 $className = $groupDefinition['class'];
961 unset( $groupDefinition['class'] );
963 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
964 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
967 $this->registerFilterGroup( new $className( $groupDefinition ) );
972 * Get filter group definition from legacy custom filters
974 * @param array $customFilters Custom filters from legacy hooks
975 * @return array Group definition
977 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
978 // Special internal unstructured group
979 $unstructuredGroupDefinition = [
980 'name' => 'unstructured',
981 'class' => ChangesListBooleanFilterGroup
::class,
982 'priority' => -1, // Won't display in structured
986 foreach ( $customFilters as $name => $params ) {
987 $unstructuredGroupDefinition['filters'][] = [
989 'showHide' => $params['msg'],
990 'default' => $params['default'],
994 return $unstructuredGroupDefinition;
998 * @return array The legacy show/hide toggle filters
1000 protected function getLegacyShowHideFilters() {
1002 foreach ( $this->filterGroups
as $group ) {
1003 if ( $group instanceof ChangesListBooleanFilterGroup
) {
1004 foreach ( $group->getFilters() as $key => $filter ) {
1005 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1006 $filters[ $key ] = $filter;
1015 * Register all the filters, including legacy hook-driven ones.
1016 * Then create a FormOptions object with options as specified by the user
1018 * @param array $parameters
1020 * @return FormOptions
1022 public function setup( $parameters ) {
1023 $this->registerFilters();
1025 $opts = $this->getDefaultOptions();
1027 $opts = $this->fetchOptionsFromRequest( $opts );
1029 // Give precedence to subpage syntax
1030 if ( $parameters !== null ) {
1031 $this->parseParameters( $parameters, $opts );
1034 $this->validateOptions( $opts );
1040 * Get a FormOptions object containing the default options. By default, returns
1041 * some basic options. The filters listed explicitly here are overriden in this
1042 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1043 * and more) are structured. Structured filters are overriden in registerFilters.
1046 * @return FormOptions
1048 public function getDefaultOptions() {
1049 $opts = new FormOptions();
1050 $structuredUI = $this->isStructuredFilterUiEnabled();
1051 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1052 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1054 /** @var ChangesListFilterGroup $filterGroup */
1055 foreach ( $this->filterGroups
as $filterGroup ) {
1056 $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
1059 $opts->add( 'namespace', '', FormOptions
::STRING );
1060 $opts->add( 'invert', false );
1061 $opts->add( 'associated', false );
1062 $opts->add( 'urlversion', 1 );
1063 $opts->add( 'tagfilter', '' );
1065 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
1066 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
1068 $opts->add( 'from', '' );
1074 * Register a structured changes list filter group
1076 * @param ChangesListFilterGroup $group
1078 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
1079 $groupName = $group->getName();
1081 $this->filterGroups
[$groupName] = $group;
1085 * Gets the currently registered filters groups
1087 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1089 protected function getFilterGroups() {
1090 return $this->filterGroups
;
1094 * Gets a specified ChangesListFilterGroup by name
1096 * @param string $groupName Name of group
1098 * @return ChangesListFilterGroup|null Group, or null if not registered
1100 public function getFilterGroup( $groupName ) {
1101 return isset( $this->filterGroups
[$groupName] ) ?
1102 $this->filterGroups
[$groupName] :
1106 // Currently, this intentionally only includes filters that display
1107 // in the structured UI. This can be changed easily, though, if we want
1108 // to include data on filters that use the unstructured UI. messageKeys is a
1109 // special top-level value, with the value being an array of the message keys to
1110 // send to the client.
1112 * Gets structured filter information needed by JS
1114 * @return array Associative array
1115 * * array $return['groups'] Group data
1116 * * array $return['messageKeys'] Array of message keys
1118 public function getStructuredFilterJsData() {
1121 'messageKeys' => [],
1124 usort( $this->filterGroups
, function ( $a, $b ) {
1125 return $b->getPriority() - $a->getPriority();
1128 foreach ( $this->filterGroups
as $groupName => $group ) {
1129 $groupOutput = $group->getJsData( $this );
1130 if ( $groupOutput !== null ) {
1131 $output['messageKeys'] = array_merge(
1132 $output['messageKeys'],
1133 $groupOutput['messageKeys']
1136 unset( $groupOutput['messageKeys'] );
1137 $output['groups'][] = $groupOutput;
1145 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
1148 * @return array Map of filter URL param names to properties (msg/default)
1150 protected function getCustomFilters() {
1151 if ( $this->customFilters
=== null ) {
1152 $this->customFilters
= [];
1153 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
1156 return $this->customFilters
;
1160 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1162 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1164 * @param FormOptions $opts
1165 * @return FormOptions
1167 protected function fetchOptionsFromRequest( $opts ) {
1168 $opts->fetchValuesFromRequest( $this->getRequest() );
1174 * Process $par and put options found in $opts. Used when including the page.
1176 * @param string $par
1177 * @param FormOptions $opts
1179 public function parseParameters( $par, FormOptions
$opts ) {
1180 $stringParameterNameSet = [];
1181 $hideParameterNameSet = [];
1183 // URL parameters can be per-group, like 'userExpLevel',
1184 // or per-filter, like 'hideminor'.
1186 foreach ( $this->filterGroups
as $filterGroup ) {
1187 if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup
) {
1188 $stringParameterNameSet[$filterGroup->getName()] = true;
1189 } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1190 foreach ( $filterGroup->getFilters() as $filter ) {
1191 $hideParameterNameSet[$filter->getName()] = true;
1196 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1197 foreach ( $bits as $bit ) {
1199 if ( isset( $hideParameterNameSet[$bit] ) ) {
1200 // hidefoo => hidefoo=true
1202 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1203 // foo => hidefoo=false
1204 $opts["hide$bit"] = false;
1205 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1206 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1207 $opts[$m[1]] = $m[2];
1214 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1216 * @param FormOptions $opts
1218 public function validateOptions( FormOptions
$opts ) {
1219 $isContradictory = $this->fixContradictoryOptions( $opts );
1220 $isReplaced = $this->replaceOldOptions( $opts );
1222 if ( $isContradictory ||
$isReplaced ) {
1223 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1224 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1227 $opts->validateIntBounds( 'limit', 0, 5000 );
1228 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1232 * Fix invalid options by resetting pairs that should never appear together.
1234 * @param FormOptions $opts
1235 * @return bool True if any option was reset
1237 private function fixContradictoryOptions( FormOptions
$opts ) {
1238 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1240 foreach ( $this->filterGroups
as $filterGroup ) {
1241 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1242 $filters = $filterGroup->getFilters();
1244 if ( count( $filters ) === 1 ) {
1245 // legacy boolean filters should not be considered
1249 $allInGroupEnabled = array_reduce(
1251 function ( $carry, $filter ) use ( $opts ) {
1252 return $carry && $opts[ $filter->getName() ];
1254 /* initialValue */ count( $filters ) > 0
1257 if ( $allInGroupEnabled ) {
1258 foreach ( $filters as $filter ) {
1259 $opts[ $filter->getName() ] = false;
1271 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1274 * This is deprecated and may be removed.
1276 * @param FormOptions $opts
1277 * @return bool True if this change was mode
1279 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1280 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1281 $opts->reset( 'hideanons' );
1282 if ( !$opts['hidebots'] ) {
1283 $opts->reset( 'hideliu' );
1284 $opts['hidehumans'] = 1;
1294 * Replace old options 'hideanons' or 'hideliu' with structured UI equivalent
1296 * @param FormOptions $opts
1297 * @return bool True if the change was made
1299 public function replaceOldOptions( FormOptions
$opts ) {
1300 if ( !$this->isStructuredFilterUiEnabled() ) {
1304 // At this point 'hideanons' and 'hideliu' cannot be both true,
1305 // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
1306 if ( $opts[ 'hideanons' ] ) {
1307 $opts->reset( 'hideanons' );
1308 $opts[ 'userExpLevel' ] = 'registered';
1312 if ( $opts[ 'hideliu' ] ) {
1313 $opts->reset( 'hideliu' );
1314 $opts[ 'userExpLevel' ] = 'unregistered';
1322 * Convert parameters values from true/false to 1/0
1323 * so they are not omitted by wfArrayToCgi()
1326 * @param array $params
1329 protected function convertParamsForLink( $params ) {
1330 foreach ( $params as &$value ) {
1331 if ( $value === false ) {
1340 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1341 * the user requested.
1343 * @param array &$tables Array of tables; see IDatabase::select $table
1344 * @param array &$fields Array of fields; see IDatabase::select $vars
1345 * @param array &$conds Array of conditions; see IDatabase::select $conds
1346 * @param array &$query_options Array of query options; see IDatabase::select $options
1347 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1348 * @param FormOptions $opts
1350 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1351 &$join_conds, FormOptions
$opts
1353 $dbr = $this->getDB();
1354 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1356 /** @var ChangesListFilterGroup $filterGroup */
1357 foreach ( $this->filterGroups
as $filterGroup ) {
1358 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1359 $query_options, $join_conds, $opts, $isStructuredUI );
1362 // Namespace filtering
1363 if ( $opts[ 'namespace' ] !== '' ) {
1364 $namespaces = explode( ';', $opts[ 'namespace' ] );
1366 if ( $opts[ 'associated' ] ) {
1367 $associatedNamespaces = array_map(
1369 return MWNamespace
::getAssociated( $ns );
1373 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1376 if ( count( $namespaces ) === 1 ) {
1377 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1378 $value = $dbr->addQuotes( reset( $namespaces ) );
1380 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1381 sort( $namespaces );
1382 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1384 $conds[] = "rc_namespace $operator $value";
1388 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1389 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1391 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1392 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
1393 $cutoff = $dbr->timestamp( $opts['from'] );
1395 $opts->reset( 'from' );
1398 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1404 * @param array $tables Array of tables; see IDatabase::select $table
1405 * @param array $fields Array of fields; see IDatabase::select $vars
1406 * @param array $conds Array of conditions; see IDatabase::select $conds
1407 * @param array $query_options Array of query options; see IDatabase::select $options
1408 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1409 * @param FormOptions $opts
1410 * @return bool|ResultWrapper Result or false
1412 protected function doMainQuery( $tables, $fields, $conds,
1413 $query_options, $join_conds, FormOptions
$opts
1415 $rcQuery = RecentChange
::getQueryInfo();
1416 $tables = array_merge( $tables, $rcQuery['tables'] );
1417 $fields = array_merge( $rcQuery['fields'], $fields );
1418 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
1420 ChangeTags
::modifyDisplayQuery(
1429 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1435 $dbr = $this->getDB();
1437 return $dbr->select(
1447 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1448 &$query_options, &$join_conds, $opts
1451 'ChangesListSpecialPageQuery',
1452 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1457 * Return a IDatabase object for reading
1461 protected function getDB() {
1462 return wfGetDB( DB_REPLICA
);
1466 * Send header output to the OutputPage object, only called if not using feeds
1468 * @param int $rowCount Number of database rows
1469 * @param FormOptions $opts
1471 private function webOutputHeader( $rowCount, $opts ) {
1472 if ( !$this->including() ) {
1473 $this->outputFeedLinks();
1474 $this->doHeader( $opts, $rowCount );
1479 * Send output to the OutputPage object, only called if not used feeds
1481 * @param ResultWrapper $rows Database rows
1482 * @param FormOptions $opts
1484 public function webOutput( $rows, $opts ) {
1485 $this->webOutputHeader( $rows->numRows(), $opts );
1487 $this->outputChangesList( $rows, $opts );
1491 * Output feed links.
1493 public function outputFeedLinks() {
1494 // nothing by default
1498 * Build and output the actual changes list.
1500 * @param ResultWrapper $rows Database rows
1501 * @param FormOptions $opts
1503 abstract public function outputChangesList( $rows, $opts );
1506 * Set the text to be displayed above the changes
1508 * @param FormOptions $opts
1509 * @param int $numRows Number of rows in the result to show after this header
1511 public function doHeader( $opts, $numRows ) {
1512 $this->setTopText( $opts );
1514 // @todo Lots of stuff should be done here.
1516 $this->setBottomText( $opts );
1520 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1521 * or similar methods to print the text.
1523 * @param FormOptions $opts
1525 public function setTopText( FormOptions
$opts ) {
1526 // nothing by default
1530 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1531 * or similar methods to print the text.
1533 * @param FormOptions $opts
1535 public function setBottomText( FormOptions
$opts ) {
1536 // nothing by default
1540 * Get options to be displayed in a form
1541 * @todo This should handle options returned by getDefaultOptions().
1542 * @todo Not called by anything in this class (but is in subclasses), should be
1543 * called by something… doHeader() maybe?
1545 * @param FormOptions $opts
1548 public function getExtraOptions( $opts ) {
1553 * Return the legend displayed within the fieldset
1557 public function makeLegend() {
1558 $context = $this->getContext();
1559 $user = $context->getUser();
1560 # The legend showing what the letters and stuff mean
1561 $legend = Html
::openElement( 'dl' ) . "\n";
1562 # Iterates through them and gets the messages for both letter and tooltip
1563 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1564 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1565 unset( $legendItems['unpatrolled'] );
1567 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1568 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1569 $letter = $item['letter'];
1570 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1572 $legend .= Html
::element( 'dt',
1573 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1575 Html
::rawElement( 'dd',
1576 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1577 $context->msg( $label )->parse()
1581 $legend .= Html
::rawElement( 'dt',
1582 [ 'class' => 'mw-plusminus-pos' ],
1583 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1585 $legend .= Html
::element(
1587 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1588 $context->msg( 'recentchanges-label-plusminus' )->text()
1590 $legend .= Html
::closeElement( 'dl' ) . "\n";
1592 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1593 $context->msg( 'rcfilters-legend-heading' )->parse() :
1594 $context->msg( 'recentchanges-legend-heading' )->parse();
1597 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1598 $collapsedClass = $collapsedState === 'collapsed' ?
' mw-collapsed' : '';
1600 '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
1602 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1609 * Add page-specific modules.
1611 protected function addModules() {
1612 $out = $this->getOutput();
1613 // Styles and behavior for the legend box (see makeLegend())
1614 $out->addModuleStyles( [
1615 'mediawiki.special.changeslist.legend',
1616 'mediawiki.special.changeslist',
1618 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1620 if ( $this->isStructuredFilterUiEnabled() ) {
1621 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1622 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1626 protected function getGroupName() {
1631 * Filter on users' experience levels; this will not be called if nothing is
1634 * @param string $specialPageClassName Class name of current special page
1635 * @param IContextSource $context Context, for e.g. user
1636 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1637 * @param array &$tables Array of tables; see IDatabase::select $table
1638 * @param array &$fields Array of fields; see IDatabase::select $vars
1639 * @param array &$conds Array of conditions; see IDatabase::select $conds
1640 * @param array &$query_options Array of query options; see IDatabase::select $options
1641 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1642 * @param array $selectedExpLevels The allowed active values, sorted
1643 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1646 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1647 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1649 global $wgLearnerEdits,
1650 $wgExperiencedUserEdits,
1651 $wgLearnerMemberSince,
1652 $wgExperiencedUserMemberSince;
1656 // If all levels are selected, don't filter
1657 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1661 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1663 in_array( 'registered', $selectedExpLevels ) &&
1664 in_array( 'unregistered', $selectedExpLevels )
1669 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1671 in_array( 'registered', $selectedExpLevels ) &&
1672 !in_array( 'unregistered', $selectedExpLevels )
1674 $conds[] = 'rc_user != 0';
1678 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1679 $conds[] = 'rc_user = 0';
1684 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1689 $secondsPerDay = 86400;
1690 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1691 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1693 $aboveNewcomer = $dbr->makeList(
1695 'user_editcount >= ' . intval( $wgLearnerEdits ),
1696 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1701 $aboveLearner = $dbr->makeList(
1703 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1704 'user_registration <= ' .
1705 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1712 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1713 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1714 $conditions[] = 'rc_user = 0';
1717 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1718 $conditions[] = "NOT ( $aboveNewcomer )";
1719 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1720 $conditions[] = $dbr->makeList(
1721 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1724 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1725 $conditions[] = $aboveLearner;
1726 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1727 $conditions[] = "NOT ( $aboveLearner )";
1728 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1729 $conditions[] = $dbr->makeList(
1730 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1733 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1734 $conditions[] = $aboveNewcomer;
1735 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1736 $conditions[] = 'rc_user != 0';
1739 if ( count( $conditions ) > 1 ) {
1740 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1741 } elseif ( count( $conditions ) === 1 ) {
1742 $conds[] = reset( $conditions );
1747 * Check whether the structured filter UI is enabled
1751 public function isStructuredFilterUiEnabled() {
1752 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1756 if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
1757 return !$this->getUser()->getOption( 'rcenhancedfilters-disable' );
1759 return $this->getUser()->getOption( 'rcenhancedfilters' );
1764 * Check whether the structured filter UI is enabled by default (regardless of
1765 * this particular user's setting)
1769 public function isStructuredFilterUiEnabledByDefault() {
1770 if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
1771 return !$this->getUser()->getDefaultOption( 'rcenhancedfilters-disable' );
1773 return $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
1777 abstract function getDefaultLimit();
1780 * Get the default value of the number of days to display when loading
1782 * Supports fractional values, and should be cast to a float.
1786 abstract function getDefaultDays();