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\IResultWrapper
;
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 * Maximum length of a tag description in UTF-8 characters.
38 * Longer descriptions will be truncated.
40 const TAG_DESC_CHARACTER_LIMIT
= 120;
43 * Preference name for saved queries. Subclasses that use saved queries should override this.
46 protected static $savedQueriesPreferenceName;
49 * Preference name for 'days'. Subclasses should override this.
52 protected static $daysPreferenceName;
55 * Preference name for 'limit'. Subclasses should override this.
58 protected static $limitPreferenceName;
63 /** @var FormOptions */
67 protected $customFilters;
69 // Order of both groups and filters is significant; first is top-most priority,
70 // descending from there.
71 // 'showHideSuffix' is a shortcut to and avoid spelling out
72 // details specific to subclasses here.
74 * Definition information for the filters and their groups
76 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
77 * However, priority is dynamically added for the core groups, to ease maintenance.
79 * Groups are displayed to the user in the structured UI. However, if necessary,
80 * all of the filters in a group can be configured to only display on the
81 * unstuctured UI, in which case you don't need a group title. This is done in
82 * getFilterGroupDefinitionFromLegacyCustomFilters, for example.
84 * @var array $filterGroupDefinitions
86 private $filterGroupDefinitions;
88 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
89 // that is registered conditionally.
90 private $reviewStatusFilterGroupDefinition;
92 // Single filter registered conditionally
93 private $hideCategorizationFilterDefinition;
96 * Filter groups, and their contained filters
97 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
99 * @var array $filterGroups
101 protected $filterGroups = [];
103 public function __construct( $name, $restriction ) {
104 parent
::__construct( $name, $restriction );
106 $nonRevisionTypes = [ RC_LOG
];
107 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
109 $this->filterGroupDefinitions
= [
111 'name' => 'registration',
112 'title' => 'rcfilters-filtergroup-registration',
113 'class' => ChangesListBooleanFilterGroup
::class,
117 // rcshowhideliu-show, rcshowhideliu-hide,
119 'showHideSuffix' => 'showhideliu',
121 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
122 &$query_options, &$join_conds
124 $actorMigration = ActorMigration
::newMigration();
125 $actorQuery = $actorMigration->getJoin( 'rc_user' );
126 $tables +
= $actorQuery['tables'];
127 $join_conds +
= $actorQuery['joins'];
128 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
130 'isReplacedInStructuredUi' => true,
134 'name' => 'hideanons',
135 // rcshowhideanons-show, rcshowhideanons-hide,
137 'showHideSuffix' => 'showhideanons',
139 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
140 &$query_options, &$join_conds
142 $actorMigration = ActorMigration
::newMigration();
143 $actorQuery = $actorMigration->getJoin( 'rc_user' );
144 $tables +
= $actorQuery['tables'];
145 $join_conds +
= $actorQuery['joins'];
146 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
148 'isReplacedInStructuredUi' => true,
154 'name' => 'userExpLevel',
155 'title' => 'rcfilters-filtergroup-userExpLevel',
156 'class' => ChangesListStringOptionsFilterGroup
::class,
157 'isFullCoverage' => true,
160 'name' => 'unregistered',
161 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
162 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
163 'cssClassSuffix' => 'user-unregistered',
164 'isRowApplicableCallable' => function ( $ctx, $rc ) {
165 return !$rc->getAttribute( 'rc_user' );
169 'name' => 'registered',
170 'label' => 'rcfilters-filter-user-experience-level-registered-label',
171 'description' => 'rcfilters-filter-user-experience-level-registered-description',
172 'cssClassSuffix' => 'user-registered',
173 'isRowApplicableCallable' => function ( $ctx, $rc ) {
174 return $rc->getAttribute( 'rc_user' );
178 'name' => 'newcomer',
179 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
180 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
181 'cssClassSuffix' => 'user-newcomer',
182 'isRowApplicableCallable' => function ( $ctx, $rc ) {
183 $performer = $rc->getPerformer();
184 return $performer && $performer->isLoggedIn() &&
185 $performer->getExperienceLevel() === 'newcomer';
190 'label' => 'rcfilters-filter-user-experience-level-learner-label',
191 'description' => 'rcfilters-filter-user-experience-level-learner-description',
192 'cssClassSuffix' => 'user-learner',
193 'isRowApplicableCallable' => function ( $ctx, $rc ) {
194 $performer = $rc->getPerformer();
195 return $performer && $performer->isLoggedIn() &&
196 $performer->getExperienceLevel() === 'learner';
200 'name' => 'experienced',
201 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
202 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
203 'cssClassSuffix' => 'user-experienced',
204 'isRowApplicableCallable' => function ( $ctx, $rc ) {
205 $performer = $rc->getPerformer();
206 return $performer && $performer->isLoggedIn() &&
207 $performer->getExperienceLevel() === 'experienced';
211 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
212 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
216 'name' => 'authorship',
217 'title' => 'rcfilters-filtergroup-authorship',
218 'class' => ChangesListBooleanFilterGroup
::class,
221 'name' => 'hidemyself',
222 'label' => 'rcfilters-filter-editsbyself-label',
223 'description' => 'rcfilters-filter-editsbyself-description',
224 // rcshowhidemine-show, rcshowhidemine-hide,
226 'showHideSuffix' => 'showhidemine',
228 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
229 &$query_options, &$join_conds
231 $actorQuery = ActorMigration
::newMigration()->getWhere( $dbr, 'rc_user', $ctx->getUser() );
232 $tables +
= $actorQuery['tables'];
233 $join_conds +
= $actorQuery['joins'];
234 $conds[] = 'NOT(' . $actorQuery['conds'] . ')';
236 'cssClassSuffix' => 'self',
237 'isRowApplicableCallable' => function ( $ctx, $rc ) {
238 return $ctx->getUser()->equals( $rc->getPerformer() );
242 'name' => 'hidebyothers',
243 'label' => 'rcfilters-filter-editsbyother-label',
244 'description' => 'rcfilters-filter-editsbyother-description',
246 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
247 &$query_options, &$join_conds
249 $actorQuery = ActorMigration
::newMigration()
250 ->getWhere( $dbr, 'rc_user', $ctx->getUser(), false );
251 $tables +
= $actorQuery['tables'];
252 $join_conds +
= $actorQuery['joins'];
253 $conds[] = $actorQuery['conds'];
255 'cssClassSuffix' => 'others',
256 'isRowApplicableCallable' => function ( $ctx, $rc ) {
257 return !$ctx->getUser()->equals( $rc->getPerformer() );
264 'name' => 'automated',
265 'title' => 'rcfilters-filtergroup-automated',
266 'class' => ChangesListBooleanFilterGroup
::class,
269 'name' => 'hidebots',
270 'label' => 'rcfilters-filter-bots-label',
271 'description' => 'rcfilters-filter-bots-description',
272 // rcshowhidebots-show, rcshowhidebots-hide,
274 'showHideSuffix' => 'showhidebots',
276 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
277 &$query_options, &$join_conds
279 $conds['rc_bot'] = 0;
281 'cssClassSuffix' => 'bot',
282 'isRowApplicableCallable' => function ( $ctx, $rc ) {
283 return $rc->getAttribute( 'rc_bot' );
287 'name' => 'hidehumans',
288 'label' => 'rcfilters-filter-humans-label',
289 'description' => 'rcfilters-filter-humans-description',
291 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
292 &$query_options, &$join_conds
294 $conds['rc_bot'] = 1;
296 'cssClassSuffix' => 'human',
297 'isRowApplicableCallable' => function ( $ctx, $rc ) {
298 return !$rc->getAttribute( 'rc_bot' );
304 // reviewStatus (conditional)
307 'name' => 'significance',
308 'title' => 'rcfilters-filtergroup-significance',
309 'class' => ChangesListBooleanFilterGroup
::class,
313 'name' => 'hideminor',
314 'label' => 'rcfilters-filter-minor-label',
315 'description' => 'rcfilters-filter-minor-description',
316 // rcshowhideminor-show, rcshowhideminor-hide,
318 'showHideSuffix' => 'showhideminor',
320 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
321 &$query_options, &$join_conds
323 $conds[] = 'rc_minor = 0';
325 'cssClassSuffix' => 'minor',
326 'isRowApplicableCallable' => function ( $ctx, $rc ) {
327 return $rc->getAttribute( 'rc_minor' );
331 'name' => 'hidemajor',
332 'label' => 'rcfilters-filter-major-label',
333 'description' => 'rcfilters-filter-major-description',
335 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
336 &$query_options, &$join_conds
338 $conds[] = 'rc_minor = 1';
340 'cssClassSuffix' => 'major',
341 'isRowApplicableCallable' => function ( $ctx, $rc ) {
342 return !$rc->getAttribute( 'rc_minor' );
349 'name' => 'lastRevision',
350 'title' => 'rcfilters-filtergroup-lastRevision',
351 'class' => ChangesListBooleanFilterGroup
::class,
355 'name' => 'hidelastrevision',
356 'label' => 'rcfilters-filter-lastrevision-label',
357 'description' => 'rcfilters-filter-lastrevision-description',
359 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
360 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
361 $conds[] = $dbr->makeList(
363 'rc_this_oldid <> page_latest',
364 'rc_type' => $nonRevisionTypes,
369 'cssClassSuffix' => 'last',
370 'isRowApplicableCallable' => function ( $ctx, $rc ) {
371 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
375 'name' => 'hidepreviousrevisions',
376 'label' => 'rcfilters-filter-previousrevision-label',
377 'description' => 'rcfilters-filter-previousrevision-description',
379 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
380 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
381 $conds[] = $dbr->makeList(
383 'rc_this_oldid = page_latest',
384 'rc_type' => $nonRevisionTypes,
389 'cssClassSuffix' => 'previous',
390 'isRowApplicableCallable' => function ( $ctx, $rc ) {
391 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
397 // With extensions, there can be change types that will not be hidden by any of these.
399 'name' => 'changeType',
400 'title' => 'rcfilters-filtergroup-changetype',
401 'class' => ChangesListBooleanFilterGroup
::class,
405 'name' => 'hidepageedits',
406 'label' => 'rcfilters-filter-pageedits-label',
407 'description' => 'rcfilters-filter-pageedits-description',
410 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
411 &$query_options, &$join_conds
413 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
415 'cssClassSuffix' => 'src-mw-edit',
416 'isRowApplicableCallable' => function ( $ctx, $rc ) {
417 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
421 'name' => 'hidenewpages',
422 'label' => 'rcfilters-filter-newpages-label',
423 'description' => 'rcfilters-filter-newpages-description',
426 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
427 &$query_options, &$join_conds
429 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
431 'cssClassSuffix' => 'src-mw-new',
432 'isRowApplicableCallable' => function ( $ctx, $rc ) {
433 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
437 // hidecategorization
441 'label' => 'rcfilters-filter-logactions-label',
442 'description' => 'rcfilters-filter-logactions-description',
445 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
446 &$query_options, &$join_conds
448 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
450 'cssClassSuffix' => 'src-mw-log',
451 'isRowApplicableCallable' => function ( $ctx, $rc ) {
452 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
460 $this->reviewStatusFilterGroupDefinition
= [
462 'name' => 'reviewStatus',
463 'title' => 'rcfilters-filtergroup-reviewstatus',
464 'class' => ChangesListBooleanFilterGroup
::class,
468 'name' => 'hidepatrolled',
469 'label' => 'rcfilters-filter-patrolled-label',
470 'description' => 'rcfilters-filter-patrolled-description',
471 // rcshowhidepatr-show, rcshowhidepatr-hide
473 'showHideSuffix' => 'showhidepatr',
475 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
476 &$query_options, &$join_conds
478 $conds[] = 'rc_patrolled = 0';
480 'cssClassSuffix' => 'patrolled',
481 'isRowApplicableCallable' => function ( $ctx, $rc ) {
482 return $rc->getAttribute( 'rc_patrolled' );
486 'name' => 'hideunpatrolled',
487 'label' => 'rcfilters-filter-unpatrolled-label',
488 'description' => 'rcfilters-filter-unpatrolled-description',
490 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
491 &$query_options, &$join_conds
493 $conds[] = 'rc_patrolled != 0';
495 'cssClassSuffix' => 'unpatrolled',
496 'isRowApplicableCallable' => function ( $ctx, $rc ) {
497 return !$rc->getAttribute( 'rc_patrolled' );
504 $this->hideCategorizationFilterDefinition
= [
505 'name' => 'hidecategorization',
506 'label' => 'rcfilters-filter-categorization-label',
507 'description' => 'rcfilters-filter-categorization-description',
508 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
509 // wlshowhidecategorization
510 'showHideSuffix' => 'showhidecategorization',
513 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
514 &$query_options, &$join_conds
516 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
518 'cssClassSuffix' => 'src-mw-categorize',
519 'isRowApplicableCallable' => function ( $ctx, $rc ) {
520 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
526 * Check if filters are in conflict and guaranteed to return no results.
530 protected function areFiltersInConflict() {
531 $opts = $this->getOptions();
532 /** @var ChangesListFilterGroup $group */
533 foreach ( $this->getFilterGroups() as $group ) {
534 if ( $group->getConflictingGroups() ) {
537 " specifies conflicts with other groups but these are not supported yet."
541 /** @var ChangesListFilter $conflictingFilter */
542 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
543 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
548 /** @var ChangesListFilter $filter */
549 foreach ( $group->getFilters() as $filter ) {
550 /** @var ChangesListFilter $conflictingFilter */
551 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
553 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
554 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
568 * Main execution point
570 * @param string $subpage
572 public function execute( $subpage ) {
573 $this->rcSubpage
= $subpage;
575 $this->considerActionsForDefaultSavedQuery( $subpage );
577 $opts = $this->getOptions();
579 $rows = $this->getRows();
580 if ( $rows === false ) {
581 $rows = new FakeResultWrapper( [] );
584 // Used by Structured UI app to get results without MW chrome
585 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
586 $this->getOutput()->setArticleBodyOnly( true );
589 // Used by "live update" and "view newest" to check
590 // if there's new changes with minimal data transfer
591 if ( $this->getRequest()->getBool( 'peek' ) ) {
592 $code = $rows->numRows() > 0 ?
200 : 204;
593 $this->getOutput()->setStatusCode( $code );
595 if ( $this->getUser()->isAnon() !==
596 $this->getRequest()->getFuzzyBool( 'isAnon' )
598 $this->getOutput()->setStatusCode( 205 );
604 $batch = new LinkBatch
;
605 foreach ( $rows as $row ) {
606 $batch->add( NS_USER
, $row->rc_user_text
);
607 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
608 $batch->add( $row->rc_namespace
, $row->rc_title
);
609 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
610 $formatter = LogFormatter
::newFromRow( $row );
611 foreach ( $formatter->getPreloadTitles() as $title ) {
612 $batch->addObj( $title );
619 $this->outputHeader();
621 $this->webOutput( $rows, $opts );
624 } catch ( DBQueryTimeoutError
$timeoutException ) {
625 MWExceptionHandler
::logException( $timeoutException );
628 $this->outputHeader();
631 $this->getOutput()->setStatusCode( 500 );
632 $this->webOutputHeader( 0, $opts );
633 $this->outputTimeout();
636 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
637 // Clean up any bad page entries for titles showing up in RC
638 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
640 LoggerFactory
::getInstance( 'objectcache' )
644 $this->includeRcFiltersApp();
648 * Check whether or not the page should load defaults, and if so, whether
649 * a default saved query is relevant to be redirected to. If it is relevant,
650 * redirect properly with all necessary query parameters.
652 * @param string $subpage
654 protected function considerActionsForDefaultSavedQuery( $subpage ) {
655 if ( !$this->isStructuredFilterUiEnabled() ||
$this->including() ) {
659 $knownParams = call_user_func_array(
660 [ $this->getRequest(), 'getValues' ],
661 array_keys( $this->getOptions()->getAllValues() )
664 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
665 // we need to exclude several parameters we know should not be counted towards preventing
666 // the loading of defaults.
667 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
668 $knownParams = array_diff_key( $knownParams, $excludedParams );
671 // If there are NO known parameters in the URL request
672 // (that are not excluded) then we need to check into loading
673 // the default saved query
674 count( $knownParams ) === 0
676 // Get the saved queries data and parse it
677 $savedQueries = FormatJson
::decode(
678 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
682 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
683 // Only load queries that are 'version' 2, since those
684 // have parameter representation
685 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
686 $savedQueryDefaultID = $savedQueries[ 'default' ];
687 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
689 // Build the entire parameter list
690 $query = array_merge(
691 $defaultQuery[ 'params' ],
692 $defaultQuery[ 'highlights' ],
697 // Add to the query any parameters that we may have ignored before
698 // but are still valid and requested in the URL
699 $query = array_merge( $this->getRequest()->getValues(), $query );
700 unset( $query[ 'title' ] );
701 $this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) );
703 // There's a default, but the version is not 2, and the server can't
704 // actually recognize the query itself. This happens if it is before
705 // the conversion, so we need to tell the UI to reload saved query as
706 // it does the conversion to version 2
707 $this->getOutput()->addJsConfigVars(
708 'wgStructuredChangeFiltersDefaultSavedQueryExists',
712 // Add the class that tells the frontend it is still loading
714 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
721 * Include the modules and configuration for the RCFilters app.
722 * Conditional on the user having the feature enabled.
724 * If it is disabled, add a <body> class marking that
726 protected function includeRcFiltersApp() {
727 $out = $this->getOutput();
728 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
729 $jsData = $this->getStructuredFilterJsData();
732 foreach ( $jsData['messageKeys'] as $key ) {
733 $messages[$key] = $this->msg( $key )->plain();
736 $out->addBodyClasses( 'mw-rcfilters-enabled' );
739 ResourceLoader
::makeInlineScript(
740 ResourceLoader
::makeMessageSetScript( $messages )
744 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
746 $out->addJsConfigVars(
747 'wgRCFiltersChangeTags',
748 $this->getChangeTagList()
750 $out->addJsConfigVars(
751 'StructuredChangeFiltersDisplayConfig',
753 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
754 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
755 'limitDefault' => $this->getDefaultLimit(),
756 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
757 'daysDefault' => $this->getDefaultDays(),
761 $out->addJsConfigVars(
762 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
763 static::$savedQueriesPreferenceName
765 $out->addJsConfigVars(
766 'wgStructuredChangeFiltersLimitPreferenceName',
767 static::$limitPreferenceName
769 $out->addJsConfigVars(
770 'wgStructuredChangeFiltersDaysPreferenceName',
771 static::$daysPreferenceName
774 $out->addJsConfigVars(
775 'StructuredChangeFiltersLiveUpdatePollingRate',
776 $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
779 $out->addBodyClasses( 'mw-rcfilters-disabled' );
784 * Fetch the change tags list for the front end
786 * @return Array Tag data
788 protected function getChangeTagList() {
789 $cache = ObjectCache
::getMainWANInstance();
790 $context = $this->getContext();
791 return $cache->getWithSetCallback(
792 $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ),
793 $cache::TTL_MINUTE
* 10,
794 function () use ( $context ) {
795 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
796 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
798 // Hit counts disabled for perf reasons, see T169997
800 $tagStats = ChangeTags::tagUsageStatistics();
801 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
804 arsort( $tagHitCounts );
806 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
808 // Build the list and data
810 foreach ( $tagHitCounts as $tagName => $hits ) {
812 // Only get active tags
813 isset( $explicitlyDefinedTags[ $tagName ] ) ||
814 isset( $softwareActivatedTags[ $tagName ] )
818 'label' => Sanitizer
::stripAllTags(
819 ChangeTags
::tagDescription( $tagName, $context )
822 ChangeTags
::truncateTagDescription(
823 $tagName, self
::TAG_DESC_CHARACTER_LIMIT
, $context
825 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
831 // Instead of sorting by hit count (disabled, see above), sort by display name
832 usort( $result, function ( $a, $b ) {
833 return strcasecmp( $a['label'], $b['label'] );
845 * Add the "no results" message to the output
847 protected function outputNoResults() {
848 $this->getOutput()->addHTML(
849 '<div class="mw-changeslist-empty">' .
850 $this->msg( 'recentchanges-noresult' )->parse() .
856 * Add the "timeout" message to the output
858 protected function outputTimeout() {
859 $this->getOutput()->addHTML(
860 '<div class="mw-changeslist-empty mw-changeslist-timeout">' .
861 $this->msg( 'recentchanges-timeout' )->parse() .
867 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
869 * @return bool|IResultWrapper Result or false
871 public function getRows() {
872 $opts = $this->getOptions();
879 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
881 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
885 * Get the current FormOptions for this request
887 * @return FormOptions
889 public function getOptions() {
890 if ( $this->rcOptions
=== null ) {
891 $this->rcOptions
= $this->setup( $this->rcSubpage
);
894 return $this->rcOptions
;
898 * Register all filters and their groups (including those from hooks), plus handle
899 * conflicts and defaults.
901 * You might want to customize these in the same method, in subclasses. You can
902 * call getFilterGroup to access a group, and (on the group) getFilter to access a
903 * filter, then make necessary modfications to the filter or group (e.g. with
906 protected function registerFilters() {
907 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
909 // Make sure this is not being transcluded (we don't want to show this
910 // information to all users just because the user that saves the edit can
911 // patrol or is logged in)
912 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
913 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
916 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
918 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
919 $transformedHideCategorizationDef = $this->transformFilterDefinition(
920 $this->hideCategorizationFilterDefinition
923 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
925 $hideCategorization = new ChangesListBooleanFilter(
926 $transformedHideCategorizationDef
930 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
932 $unstructuredGroupDefinition =
933 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
934 $this->getCustomFilters()
936 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
938 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
939 $registered = $userExperienceLevel->getFilter( 'registered' );
940 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
941 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
942 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
944 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
945 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
946 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
948 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
949 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
951 // categoryFilter is conditional; see registerFilters
952 if ( $categoryFilter !== null ) {
953 $hideMinorFilter->conflictsWith(
955 'rcfilters-hideminor-conflicts-typeofchange-global',
956 'rcfilters-hideminor-conflicts-typeofchange',
957 'rcfilters-typeofchange-conflicts-hideminor'
960 $hideMinorFilter->conflictsWith(
962 'rcfilters-hideminor-conflicts-typeofchange-global',
963 'rcfilters-hideminor-conflicts-typeofchange',
964 'rcfilters-typeofchange-conflicts-hideminor'
966 $hideMinorFilter->conflictsWith(
968 'rcfilters-hideminor-conflicts-typeofchange-global',
969 'rcfilters-hideminor-conflicts-typeofchange',
970 'rcfilters-typeofchange-conflicts-hideminor'
975 * Transforms filter definition to prepare it for constructor.
977 * See overrides of this method as well.
979 * @param array $filterDefinition Original filter definition
981 * @return array Transformed definition
983 protected function transformFilterDefinition( array $filterDefinition ) {
984 return $filterDefinition;
988 * Register filters from a definition object
990 * Array specifying groups and their filters; see Filter and
991 * ChangesListFilterGroup constructors.
993 * There is light processing to simplify core maintenance.
994 * @param array $definition
996 protected function registerFiltersFromDefinitions( array $definition ) {
997 $autoFillPriority = -1;
998 foreach ( $definition as $groupDefinition ) {
999 if ( !isset( $groupDefinition['priority'] ) ) {
1000 $groupDefinition['priority'] = $autoFillPriority;
1002 // If it's explicitly specified, start over the auto-fill
1003 $autoFillPriority = $groupDefinition['priority'];
1006 $autoFillPriority--;
1008 $className = $groupDefinition['class'];
1009 unset( $groupDefinition['class'] );
1011 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
1012 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
1015 $this->registerFilterGroup( new $className( $groupDefinition ) );
1020 * Get filter group definition from legacy custom filters
1022 * @param array $customFilters Custom filters from legacy hooks
1023 * @return array Group definition
1025 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
1026 // Special internal unstructured group
1027 $unstructuredGroupDefinition = [
1028 'name' => 'unstructured',
1029 'class' => ChangesListBooleanFilterGroup
::class,
1030 'priority' => -1, // Won't display in structured
1034 foreach ( $customFilters as $name => $params ) {
1035 $unstructuredGroupDefinition['filters'][] = [
1037 'showHide' => $params['msg'],
1038 'default' => $params['default'],
1042 return $unstructuredGroupDefinition;
1046 * @return array The legacy show/hide toggle filters
1048 protected function getLegacyShowHideFilters() {
1050 foreach ( $this->filterGroups
as $group ) {
1051 if ( $group instanceof ChangesListBooleanFilterGroup
) {
1052 foreach ( $group->getFilters() as $key => $filter ) {
1053 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1054 $filters[ $key ] = $filter;
1063 * Register all the filters, including legacy hook-driven ones.
1064 * Then create a FormOptions object with options as specified by the user
1066 * @param array $parameters
1068 * @return FormOptions
1070 public function setup( $parameters ) {
1071 $this->registerFilters();
1073 $opts = $this->getDefaultOptions();
1075 $opts = $this->fetchOptionsFromRequest( $opts );
1077 // Give precedence to subpage syntax
1078 if ( $parameters !== null ) {
1079 $this->parseParameters( $parameters, $opts );
1082 $this->validateOptions( $opts );
1088 * Get a FormOptions object containing the default options. By default, returns
1089 * some basic options. The filters listed explicitly here are overriden in this
1090 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1091 * and more) are structured. Structured filters are overriden in registerFilters.
1094 * @return FormOptions
1096 public function getDefaultOptions() {
1097 $opts = new FormOptions();
1098 $structuredUI = $this->isStructuredFilterUiEnabled();
1099 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1100 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1102 /** @var ChangesListFilterGroup $filterGroup */
1103 foreach ( $this->filterGroups
as $filterGroup ) {
1104 $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
1107 $opts->add( 'namespace', '', FormOptions
::STRING );
1108 $opts->add( 'invert', false );
1109 $opts->add( 'associated', false );
1110 $opts->add( 'urlversion', 1 );
1111 $opts->add( 'tagfilter', '' );
1113 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
1114 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
1116 $opts->add( 'from', '' );
1122 * Register a structured changes list filter group
1124 * @param ChangesListFilterGroup $group
1126 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
1127 $groupName = $group->getName();
1129 $this->filterGroups
[$groupName] = $group;
1133 * Gets the currently registered filters groups
1135 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1137 protected function getFilterGroups() {
1138 return $this->filterGroups
;
1142 * Gets a specified ChangesListFilterGroup by name
1144 * @param string $groupName Name of group
1146 * @return ChangesListFilterGroup|null Group, or null if not registered
1148 public function getFilterGroup( $groupName ) {
1149 return isset( $this->filterGroups
[$groupName] ) ?
1150 $this->filterGroups
[$groupName] :
1154 // Currently, this intentionally only includes filters that display
1155 // in the structured UI. This can be changed easily, though, if we want
1156 // to include data on filters that use the unstructured UI. messageKeys is a
1157 // special top-level value, with the value being an array of the message keys to
1158 // send to the client.
1160 * Gets structured filter information needed by JS
1162 * @return array Associative array
1163 * * array $return['groups'] Group data
1164 * * array $return['messageKeys'] Array of message keys
1166 public function getStructuredFilterJsData() {
1169 'messageKeys' => [],
1172 usort( $this->filterGroups
, function ( $a, $b ) {
1173 return $b->getPriority() - $a->getPriority();
1176 foreach ( $this->filterGroups
as $groupName => $group ) {
1177 $groupOutput = $group->getJsData( $this );
1178 if ( $groupOutput !== null ) {
1179 $output['messageKeys'] = array_merge(
1180 $output['messageKeys'],
1181 $groupOutput['messageKeys']
1184 unset( $groupOutput['messageKeys'] );
1185 $output['groups'][] = $groupOutput;
1193 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
1196 * @return array Map of filter URL param names to properties (msg/default)
1198 protected function getCustomFilters() {
1199 if ( $this->customFilters
=== null ) {
1200 $this->customFilters
= [];
1201 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
1204 return $this->customFilters
;
1208 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1210 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1212 * @param FormOptions $opts
1213 * @return FormOptions
1215 protected function fetchOptionsFromRequest( $opts ) {
1216 $opts->fetchValuesFromRequest( $this->getRequest() );
1222 * Process $par and put options found in $opts. Used when including the page.
1224 * @param string $par
1225 * @param FormOptions $opts
1227 public function parseParameters( $par, FormOptions
$opts ) {
1228 $stringParameterNameSet = [];
1229 $hideParameterNameSet = [];
1231 // URL parameters can be per-group, like 'userExpLevel',
1232 // or per-filter, like 'hideminor'.
1234 foreach ( $this->filterGroups
as $filterGroup ) {
1235 if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup
) {
1236 $stringParameterNameSet[$filterGroup->getName()] = true;
1237 } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1238 foreach ( $filterGroup->getFilters() as $filter ) {
1239 $hideParameterNameSet[$filter->getName()] = true;
1244 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1245 foreach ( $bits as $bit ) {
1247 if ( isset( $hideParameterNameSet[$bit] ) ) {
1248 // hidefoo => hidefoo=true
1250 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1251 // foo => hidefoo=false
1252 $opts["hide$bit"] = false;
1253 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1254 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1255 $opts[$m[1]] = $m[2];
1262 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1264 * @param FormOptions $opts
1266 public function validateOptions( FormOptions
$opts ) {
1267 $isContradictory = $this->fixContradictoryOptions( $opts );
1268 $isReplaced = $this->replaceOldOptions( $opts );
1270 if ( $isContradictory ||
$isReplaced ) {
1271 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1272 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1275 $opts->validateIntBounds( 'limit', 0, 5000 );
1276 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1280 * Fix invalid options by resetting pairs that should never appear together.
1282 * @param FormOptions $opts
1283 * @return bool True if any option was reset
1285 private function fixContradictoryOptions( FormOptions
$opts ) {
1286 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1288 foreach ( $this->filterGroups
as $filterGroup ) {
1289 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1290 $filters = $filterGroup->getFilters();
1292 if ( count( $filters ) === 1 ) {
1293 // legacy boolean filters should not be considered
1297 $allInGroupEnabled = array_reduce(
1299 function ( $carry, $filter ) use ( $opts ) {
1300 return $carry && $opts[ $filter->getName() ];
1302 /* initialValue */ count( $filters ) > 0
1305 if ( $allInGroupEnabled ) {
1306 foreach ( $filters as $filter ) {
1307 $opts[ $filter->getName() ] = false;
1319 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1322 * This is deprecated and may be removed.
1324 * @param FormOptions $opts
1325 * @return bool True if this change was mode
1327 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1328 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1329 $opts->reset( 'hideanons' );
1330 if ( !$opts['hidebots'] ) {
1331 $opts->reset( 'hideliu' );
1332 $opts['hidehumans'] = 1;
1342 * Replace old options 'hideanons' or 'hideliu' with structured UI equivalent
1344 * @param FormOptions $opts
1345 * @return bool True if the change was made
1347 public function replaceOldOptions( FormOptions
$opts ) {
1348 if ( !$this->isStructuredFilterUiEnabled() ) {
1352 // At this point 'hideanons' and 'hideliu' cannot be both true,
1353 // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
1354 if ( $opts[ 'hideanons' ] ) {
1355 $opts->reset( 'hideanons' );
1356 $opts[ 'userExpLevel' ] = 'registered';
1360 if ( $opts[ 'hideliu' ] ) {
1361 $opts->reset( 'hideliu' );
1362 $opts[ 'userExpLevel' ] = 'unregistered';
1370 * Convert parameters values from true/false to 1/0
1371 * so they are not omitted by wfArrayToCgi()
1374 * @param array $params
1377 protected function convertParamsForLink( $params ) {
1378 foreach ( $params as &$value ) {
1379 if ( $value === false ) {
1388 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1389 * the user requested.
1391 * @param array &$tables Array of tables; see IDatabase::select $table
1392 * @param array &$fields Array of fields; see IDatabase::select $vars
1393 * @param array &$conds Array of conditions; see IDatabase::select $conds
1394 * @param array &$query_options Array of query options; see IDatabase::select $options
1395 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1396 * @param FormOptions $opts
1398 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1399 &$join_conds, FormOptions
$opts
1401 $dbr = $this->getDB();
1402 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1404 /** @var ChangesListFilterGroup $filterGroup */
1405 foreach ( $this->filterGroups
as $filterGroup ) {
1406 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1407 $query_options, $join_conds, $opts, $isStructuredUI );
1410 // Namespace filtering
1411 if ( $opts[ 'namespace' ] !== '' ) {
1412 $namespaces = explode( ';', $opts[ 'namespace' ] );
1414 if ( $opts[ 'associated' ] ) {
1415 $associatedNamespaces = array_map(
1417 return MWNamespace
::getAssociated( $ns );
1421 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1424 if ( count( $namespaces ) === 1 ) {
1425 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1426 $value = $dbr->addQuotes( reset( $namespaces ) );
1428 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1429 sort( $namespaces );
1430 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1432 $conds[] = "rc_namespace $operator $value";
1436 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1437 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1439 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1440 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
1441 $cutoff = $dbr->timestamp( $opts['from'] );
1443 $opts->reset( 'from' );
1446 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1452 * @param array $tables Array of tables; see IDatabase::select $table
1453 * @param array $fields Array of fields; see IDatabase::select $vars
1454 * @param array $conds Array of conditions; see IDatabase::select $conds
1455 * @param array $query_options Array of query options; see IDatabase::select $options
1456 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1457 * @param FormOptions $opts
1458 * @return bool|IResultWrapper Result or false
1460 protected function doMainQuery( $tables, $fields, $conds,
1461 $query_options, $join_conds, FormOptions
$opts
1463 $rcQuery = RecentChange
::getQueryInfo();
1464 $tables = array_merge( $tables, $rcQuery['tables'] );
1465 $fields = array_merge( $rcQuery['fields'], $fields );
1466 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
1468 ChangeTags
::modifyDisplayQuery(
1477 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1483 $dbr = $this->getDB();
1485 return $dbr->select(
1495 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1496 &$query_options, &$join_conds, $opts
1499 'ChangesListSpecialPageQuery',
1500 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1505 * Return a IDatabase object for reading
1509 protected function getDB() {
1510 return wfGetDB( DB_REPLICA
);
1514 * Send header output to the OutputPage object, only called if not using feeds
1516 * @param int $rowCount Number of database rows
1517 * @param FormOptions $opts
1519 private function webOutputHeader( $rowCount, $opts ) {
1520 if ( !$this->including() ) {
1521 $this->outputFeedLinks();
1522 $this->doHeader( $opts, $rowCount );
1527 * Send output to the OutputPage object, only called if not used feeds
1529 * @param IResultWrapper $rows Database rows
1530 * @param FormOptions $opts
1532 public function webOutput( $rows, $opts ) {
1533 $this->webOutputHeader( $rows->numRows(), $opts );
1535 $this->outputChangesList( $rows, $opts );
1539 * Output feed links.
1541 public function outputFeedLinks() {
1542 // nothing by default
1546 * Build and output the actual changes list.
1548 * @param IResultWrapper $rows Database rows
1549 * @param FormOptions $opts
1551 abstract public function outputChangesList( $rows, $opts );
1554 * Set the text to be displayed above the changes
1556 * @param FormOptions $opts
1557 * @param int $numRows Number of rows in the result to show after this header
1559 public function doHeader( $opts, $numRows ) {
1560 $this->setTopText( $opts );
1562 // @todo Lots of stuff should be done here.
1564 $this->setBottomText( $opts );
1568 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1569 * or similar methods to print the text.
1571 * @param FormOptions $opts
1573 public function setTopText( FormOptions
$opts ) {
1574 // nothing by default
1578 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1579 * or similar methods to print the text.
1581 * @param FormOptions $opts
1583 public function setBottomText( FormOptions
$opts ) {
1584 // nothing by default
1588 * Get options to be displayed in a form
1589 * @todo This should handle options returned by getDefaultOptions().
1590 * @todo Not called by anything in this class (but is in subclasses), should be
1591 * called by something… doHeader() maybe?
1593 * @param FormOptions $opts
1596 public function getExtraOptions( $opts ) {
1601 * Return the legend displayed within the fieldset
1605 public function makeLegend() {
1606 $context = $this->getContext();
1607 $user = $context->getUser();
1608 # The legend showing what the letters and stuff mean
1609 $legend = Html
::openElement( 'dl' ) . "\n";
1610 # Iterates through them and gets the messages for both letter and tooltip
1611 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1612 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1613 unset( $legendItems['unpatrolled'] );
1615 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1616 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1617 $letter = $item['letter'];
1618 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1620 $legend .= Html
::element( 'dt',
1621 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1623 Html
::rawElement( 'dd',
1624 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1625 $context->msg( $label )->parse()
1629 $legend .= Html
::rawElement( 'dt',
1630 [ 'class' => 'mw-plusminus-pos' ],
1631 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1633 $legend .= Html
::element(
1635 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1636 $context->msg( 'recentchanges-label-plusminus' )->text()
1638 $legend .= Html
::closeElement( 'dl' ) . "\n";
1640 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1641 $context->msg( 'rcfilters-legend-heading' )->parse() :
1642 $context->msg( 'recentchanges-legend-heading' )->parse();
1645 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1646 $collapsedClass = $collapsedState === 'collapsed' ?
' mw-collapsed' : '';
1649 '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
1651 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1658 * Add page-specific modules.
1660 protected function addModules() {
1661 $out = $this->getOutput();
1662 // Styles and behavior for the legend box (see makeLegend())
1663 $out->addModuleStyles( [
1664 'mediawiki.special.changeslist.legend',
1665 'mediawiki.special.changeslist',
1667 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1669 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
1670 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1671 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1675 protected function getGroupName() {
1680 * Filter on users' experience levels; this will not be called if nothing is
1683 * @param string $specialPageClassName Class name of current special page
1684 * @param IContextSource $context Context, for e.g. user
1685 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1686 * @param array &$tables Array of tables; see IDatabase::select $table
1687 * @param array &$fields Array of fields; see IDatabase::select $vars
1688 * @param array &$conds Array of conditions; see IDatabase::select $conds
1689 * @param array &$query_options Array of query options; see IDatabase::select $options
1690 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1691 * @param array $selectedExpLevels The allowed active values, sorted
1692 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1695 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1696 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1698 global $wgLearnerEdits,
1699 $wgExperiencedUserEdits,
1700 $wgLearnerMemberSince,
1701 $wgExperiencedUserMemberSince;
1705 // If all levels are selected, don't filter
1706 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1710 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1712 in_array( 'registered', $selectedExpLevels ) &&
1713 in_array( 'unregistered', $selectedExpLevels )
1718 $actorMigration = ActorMigration
::newMigration();
1719 $actorQuery = $actorMigration->getJoin( 'rc_user' );
1720 $tables +
= $actorQuery['tables'];
1721 $join_conds +
= $actorQuery['joins'];
1723 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1725 in_array( 'registered', $selectedExpLevels ) &&
1726 !in_array( 'unregistered', $selectedExpLevels )
1728 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1732 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1733 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1738 $join_conds['user'] = [ 'LEFT JOIN', $actorQuery['fields']['rc_user'] . ' = user_id' ];
1743 $secondsPerDay = 86400;
1744 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1745 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1747 $aboveNewcomer = $dbr->makeList(
1749 'user_editcount >= ' . intval( $wgLearnerEdits ),
1750 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1755 $aboveLearner = $dbr->makeList(
1757 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1758 'user_registration <= ' .
1759 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1766 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1767 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1768 $conditions[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1771 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1772 $conditions[] = "NOT ( $aboveNewcomer )";
1773 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1774 $conditions[] = $dbr->makeList(
1775 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1778 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1779 $conditions[] = $aboveLearner;
1780 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1781 $conditions[] = "NOT ( $aboveLearner )";
1782 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1783 $conditions[] = $dbr->makeList(
1784 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1787 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1788 $conditions[] = $aboveNewcomer;
1789 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1790 $conditions[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1793 if ( count( $conditions ) > 1 ) {
1794 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1795 } elseif ( count( $conditions ) === 1 ) {
1796 $conds[] = reset( $conditions );
1801 * Check whether the structured filter UI is enabled
1805 public function isStructuredFilterUiEnabled() {
1806 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1810 return static::checkStructuredFilterUiEnabled(
1817 * Check whether the structured filter UI is enabled by default (regardless of
1818 * this particular user's setting)
1822 public function isStructuredFilterUiEnabledByDefault() {
1823 if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
1824 return !$this->getUser()->getDefaultOption( 'rcenhancedfilters-disable' );
1826 return $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
1831 * Static method to check whether StructuredFilter UI is enabled for the given user
1834 * @param Config $config
1838 public static function checkStructuredFilterUiEnabled( Config
$config, User
$user ) {
1839 if ( $config->get( 'StructuredChangeFiltersShowPreference' ) ) {
1840 return !$user->getOption( 'rcenhancedfilters-disable' );
1842 return $user->getOption( 'rcenhancedfilters' );
1847 * Get the default value of the number of changes to display when loading
1853 public function getDefaultLimit() {
1854 return $this->getUser()->getIntOption( static::$limitPreferenceName );
1858 * Get the default value of the number of days to display when loading
1860 * Supports fractional values, and should be cast to a float.
1865 public function getDefaultDays() {
1866 return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );