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 */
73 protected $customFilters;
75 // Order of both groups and filters is significant; first is top-most priority,
76 // descending from there.
77 // 'showHideSuffix' is a shortcut to and avoid spelling out
78 // details specific to subclasses here.
80 * Definition information for the filters and their groups
82 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
83 * However, priority is dynamically added for the core groups, to ease maintenance.
85 * Groups are displayed to the user in the structured UI. However, if necessary,
86 * all of the filters in a group can be configured to only display on the
87 * unstuctured UI, in which case you don't need a group title. This is done in
88 * getFilterGroupDefinitionFromLegacyCustomFilters, for example.
90 * @var array $filterGroupDefinitions
92 private $filterGroupDefinitions;
94 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
95 // that is registered conditionally.
96 private $legacyReviewStatusFilterGroupDefinition;
98 // Single filter group registered conditionally
99 private $reviewStatusFilterGroupDefinition;
101 // Single filter group registered conditionally
102 private $hideCategorizationFilterDefinition;
105 * Filter groups, and their contained filters
106 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
108 * @var array $filterGroups
110 protected $filterGroups = [];
112 public function __construct( $name, $restriction ) {
113 parent
::__construct( $name, $restriction );
115 $nonRevisionTypes = [ RC_LOG
];
116 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
118 $this->filterGroupDefinitions
= [
120 'name' => 'registration',
121 'title' => 'rcfilters-filtergroup-registration',
122 'class' => ChangesListBooleanFilterGroup
::class,
126 // rcshowhideliu-show, rcshowhideliu-hide,
128 'showHideSuffix' => 'showhideliu',
130 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
131 &$query_options, &$join_conds
133 $actorMigration = ActorMigration
::newMigration();
134 $actorQuery = $actorMigration->getJoin( 'rc_user' );
135 $tables +
= $actorQuery['tables'];
136 $join_conds +
= $actorQuery['joins'];
137 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
139 'isReplacedInStructuredUi' => true,
143 'name' => 'hideanons',
144 // rcshowhideanons-show, rcshowhideanons-hide,
146 'showHideSuffix' => 'showhideanons',
148 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
149 &$query_options, &$join_conds
151 $actorMigration = ActorMigration
::newMigration();
152 $actorQuery = $actorMigration->getJoin( 'rc_user' );
153 $tables +
= $actorQuery['tables'];
154 $join_conds +
= $actorQuery['joins'];
155 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
157 'isReplacedInStructuredUi' => true,
163 'name' => 'userExpLevel',
164 'title' => 'rcfilters-filtergroup-userExpLevel',
165 'class' => ChangesListStringOptionsFilterGroup
::class,
166 'isFullCoverage' => true,
169 'name' => 'unregistered',
170 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
171 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
172 'cssClassSuffix' => 'user-unregistered',
173 'isRowApplicableCallable' => function ( $ctx, $rc ) {
174 return !$rc->getAttribute( 'rc_user' );
178 'name' => 'registered',
179 'label' => 'rcfilters-filter-user-experience-level-registered-label',
180 'description' => 'rcfilters-filter-user-experience-level-registered-description',
181 'cssClassSuffix' => 'user-registered',
182 'isRowApplicableCallable' => function ( $ctx, $rc ) {
183 return $rc->getAttribute( 'rc_user' );
187 'name' => 'newcomer',
188 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
189 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
190 'cssClassSuffix' => 'user-newcomer',
191 'isRowApplicableCallable' => function ( $ctx, $rc ) {
192 $performer = $rc->getPerformer();
193 return $performer && $performer->isLoggedIn() &&
194 $performer->getExperienceLevel() === 'newcomer';
199 'label' => 'rcfilters-filter-user-experience-level-learner-label',
200 'description' => 'rcfilters-filter-user-experience-level-learner-description',
201 'cssClassSuffix' => 'user-learner',
202 'isRowApplicableCallable' => function ( $ctx, $rc ) {
203 $performer = $rc->getPerformer();
204 return $performer && $performer->isLoggedIn() &&
205 $performer->getExperienceLevel() === 'learner';
209 'name' => 'experienced',
210 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
211 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
212 'cssClassSuffix' => 'user-experienced',
213 'isRowApplicableCallable' => function ( $ctx, $rc ) {
214 $performer = $rc->getPerformer();
215 return $performer && $performer->isLoggedIn() &&
216 $performer->getExperienceLevel() === 'experienced';
220 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
221 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
225 'name' => 'authorship',
226 'title' => 'rcfilters-filtergroup-authorship',
227 'class' => ChangesListBooleanFilterGroup
::class,
230 'name' => 'hidemyself',
231 'label' => 'rcfilters-filter-editsbyself-label',
232 'description' => 'rcfilters-filter-editsbyself-description',
233 // rcshowhidemine-show, rcshowhidemine-hide,
235 'showHideSuffix' => 'showhidemine',
237 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
238 &$query_options, &$join_conds
240 $actorQuery = ActorMigration
::newMigration()->getWhere( $dbr, 'rc_user', $ctx->getUser() );
241 $tables +
= $actorQuery['tables'];
242 $join_conds +
= $actorQuery['joins'];
243 $conds[] = 'NOT(' . $actorQuery['conds'] . ')';
245 'cssClassSuffix' => 'self',
246 'isRowApplicableCallable' => function ( $ctx, $rc ) {
247 return $ctx->getUser()->equals( $rc->getPerformer() );
251 'name' => 'hidebyothers',
252 'label' => 'rcfilters-filter-editsbyother-label',
253 'description' => 'rcfilters-filter-editsbyother-description',
255 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
256 &$query_options, &$join_conds
258 $actorQuery = ActorMigration
::newMigration()
259 ->getWhere( $dbr, 'rc_user', $ctx->getUser(), false );
260 $tables +
= $actorQuery['tables'];
261 $join_conds +
= $actorQuery['joins'];
262 $conds[] = $actorQuery['conds'];
264 'cssClassSuffix' => 'others',
265 'isRowApplicableCallable' => function ( $ctx, $rc ) {
266 return !$ctx->getUser()->equals( $rc->getPerformer() );
273 'name' => 'automated',
274 'title' => 'rcfilters-filtergroup-automated',
275 'class' => ChangesListBooleanFilterGroup
::class,
278 'name' => 'hidebots',
279 'label' => 'rcfilters-filter-bots-label',
280 'description' => 'rcfilters-filter-bots-description',
281 // rcshowhidebots-show, rcshowhidebots-hide,
283 'showHideSuffix' => 'showhidebots',
285 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
286 &$query_options, &$join_conds
288 $conds['rc_bot'] = 0;
290 'cssClassSuffix' => 'bot',
291 'isRowApplicableCallable' => function ( $ctx, $rc ) {
292 return $rc->getAttribute( 'rc_bot' );
296 'name' => 'hidehumans',
297 'label' => 'rcfilters-filter-humans-label',
298 'description' => 'rcfilters-filter-humans-description',
300 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
301 &$query_options, &$join_conds
303 $conds['rc_bot'] = 1;
305 'cssClassSuffix' => 'human',
306 'isRowApplicableCallable' => function ( $ctx, $rc ) {
307 return !$rc->getAttribute( 'rc_bot' );
313 // significance (conditional)
316 'name' => 'significance',
317 'title' => 'rcfilters-filtergroup-significance',
318 'class' => ChangesListBooleanFilterGroup
::class,
322 'name' => 'hideminor',
323 'label' => 'rcfilters-filter-minor-label',
324 'description' => 'rcfilters-filter-minor-description',
325 // rcshowhideminor-show, rcshowhideminor-hide,
327 'showHideSuffix' => 'showhideminor',
329 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
330 &$query_options, &$join_conds
332 $conds[] = 'rc_minor = 0';
334 'cssClassSuffix' => 'minor',
335 'isRowApplicableCallable' => function ( $ctx, $rc ) {
336 return $rc->getAttribute( 'rc_minor' );
340 'name' => 'hidemajor',
341 'label' => 'rcfilters-filter-major-label',
342 'description' => 'rcfilters-filter-major-description',
344 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
345 &$query_options, &$join_conds
347 $conds[] = 'rc_minor = 1';
349 'cssClassSuffix' => 'major',
350 'isRowApplicableCallable' => function ( $ctx, $rc ) {
351 return !$rc->getAttribute( 'rc_minor' );
358 'name' => 'lastRevision',
359 'title' => 'rcfilters-filtergroup-lastRevision',
360 'class' => ChangesListBooleanFilterGroup
::class,
364 'name' => 'hidelastrevision',
365 'label' => 'rcfilters-filter-lastrevision-label',
366 'description' => 'rcfilters-filter-lastrevision-description',
368 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
369 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
370 $conds[] = $dbr->makeList(
372 'rc_this_oldid <> page_latest',
373 'rc_type' => $nonRevisionTypes,
378 'cssClassSuffix' => 'last',
379 'isRowApplicableCallable' => function ( $ctx, $rc ) {
380 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
384 'name' => 'hidepreviousrevisions',
385 'label' => 'rcfilters-filter-previousrevision-label',
386 'description' => 'rcfilters-filter-previousrevision-description',
388 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
389 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
390 $conds[] = $dbr->makeList(
392 'rc_this_oldid = page_latest',
393 'rc_type' => $nonRevisionTypes,
398 'cssClassSuffix' => 'previous',
399 'isRowApplicableCallable' => function ( $ctx, $rc ) {
400 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
406 // With extensions, there can be change types that will not be hidden by any of these.
408 'name' => 'changeType',
409 'title' => 'rcfilters-filtergroup-changetype',
410 'class' => ChangesListBooleanFilterGroup
::class,
414 'name' => 'hidepageedits',
415 'label' => 'rcfilters-filter-pageedits-label',
416 'description' => 'rcfilters-filter-pageedits-description',
419 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
420 &$query_options, &$join_conds
422 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
424 'cssClassSuffix' => 'src-mw-edit',
425 'isRowApplicableCallable' => function ( $ctx, $rc ) {
426 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
430 'name' => 'hidenewpages',
431 'label' => 'rcfilters-filter-newpages-label',
432 'description' => 'rcfilters-filter-newpages-description',
435 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
436 &$query_options, &$join_conds
438 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
440 'cssClassSuffix' => 'src-mw-new',
441 'isRowApplicableCallable' => function ( $ctx, $rc ) {
442 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
446 // hidecategorization
450 'label' => 'rcfilters-filter-logactions-label',
451 'description' => 'rcfilters-filter-logactions-description',
454 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
455 &$query_options, &$join_conds
457 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
459 'cssClassSuffix' => 'src-mw-log',
460 'isRowApplicableCallable' => function ( $ctx, $rc ) {
461 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
469 $this->legacyReviewStatusFilterGroupDefinition
= [
471 'name' => 'legacyReviewStatus',
472 'title' => 'rcfilters-filtergroup-reviewstatus',
473 'class' => ChangesListBooleanFilterGroup
::class,
476 'name' => 'hidepatrolled',
477 // rcshowhidepatr-show, rcshowhidepatr-hide
479 'showHideSuffix' => 'showhidepatr',
481 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
482 &$query_options, &$join_conds
484 $conds['rc_patrolled'] = RecentChange
::PRC_UNPATROLLED
;
486 'isReplacedInStructuredUi' => true,
489 'name' => 'hideunpatrolled',
491 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
492 &$query_options, &$join_conds
494 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
;
496 'isReplacedInStructuredUi' => true,
502 $this->reviewStatusFilterGroupDefinition
= [
504 'name' => 'reviewStatus',
505 'title' => 'rcfilters-filtergroup-reviewstatus',
506 'class' => ChangesListStringOptionsFilterGroup
::class,
507 'isFullCoverage' => true,
511 'name' => 'unpatrolled',
512 'label' => 'rcfilters-filter-reviewstatus-unpatrolled-label',
513 'description' => 'rcfilters-filter-reviewstatus-unpatrolled-description',
514 'cssClassSuffix' => 'reviewstatus-unpatrolled',
515 'isRowApplicableCallable' => function ( $ctx, $rc ) {
516 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_UNPATROLLED
;
521 'label' => 'rcfilters-filter-reviewstatus-manual-label',
522 'description' => 'rcfilters-filter-reviewstatus-manual-description',
523 'cssClassSuffix' => 'reviewstatus-manual',
524 'isRowApplicableCallable' => function ( $ctx, $rc ) {
525 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_PATROLLED
;
530 'label' => 'rcfilters-filter-reviewstatus-auto-label',
531 'description' => 'rcfilters-filter-reviewstatus-auto-description',
532 'cssClassSuffix' => 'reviewstatus-auto',
533 'isRowApplicableCallable' => function ( $ctx, $rc ) {
534 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_AUTOPATROLLED
;
538 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
539 'queryCallable' => function ( $specialPageClassName, $ctx, $dbr,
540 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selected
542 if ( $selected === [] ) {
545 $rcPatrolledValues = [
546 'unpatrolled' => RecentChange
::PRC_UNPATROLLED
,
547 'manual' => RecentChange
::PRC_PATROLLED
,
548 'auto' => RecentChange
::PRC_AUTOPATROLLED
,
550 // e.g. rc_patrolled IN (0, 2)
551 $conds['rc_patrolled'] = array_map( function ( $s ) use ( $rcPatrolledValues ) {
552 return $rcPatrolledValues[ $s ];
558 $this->hideCategorizationFilterDefinition
= [
559 'name' => 'hidecategorization',
560 'label' => 'rcfilters-filter-categorization-label',
561 'description' => 'rcfilters-filter-categorization-description',
562 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
563 // wlshowhidecategorization
564 'showHideSuffix' => 'showhidecategorization',
567 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
568 &$query_options, &$join_conds
570 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
572 'cssClassSuffix' => 'src-mw-categorize',
573 'isRowApplicableCallable' => function ( $ctx, $rc ) {
574 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
580 * Check if filters are in conflict and guaranteed to return no results.
584 protected function areFiltersInConflict() {
585 $opts = $this->getOptions();
586 /** @var ChangesListFilterGroup $group */
587 foreach ( $this->getFilterGroups() as $group ) {
588 if ( $group->getConflictingGroups() ) {
591 " specifies conflicts with other groups but these are not supported yet."
595 /** @var ChangesListFilter $conflictingFilter */
596 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
597 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
602 /** @var ChangesListFilter $filter */
603 foreach ( $group->getFilters() as $filter ) {
604 /** @var ChangesListFilter $conflictingFilter */
605 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
607 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
608 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
622 * Main execution point
624 * @param string $subpage
626 public function execute( $subpage ) {
627 $this->rcSubpage
= $subpage;
629 $this->considerActionsForDefaultSavedQuery( $subpage );
631 $opts = $this->getOptions();
633 $rows = $this->getRows();
634 if ( $rows === false ) {
635 $rows = new FakeResultWrapper( [] );
638 // Used by Structured UI app to get results without MW chrome
639 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
640 $this->getOutput()->setArticleBodyOnly( true );
643 // Used by "live update" and "view newest" to check
644 // if there's new changes with minimal data transfer
645 if ( $this->getRequest()->getBool( 'peek' ) ) {
646 $code = $rows->numRows() > 0 ?
200 : 204;
647 $this->getOutput()->setStatusCode( $code );
649 if ( $this->getUser()->isAnon() !==
650 $this->getRequest()->getFuzzyBool( 'isAnon' )
652 $this->getOutput()->setStatusCode( 205 );
658 $batch = new LinkBatch
;
659 foreach ( $rows as $row ) {
660 $batch->add( NS_USER
, $row->rc_user_text
);
661 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
662 $batch->add( $row->rc_namespace
, $row->rc_title
);
663 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
664 $formatter = LogFormatter
::newFromRow( $row );
665 foreach ( $formatter->getPreloadTitles() as $title ) {
666 $batch->addObj( $title );
673 $this->outputHeader();
675 $this->webOutput( $rows, $opts );
678 } catch ( DBQueryTimeoutError
$timeoutException ) {
679 MWExceptionHandler
::logException( $timeoutException );
682 $this->outputHeader();
685 $this->getOutput()->setStatusCode( 500 );
686 $this->webOutputHeader( 0, $opts );
687 $this->outputTimeout();
690 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
691 // Clean up any bad page entries for titles showing up in RC
692 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
694 LoggerFactory
::getInstance( 'objectcache' )
698 $this->includeRcFiltersApp();
702 * Check whether or not the page should load defaults, and if so, whether
703 * a default saved query is relevant to be redirected to. If it is relevant,
704 * redirect properly with all necessary query parameters.
706 * @param string $subpage
708 protected function considerActionsForDefaultSavedQuery( $subpage ) {
709 if ( !$this->isStructuredFilterUiEnabled() ||
$this->including() ) {
713 $knownParams = $this->getRequest()->getValues(
714 ...array_keys( $this->getOptions()->getAllValues() )
717 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
718 // we need to exclude several parameters we know should not be counted towards preventing
719 // the loading of defaults.
720 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
721 $knownParams = array_diff_key( $knownParams, $excludedParams );
724 // If there are NO known parameters in the URL request
725 // (that are not excluded) then we need to check into loading
726 // the default saved query
727 count( $knownParams ) === 0
729 // Get the saved queries data and parse it
730 $savedQueries = FormatJson
::decode(
731 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
735 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
736 // Only load queries that are 'version' 2, since those
737 // have parameter representation
738 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
739 $savedQueryDefaultID = $savedQueries[ 'default' ];
740 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
742 // Build the entire parameter list
743 $query = array_merge(
744 $defaultQuery[ 'params' ],
745 $defaultQuery[ 'highlights' ],
750 // Add to the query any parameters that we may have ignored before
751 // but are still valid and requested in the URL
752 $query = array_merge( $this->getRequest()->getValues(), $query );
753 unset( $query[ 'title' ] );
754 $this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) );
756 // There's a default, but the version is not 2, and the server can't
757 // actually recognize the query itself. This happens if it is before
758 // the conversion, so we need to tell the UI to reload saved query as
759 // it does the conversion to version 2
760 $this->getOutput()->addJsConfigVars(
761 'wgStructuredChangeFiltersDefaultSavedQueryExists',
765 // Add the class that tells the frontend it is still loading
767 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
774 * Include the modules and configuration for the RCFilters app.
775 * Conditional on the user having the feature enabled.
777 * If it is disabled, add a <body> class marking that
779 protected function includeRcFiltersApp() {
780 $out = $this->getOutput();
781 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
782 $jsData = $this->getStructuredFilterJsData();
784 foreach ( $jsData['messageKeys'] as $key ) {
785 $messages[$key] = $this->msg( $key )->plain();
788 $out->addBodyClasses( 'mw-rcfilters-enabled' );
789 $collapsed = $this->getUser()->getBoolOption( static::$collapsedPreferenceName );
791 $out->addBodyClasses( 'mw-rcfilters-collapsed' );
794 // These config and message exports should be moved into a ResourceLoader data module (T201574)
795 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
796 $out->addJsConfigVars( 'wgStructuredChangeFiltersMessages', $messages );
797 $out->addJsConfigVars( 'wgStructuredChangeFiltersCollapsedState', $collapsed );
799 $out->addJsConfigVars(
800 'wgRCFiltersChangeTags',
801 $this->getChangeTagList()
803 $out->addJsConfigVars(
804 'StructuredChangeFiltersDisplayConfig',
806 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
807 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
808 'limitDefault' => $this->getDefaultLimit(),
809 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
810 'daysDefault' => $this->getDefaultDays(),
814 $out->addJsConfigVars(
815 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
816 static::$savedQueriesPreferenceName
818 $out->addJsConfigVars(
819 'wgStructuredChangeFiltersLimitPreferenceName',
820 static::$limitPreferenceName
822 $out->addJsConfigVars(
823 'wgStructuredChangeFiltersDaysPreferenceName',
824 static::$daysPreferenceName
826 $out->addJsConfigVars(
827 'wgStructuredChangeFiltersCollapsedPreferenceName',
828 static::$collapsedPreferenceName
831 $out->addJsConfigVars(
832 'StructuredChangeFiltersLiveUpdatePollingRate',
833 $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
836 $out->addBodyClasses( 'mw-rcfilters-disabled' );
841 * Fetch the change tags list for the front end
843 * @return Array Tag data
845 protected function getChangeTagList() {
846 $cache = ObjectCache
::getMainWANInstance();
847 $context = $this->getContext();
848 return $cache->getWithSetCallback(
849 $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ),
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 // Hit counts disabled for perf reasons, see T169997
857 $tagStats = ChangeTags::tagUsageStatistics();
858 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
861 arsort( $tagHitCounts );
863 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
865 // Build the list and data
867 foreach ( $tagHitCounts as $tagName => $hits ) {
869 // Only get active tags
870 isset( $explicitlyDefinedTags[ $tagName ] ) ||
871 isset( $softwareActivatedTags[ $tagName ] )
875 'label' => Sanitizer
::stripAllTags(
876 ChangeTags
::tagDescription( $tagName, $context )
879 ChangeTags
::truncateTagDescription(
880 $tagName, self
::TAG_DESC_CHARACTER_LIMIT
, $context
882 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
888 // Instead of sorting by hit count (disabled, see above), sort by display name
889 usort( $result, function ( $a, $b ) {
890 return strcasecmp( $a['label'], $b['label'] );
902 * Add the "no results" message to the output
904 protected function outputNoResults() {
905 $this->getOutput()->addHTML(
906 '<div class="mw-changeslist-empty">' .
907 $this->msg( 'recentchanges-noresult' )->parse() .
913 * Add the "timeout" message to the output
915 protected function outputTimeout() {
916 $this->getOutput()->addHTML(
917 '<div class="mw-changeslist-empty mw-changeslist-timeout">' .
918 $this->msg( 'recentchanges-timeout' )->parse() .
924 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
926 * @return bool|IResultWrapper Result or false
928 public function getRows() {
929 $opts = $this->getOptions();
936 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
938 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
942 * Get the current FormOptions for this request
944 * @return FormOptions
946 public function getOptions() {
947 if ( $this->rcOptions
=== null ) {
948 $this->rcOptions
= $this->setup( $this->rcSubpage
);
951 return $this->rcOptions
;
955 * Register all filters and their groups (including those from hooks), plus handle
956 * conflicts and defaults.
958 * You might want to customize these in the same method, in subclasses. You can
959 * call getFilterGroup to access a group, and (on the group) getFilter to access a
960 * filter, then make necessary modfications to the filter or group (e.g. with
963 protected function registerFilters() {
964 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
966 // Make sure this is not being transcluded (we don't want to show this
967 // information to all users just because the user that saves the edit can
968 // patrol or is logged in)
969 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
970 $this->registerFiltersFromDefinitions( $this->legacyReviewStatusFilterGroupDefinition
);
971 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
974 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
976 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
977 $transformedHideCategorizationDef = $this->transformFilterDefinition(
978 $this->hideCategorizationFilterDefinition
981 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
983 $hideCategorization = new ChangesListBooleanFilter(
984 $transformedHideCategorizationDef
988 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
990 $unstructuredGroupDefinition =
991 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
992 $this->getCustomFilters()
994 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
996 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
997 $registered = $userExperienceLevel->getFilter( 'registered' );
998 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
999 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
1000 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
1002 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
1003 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
1004 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
1006 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
1007 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
1009 // categoryFilter is conditional; see registerFilters
1010 if ( $categoryFilter !== null ) {
1011 $hideMinorFilter->conflictsWith(
1013 'rcfilters-hideminor-conflicts-typeofchange-global',
1014 'rcfilters-hideminor-conflicts-typeofchange',
1015 'rcfilters-typeofchange-conflicts-hideminor'
1018 $hideMinorFilter->conflictsWith(
1020 'rcfilters-hideminor-conflicts-typeofchange-global',
1021 'rcfilters-hideminor-conflicts-typeofchange',
1022 'rcfilters-typeofchange-conflicts-hideminor'
1024 $hideMinorFilter->conflictsWith(
1025 $pagecreationFilter,
1026 'rcfilters-hideminor-conflicts-typeofchange-global',
1027 'rcfilters-hideminor-conflicts-typeofchange',
1028 'rcfilters-typeofchange-conflicts-hideminor'
1033 * Transforms filter definition to prepare it for constructor.
1035 * See overrides of this method as well.
1037 * @param array $filterDefinition Original filter definition
1039 * @return array Transformed definition
1041 protected function transformFilterDefinition( array $filterDefinition ) {
1042 return $filterDefinition;
1046 * Register filters from a definition object
1048 * Array specifying groups and their filters; see Filter and
1049 * ChangesListFilterGroup constructors.
1051 * There is light processing to simplify core maintenance.
1052 * @param array $definition
1054 protected function registerFiltersFromDefinitions( array $definition ) {
1055 $autoFillPriority = -1;
1056 foreach ( $definition as $groupDefinition ) {
1057 if ( !isset( $groupDefinition['priority'] ) ) {
1058 $groupDefinition['priority'] = $autoFillPriority;
1060 // If it's explicitly specified, start over the auto-fill
1061 $autoFillPriority = $groupDefinition['priority'];
1064 $autoFillPriority--;
1066 $className = $groupDefinition['class'];
1067 unset( $groupDefinition['class'] );
1069 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
1070 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
1073 $this->registerFilterGroup( new $className( $groupDefinition ) );
1078 * Get filter group definition from legacy custom filters
1080 * @param array $customFilters Custom filters from legacy hooks
1081 * @return array Group definition
1083 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
1084 // Special internal unstructured group
1085 $unstructuredGroupDefinition = [
1086 'name' => 'unstructured',
1087 'class' => ChangesListBooleanFilterGroup
::class,
1088 'priority' => -1, // Won't display in structured
1092 foreach ( $customFilters as $name => $params ) {
1093 $unstructuredGroupDefinition['filters'][] = [
1095 'showHide' => $params['msg'],
1096 'default' => $params['default'],
1100 return $unstructuredGroupDefinition;
1104 * @return array The legacy show/hide toggle filters
1106 protected function getLegacyShowHideFilters() {
1108 foreach ( $this->filterGroups
as $group ) {
1109 if ( $group instanceof ChangesListBooleanFilterGroup
) {
1110 foreach ( $group->getFilters() as $key => $filter ) {
1111 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1112 $filters[ $key ] = $filter;
1121 * Register all the filters, including legacy hook-driven ones.
1122 * Then create a FormOptions object with options as specified by the user
1124 * @param array $parameters
1126 * @return FormOptions
1128 public function setup( $parameters ) {
1129 $this->registerFilters();
1131 $opts = $this->getDefaultOptions();
1133 $opts = $this->fetchOptionsFromRequest( $opts );
1135 // Give precedence to subpage syntax
1136 if ( $parameters !== null ) {
1137 $this->parseParameters( $parameters, $opts );
1140 $this->validateOptions( $opts );
1146 * Get a FormOptions object containing the default options. By default, returns
1147 * some basic options. The filters listed explicitly here are overriden in this
1148 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1149 * and more) are structured. Structured filters are overriden in registerFilters.
1152 * @return FormOptions
1154 public function getDefaultOptions() {
1155 $opts = new FormOptions();
1156 $structuredUI = $this->isStructuredFilterUiEnabled();
1157 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1158 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1160 /** @var ChangesListFilterGroup $filterGroup */
1161 foreach ( $this->filterGroups
as $filterGroup ) {
1162 $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
1165 $opts->add( 'namespace', '', FormOptions
::STRING );
1166 $opts->add( 'invert', false );
1167 $opts->add( 'associated', false );
1168 $opts->add( 'urlversion', 1 );
1169 $opts->add( 'tagfilter', '' );
1171 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
1172 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
1174 $opts->add( 'from', '' );
1180 * Register a structured changes list filter group
1182 * @param ChangesListFilterGroup $group
1184 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
1185 $groupName = $group->getName();
1187 $this->filterGroups
[$groupName] = $group;
1191 * Gets the currently registered filters groups
1193 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1195 protected function getFilterGroups() {
1196 return $this->filterGroups
;
1200 * Gets a specified ChangesListFilterGroup by name
1202 * @param string $groupName Name of group
1204 * @return ChangesListFilterGroup|null Group, or null if not registered
1206 public function getFilterGroup( $groupName ) {
1207 return $this->filterGroups
[$groupName] ??
null;
1210 // Currently, this intentionally only includes filters that display
1211 // in the structured UI. This can be changed easily, though, if we want
1212 // to include data on filters that use the unstructured UI. messageKeys is a
1213 // special top-level value, with the value being an array of the message keys to
1214 // send to the client.
1216 * Gets structured filter information needed by JS
1218 * @return array Associative array
1219 * * array $return['groups'] Group data
1220 * * array $return['messageKeys'] Array of message keys
1222 public function getStructuredFilterJsData() {
1225 'messageKeys' => [],
1228 usort( $this->filterGroups
, function ( $a, $b ) {
1229 return $b->getPriority() <=> $a->getPriority();
1232 foreach ( $this->filterGroups
as $groupName => $group ) {
1233 $groupOutput = $group->getJsData( $this );
1234 if ( $groupOutput !== null ) {
1235 $output['messageKeys'] = array_merge(
1236 $output['messageKeys'],
1237 $groupOutput['messageKeys']
1240 unset( $groupOutput['messageKeys'] );
1241 $output['groups'][] = $groupOutput;
1249 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
1252 * @return array Map of filter URL param names to properties (msg/default)
1254 protected function getCustomFilters() {
1255 if ( $this->customFilters
=== null ) {
1256 $this->customFilters
= [];
1257 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
1260 return $this->customFilters
;
1264 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1266 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1268 * @param FormOptions $opts
1269 * @return FormOptions
1271 protected function fetchOptionsFromRequest( $opts ) {
1272 $opts->fetchValuesFromRequest( $this->getRequest() );
1278 * Process $par and put options found in $opts. Used when including the page.
1280 * @param string $par
1281 * @param FormOptions $opts
1283 public function parseParameters( $par, FormOptions
$opts ) {
1284 $stringParameterNameSet = [];
1285 $hideParameterNameSet = [];
1287 // URL parameters can be per-group, like 'userExpLevel',
1288 // or per-filter, like 'hideminor'.
1290 foreach ( $this->filterGroups
as $filterGroup ) {
1291 if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup
) {
1292 $stringParameterNameSet[$filterGroup->getName()] = true;
1293 } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1294 foreach ( $filterGroup->getFilters() as $filter ) {
1295 $hideParameterNameSet[$filter->getName()] = true;
1300 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1301 foreach ( $bits as $bit ) {
1303 if ( isset( $hideParameterNameSet[$bit] ) ) {
1304 // hidefoo => hidefoo=true
1306 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1307 // foo => hidefoo=false
1308 $opts["hide$bit"] = false;
1309 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1310 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1311 $opts[$m[1]] = $m[2];
1318 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1320 * @param FormOptions $opts
1322 public function validateOptions( FormOptions
$opts ) {
1323 $isContradictory = $this->fixContradictoryOptions( $opts );
1324 $isReplaced = $this->replaceOldOptions( $opts );
1326 if ( $isContradictory ||
$isReplaced ) {
1327 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1328 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1331 $opts->validateIntBounds( 'limit', 0, 5000 );
1332 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1336 * Fix invalid options by resetting pairs that should never appear together.
1338 * @param FormOptions $opts
1339 * @return bool True if any option was reset
1341 private function fixContradictoryOptions( FormOptions
$opts ) {
1342 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1344 foreach ( $this->filterGroups
as $filterGroup ) {
1345 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1346 $filters = $filterGroup->getFilters();
1348 if ( count( $filters ) === 1 ) {
1349 // legacy boolean filters should not be considered
1353 $allInGroupEnabled = array_reduce(
1355 function ( $carry, $filter ) use ( $opts ) {
1356 return $carry && $opts[ $filter->getName() ];
1358 /* initialValue */ count( $filters ) > 0
1361 if ( $allInGroupEnabled ) {
1362 foreach ( $filters as $filter ) {
1363 $opts[ $filter->getName() ] = false;
1375 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1378 * This is deprecated and may be removed.
1380 * @param FormOptions $opts
1381 * @return bool True if this change was mode
1383 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1384 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1385 $opts->reset( 'hideanons' );
1386 if ( !$opts['hidebots'] ) {
1387 $opts->reset( 'hideliu' );
1388 $opts['hidehumans'] = 1;
1398 * Replace old options with their structured UI equivalents
1400 * @param FormOptions $opts
1401 * @return bool True if the change was made
1403 public function replaceOldOptions( FormOptions
$opts ) {
1404 if ( !$this->isStructuredFilterUiEnabled() ) {
1410 // At this point 'hideanons' and 'hideliu' cannot be both true,
1411 // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
1412 if ( $opts[ 'hideanons' ] ) {
1413 $opts->reset( 'hideanons' );
1414 $opts[ 'userExpLevel' ] = 'registered';
1418 if ( $opts[ 'hideliu' ] ) {
1419 $opts->reset( 'hideliu' );
1420 $opts[ 'userExpLevel' ] = 'unregistered';
1424 if ( $this->getFilterGroup( 'legacyReviewStatus' ) ) {
1425 if ( $opts[ 'hidepatrolled' ] ) {
1426 $opts->reset( 'hidepatrolled' );
1427 $opts[ 'reviewStatus' ] = 'unpatrolled';
1431 if ( $opts[ 'hideunpatrolled' ] ) {
1432 $opts->reset( 'hideunpatrolled' );
1433 $opts[ 'reviewStatus' ] = implode(
1434 ChangesListStringOptionsFilterGroup
::SEPARATOR
,
1435 [ 'manual', 'auto' ]
1445 * Convert parameters values from true/false to 1/0
1446 * so they are not omitted by wfArrayToCgi()
1449 * @param array $params
1452 protected function convertParamsForLink( $params ) {
1453 foreach ( $params as &$value ) {
1454 if ( $value === false ) {
1463 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1464 * the user requested.
1466 * @param array &$tables Array of tables; see IDatabase::select $table
1467 * @param array &$fields Array of fields; see IDatabase::select $vars
1468 * @param array &$conds Array of conditions; see IDatabase::select $conds
1469 * @param array &$query_options Array of query options; see IDatabase::select $options
1470 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1471 * @param FormOptions $opts
1473 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1474 &$join_conds, FormOptions
$opts
1476 $dbr = $this->getDB();
1477 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1479 /** @var ChangesListFilterGroup $filterGroup */
1480 foreach ( $this->filterGroups
as $filterGroup ) {
1481 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1482 $query_options, $join_conds, $opts, $isStructuredUI );
1485 // Namespace filtering
1486 if ( $opts[ 'namespace' ] !== '' ) {
1487 $namespaces = explode( ';', $opts[ 'namespace' ] );
1489 if ( $opts[ 'associated' ] ) {
1490 $associatedNamespaces = array_map(
1492 return MWNamespace
::getAssociated( $ns );
1496 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1499 if ( count( $namespaces ) === 1 ) {
1500 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1501 $value = $dbr->addQuotes( reset( $namespaces ) );
1503 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1504 sort( $namespaces );
1505 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1507 $conds[] = "rc_namespace $operator $value";
1511 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1512 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1514 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1515 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
1516 $cutoff = $dbr->timestamp( $opts['from'] );
1518 $opts->reset( 'from' );
1521 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1527 * @param array $tables Array of tables; see IDatabase::select $table
1528 * @param array $fields Array of fields; see IDatabase::select $vars
1529 * @param array $conds Array of conditions; see IDatabase::select $conds
1530 * @param array $query_options Array of query options; see IDatabase::select $options
1531 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1532 * @param FormOptions $opts
1533 * @return bool|IResultWrapper Result or false
1535 protected function doMainQuery( $tables, $fields, $conds,
1536 $query_options, $join_conds, FormOptions
$opts
1538 $rcQuery = RecentChange
::getQueryInfo();
1539 $tables = array_merge( $tables, $rcQuery['tables'] );
1540 $fields = array_merge( $rcQuery['fields'], $fields );
1541 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
1543 ChangeTags
::modifyDisplayQuery(
1552 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1558 $dbr = $this->getDB();
1560 return $dbr->select(
1570 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1571 &$query_options, &$join_conds, $opts
1574 'ChangesListSpecialPageQuery',
1575 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1580 * Return a IDatabase object for reading
1584 protected function getDB() {
1585 return wfGetDB( DB_REPLICA
);
1589 * Send header output to the OutputPage object, only called if not using feeds
1591 * @param int $rowCount Number of database rows
1592 * @param FormOptions $opts
1594 private function webOutputHeader( $rowCount, $opts ) {
1595 if ( !$this->including() ) {
1596 $this->outputFeedLinks();
1597 $this->doHeader( $opts, $rowCount );
1602 * Send output to the OutputPage object, only called if not used feeds
1604 * @param IResultWrapper $rows Database rows
1605 * @param FormOptions $opts
1607 public function webOutput( $rows, $opts ) {
1608 $this->webOutputHeader( $rows->numRows(), $opts );
1610 $this->outputChangesList( $rows, $opts );
1614 * Output feed links.
1616 public function outputFeedLinks() {
1617 // nothing by default
1621 * Build and output the actual changes list.
1623 * @param IResultWrapper $rows Database rows
1624 * @param FormOptions $opts
1626 abstract public function outputChangesList( $rows, $opts );
1629 * Set the text to be displayed above the changes
1631 * @param FormOptions $opts
1632 * @param int $numRows Number of rows in the result to show after this header
1634 public function doHeader( $opts, $numRows ) {
1635 $this->setTopText( $opts );
1637 // @todo Lots of stuff should be done here.
1639 $this->setBottomText( $opts );
1643 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1644 * or similar methods to print the text.
1646 * @param FormOptions $opts
1648 public function setTopText( FormOptions
$opts ) {
1649 // nothing by default
1653 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1654 * or similar methods to print the text.
1656 * @param FormOptions $opts
1658 public function setBottomText( FormOptions
$opts ) {
1659 // nothing by default
1663 * Get options to be displayed in a form
1664 * @todo This should handle options returned by getDefaultOptions().
1665 * @todo Not called by anything in this class (but is in subclasses), should be
1666 * called by something… doHeader() maybe?
1668 * @param FormOptions $opts
1671 public function getExtraOptions( $opts ) {
1676 * Return the legend displayed within the fieldset
1680 public function makeLegend() {
1681 $context = $this->getContext();
1682 $user = $context->getUser();
1683 # The legend showing what the letters and stuff mean
1684 $legend = Html
::openElement( 'dl' ) . "\n";
1685 # Iterates through them and gets the messages for both letter and tooltip
1686 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1687 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1688 unset( $legendItems['unpatrolled'] );
1690 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1691 $label = $item['legend'] ??
$item['title'];
1692 $letter = $item['letter'];
1693 $cssClass = $item['class'] ??
$key;
1695 $legend .= Html
::element( 'dt',
1696 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1698 Html
::rawElement( 'dd',
1699 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1700 $context->msg( $label )->parse()
1704 $legend .= Html
::rawElement( 'dt',
1705 [ 'class' => 'mw-plusminus-pos' ],
1706 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1708 $legend .= Html
::element(
1710 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1711 $context->msg( 'recentchanges-label-plusminus' )->text()
1713 $legend .= Html
::closeElement( 'dl' ) . "\n";
1715 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1716 $context->msg( 'rcfilters-legend-heading' )->parse() :
1717 $context->msg( 'recentchanges-legend-heading' )->parse();
1720 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1721 $collapsedClass = $collapsedState === 'collapsed' ?
' mw-collapsed' : '';
1724 '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
1726 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1733 * Add page-specific modules.
1735 protected function addModules() {
1736 $out = $this->getOutput();
1737 // Styles and behavior for the legend box (see makeLegend())
1738 $out->addModuleStyles( [
1739 'mediawiki.special.changeslist.legend',
1740 'mediawiki.special.changeslist',
1742 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1744 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
1745 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1746 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1750 protected function getGroupName() {
1755 * Filter on users' experience levels; this will not be called if nothing is
1758 * @param string $specialPageClassName Class name of current special page
1759 * @param IContextSource $context Context, for e.g. user
1760 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1761 * @param array &$tables Array of tables; see IDatabase::select $table
1762 * @param array &$fields Array of fields; see IDatabase::select $vars
1763 * @param array &$conds Array of conditions; see IDatabase::select $conds
1764 * @param array &$query_options Array of query options; see IDatabase::select $options
1765 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1766 * @param array $selectedExpLevels The allowed active values, sorted
1767 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1770 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1771 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1773 global $wgLearnerEdits,
1774 $wgExperiencedUserEdits,
1775 $wgLearnerMemberSince,
1776 $wgExperiencedUserMemberSince;
1780 // If all levels are selected, don't filter
1781 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1785 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1787 in_array( 'registered', $selectedExpLevels ) &&
1788 in_array( 'unregistered', $selectedExpLevels )
1793 $actorMigration = ActorMigration
::newMigration();
1794 $actorQuery = $actorMigration->getJoin( 'rc_user' );
1795 $tables +
= $actorQuery['tables'];
1796 $join_conds +
= $actorQuery['joins'];
1798 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1800 in_array( 'registered', $selectedExpLevels ) &&
1801 !in_array( 'unregistered', $selectedExpLevels )
1803 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1807 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1808 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1813 $join_conds['user'] = [ 'LEFT JOIN', $actorQuery['fields']['rc_user'] . ' = user_id' ];
1818 $secondsPerDay = 86400;
1819 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1820 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1822 $aboveNewcomer = $dbr->makeList(
1824 'user_editcount >= ' . intval( $wgLearnerEdits ),
1825 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1830 $aboveLearner = $dbr->makeList(
1832 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1833 'user_registration <= ' .
1834 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1841 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1842 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1843 $conditions[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1846 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1847 $conditions[] = "NOT ( $aboveNewcomer )";
1848 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1849 $conditions[] = $dbr->makeList(
1850 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1853 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1854 $conditions[] = $aboveLearner;
1855 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1856 $conditions[] = "NOT ( $aboveLearner )";
1857 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1858 $conditions[] = $dbr->makeList(
1859 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1862 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1863 $conditions[] = $aboveNewcomer;
1864 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1865 $conditions[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1868 if ( count( $conditions ) > 1 ) {
1869 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1870 } elseif ( count( $conditions ) === 1 ) {
1871 $conds[] = reset( $conditions );
1876 * Check whether the structured filter UI is enabled
1880 public function isStructuredFilterUiEnabled() {
1881 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1885 return static::checkStructuredFilterUiEnabled(
1892 * Check whether the structured filter UI is enabled by default (regardless of
1893 * this particular user's setting)
1897 public function isStructuredFilterUiEnabledByDefault() {
1898 if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
1899 return !$this->getUser()->getDefaultOption( 'rcenhancedfilters-disable' );
1901 return $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
1906 * Static method to check whether StructuredFilter UI is enabled for the given user
1909 * @param Config $config
1913 public static function checkStructuredFilterUiEnabled( Config
$config, User
$user ) {
1914 if ( $config->get( 'StructuredChangeFiltersShowPreference' ) ) {
1915 return !$user->getOption( 'rcenhancedfilters-disable' );
1917 return $user->getOption( 'rcenhancedfilters' );
1922 * Get the default value of the number of changes to display when loading
1928 public function getDefaultLimit() {
1929 return $this->getUser()->getIntOption( static::$limitPreferenceName );
1933 * Get the default value of the number of days to display when loading
1935 * Supports fractional values, and should be cast to a float.
1940 public function getDefaultDays() {
1941 return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );