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
;
28 use MediaWiki\MediaWikiServices
;
31 * Special page which uses a ChangesList to show query results.
32 * @todo Way too many public functions, most of them should be protected
34 * @ingroup SpecialPage
36 abstract class ChangesListSpecialPage
extends SpecialPage
{
38 * Maximum length of a tag description in UTF-8 characters.
39 * Longer descriptions will be truncated.
41 const TAG_DESC_CHARACTER_LIMIT
= 120;
44 * Preference name for saved queries. Subclasses that use saved queries should override this.
47 protected static $savedQueriesPreferenceName;
50 * Preference name for 'days'. Subclasses should override this.
53 protected static $daysPreferenceName;
56 * Preference name for 'limit'. Subclasses should override this.
59 protected static $limitPreferenceName;
62 * Preference name for collapsing the active filter display. Subclasses should override this.
65 protected static $collapsedPreferenceName;
70 /** @var FormOptions */
73 // Order of both groups and filters is significant; first is top-most priority,
74 // descending from there.
75 // 'showHideSuffix' is a shortcut to and avoid spelling out
76 // details specific to subclasses here.
78 * Definition information for the filters and their groups
80 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
81 * However, priority is dynamically added for the core groups, to ease maintenance.
83 * Groups are displayed to the user in the structured UI. However, if necessary,
84 * all of the filters in a group can be configured to only display on the
85 * unstuctured UI, in which case you don't need a group title.
87 * @var array $filterGroupDefinitions
89 private $filterGroupDefinitions;
91 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
92 // that is registered conditionally.
93 private $legacyReviewStatusFilterGroupDefinition;
95 // Single filter group registered conditionally
96 private $reviewStatusFilterGroupDefinition;
98 // Single filter group registered conditionally
99 private $hideCategorizationFilterDefinition;
102 * Filter groups, and their contained filters
103 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
105 * @var array $filterGroups
107 protected $filterGroups = [];
109 public function __construct( $name, $restriction ) {
110 parent
::__construct( $name, $restriction );
112 $nonRevisionTypes = [ RC_LOG
];
113 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
115 $this->filterGroupDefinitions
= [
117 'name' => 'registration',
118 'title' => 'rcfilters-filtergroup-registration',
119 'class' => ChangesListBooleanFilterGroup
::class,
123 // rcshowhideliu-show, rcshowhideliu-hide,
125 'showHideSuffix' => 'showhideliu',
127 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
128 &$query_options, &$join_conds
130 $actorMigration = ActorMigration
::newMigration();
131 $actorQuery = $actorMigration->getJoin( 'rc_user' );
132 $tables +
= $actorQuery['tables'];
133 $join_conds +
= $actorQuery['joins'];
134 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
136 'isReplacedInStructuredUi' => true,
140 'name' => 'hideanons',
141 // rcshowhideanons-show, rcshowhideanons-hide,
143 'showHideSuffix' => 'showhideanons',
145 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
146 &$query_options, &$join_conds
148 $actorMigration = ActorMigration
::newMigration();
149 $actorQuery = $actorMigration->getJoin( 'rc_user' );
150 $tables +
= $actorQuery['tables'];
151 $join_conds +
= $actorQuery['joins'];
152 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
154 'isReplacedInStructuredUi' => true,
160 'name' => 'userExpLevel',
161 'title' => 'rcfilters-filtergroup-userExpLevel',
162 'class' => ChangesListStringOptionsFilterGroup
::class,
163 'isFullCoverage' => true,
166 'name' => 'unregistered',
167 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
168 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
169 'cssClassSuffix' => 'user-unregistered',
170 'isRowApplicableCallable' => function ( $ctx, $rc ) {
171 return !$rc->getAttribute( 'rc_user' );
175 'name' => 'registered',
176 'label' => 'rcfilters-filter-user-experience-level-registered-label',
177 'description' => 'rcfilters-filter-user-experience-level-registered-description',
178 'cssClassSuffix' => 'user-registered',
179 'isRowApplicableCallable' => function ( $ctx, $rc ) {
180 return $rc->getAttribute( 'rc_user' );
184 'name' => 'newcomer',
185 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
186 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
187 'cssClassSuffix' => 'user-newcomer',
188 'isRowApplicableCallable' => function ( $ctx, $rc ) {
189 $performer = $rc->getPerformer();
190 return $performer && $performer->isLoggedIn() &&
191 $performer->getExperienceLevel() === 'newcomer';
196 'label' => 'rcfilters-filter-user-experience-level-learner-label',
197 'description' => 'rcfilters-filter-user-experience-level-learner-description',
198 'cssClassSuffix' => 'user-learner',
199 'isRowApplicableCallable' => function ( $ctx, $rc ) {
200 $performer = $rc->getPerformer();
201 return $performer && $performer->isLoggedIn() &&
202 $performer->getExperienceLevel() === 'learner';
206 'name' => 'experienced',
207 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
208 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
209 'cssClassSuffix' => 'user-experienced',
210 'isRowApplicableCallable' => function ( $ctx, $rc ) {
211 $performer = $rc->getPerformer();
212 return $performer && $performer->isLoggedIn() &&
213 $performer->getExperienceLevel() === 'experienced';
217 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
218 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
222 'name' => 'authorship',
223 'title' => 'rcfilters-filtergroup-authorship',
224 'class' => ChangesListBooleanFilterGroup
::class,
227 'name' => 'hidemyself',
228 'label' => 'rcfilters-filter-editsbyself-label',
229 'description' => 'rcfilters-filter-editsbyself-description',
230 // rcshowhidemine-show, rcshowhidemine-hide,
232 'showHideSuffix' => 'showhidemine',
234 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
235 &$query_options, &$join_conds
237 $actorQuery = ActorMigration
::newMigration()->getWhere( $dbr, 'rc_user', $ctx->getUser() );
238 $tables +
= $actorQuery['tables'];
239 $join_conds +
= $actorQuery['joins'];
240 $conds[] = 'NOT(' . $actorQuery['conds'] . ')';
242 'cssClassSuffix' => 'self',
243 'isRowApplicableCallable' => function ( $ctx, $rc ) {
244 return $ctx->getUser()->equals( $rc->getPerformer() );
248 'name' => 'hidebyothers',
249 'label' => 'rcfilters-filter-editsbyother-label',
250 'description' => 'rcfilters-filter-editsbyother-description',
252 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
253 &$query_options, &$join_conds
255 $actorQuery = ActorMigration
::newMigration()
256 ->getWhere( $dbr, 'rc_user', $ctx->getUser(), false );
257 $tables +
= $actorQuery['tables'];
258 $join_conds +
= $actorQuery['joins'];
259 $conds[] = $actorQuery['conds'];
261 'cssClassSuffix' => 'others',
262 'isRowApplicableCallable' => function ( $ctx, $rc ) {
263 return !$ctx->getUser()->equals( $rc->getPerformer() );
270 'name' => 'automated',
271 'title' => 'rcfilters-filtergroup-automated',
272 'class' => ChangesListBooleanFilterGroup
::class,
275 'name' => 'hidebots',
276 'label' => 'rcfilters-filter-bots-label',
277 'description' => 'rcfilters-filter-bots-description',
278 // rcshowhidebots-show, rcshowhidebots-hide,
280 'showHideSuffix' => 'showhidebots',
282 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
283 &$query_options, &$join_conds
285 $conds['rc_bot'] = 0;
287 'cssClassSuffix' => 'bot',
288 'isRowApplicableCallable' => function ( $ctx, $rc ) {
289 return $rc->getAttribute( 'rc_bot' );
293 'name' => 'hidehumans',
294 'label' => 'rcfilters-filter-humans-label',
295 'description' => 'rcfilters-filter-humans-description',
297 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
298 &$query_options, &$join_conds
300 $conds['rc_bot'] = 1;
302 'cssClassSuffix' => 'human',
303 'isRowApplicableCallable' => function ( $ctx, $rc ) {
304 return !$rc->getAttribute( 'rc_bot' );
310 // significance (conditional)
313 'name' => 'significance',
314 'title' => 'rcfilters-filtergroup-significance',
315 'class' => ChangesListBooleanFilterGroup
::class,
319 'name' => 'hideminor',
320 'label' => 'rcfilters-filter-minor-label',
321 'description' => 'rcfilters-filter-minor-description',
322 // rcshowhideminor-show, rcshowhideminor-hide,
324 'showHideSuffix' => 'showhideminor',
326 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
327 &$query_options, &$join_conds
329 $conds[] = 'rc_minor = 0';
331 'cssClassSuffix' => 'minor',
332 'isRowApplicableCallable' => function ( $ctx, $rc ) {
333 return $rc->getAttribute( 'rc_minor' );
337 'name' => 'hidemajor',
338 'label' => 'rcfilters-filter-major-label',
339 'description' => 'rcfilters-filter-major-description',
341 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
342 &$query_options, &$join_conds
344 $conds[] = 'rc_minor = 1';
346 'cssClassSuffix' => 'major',
347 'isRowApplicableCallable' => function ( $ctx, $rc ) {
348 return !$rc->getAttribute( 'rc_minor' );
355 'name' => 'lastRevision',
356 'title' => 'rcfilters-filtergroup-lastRevision',
357 'class' => ChangesListBooleanFilterGroup
::class,
361 'name' => 'hidelastrevision',
362 'label' => 'rcfilters-filter-lastrevision-label',
363 'description' => 'rcfilters-filter-lastrevision-description',
365 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
366 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
367 $conds[] = $dbr->makeList(
369 'rc_this_oldid <> page_latest',
370 'rc_type' => $nonRevisionTypes,
375 'cssClassSuffix' => 'last',
376 'isRowApplicableCallable' => function ( $ctx, $rc ) {
377 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
381 'name' => 'hidepreviousrevisions',
382 'label' => 'rcfilters-filter-previousrevision-label',
383 'description' => 'rcfilters-filter-previousrevision-description',
385 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
386 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
387 $conds[] = $dbr->makeList(
389 'rc_this_oldid = page_latest',
390 'rc_type' => $nonRevisionTypes,
395 'cssClassSuffix' => 'previous',
396 'isRowApplicableCallable' => function ( $ctx, $rc ) {
397 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
403 // With extensions, there can be change types that will not be hidden by any of these.
405 'name' => 'changeType',
406 'title' => 'rcfilters-filtergroup-changetype',
407 'class' => ChangesListBooleanFilterGroup
::class,
411 'name' => 'hidepageedits',
412 'label' => 'rcfilters-filter-pageedits-label',
413 'description' => 'rcfilters-filter-pageedits-description',
416 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
417 &$query_options, &$join_conds
419 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
421 'cssClassSuffix' => 'src-mw-edit',
422 'isRowApplicableCallable' => function ( $ctx, $rc ) {
423 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
427 'name' => 'hidenewpages',
428 'label' => 'rcfilters-filter-newpages-label',
429 'description' => 'rcfilters-filter-newpages-description',
432 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
433 &$query_options, &$join_conds
435 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
437 'cssClassSuffix' => 'src-mw-new',
438 'isRowApplicableCallable' => function ( $ctx, $rc ) {
439 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
443 // hidecategorization
447 'label' => 'rcfilters-filter-logactions-label',
448 'description' => 'rcfilters-filter-logactions-description',
451 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
452 &$query_options, &$join_conds
454 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
456 'cssClassSuffix' => 'src-mw-log',
457 'isRowApplicableCallable' => function ( $ctx, $rc ) {
458 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
466 $this->legacyReviewStatusFilterGroupDefinition
= [
468 'name' => 'legacyReviewStatus',
469 'title' => 'rcfilters-filtergroup-reviewstatus',
470 'class' => ChangesListBooleanFilterGroup
::class,
473 'name' => 'hidepatrolled',
474 // rcshowhidepatr-show, rcshowhidepatr-hide
476 'showHideSuffix' => 'showhidepatr',
478 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
479 &$query_options, &$join_conds
481 $conds['rc_patrolled'] = RecentChange
::PRC_UNPATROLLED
;
483 'isReplacedInStructuredUi' => true,
486 'name' => 'hideunpatrolled',
488 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
489 &$query_options, &$join_conds
491 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
;
493 'isReplacedInStructuredUi' => true,
499 $this->reviewStatusFilterGroupDefinition
= [
501 'name' => 'reviewStatus',
502 'title' => 'rcfilters-filtergroup-reviewstatus',
503 'class' => ChangesListStringOptionsFilterGroup
::class,
504 'isFullCoverage' => true,
508 'name' => 'unpatrolled',
509 'label' => 'rcfilters-filter-reviewstatus-unpatrolled-label',
510 'description' => 'rcfilters-filter-reviewstatus-unpatrolled-description',
511 'cssClassSuffix' => 'reviewstatus-unpatrolled',
512 'isRowApplicableCallable' => function ( $ctx, $rc ) {
513 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_UNPATROLLED
;
518 'label' => 'rcfilters-filter-reviewstatus-manual-label',
519 'description' => 'rcfilters-filter-reviewstatus-manual-description',
520 'cssClassSuffix' => 'reviewstatus-manual',
521 'isRowApplicableCallable' => function ( $ctx, $rc ) {
522 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_PATROLLED
;
527 'label' => 'rcfilters-filter-reviewstatus-auto-label',
528 'description' => 'rcfilters-filter-reviewstatus-auto-description',
529 'cssClassSuffix' => 'reviewstatus-auto',
530 'isRowApplicableCallable' => function ( $ctx, $rc ) {
531 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_AUTOPATROLLED
;
535 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
536 'queryCallable' => function ( $specialPageClassName, $ctx, $dbr,
537 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selected
539 if ( $selected === [] ) {
542 $rcPatrolledValues = [
543 'unpatrolled' => RecentChange
::PRC_UNPATROLLED
,
544 'manual' => RecentChange
::PRC_PATROLLED
,
545 'auto' => RecentChange
::PRC_AUTOPATROLLED
,
547 // e.g. rc_patrolled IN (0, 2)
548 $conds['rc_patrolled'] = array_map( function ( $s ) use ( $rcPatrolledValues ) {
549 return $rcPatrolledValues[ $s ];
555 $this->hideCategorizationFilterDefinition
= [
556 'name' => 'hidecategorization',
557 'label' => 'rcfilters-filter-categorization-label',
558 'description' => 'rcfilters-filter-categorization-description',
559 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
560 // wlshowhidecategorization
561 'showHideSuffix' => 'showhidecategorization',
564 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
565 &$query_options, &$join_conds
567 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
569 'cssClassSuffix' => 'src-mw-categorize',
570 'isRowApplicableCallable' => function ( $ctx, $rc ) {
571 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
577 * Check if filters are in conflict and guaranteed to return no results.
581 protected function areFiltersInConflict() {
582 $opts = $this->getOptions();
583 /** @var ChangesListFilterGroup $group */
584 foreach ( $this->getFilterGroups() as $group ) {
585 if ( $group->getConflictingGroups() ) {
588 " specifies conflicts with other groups but these are not supported yet."
592 /** @var ChangesListFilter $conflictingFilter */
593 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
594 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
599 /** @var ChangesListFilter $filter */
600 foreach ( $group->getFilters() as $filter ) {
601 /** @var ChangesListFilter $conflictingFilter */
602 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
604 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
605 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
619 * @param string|null $subpage
621 public function execute( $subpage ) {
622 $this->rcSubpage
= $subpage;
624 $this->considerActionsForDefaultSavedQuery( $subpage );
626 $opts = $this->getOptions();
628 $rows = $this->getRows();
629 if ( $rows === false ) {
630 $rows = new FakeResultWrapper( [] );
633 // Used by Structured UI app to get results without MW chrome
634 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
635 $this->getOutput()->setArticleBodyOnly( true );
638 // Used by "live update" and "view newest" to check
639 // if there's new changes with minimal data transfer
640 if ( $this->getRequest()->getBool( 'peek' ) ) {
641 $code = $rows->numRows() > 0 ?
200 : 204;
642 $this->getOutput()->setStatusCode( $code );
644 if ( $this->getUser()->isAnon() !==
645 $this->getRequest()->getFuzzyBool( 'isAnon' )
647 $this->getOutput()->setStatusCode( 205 );
653 $batch = new LinkBatch
;
654 foreach ( $rows as $row ) {
655 $batch->add( NS_USER
, $row->rc_user_text
);
656 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
657 $batch->add( $row->rc_namespace
, $row->rc_title
);
658 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
659 $formatter = LogFormatter
::newFromRow( $row );
660 foreach ( $formatter->getPreloadTitles() as $title ) {
661 $batch->addObj( $title );
668 $this->outputHeader();
670 $this->webOutput( $rows, $opts );
673 } catch ( DBQueryTimeoutError
$timeoutException ) {
674 MWExceptionHandler
::logException( $timeoutException );
677 $this->outputHeader();
680 $this->getOutput()->setStatusCode( 500 );
681 $this->webOutputHeader( 0, $opts );
682 $this->outputTimeout();
685 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
686 // Clean up any bad page entries for titles showing up in RC
687 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
689 LoggerFactory
::getInstance( 'objectcache' )
693 $this->includeRcFiltersApp();
697 * Check whether or not the page should load defaults, and if so, whether
698 * a default saved query is relevant to be redirected to. If it is relevant,
699 * redirect properly with all necessary query parameters.
701 * @param string $subpage
703 protected function considerActionsForDefaultSavedQuery( $subpage ) {
704 if ( !$this->isStructuredFilterUiEnabled() ||
$this->including() ) {
708 $knownParams = $this->getRequest()->getValues(
709 ...array_keys( $this->getOptions()->getAllValues() )
712 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
713 // we need to exclude several parameters we know should not be counted towards preventing
714 // the loading of defaults.
715 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
716 $knownParams = array_diff_key( $knownParams, $excludedParams );
719 // If there are NO known parameters in the URL request
720 // (that are not excluded) then we need to check into loading
721 // the default saved query
722 count( $knownParams ) === 0
724 // Get the saved queries data and parse it
725 $savedQueries = FormatJson
::decode(
726 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
730 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
731 // Only load queries that are 'version' 2, since those
732 // have parameter representation
733 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
734 $savedQueryDefaultID = $savedQueries[ 'default' ];
735 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
737 // Build the entire parameter list
738 $query = array_merge(
739 $defaultQuery[ 'params' ],
740 $defaultQuery[ 'highlights' ],
745 // Add to the query any parameters that we may have ignored before
746 // but are still valid and requested in the URL
747 $query = array_merge( $this->getRequest()->getValues(), $query );
748 unset( $query[ 'title' ] );
749 $this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) );
751 // There's a default, but the version is not 2, and the server can't
752 // actually recognize the query itself. This happens if it is before
753 // the conversion, so we need to tell the UI to reload saved query as
754 // it does the conversion to version 2
755 $this->getOutput()->addJsConfigVars(
756 'wgStructuredChangeFiltersDefaultSavedQueryExists',
760 // Add the class that tells the frontend it is still loading
762 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
769 * Include the modules and configuration for the RCFilters app.
770 * Conditional on the user having the feature enabled.
772 * If it is disabled, add a <body> class marking that
774 protected function includeRcFiltersApp() {
775 $out = $this->getOutput();
776 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
777 $jsData = $this->getStructuredFilterJsData();
779 foreach ( $jsData['messageKeys'] as $key ) {
780 $messages[$key] = $this->msg( $key )->plain();
783 $out->addBodyClasses( 'mw-rcfilters-enabled' );
784 $collapsed = $this->getUser()->getBoolOption( static::$collapsedPreferenceName );
786 $out->addBodyClasses( 'mw-rcfilters-collapsed' );
789 // These config and message exports should be moved into a ResourceLoader data module (T201574)
790 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
791 $out->addJsConfigVars( 'wgStructuredChangeFiltersMessages', $messages );
792 $out->addJsConfigVars( 'wgStructuredChangeFiltersCollapsedState', $collapsed );
794 $out->addJsConfigVars(
795 'StructuredChangeFiltersDisplayConfig',
797 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
798 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
799 'limitDefault' => $this->getDefaultLimit(),
800 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
801 'daysDefault' => $this->getDefaultDays(),
805 $out->addJsConfigVars(
806 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
807 static::$savedQueriesPreferenceName
809 $out->addJsConfigVars(
810 'wgStructuredChangeFiltersLimitPreferenceName',
811 static::$limitPreferenceName
813 $out->addJsConfigVars(
814 'wgStructuredChangeFiltersDaysPreferenceName',
815 static::$daysPreferenceName
817 $out->addJsConfigVars(
818 'wgStructuredChangeFiltersCollapsedPreferenceName',
819 static::$collapsedPreferenceName
822 $out->addBodyClasses( 'mw-rcfilters-disabled' );
827 * Get config vars to export with the mediawiki.rcfilters.filters.ui module.
829 * @param ResourceLoaderContext $context
832 public static function getRcFiltersConfigVars( ResourceLoaderContext
$context ) {
834 'RCFiltersChangeTags' => self
::getChangeTagList( $context ),
835 'StructuredChangeFiltersEditWatchlistUrl' =>
836 SpecialPage
::getTitleFor( 'EditWatchlist' )->getLocalURL()
841 * Fetch the change tags list for the front end
843 * @param ResourceLoaderContext $context
844 * @return array Tag data
846 protected static function getChangeTagList( ResourceLoaderContext
$context ) {
847 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
848 return $cache->getWithSetCallback(
849 $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage() ),
850 $cache::TTL_MINUTE
* 10,
851 function () use ( $context ) {
852 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
853 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
855 $tagStats = ChangeTags
::tagUsageStatistics();
856 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
858 // Sort by hits (disabled for now)
859 //arsort( $tagHitCounts );
861 // HACK work around ChangeTags::truncateTagDescription() requiring a RequestContext
862 $fakeContext = RequestContext
::newExtraneousContext( Title
::newFromText( 'Dwimmerlaik' ) );
863 $fakeContext->setLanguage( Language
::factory( $context->getLanguage() ) );
865 // Build the list and data
867 foreach ( $tagHitCounts as $tagName => $hits ) {
870 // Only get active tags
871 isset( $explicitlyDefinedTags[ $tagName ] ) ||
872 isset( $softwareActivatedTags[ $tagName ] )
874 // Only get tags with more than 0 hits
879 'label' => Sanitizer
::stripAllTags(
880 ChangeTags
::tagDescription( $tagName, $context )
883 ChangeTags
::truncateTagDescription(
885 self
::TAG_DESC_CHARACTER_LIMIT
,
888 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
894 // Instead of sorting by hit count (disabled, see above), sort by display name
895 usort( $result, function ( $a, $b ) {
896 return strcasecmp( $a['label'], $b['label'] );
908 * Add the "no results" message to the output
910 protected function outputNoResults() {
911 $this->getOutput()->addHTML(
912 '<div class="mw-changeslist-empty">' .
913 $this->msg( 'recentchanges-noresult' )->parse() .
919 * Add the "timeout" message to the output
921 protected function outputTimeout() {
922 $this->getOutput()->addHTML(
923 '<div class="mw-changeslist-empty mw-changeslist-timeout">' .
924 $this->msg( 'recentchanges-timeout' )->parse() .
930 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
932 * @return bool|IResultWrapper Result or false
934 public function getRows() {
935 $opts = $this->getOptions();
942 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
944 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
948 * Get the current FormOptions for this request
950 * @return FormOptions
952 public function getOptions() {
953 if ( $this->rcOptions
=== null ) {
954 $this->rcOptions
= $this->setup( $this->rcSubpage
);
957 return $this->rcOptions
;
961 * Register all filters and their groups (including those from hooks), plus handle
962 * conflicts and defaults.
964 * You might want to customize these in the same method, in subclasses. You can
965 * call getFilterGroup to access a group, and (on the group) getFilter to access a
966 * filter, then make necessary modfications to the filter or group (e.g. with
969 protected function registerFilters() {
970 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
972 // Make sure this is not being transcluded (we don't want to show this
973 // information to all users just because the user that saves the edit can
974 // patrol or is logged in)
975 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
976 $this->registerFiltersFromDefinitions( $this->legacyReviewStatusFilterGroupDefinition
);
977 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
980 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
982 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
983 $transformedHideCategorizationDef = $this->transformFilterDefinition(
984 $this->hideCategorizationFilterDefinition
987 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
989 $hideCategorization = new ChangesListBooleanFilter(
990 $transformedHideCategorizationDef
994 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
996 $this->registerFiltersFromDefinitions( [] );
998 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
999 $registered = $userExperienceLevel->getFilter( 'registered' );
1000 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
1001 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
1002 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
1004 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
1005 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
1006 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
1008 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
1009 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
1011 // categoryFilter is conditional; see registerFilters
1012 if ( $categoryFilter !== null ) {
1013 $hideMinorFilter->conflictsWith(
1015 'rcfilters-hideminor-conflicts-typeofchange-global',
1016 'rcfilters-hideminor-conflicts-typeofchange',
1017 'rcfilters-typeofchange-conflicts-hideminor'
1020 $hideMinorFilter->conflictsWith(
1022 'rcfilters-hideminor-conflicts-typeofchange-global',
1023 'rcfilters-hideminor-conflicts-typeofchange',
1024 'rcfilters-typeofchange-conflicts-hideminor'
1026 $hideMinorFilter->conflictsWith(
1027 $pagecreationFilter,
1028 'rcfilters-hideminor-conflicts-typeofchange-global',
1029 'rcfilters-hideminor-conflicts-typeofchange',
1030 'rcfilters-typeofchange-conflicts-hideminor'
1035 * Transforms filter definition to prepare it for constructor.
1037 * See overrides of this method as well.
1039 * @param array $filterDefinition Original filter definition
1041 * @return array Transformed definition
1043 protected function transformFilterDefinition( array $filterDefinition ) {
1044 return $filterDefinition;
1048 * Register filters from a definition object
1050 * Array specifying groups and their filters; see Filter and
1051 * ChangesListFilterGroup constructors.
1053 * There is light processing to simplify core maintenance.
1054 * @param array $definition
1056 protected function registerFiltersFromDefinitions( array $definition ) {
1057 $autoFillPriority = -1;
1058 foreach ( $definition as $groupDefinition ) {
1059 if ( !isset( $groupDefinition['priority'] ) ) {
1060 $groupDefinition['priority'] = $autoFillPriority;
1062 // If it's explicitly specified, start over the auto-fill
1063 $autoFillPriority = $groupDefinition['priority'];
1066 $autoFillPriority--;
1068 $className = $groupDefinition['class'];
1069 unset( $groupDefinition['class'] );
1071 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
1072 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
1075 $this->registerFilterGroup( new $className( $groupDefinition ) );
1080 * @return array The legacy show/hide toggle filters
1082 protected function getLegacyShowHideFilters() {
1084 foreach ( $this->filterGroups
as $group ) {
1085 if ( $group instanceof ChangesListBooleanFilterGroup
) {
1086 foreach ( $group->getFilters() as $key => $filter ) {
1087 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1088 $filters[ $key ] = $filter;
1097 * Register all the filters, including legacy hook-driven ones.
1098 * Then create a FormOptions object with options as specified by the user
1100 * @param array $parameters
1102 * @return FormOptions
1104 public function setup( $parameters ) {
1105 $this->registerFilters();
1107 $opts = $this->getDefaultOptions();
1109 $opts = $this->fetchOptionsFromRequest( $opts );
1111 // Give precedence to subpage syntax
1112 if ( $parameters !== null ) {
1113 $this->parseParameters( $parameters, $opts );
1116 $this->validateOptions( $opts );
1122 * Get a FormOptions object containing the default options. By default, returns
1123 * some basic options. The filters listed explicitly here are overriden in this
1124 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1125 * and more) are structured. Structured filters are overriden in registerFilters.
1128 * @return FormOptions
1130 public function getDefaultOptions() {
1131 $opts = new FormOptions();
1132 $structuredUI = $this->isStructuredFilterUiEnabled();
1133 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1134 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1136 /** @var ChangesListFilterGroup $filterGroup */
1137 foreach ( $this->filterGroups
as $filterGroup ) {
1138 $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
1141 $opts->add( 'namespace', '', FormOptions
::STRING );
1142 $opts->add( 'invert', false );
1143 $opts->add( 'associated', false );
1144 $opts->add( 'urlversion', 1 );
1145 $opts->add( 'tagfilter', '' );
1147 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
1148 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
1150 $opts->add( 'from', '' );
1156 * Register a structured changes list filter group
1158 * @param ChangesListFilterGroup $group
1160 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
1161 $groupName = $group->getName();
1163 $this->filterGroups
[$groupName] = $group;
1167 * Gets the currently registered filters groups
1169 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1171 protected function getFilterGroups() {
1172 return $this->filterGroups
;
1176 * Gets a specified ChangesListFilterGroup by name
1178 * @param string $groupName Name of group
1180 * @return ChangesListFilterGroup|null Group, or null if not registered
1182 public function getFilterGroup( $groupName ) {
1183 return $this->filterGroups
[$groupName] ??
null;
1186 // Currently, this intentionally only includes filters that display
1187 // in the structured UI. This can be changed easily, though, if we want
1188 // to include data on filters that use the unstructured UI. messageKeys is a
1189 // special top-level value, with the value being an array of the message keys to
1190 // send to the client.
1192 * Gets structured filter information needed by JS
1194 * @return array Associative array
1195 * * array $return['groups'] Group data
1196 * * array $return['messageKeys'] Array of message keys
1198 public function getStructuredFilterJsData() {
1201 'messageKeys' => [],
1204 usort( $this->filterGroups
, function ( $a, $b ) {
1205 return $b->getPriority() <=> $a->getPriority();
1208 foreach ( $this->filterGroups
as $groupName => $group ) {
1209 $groupOutput = $group->getJsData( $this );
1210 if ( $groupOutput !== null ) {
1211 $output['messageKeys'] = array_merge(
1212 $output['messageKeys'],
1213 $groupOutput['messageKeys']
1216 unset( $groupOutput['messageKeys'] );
1217 $output['groups'][] = $groupOutput;
1225 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1227 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1229 * @param FormOptions $opts
1230 * @return FormOptions
1232 protected function fetchOptionsFromRequest( $opts ) {
1233 $opts->fetchValuesFromRequest( $this->getRequest() );
1239 * Process $par and put options found in $opts. Used when including the page.
1241 * @param string $par
1242 * @param FormOptions $opts
1244 public function parseParameters( $par, FormOptions
$opts ) {
1245 $stringParameterNameSet = [];
1246 $hideParameterNameSet = [];
1248 // URL parameters can be per-group, like 'userExpLevel',
1249 // or per-filter, like 'hideminor'.
1251 foreach ( $this->filterGroups
as $filterGroup ) {
1252 if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup
) {
1253 $stringParameterNameSet[$filterGroup->getName()] = true;
1254 } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1255 foreach ( $filterGroup->getFilters() as $filter ) {
1256 $hideParameterNameSet[$filter->getName()] = true;
1261 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1262 foreach ( $bits as $bit ) {
1264 if ( isset( $hideParameterNameSet[$bit] ) ) {
1265 // hidefoo => hidefoo=true
1267 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1268 // foo => hidefoo=false
1269 $opts["hide$bit"] = false;
1270 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1271 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1272 $opts[$m[1]] = $m[2];
1279 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1281 * @param FormOptions $opts
1283 public function validateOptions( FormOptions
$opts ) {
1284 $isContradictory = $this->fixContradictoryOptions( $opts );
1285 $isReplaced = $this->replaceOldOptions( $opts );
1287 if ( $isContradictory ||
$isReplaced ) {
1288 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1289 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1292 $opts->validateIntBounds( 'limit', 0, 5000 );
1293 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1297 * Fix invalid options by resetting pairs that should never appear together.
1299 * @param FormOptions $opts
1300 * @return bool True if any option was reset
1302 private function fixContradictoryOptions( FormOptions
$opts ) {
1303 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1305 foreach ( $this->filterGroups
as $filterGroup ) {
1306 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1307 $filters = $filterGroup->getFilters();
1309 if ( count( $filters ) === 1 ) {
1310 // legacy boolean filters should not be considered
1314 $allInGroupEnabled = array_reduce(
1316 function ( $carry, $filter ) use ( $opts ) {
1317 return $carry && $opts[ $filter->getName() ];
1319 /* initialValue */ count( $filters ) > 0
1322 if ( $allInGroupEnabled ) {
1323 foreach ( $filters as $filter ) {
1324 $opts[ $filter->getName() ] = false;
1336 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1339 * This is deprecated and may be removed.
1341 * @param FormOptions $opts
1342 * @return bool True if this change was mode
1344 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1345 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1346 $opts->reset( 'hideanons' );
1347 if ( !$opts['hidebots'] ) {
1348 $opts->reset( 'hideliu' );
1349 $opts['hidehumans'] = 1;
1359 * Replace old options with their structured UI equivalents
1361 * @param FormOptions $opts
1362 * @return bool True if the change was made
1364 public function replaceOldOptions( FormOptions
$opts ) {
1365 if ( !$this->isStructuredFilterUiEnabled() ) {
1371 // At this point 'hideanons' and 'hideliu' cannot be both true,
1372 // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
1373 if ( $opts[ 'hideanons' ] ) {
1374 $opts->reset( 'hideanons' );
1375 $opts[ 'userExpLevel' ] = 'registered';
1379 if ( $opts[ 'hideliu' ] ) {
1380 $opts->reset( 'hideliu' );
1381 $opts[ 'userExpLevel' ] = 'unregistered';
1385 if ( $this->getFilterGroup( 'legacyReviewStatus' ) ) {
1386 if ( $opts[ 'hidepatrolled' ] ) {
1387 $opts->reset( 'hidepatrolled' );
1388 $opts[ 'reviewStatus' ] = 'unpatrolled';
1392 if ( $opts[ 'hideunpatrolled' ] ) {
1393 $opts->reset( 'hideunpatrolled' );
1394 $opts[ 'reviewStatus' ] = implode(
1395 ChangesListStringOptionsFilterGroup
::SEPARATOR
,
1396 [ 'manual', 'auto' ]
1406 * Convert parameters values from true/false to 1/0
1407 * so they are not omitted by wfArrayToCgi()
1410 * @param array $params
1413 protected function convertParamsForLink( $params ) {
1414 foreach ( $params as &$value ) {
1415 if ( $value === false ) {
1424 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1425 * the user requested.
1427 * @param array &$tables Array of tables; see IDatabase::select $table
1428 * @param array &$fields Array of fields; see IDatabase::select $vars
1429 * @param array &$conds Array of conditions; see IDatabase::select $conds
1430 * @param array &$query_options Array of query options; see IDatabase::select $options
1431 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1432 * @param FormOptions $opts
1434 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1435 &$join_conds, FormOptions
$opts
1437 $dbr = $this->getDB();
1438 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1440 /** @var ChangesListFilterGroup $filterGroup */
1441 foreach ( $this->filterGroups
as $filterGroup ) {
1442 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1443 $query_options, $join_conds, $opts, $isStructuredUI );
1446 // Namespace filtering
1447 if ( $opts[ 'namespace' ] !== '' ) {
1448 $namespaces = explode( ';', $opts[ 'namespace' ] );
1450 if ( $opts[ 'associated' ] ) {
1451 $associatedNamespaces = array_map(
1453 return MWNamespace
::getAssociated( $ns );
1457 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1460 if ( count( $namespaces ) === 1 ) {
1461 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1462 $value = $dbr->addQuotes( reset( $namespaces ) );
1464 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1465 sort( $namespaces );
1466 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1468 $conds[] = "rc_namespace $operator $value";
1472 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1473 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1475 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1476 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
1477 $cutoff = $dbr->timestamp( $opts['from'] );
1479 $opts->reset( 'from' );
1482 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1488 * @param array $tables Array of tables; see IDatabase::select $table
1489 * @param array $fields Array of fields; see IDatabase::select $vars
1490 * @param array $conds Array of conditions; see IDatabase::select $conds
1491 * @param array $query_options Array of query options; see IDatabase::select $options
1492 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1493 * @param FormOptions $opts
1494 * @return bool|IResultWrapper Result or false
1496 protected function doMainQuery( $tables, $fields, $conds,
1497 $query_options, $join_conds, FormOptions
$opts
1499 $rcQuery = RecentChange
::getQueryInfo();
1500 $tables = array_merge( $tables, $rcQuery['tables'] );
1501 $fields = array_merge( $rcQuery['fields'], $fields );
1502 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
1504 ChangeTags
::modifyDisplayQuery(
1513 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1519 $dbr = $this->getDB();
1521 return $dbr->select(
1531 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1532 &$query_options, &$join_conds, $opts
1535 'ChangesListSpecialPageQuery',
1536 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1541 * Return a IDatabase object for reading
1545 protected function getDB() {
1546 return wfGetDB( DB_REPLICA
);
1550 * Send header output to the OutputPage object, only called if not using feeds
1552 * @param int $rowCount Number of database rows
1553 * @param FormOptions $opts
1555 private function webOutputHeader( $rowCount, $opts ) {
1556 if ( !$this->including() ) {
1557 $this->outputFeedLinks();
1558 $this->doHeader( $opts, $rowCount );
1563 * Send output to the OutputPage object, only called if not used feeds
1565 * @param IResultWrapper $rows Database rows
1566 * @param FormOptions $opts
1568 public function webOutput( $rows, $opts ) {
1569 $this->webOutputHeader( $rows->numRows(), $opts );
1571 $this->outputChangesList( $rows, $opts );
1575 * Output feed links.
1577 public function outputFeedLinks() {
1578 // nothing by default
1582 * Build and output the actual changes list.
1584 * @param IResultWrapper $rows Database rows
1585 * @param FormOptions $opts
1587 abstract public function outputChangesList( $rows, $opts );
1590 * Set the text to be displayed above the changes
1592 * @param FormOptions $opts
1593 * @param int $numRows Number of rows in the result to show after this header
1595 public function doHeader( $opts, $numRows ) {
1596 $this->setTopText( $opts );
1598 // @todo Lots of stuff should be done here.
1600 $this->setBottomText( $opts );
1604 * Send the text to be displayed before the options.
1605 * Should use $this->getOutput()->addWikiTextAsInterface()
1606 * or similar methods to print the text.
1608 * @param FormOptions $opts
1610 public function setTopText( FormOptions
$opts ) {
1611 // nothing by default
1615 * Send the text to be displayed after the options.
1616 * Should use $this->getOutput()->addWikiTextAsInterface()
1617 * or similar methods to print the text.
1619 * @param FormOptions $opts
1621 public function setBottomText( FormOptions
$opts ) {
1622 // nothing by default
1626 * Get options to be displayed in a form
1627 * @todo This should handle options returned by getDefaultOptions().
1628 * @todo Not called by anything in this class (but is in subclasses), should be
1629 * called by something… doHeader() maybe?
1631 * @param FormOptions $opts
1634 public function getExtraOptions( $opts ) {
1639 * Return the legend displayed within the fieldset
1643 public function makeLegend() {
1644 $context = $this->getContext();
1645 $user = $context->getUser();
1646 # The legend showing what the letters and stuff mean
1647 $legend = Html
::openElement( 'dl' ) . "\n";
1648 # Iterates through them and gets the messages for both letter and tooltip
1649 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1650 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1651 unset( $legendItems['unpatrolled'] );
1653 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1654 $label = $item['legend'] ??
$item['title'];
1655 $letter = $item['letter'];
1656 $cssClass = $item['class'] ??
$key;
1658 $legend .= Html
::element( 'dt',
1659 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1661 Html
::rawElement( 'dd',
1662 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1663 $context->msg( $label )->parse()
1667 $legend .= Html
::rawElement( 'dt',
1668 [ 'class' => 'mw-plusminus-pos' ],
1669 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1671 $legend .= Html
::element(
1673 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1674 $context->msg( 'recentchanges-label-plusminus' )->text()
1676 $legend .= Html
::closeElement( 'dl' ) . "\n";
1678 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1679 $context->msg( 'rcfilters-legend-heading' )->parse() :
1680 $context->msg( 'recentchanges-legend-heading' )->parse();
1683 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1684 $collapsedClass = $collapsedState === 'collapsed' ?
' mw-collapsed' : '';
1687 '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
1689 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1696 * Add page-specific modules.
1698 protected function addModules() {
1699 $out = $this->getOutput();
1700 // Styles and behavior for the legend box (see makeLegend())
1701 $out->addModuleStyles( [
1702 'mediawiki.interface.helpers.styles',
1703 'mediawiki.special.changeslist.legend',
1704 'mediawiki.special.changeslist',
1706 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1708 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
1709 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1710 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1714 protected function getGroupName() {
1719 * Filter on users' experience levels; this will not be called if nothing is
1722 * @param string $specialPageClassName Class name of current special page
1723 * @param IContextSource $context Context, for e.g. user
1724 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1725 * @param array &$tables Array of tables; see IDatabase::select $table
1726 * @param array &$fields Array of fields; see IDatabase::select $vars
1727 * @param array &$conds Array of conditions; see IDatabase::select $conds
1728 * @param array &$query_options Array of query options; see IDatabase::select $options
1729 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1730 * @param array $selectedExpLevels The allowed active values, sorted
1731 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1734 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1735 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1737 global $wgLearnerEdits,
1738 $wgExperiencedUserEdits,
1739 $wgLearnerMemberSince,
1740 $wgExperiencedUserMemberSince;
1744 // If all levels are selected, don't filter
1745 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1749 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1751 in_array( 'registered', $selectedExpLevels ) &&
1752 in_array( 'unregistered', $selectedExpLevels )
1757 $actorMigration = ActorMigration
::newMigration();
1758 $actorQuery = $actorMigration->getJoin( 'rc_user' );
1759 $tables +
= $actorQuery['tables'];
1760 $join_conds +
= $actorQuery['joins'];
1762 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1764 in_array( 'registered', $selectedExpLevels ) &&
1765 !in_array( 'unregistered', $selectedExpLevels )
1767 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1771 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1772 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1777 $join_conds['user'] = [ 'LEFT JOIN', $actorQuery['fields']['rc_user'] . ' = user_id' ];
1782 $secondsPerDay = 86400;
1783 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1784 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1786 $aboveNewcomer = $dbr->makeList(
1788 'user_editcount >= ' . intval( $wgLearnerEdits ),
1789 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1794 $aboveLearner = $dbr->makeList(
1796 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1797 'user_registration <= ' .
1798 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1805 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1806 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1807 $conditions[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1810 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1811 $conditions[] = "NOT ( $aboveNewcomer )";
1812 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1813 $conditions[] = $dbr->makeList(
1814 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1817 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1818 $conditions[] = $aboveLearner;
1819 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1820 $conditions[] = "NOT ( $aboveLearner )";
1821 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1822 $conditions[] = $dbr->makeList(
1823 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1826 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1827 $conditions[] = $aboveNewcomer;
1828 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1829 $conditions[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1832 if ( count( $conditions ) > 1 ) {
1833 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1834 } elseif ( count( $conditions ) === 1 ) {
1835 $conds[] = reset( $conditions );
1840 * Check whether the structured filter UI is enabled
1844 public function isStructuredFilterUiEnabled() {
1845 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1849 return static::checkStructuredFilterUiEnabled(
1856 * Static method to check whether StructuredFilter UI is enabled for the given user
1859 * @param Config $config
1863 public static function checkStructuredFilterUiEnabled( Config
$config, User
$user ) {
1864 return !$user->getOption( 'rcenhancedfilters-disable' );
1868 * Get the default value of the number of changes to display when loading
1874 public function getDefaultLimit() {
1875 return $this->getUser()->getIntOption( static::$limitPreferenceName );
1879 * Get the default value of the number of days to display when loading
1881 * Supports fractional values, and should be cast to a float.
1886 public function getDefaultDays() {
1887 return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );