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;
61 * Preference name for collapsing the active filter display. Subclasses should override this.
64 protected static $collapsedPreferenceName;
69 /** @var FormOptions */
72 // Order of both groups and filters is significant; first is top-most priority,
73 // descending from there.
74 // 'showHideSuffix' is a shortcut to and avoid spelling out
75 // details specific to subclasses here.
77 * Definition information for the filters and their groups
79 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
80 * However, priority is dynamically added for the core groups, to ease maintenance.
82 * Groups are displayed to the user in the structured UI. However, if necessary,
83 * all of the filters in a group can be configured to only display on the
84 * unstuctured UI, in which case you don't need a group title.
86 * @var array $filterGroupDefinitions
88 private $filterGroupDefinitions;
90 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
91 // that is registered conditionally.
92 private $legacyReviewStatusFilterGroupDefinition;
94 // Single filter group registered conditionally
95 private $reviewStatusFilterGroupDefinition;
97 // Single filter group registered conditionally
98 private $hideCategorizationFilterDefinition;
101 * Filter groups, and their contained filters
102 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
104 * @var array $filterGroups
106 protected $filterGroups = [];
108 public function __construct( $name, $restriction ) {
109 parent
::__construct( $name, $restriction );
111 $nonRevisionTypes = [ RC_LOG
];
112 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
114 $this->filterGroupDefinitions
= [
116 'name' => 'registration',
117 'title' => 'rcfilters-filtergroup-registration',
118 'class' => ChangesListBooleanFilterGroup
::class,
122 // rcshowhideliu-show, rcshowhideliu-hide,
124 'showHideSuffix' => 'showhideliu',
126 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
127 &$query_options, &$join_conds
129 $actorMigration = ActorMigration
::newMigration();
130 $actorQuery = $actorMigration->getJoin( 'rc_user' );
131 $tables +
= $actorQuery['tables'];
132 $join_conds +
= $actorQuery['joins'];
133 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
135 'isReplacedInStructuredUi' => true,
139 'name' => 'hideanons',
140 // rcshowhideanons-show, rcshowhideanons-hide,
142 'showHideSuffix' => 'showhideanons',
144 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
145 &$query_options, &$join_conds
147 $actorMigration = ActorMigration
::newMigration();
148 $actorQuery = $actorMigration->getJoin( 'rc_user' );
149 $tables +
= $actorQuery['tables'];
150 $join_conds +
= $actorQuery['joins'];
151 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
153 'isReplacedInStructuredUi' => true,
159 'name' => 'userExpLevel',
160 'title' => 'rcfilters-filtergroup-userExpLevel',
161 'class' => ChangesListStringOptionsFilterGroup
::class,
162 'isFullCoverage' => true,
165 'name' => 'unregistered',
166 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
167 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
168 'cssClassSuffix' => 'user-unregistered',
169 'isRowApplicableCallable' => function ( $ctx, $rc ) {
170 return !$rc->getAttribute( 'rc_user' );
174 'name' => 'registered',
175 'label' => 'rcfilters-filter-user-experience-level-registered-label',
176 'description' => 'rcfilters-filter-user-experience-level-registered-description',
177 'cssClassSuffix' => 'user-registered',
178 'isRowApplicableCallable' => function ( $ctx, $rc ) {
179 return $rc->getAttribute( 'rc_user' );
183 'name' => 'newcomer',
184 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
185 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
186 'cssClassSuffix' => 'user-newcomer',
187 'isRowApplicableCallable' => function ( $ctx, $rc ) {
188 $performer = $rc->getPerformer();
189 return $performer && $performer->isLoggedIn() &&
190 $performer->getExperienceLevel() === 'newcomer';
195 'label' => 'rcfilters-filter-user-experience-level-learner-label',
196 'description' => 'rcfilters-filter-user-experience-level-learner-description',
197 'cssClassSuffix' => 'user-learner',
198 'isRowApplicableCallable' => function ( $ctx, $rc ) {
199 $performer = $rc->getPerformer();
200 return $performer && $performer->isLoggedIn() &&
201 $performer->getExperienceLevel() === 'learner';
205 'name' => 'experienced',
206 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
207 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
208 'cssClassSuffix' => 'user-experienced',
209 'isRowApplicableCallable' => function ( $ctx, $rc ) {
210 $performer = $rc->getPerformer();
211 return $performer && $performer->isLoggedIn() &&
212 $performer->getExperienceLevel() === 'experienced';
216 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
217 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
221 'name' => 'authorship',
222 'title' => 'rcfilters-filtergroup-authorship',
223 'class' => ChangesListBooleanFilterGroup
::class,
226 'name' => 'hidemyself',
227 'label' => 'rcfilters-filter-editsbyself-label',
228 'description' => 'rcfilters-filter-editsbyself-description',
229 // rcshowhidemine-show, rcshowhidemine-hide,
231 'showHideSuffix' => 'showhidemine',
233 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
234 &$query_options, &$join_conds
236 $actorQuery = ActorMigration
::newMigration()->getWhere( $dbr, 'rc_user', $ctx->getUser() );
237 $tables +
= $actorQuery['tables'];
238 $join_conds +
= $actorQuery['joins'];
239 $conds[] = 'NOT(' . $actorQuery['conds'] . ')';
241 'cssClassSuffix' => 'self',
242 'isRowApplicableCallable' => function ( $ctx, $rc ) {
243 return $ctx->getUser()->equals( $rc->getPerformer() );
247 'name' => 'hidebyothers',
248 'label' => 'rcfilters-filter-editsbyother-label',
249 'description' => 'rcfilters-filter-editsbyother-description',
251 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
252 &$query_options, &$join_conds
254 $actorQuery = ActorMigration
::newMigration()
255 ->getWhere( $dbr, 'rc_user', $ctx->getUser(), false );
256 $tables +
= $actorQuery['tables'];
257 $join_conds +
= $actorQuery['joins'];
258 $conds[] = $actorQuery['conds'];
260 'cssClassSuffix' => 'others',
261 'isRowApplicableCallable' => function ( $ctx, $rc ) {
262 return !$ctx->getUser()->equals( $rc->getPerformer() );
269 'name' => 'automated',
270 'title' => 'rcfilters-filtergroup-automated',
271 'class' => ChangesListBooleanFilterGroup
::class,
274 'name' => 'hidebots',
275 'label' => 'rcfilters-filter-bots-label',
276 'description' => 'rcfilters-filter-bots-description',
277 // rcshowhidebots-show, rcshowhidebots-hide,
279 'showHideSuffix' => 'showhidebots',
281 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
282 &$query_options, &$join_conds
284 $conds['rc_bot'] = 0;
286 'cssClassSuffix' => 'bot',
287 'isRowApplicableCallable' => function ( $ctx, $rc ) {
288 return $rc->getAttribute( 'rc_bot' );
292 'name' => 'hidehumans',
293 'label' => 'rcfilters-filter-humans-label',
294 'description' => 'rcfilters-filter-humans-description',
296 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
297 &$query_options, &$join_conds
299 $conds['rc_bot'] = 1;
301 'cssClassSuffix' => 'human',
302 'isRowApplicableCallable' => function ( $ctx, $rc ) {
303 return !$rc->getAttribute( 'rc_bot' );
309 // significance (conditional)
312 'name' => 'significance',
313 'title' => 'rcfilters-filtergroup-significance',
314 'class' => ChangesListBooleanFilterGroup
::class,
318 'name' => 'hideminor',
319 'label' => 'rcfilters-filter-minor-label',
320 'description' => 'rcfilters-filter-minor-description',
321 // rcshowhideminor-show, rcshowhideminor-hide,
323 'showHideSuffix' => 'showhideminor',
325 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
326 &$query_options, &$join_conds
328 $conds[] = 'rc_minor = 0';
330 'cssClassSuffix' => 'minor',
331 'isRowApplicableCallable' => function ( $ctx, $rc ) {
332 return $rc->getAttribute( 'rc_minor' );
336 'name' => 'hidemajor',
337 'label' => 'rcfilters-filter-major-label',
338 'description' => 'rcfilters-filter-major-description',
340 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
341 &$query_options, &$join_conds
343 $conds[] = 'rc_minor = 1';
345 'cssClassSuffix' => 'major',
346 'isRowApplicableCallable' => function ( $ctx, $rc ) {
347 return !$rc->getAttribute( 'rc_minor' );
354 'name' => 'lastRevision',
355 'title' => 'rcfilters-filtergroup-lastRevision',
356 'class' => ChangesListBooleanFilterGroup
::class,
360 'name' => 'hidelastrevision',
361 'label' => 'rcfilters-filter-lastrevision-label',
362 'description' => 'rcfilters-filter-lastrevision-description',
364 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
365 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
366 $conds[] = $dbr->makeList(
368 'rc_this_oldid <> page_latest',
369 'rc_type' => $nonRevisionTypes,
374 'cssClassSuffix' => 'last',
375 'isRowApplicableCallable' => function ( $ctx, $rc ) {
376 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
380 'name' => 'hidepreviousrevisions',
381 'label' => 'rcfilters-filter-previousrevision-label',
382 'description' => 'rcfilters-filter-previousrevision-description',
384 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
385 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
386 $conds[] = $dbr->makeList(
388 'rc_this_oldid = page_latest',
389 'rc_type' => $nonRevisionTypes,
394 'cssClassSuffix' => 'previous',
395 'isRowApplicableCallable' => function ( $ctx, $rc ) {
396 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
402 // With extensions, there can be change types that will not be hidden by any of these.
404 'name' => 'changeType',
405 'title' => 'rcfilters-filtergroup-changetype',
406 'class' => ChangesListBooleanFilterGroup
::class,
410 'name' => 'hidepageedits',
411 'label' => 'rcfilters-filter-pageedits-label',
412 'description' => 'rcfilters-filter-pageedits-description',
415 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
416 &$query_options, &$join_conds
418 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
420 'cssClassSuffix' => 'src-mw-edit',
421 'isRowApplicableCallable' => function ( $ctx, $rc ) {
422 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
426 'name' => 'hidenewpages',
427 'label' => 'rcfilters-filter-newpages-label',
428 'description' => 'rcfilters-filter-newpages-description',
431 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
432 &$query_options, &$join_conds
434 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
436 'cssClassSuffix' => 'src-mw-new',
437 'isRowApplicableCallable' => function ( $ctx, $rc ) {
438 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
442 // hidecategorization
446 'label' => 'rcfilters-filter-logactions-label',
447 'description' => 'rcfilters-filter-logactions-description',
450 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
451 &$query_options, &$join_conds
453 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
455 'cssClassSuffix' => 'src-mw-log',
456 'isRowApplicableCallable' => function ( $ctx, $rc ) {
457 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
465 $this->legacyReviewStatusFilterGroupDefinition
= [
467 'name' => 'legacyReviewStatus',
468 'title' => 'rcfilters-filtergroup-reviewstatus',
469 'class' => ChangesListBooleanFilterGroup
::class,
472 'name' => 'hidepatrolled',
473 // rcshowhidepatr-show, rcshowhidepatr-hide
475 'showHideSuffix' => 'showhidepatr',
477 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
478 &$query_options, &$join_conds
480 $conds['rc_patrolled'] = RecentChange
::PRC_UNPATROLLED
;
482 'isReplacedInStructuredUi' => true,
485 'name' => 'hideunpatrolled',
487 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
488 &$query_options, &$join_conds
490 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
;
492 'isReplacedInStructuredUi' => true,
498 $this->reviewStatusFilterGroupDefinition
= [
500 'name' => 'reviewStatus',
501 'title' => 'rcfilters-filtergroup-reviewstatus',
502 'class' => ChangesListStringOptionsFilterGroup
::class,
503 'isFullCoverage' => true,
507 'name' => 'unpatrolled',
508 'label' => 'rcfilters-filter-reviewstatus-unpatrolled-label',
509 'description' => 'rcfilters-filter-reviewstatus-unpatrolled-description',
510 'cssClassSuffix' => 'reviewstatus-unpatrolled',
511 'isRowApplicableCallable' => function ( $ctx, $rc ) {
512 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_UNPATROLLED
;
517 'label' => 'rcfilters-filter-reviewstatus-manual-label',
518 'description' => 'rcfilters-filter-reviewstatus-manual-description',
519 'cssClassSuffix' => 'reviewstatus-manual',
520 'isRowApplicableCallable' => function ( $ctx, $rc ) {
521 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_PATROLLED
;
526 'label' => 'rcfilters-filter-reviewstatus-auto-label',
527 'description' => 'rcfilters-filter-reviewstatus-auto-description',
528 'cssClassSuffix' => 'reviewstatus-auto',
529 'isRowApplicableCallable' => function ( $ctx, $rc ) {
530 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_AUTOPATROLLED
;
534 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
535 'queryCallable' => function ( $specialPageClassName, $ctx, $dbr,
536 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selected
538 if ( $selected === [] ) {
541 $rcPatrolledValues = [
542 'unpatrolled' => RecentChange
::PRC_UNPATROLLED
,
543 'manual' => RecentChange
::PRC_PATROLLED
,
544 'auto' => RecentChange
::PRC_AUTOPATROLLED
,
546 // e.g. rc_patrolled IN (0, 2)
547 $conds['rc_patrolled'] = array_map( function ( $s ) use ( $rcPatrolledValues ) {
548 return $rcPatrolledValues[ $s ];
554 $this->hideCategorizationFilterDefinition
= [
555 'name' => 'hidecategorization',
556 'label' => 'rcfilters-filter-categorization-label',
557 'description' => 'rcfilters-filter-categorization-description',
558 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
559 // wlshowhidecategorization
560 'showHideSuffix' => 'showhidecategorization',
563 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
564 &$query_options, &$join_conds
566 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
568 'cssClassSuffix' => 'src-mw-categorize',
569 'isRowApplicableCallable' => function ( $ctx, $rc ) {
570 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
576 * Check if filters are in conflict and guaranteed to return no results.
580 protected function areFiltersInConflict() {
581 $opts = $this->getOptions();
582 /** @var ChangesListFilterGroup $group */
583 foreach ( $this->getFilterGroups() as $group ) {
584 if ( $group->getConflictingGroups() ) {
587 " specifies conflicts with other groups but these are not supported yet."
591 /** @var ChangesListFilter $conflictingFilter */
592 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
593 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
598 /** @var ChangesListFilter $filter */
599 foreach ( $group->getFilters() as $filter ) {
600 /** @var ChangesListFilter $conflictingFilter */
601 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
603 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
604 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
618 * Main execution point
620 * @param string $subpage
622 public function execute( $subpage ) {
623 $this->rcSubpage
= $subpage;
625 $this->considerActionsForDefaultSavedQuery( $subpage );
627 $opts = $this->getOptions();
629 $rows = $this->getRows();
630 if ( $rows === false ) {
631 $rows = new FakeResultWrapper( [] );
634 // Used by Structured UI app to get results without MW chrome
635 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
636 $this->getOutput()->setArticleBodyOnly( true );
639 // Used by "live update" and "view newest" to check
640 // if there's new changes with minimal data transfer
641 if ( $this->getRequest()->getBool( 'peek' ) ) {
642 $code = $rows->numRows() > 0 ?
200 : 204;
643 $this->getOutput()->setStatusCode( $code );
645 if ( $this->getUser()->isAnon() !==
646 $this->getRequest()->getFuzzyBool( 'isAnon' )
648 $this->getOutput()->setStatusCode( 205 );
654 $batch = new LinkBatch
;
655 foreach ( $rows as $row ) {
656 $batch->add( NS_USER
, $row->rc_user_text
);
657 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
658 $batch->add( $row->rc_namespace
, $row->rc_title
);
659 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
660 $formatter = LogFormatter
::newFromRow( $row );
661 foreach ( $formatter->getPreloadTitles() as $title ) {
662 $batch->addObj( $title );
669 $this->outputHeader();
671 $this->webOutput( $rows, $opts );
674 } catch ( DBQueryTimeoutError
$timeoutException ) {
675 MWExceptionHandler
::logException( $timeoutException );
678 $this->outputHeader();
681 $this->getOutput()->setStatusCode( 500 );
682 $this->webOutputHeader( 0, $opts );
683 $this->outputTimeout();
686 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
687 // Clean up any bad page entries for titles showing up in RC
688 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
690 LoggerFactory
::getInstance( 'objectcache' )
694 $this->includeRcFiltersApp();
698 * Check whether or not the page should load defaults, and if so, whether
699 * a default saved query is relevant to be redirected to. If it is relevant,
700 * redirect properly with all necessary query parameters.
702 * @param string $subpage
704 protected function considerActionsForDefaultSavedQuery( $subpage ) {
705 if ( !$this->isStructuredFilterUiEnabled() ||
$this->including() ) {
709 $knownParams = $this->getRequest()->getValues(
710 ...array_keys( $this->getOptions()->getAllValues() )
713 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
714 // we need to exclude several parameters we know should not be counted towards preventing
715 // the loading of defaults.
716 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
717 $knownParams = array_diff_key( $knownParams, $excludedParams );
720 // If there are NO known parameters in the URL request
721 // (that are not excluded) then we need to check into loading
722 // the default saved query
723 count( $knownParams ) === 0
725 // Get the saved queries data and parse it
726 $savedQueries = FormatJson
::decode(
727 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
731 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
732 // Only load queries that are 'version' 2, since those
733 // have parameter representation
734 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
735 $savedQueryDefaultID = $savedQueries[ 'default' ];
736 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
738 // Build the entire parameter list
739 $query = array_merge(
740 $defaultQuery[ 'params' ],
741 $defaultQuery[ 'highlights' ],
746 // Add to the query any parameters that we may have ignored before
747 // but are still valid and requested in the URL
748 $query = array_merge( $this->getRequest()->getValues(), $query );
749 unset( $query[ 'title' ] );
750 $this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) );
752 // There's a default, but the version is not 2, and the server can't
753 // actually recognize the query itself. This happens if it is before
754 // the conversion, so we need to tell the UI to reload saved query as
755 // it does the conversion to version 2
756 $this->getOutput()->addJsConfigVars(
757 'wgStructuredChangeFiltersDefaultSavedQueryExists',
761 // Add the class that tells the frontend it is still loading
763 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
770 * Include the modules and configuration for the RCFilters app.
771 * Conditional on the user having the feature enabled.
773 * If it is disabled, add a <body> class marking that
775 protected function includeRcFiltersApp() {
776 $out = $this->getOutput();
777 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
778 $jsData = $this->getStructuredFilterJsData();
780 foreach ( $jsData['messageKeys'] as $key ) {
781 $messages[$key] = $this->msg( $key )->plain();
784 $out->addBodyClasses( 'mw-rcfilters-enabled' );
785 $collapsed = $this->getUser()->getBoolOption( static::$collapsedPreferenceName );
787 $out->addBodyClasses( 'mw-rcfilters-collapsed' );
790 // These config and message exports should be moved into a ResourceLoader data module (T201574)
791 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
792 $out->addJsConfigVars( 'wgStructuredChangeFiltersMessages', $messages );
793 $out->addJsConfigVars( 'wgStructuredChangeFiltersCollapsedState', $collapsed );
795 $out->addJsConfigVars(
796 'wgRCFiltersChangeTags',
797 $this->getChangeTagList()
799 $out->addJsConfigVars(
800 'StructuredChangeFiltersDisplayConfig',
802 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
803 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
804 'limitDefault' => $this->getDefaultLimit(),
805 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
806 'daysDefault' => $this->getDefaultDays(),
810 $out->addJsConfigVars(
811 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
812 static::$savedQueriesPreferenceName
814 $out->addJsConfigVars(
815 'wgStructuredChangeFiltersLimitPreferenceName',
816 static::$limitPreferenceName
818 $out->addJsConfigVars(
819 'wgStructuredChangeFiltersDaysPreferenceName',
820 static::$daysPreferenceName
822 $out->addJsConfigVars(
823 'wgStructuredChangeFiltersCollapsedPreferenceName',
824 static::$collapsedPreferenceName
827 $out->addJsConfigVars(
828 'StructuredChangeFiltersLiveUpdatePollingRate',
829 $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
832 $out->addBodyClasses( 'mw-rcfilters-disabled' );
837 * Fetch the change tags list for the front end
839 * @return array Tag data
841 protected function getChangeTagList() {
842 $cache = ObjectCache
::getMainWANInstance();
843 $context = $this->getContext();
844 return $cache->getWithSetCallback(
845 $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ),
846 $cache::TTL_MINUTE
* 10,
847 function () use ( $context ) {
848 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
849 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
851 // Hit counts disabled for perf reasons, see T169997
853 $tagStats = ChangeTags::tagUsageStatistics();
854 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
857 arsort( $tagHitCounts );
859 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
861 // Build the list and data
863 foreach ( $tagHitCounts as $tagName => $hits ) {
865 // Only get active tags
866 isset( $explicitlyDefinedTags[ $tagName ] ) ||
867 isset( $softwareActivatedTags[ $tagName ] )
871 'label' => Sanitizer
::stripAllTags(
872 ChangeTags
::tagDescription( $tagName, $context )
875 ChangeTags
::truncateTagDescription(
876 $tagName, self
::TAG_DESC_CHARACTER_LIMIT
, $context
878 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
884 // Instead of sorting by hit count (disabled, see above), sort by display name
885 usort( $result, function ( $a, $b ) {
886 return strcasecmp( $a['label'], $b['label'] );
898 * Add the "no results" message to the output
900 protected function outputNoResults() {
901 $this->getOutput()->addHTML(
902 '<div class="mw-changeslist-empty">' .
903 $this->msg( 'recentchanges-noresult' )->parse() .
909 * Add the "timeout" message to the output
911 protected function outputTimeout() {
912 $this->getOutput()->addHTML(
913 '<div class="mw-changeslist-empty mw-changeslist-timeout">' .
914 $this->msg( 'recentchanges-timeout' )->parse() .
920 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
922 * @return bool|IResultWrapper Result or false
924 public function getRows() {
925 $opts = $this->getOptions();
932 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
934 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
938 * Get the current FormOptions for this request
940 * @return FormOptions
942 public function getOptions() {
943 if ( $this->rcOptions
=== null ) {
944 $this->rcOptions
= $this->setup( $this->rcSubpage
);
947 return $this->rcOptions
;
951 * Register all filters and their groups (including those from hooks), plus handle
952 * conflicts and defaults.
954 * You might want to customize these in the same method, in subclasses. You can
955 * call getFilterGroup to access a group, and (on the group) getFilter to access a
956 * filter, then make necessary modfications to the filter or group (e.g. with
959 protected function registerFilters() {
960 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
962 // Make sure this is not being transcluded (we don't want to show this
963 // information to all users just because the user that saves the edit can
964 // patrol or is logged in)
965 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
966 $this->registerFiltersFromDefinitions( $this->legacyReviewStatusFilterGroupDefinition
);
967 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
970 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
972 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
973 $transformedHideCategorizationDef = $this->transformFilterDefinition(
974 $this->hideCategorizationFilterDefinition
977 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
979 $hideCategorization = new ChangesListBooleanFilter(
980 $transformedHideCategorizationDef
984 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
986 $this->registerFiltersFromDefinitions( [] );
988 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
989 $registered = $userExperienceLevel->getFilter( 'registered' );
990 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
991 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
992 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
994 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
995 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
996 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
998 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
999 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
1001 // categoryFilter is conditional; see registerFilters
1002 if ( $categoryFilter !== null ) {
1003 $hideMinorFilter->conflictsWith(
1005 'rcfilters-hideminor-conflicts-typeofchange-global',
1006 'rcfilters-hideminor-conflicts-typeofchange',
1007 'rcfilters-typeofchange-conflicts-hideminor'
1010 $hideMinorFilter->conflictsWith(
1012 'rcfilters-hideminor-conflicts-typeofchange-global',
1013 'rcfilters-hideminor-conflicts-typeofchange',
1014 'rcfilters-typeofchange-conflicts-hideminor'
1016 $hideMinorFilter->conflictsWith(
1017 $pagecreationFilter,
1018 'rcfilters-hideminor-conflicts-typeofchange-global',
1019 'rcfilters-hideminor-conflicts-typeofchange',
1020 'rcfilters-typeofchange-conflicts-hideminor'
1025 * Transforms filter definition to prepare it for constructor.
1027 * See overrides of this method as well.
1029 * @param array $filterDefinition Original filter definition
1031 * @return array Transformed definition
1033 protected function transformFilterDefinition( array $filterDefinition ) {
1034 return $filterDefinition;
1038 * Register filters from a definition object
1040 * Array specifying groups and their filters; see Filter and
1041 * ChangesListFilterGroup constructors.
1043 * There is light processing to simplify core maintenance.
1044 * @param array $definition
1046 protected function registerFiltersFromDefinitions( array $definition ) {
1047 $autoFillPriority = -1;
1048 foreach ( $definition as $groupDefinition ) {
1049 if ( !isset( $groupDefinition['priority'] ) ) {
1050 $groupDefinition['priority'] = $autoFillPriority;
1052 // If it's explicitly specified, start over the auto-fill
1053 $autoFillPriority = $groupDefinition['priority'];
1056 $autoFillPriority--;
1058 $className = $groupDefinition['class'];
1059 unset( $groupDefinition['class'] );
1061 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
1062 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
1065 $this->registerFilterGroup( new $className( $groupDefinition ) );
1070 * @return array The legacy show/hide toggle filters
1072 protected function getLegacyShowHideFilters() {
1074 foreach ( $this->filterGroups
as $group ) {
1075 if ( $group instanceof ChangesListBooleanFilterGroup
) {
1076 foreach ( $group->getFilters() as $key => $filter ) {
1077 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1078 $filters[ $key ] = $filter;
1087 * Register all the filters, including legacy hook-driven ones.
1088 * Then create a FormOptions object with options as specified by the user
1090 * @param array $parameters
1092 * @return FormOptions
1094 public function setup( $parameters ) {
1095 $this->registerFilters();
1097 $opts = $this->getDefaultOptions();
1099 $opts = $this->fetchOptionsFromRequest( $opts );
1101 // Give precedence to subpage syntax
1102 if ( $parameters !== null ) {
1103 $this->parseParameters( $parameters, $opts );
1106 $this->validateOptions( $opts );
1112 * Get a FormOptions object containing the default options. By default, returns
1113 * some basic options. The filters listed explicitly here are overriden in this
1114 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1115 * and more) are structured. Structured filters are overriden in registerFilters.
1118 * @return FormOptions
1120 public function getDefaultOptions() {
1121 $opts = new FormOptions();
1122 $structuredUI = $this->isStructuredFilterUiEnabled();
1123 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1124 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1126 /** @var ChangesListFilterGroup $filterGroup */
1127 foreach ( $this->filterGroups
as $filterGroup ) {
1128 $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
1131 $opts->add( 'namespace', '', FormOptions
::STRING );
1132 $opts->add( 'invert', false );
1133 $opts->add( 'associated', false );
1134 $opts->add( 'urlversion', 1 );
1135 $opts->add( 'tagfilter', '' );
1137 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
1138 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
1140 $opts->add( 'from', '' );
1146 * Register a structured changes list filter group
1148 * @param ChangesListFilterGroup $group
1150 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
1151 $groupName = $group->getName();
1153 $this->filterGroups
[$groupName] = $group;
1157 * Gets the currently registered filters groups
1159 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1161 protected function getFilterGroups() {
1162 return $this->filterGroups
;
1166 * Gets a specified ChangesListFilterGroup by name
1168 * @param string $groupName Name of group
1170 * @return ChangesListFilterGroup|null Group, or null if not registered
1172 public function getFilterGroup( $groupName ) {
1173 return $this->filterGroups
[$groupName] ??
null;
1176 // Currently, this intentionally only includes filters that display
1177 // in the structured UI. This can be changed easily, though, if we want
1178 // to include data on filters that use the unstructured UI. messageKeys is a
1179 // special top-level value, with the value being an array of the message keys to
1180 // send to the client.
1182 * Gets structured filter information needed by JS
1184 * @return array Associative array
1185 * * array $return['groups'] Group data
1186 * * array $return['messageKeys'] Array of message keys
1188 public function getStructuredFilterJsData() {
1191 'messageKeys' => [],
1194 usort( $this->filterGroups
, function ( $a, $b ) {
1195 return $b->getPriority() <=> $a->getPriority();
1198 foreach ( $this->filterGroups
as $groupName => $group ) {
1199 $groupOutput = $group->getJsData( $this );
1200 if ( $groupOutput !== null ) {
1201 $output['messageKeys'] = array_merge(
1202 $output['messageKeys'],
1203 $groupOutput['messageKeys']
1206 unset( $groupOutput['messageKeys'] );
1207 $output['groups'][] = $groupOutput;
1215 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1217 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1219 * @param FormOptions $opts
1220 * @return FormOptions
1222 protected function fetchOptionsFromRequest( $opts ) {
1223 $opts->fetchValuesFromRequest( $this->getRequest() );
1229 * Process $par and put options found in $opts. Used when including the page.
1231 * @param string $par
1232 * @param FormOptions $opts
1234 public function parseParameters( $par, FormOptions
$opts ) {
1235 $stringParameterNameSet = [];
1236 $hideParameterNameSet = [];
1238 // URL parameters can be per-group, like 'userExpLevel',
1239 // or per-filter, like 'hideminor'.
1241 foreach ( $this->filterGroups
as $filterGroup ) {
1242 if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup
) {
1243 $stringParameterNameSet[$filterGroup->getName()] = true;
1244 } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1245 foreach ( $filterGroup->getFilters() as $filter ) {
1246 $hideParameterNameSet[$filter->getName()] = true;
1251 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1252 foreach ( $bits as $bit ) {
1254 if ( isset( $hideParameterNameSet[$bit] ) ) {
1255 // hidefoo => hidefoo=true
1257 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1258 // foo => hidefoo=false
1259 $opts["hide$bit"] = false;
1260 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1261 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1262 $opts[$m[1]] = $m[2];
1269 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1271 * @param FormOptions $opts
1273 public function validateOptions( FormOptions
$opts ) {
1274 $isContradictory = $this->fixContradictoryOptions( $opts );
1275 $isReplaced = $this->replaceOldOptions( $opts );
1277 if ( $isContradictory ||
$isReplaced ) {
1278 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1279 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1282 $opts->validateIntBounds( 'limit', 0, 5000 );
1283 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1287 * Fix invalid options by resetting pairs that should never appear together.
1289 * @param FormOptions $opts
1290 * @return bool True if any option was reset
1292 private function fixContradictoryOptions( FormOptions
$opts ) {
1293 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1295 foreach ( $this->filterGroups
as $filterGroup ) {
1296 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1297 $filters = $filterGroup->getFilters();
1299 if ( count( $filters ) === 1 ) {
1300 // legacy boolean filters should not be considered
1304 $allInGroupEnabled = array_reduce(
1306 function ( $carry, $filter ) use ( $opts ) {
1307 return $carry && $opts[ $filter->getName() ];
1309 /* initialValue */ count( $filters ) > 0
1312 if ( $allInGroupEnabled ) {
1313 foreach ( $filters as $filter ) {
1314 $opts[ $filter->getName() ] = false;
1326 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1329 * This is deprecated and may be removed.
1331 * @param FormOptions $opts
1332 * @return bool True if this change was mode
1334 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1335 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1336 $opts->reset( 'hideanons' );
1337 if ( !$opts['hidebots'] ) {
1338 $opts->reset( 'hideliu' );
1339 $opts['hidehumans'] = 1;
1349 * Replace old options with their structured UI equivalents
1351 * @param FormOptions $opts
1352 * @return bool True if the change was made
1354 public function replaceOldOptions( FormOptions
$opts ) {
1355 if ( !$this->isStructuredFilterUiEnabled() ) {
1361 // At this point 'hideanons' and 'hideliu' cannot be both true,
1362 // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
1363 if ( $opts[ 'hideanons' ] ) {
1364 $opts->reset( 'hideanons' );
1365 $opts[ 'userExpLevel' ] = 'registered';
1369 if ( $opts[ 'hideliu' ] ) {
1370 $opts->reset( 'hideliu' );
1371 $opts[ 'userExpLevel' ] = 'unregistered';
1375 if ( $this->getFilterGroup( 'legacyReviewStatus' ) ) {
1376 if ( $opts[ 'hidepatrolled' ] ) {
1377 $opts->reset( 'hidepatrolled' );
1378 $opts[ 'reviewStatus' ] = 'unpatrolled';
1382 if ( $opts[ 'hideunpatrolled' ] ) {
1383 $opts->reset( 'hideunpatrolled' );
1384 $opts[ 'reviewStatus' ] = implode(
1385 ChangesListStringOptionsFilterGroup
::SEPARATOR
,
1386 [ 'manual', 'auto' ]
1396 * Convert parameters values from true/false to 1/0
1397 * so they are not omitted by wfArrayToCgi()
1400 * @param array $params
1403 protected function convertParamsForLink( $params ) {
1404 foreach ( $params as &$value ) {
1405 if ( $value === false ) {
1414 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1415 * the user requested.
1417 * @param array &$tables Array of tables; see IDatabase::select $table
1418 * @param array &$fields Array of fields; see IDatabase::select $vars
1419 * @param array &$conds Array of conditions; see IDatabase::select $conds
1420 * @param array &$query_options Array of query options; see IDatabase::select $options
1421 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1422 * @param FormOptions $opts
1424 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1425 &$join_conds, FormOptions
$opts
1427 $dbr = $this->getDB();
1428 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1430 /** @var ChangesListFilterGroup $filterGroup */
1431 foreach ( $this->filterGroups
as $filterGroup ) {
1432 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1433 $query_options, $join_conds, $opts, $isStructuredUI );
1436 // Namespace filtering
1437 if ( $opts[ 'namespace' ] !== '' ) {
1438 $namespaces = explode( ';', $opts[ 'namespace' ] );
1440 if ( $opts[ 'associated' ] ) {
1441 $associatedNamespaces = array_map(
1443 return MWNamespace
::getAssociated( $ns );
1447 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1450 if ( count( $namespaces ) === 1 ) {
1451 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1452 $value = $dbr->addQuotes( reset( $namespaces ) );
1454 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1455 sort( $namespaces );
1456 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1458 $conds[] = "rc_namespace $operator $value";
1462 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1463 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1465 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1466 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
1467 $cutoff = $dbr->timestamp( $opts['from'] );
1469 $opts->reset( 'from' );
1472 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1478 * @param array $tables Array of tables; see IDatabase::select $table
1479 * @param array $fields Array of fields; see IDatabase::select $vars
1480 * @param array $conds Array of conditions; see IDatabase::select $conds
1481 * @param array $query_options Array of query options; see IDatabase::select $options
1482 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1483 * @param FormOptions $opts
1484 * @return bool|IResultWrapper Result or false
1486 protected function doMainQuery( $tables, $fields, $conds,
1487 $query_options, $join_conds, FormOptions
$opts
1489 $rcQuery = RecentChange
::getQueryInfo();
1490 $tables = array_merge( $tables, $rcQuery['tables'] );
1491 $fields = array_merge( $rcQuery['fields'], $fields );
1492 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
1494 ChangeTags
::modifyDisplayQuery(
1503 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1509 $dbr = $this->getDB();
1511 return $dbr->select(
1521 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1522 &$query_options, &$join_conds, $opts
1525 'ChangesListSpecialPageQuery',
1526 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1531 * Return a IDatabase object for reading
1535 protected function getDB() {
1536 return wfGetDB( DB_REPLICA
);
1540 * Send header output to the OutputPage object, only called if not using feeds
1542 * @param int $rowCount Number of database rows
1543 * @param FormOptions $opts
1545 private function webOutputHeader( $rowCount, $opts ) {
1546 if ( !$this->including() ) {
1547 $this->outputFeedLinks();
1548 $this->doHeader( $opts, $rowCount );
1553 * Send output to the OutputPage object, only called if not used feeds
1555 * @param IResultWrapper $rows Database rows
1556 * @param FormOptions $opts
1558 public function webOutput( $rows, $opts ) {
1559 $this->webOutputHeader( $rows->numRows(), $opts );
1561 $this->outputChangesList( $rows, $opts );
1565 * Output feed links.
1567 public function outputFeedLinks() {
1568 // nothing by default
1572 * Build and output the actual changes list.
1574 * @param IResultWrapper $rows Database rows
1575 * @param FormOptions $opts
1577 abstract public function outputChangesList( $rows, $opts );
1580 * Set the text to be displayed above the changes
1582 * @param FormOptions $opts
1583 * @param int $numRows Number of rows in the result to show after this header
1585 public function doHeader( $opts, $numRows ) {
1586 $this->setTopText( $opts );
1588 // @todo Lots of stuff should be done here.
1590 $this->setBottomText( $opts );
1594 * Send the text to be displayed before the options.
1595 * Should use $this->getOutput()->addWikiTextAsInterface()
1596 * or similar methods to print the text.
1598 * @param FormOptions $opts
1600 public function setTopText( FormOptions
$opts ) {
1601 // nothing by default
1605 * Send the text to be displayed after the options.
1606 * Should use $this->getOutput()->addWikiTextAsInterface()
1607 * or similar methods to print the text.
1609 * @param FormOptions $opts
1611 public function setBottomText( FormOptions
$opts ) {
1612 // nothing by default
1616 * Get options to be displayed in a form
1617 * @todo This should handle options returned by getDefaultOptions().
1618 * @todo Not called by anything in this class (but is in subclasses), should be
1619 * called by something… doHeader() maybe?
1621 * @param FormOptions $opts
1624 public function getExtraOptions( $opts ) {
1629 * Return the legend displayed within the fieldset
1633 public function makeLegend() {
1634 $context = $this->getContext();
1635 $user = $context->getUser();
1636 # The legend showing what the letters and stuff mean
1637 $legend = Html
::openElement( 'dl' ) . "\n";
1638 # Iterates through them and gets the messages for both letter and tooltip
1639 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1640 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1641 unset( $legendItems['unpatrolled'] );
1643 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1644 $label = $item['legend'] ??
$item['title'];
1645 $letter = $item['letter'];
1646 $cssClass = $item['class'] ??
$key;
1648 $legend .= Html
::element( 'dt',
1649 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1651 Html
::rawElement( 'dd',
1652 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1653 $context->msg( $label )->parse()
1657 $legend .= Html
::rawElement( 'dt',
1658 [ 'class' => 'mw-plusminus-pos' ],
1659 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1661 $legend .= Html
::element(
1663 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1664 $context->msg( 'recentchanges-label-plusminus' )->text()
1666 $legend .= Html
::closeElement( 'dl' ) . "\n";
1668 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1669 $context->msg( 'rcfilters-legend-heading' )->parse() :
1670 $context->msg( 'recentchanges-legend-heading' )->parse();
1673 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1674 $collapsedClass = $collapsedState === 'collapsed' ?
' mw-collapsed' : '';
1677 '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
1679 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1686 * Add page-specific modules.
1688 protected function addModules() {
1689 $out = $this->getOutput();
1690 // Styles and behavior for the legend box (see makeLegend())
1691 $out->addModuleStyles( [
1692 'mediawiki.special.changeslist.legend',
1693 'mediawiki.special.changeslist',
1695 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1697 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
1698 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1699 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1703 protected function getGroupName() {
1708 * Filter on users' experience levels; this will not be called if nothing is
1711 * @param string $specialPageClassName Class name of current special page
1712 * @param IContextSource $context Context, for e.g. user
1713 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1714 * @param array &$tables Array of tables; see IDatabase::select $table
1715 * @param array &$fields Array of fields; see IDatabase::select $vars
1716 * @param array &$conds Array of conditions; see IDatabase::select $conds
1717 * @param array &$query_options Array of query options; see IDatabase::select $options
1718 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1719 * @param array $selectedExpLevels The allowed active values, sorted
1720 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1723 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1724 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1726 global $wgLearnerEdits,
1727 $wgExperiencedUserEdits,
1728 $wgLearnerMemberSince,
1729 $wgExperiencedUserMemberSince;
1733 // If all levels are selected, don't filter
1734 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1738 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1740 in_array( 'registered', $selectedExpLevels ) &&
1741 in_array( 'unregistered', $selectedExpLevels )
1746 $actorMigration = ActorMigration
::newMigration();
1747 $actorQuery = $actorMigration->getJoin( 'rc_user' );
1748 $tables +
= $actorQuery['tables'];
1749 $join_conds +
= $actorQuery['joins'];
1751 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1753 in_array( 'registered', $selectedExpLevels ) &&
1754 !in_array( 'unregistered', $selectedExpLevels )
1756 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1760 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1761 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1766 $join_conds['user'] = [ 'LEFT JOIN', $actorQuery['fields']['rc_user'] . ' = user_id' ];
1771 $secondsPerDay = 86400;
1772 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1773 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1775 $aboveNewcomer = $dbr->makeList(
1777 'user_editcount >= ' . intval( $wgLearnerEdits ),
1778 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1783 $aboveLearner = $dbr->makeList(
1785 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1786 'user_registration <= ' .
1787 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1794 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1795 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1796 $conditions[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1799 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1800 $conditions[] = "NOT ( $aboveNewcomer )";
1801 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1802 $conditions[] = $dbr->makeList(
1803 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1806 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1807 $conditions[] = $aboveLearner;
1808 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1809 $conditions[] = "NOT ( $aboveLearner )";
1810 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1811 $conditions[] = $dbr->makeList(
1812 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1815 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1816 $conditions[] = $aboveNewcomer;
1817 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1818 $conditions[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1821 if ( count( $conditions ) > 1 ) {
1822 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1823 } elseif ( count( $conditions ) === 1 ) {
1824 $conds[] = reset( $conditions );
1829 * Check whether the structured filter UI is enabled
1833 public function isStructuredFilterUiEnabled() {
1834 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1838 return static::checkStructuredFilterUiEnabled(
1845 * Static method to check whether StructuredFilter UI is enabled for the given user
1848 * @param Config $config
1852 public static function checkStructuredFilterUiEnabled( Config
$config, User
$user ) {
1853 return !$user->getOption( 'rcenhancedfilters-disable' );
1857 * Get the default value of the number of changes to display when loading
1863 public function getDefaultLimit() {
1864 return $this->getUser()->getIntOption( static::$limitPreferenceName );
1868 * Get the default value of the number of days to display when loading
1870 * Supports fractional values, and should be cast to a float.
1875 public function getDefaultDays() {
1876 return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );