3 * Special page which uses a ChangesList to show query results.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
23 use MediaWiki\Logger\LoggerFactory
;
24 use Wikimedia\Rdbms\DBQueryTimeoutError
;
25 use Wikimedia\Rdbms\IResultWrapper
;
26 use Wikimedia\Rdbms\FakeResultWrapper
;
27 use Wikimedia\Rdbms\IDatabase
;
30 * Special page which uses a ChangesList to show query results.
31 * @todo Way too many public functions, most of them should be protected
33 * @ingroup SpecialPage
35 abstract class ChangesListSpecialPage
extends SpecialPage
{
37 * Maximum length of a tag description in UTF-8 characters.
38 * Longer descriptions will be truncated.
40 const TAG_DESC_CHARACTER_LIMIT
= 120;
43 * Preference name for saved queries. Subclasses that use saved queries should override this.
46 protected static $savedQueriesPreferenceName;
49 * Preference name for 'days'. Subclasses should override this.
52 protected static $daysPreferenceName;
55 * Preference name for 'limit'. Subclasses should override this.
58 protected static $limitPreferenceName;
63 /** @var FormOptions */
67 protected $customFilters;
69 // Order of both groups and filters is significant; first is top-most priority,
70 // descending from there.
71 // 'showHideSuffix' is a shortcut to and avoid spelling out
72 // details specific to subclasses here.
74 * Definition information for the filters and their groups
76 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
77 * However, priority is dynamically added for the core groups, to ease maintenance.
79 * Groups are displayed to the user in the structured UI. However, if necessary,
80 * all of the filters in a group can be configured to only display on the
81 * unstuctured UI, in which case you don't need a group title. This is done in
82 * getFilterGroupDefinitionFromLegacyCustomFilters, for example.
84 * @var array $filterGroupDefinitions
86 private $filterGroupDefinitions;
88 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
89 // that is registered conditionally.
90 private $legacyReviewStatusFilterGroupDefinition;
92 // Single filter group registered conditionally
93 private $reviewStatusFilterGroupDefinition;
95 // Single filter group registered conditionally
96 private $hideCategorizationFilterDefinition;
99 * Filter groups, and their contained filters
100 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
102 * @var array $filterGroups
104 protected $filterGroups = [];
106 public function __construct( $name, $restriction ) {
107 parent
::__construct( $name, $restriction );
109 $nonRevisionTypes = [ RC_LOG
];
110 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
112 $this->filterGroupDefinitions
= [
114 'name' => 'registration',
115 'title' => 'rcfilters-filtergroup-registration',
116 'class' => ChangesListBooleanFilterGroup
::class,
120 // rcshowhideliu-show, rcshowhideliu-hide,
122 'showHideSuffix' => 'showhideliu',
124 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
125 &$query_options, &$join_conds
127 $actorMigration = ActorMigration
::newMigration();
128 $actorQuery = $actorMigration->getJoin( 'rc_user' );
129 $tables +
= $actorQuery['tables'];
130 $join_conds +
= $actorQuery['joins'];
131 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
133 'isReplacedInStructuredUi' => true,
137 'name' => 'hideanons',
138 // rcshowhideanons-show, rcshowhideanons-hide,
140 'showHideSuffix' => 'showhideanons',
142 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
143 &$query_options, &$join_conds
145 $actorMigration = ActorMigration
::newMigration();
146 $actorQuery = $actorMigration->getJoin( 'rc_user' );
147 $tables +
= $actorQuery['tables'];
148 $join_conds +
= $actorQuery['joins'];
149 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
151 'isReplacedInStructuredUi' => true,
157 'name' => 'userExpLevel',
158 'title' => 'rcfilters-filtergroup-userExpLevel',
159 'class' => ChangesListStringOptionsFilterGroup
::class,
160 'isFullCoverage' => true,
163 'name' => 'unregistered',
164 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
165 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
166 'cssClassSuffix' => 'user-unregistered',
167 'isRowApplicableCallable' => function ( $ctx, $rc ) {
168 return !$rc->getAttribute( 'rc_user' );
172 'name' => 'registered',
173 'label' => 'rcfilters-filter-user-experience-level-registered-label',
174 'description' => 'rcfilters-filter-user-experience-level-registered-description',
175 'cssClassSuffix' => 'user-registered',
176 'isRowApplicableCallable' => function ( $ctx, $rc ) {
177 return $rc->getAttribute( 'rc_user' );
181 'name' => 'newcomer',
182 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
183 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
184 'cssClassSuffix' => 'user-newcomer',
185 'isRowApplicableCallable' => function ( $ctx, $rc ) {
186 $performer = $rc->getPerformer();
187 return $performer && $performer->isLoggedIn() &&
188 $performer->getExperienceLevel() === 'newcomer';
193 'label' => 'rcfilters-filter-user-experience-level-learner-label',
194 'description' => 'rcfilters-filter-user-experience-level-learner-description',
195 'cssClassSuffix' => 'user-learner',
196 'isRowApplicableCallable' => function ( $ctx, $rc ) {
197 $performer = $rc->getPerformer();
198 return $performer && $performer->isLoggedIn() &&
199 $performer->getExperienceLevel() === 'learner';
203 'name' => 'experienced',
204 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
205 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
206 'cssClassSuffix' => 'user-experienced',
207 'isRowApplicableCallable' => function ( $ctx, $rc ) {
208 $performer = $rc->getPerformer();
209 return $performer && $performer->isLoggedIn() &&
210 $performer->getExperienceLevel() === 'experienced';
214 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
215 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
219 'name' => 'authorship',
220 'title' => 'rcfilters-filtergroup-authorship',
221 'class' => ChangesListBooleanFilterGroup
::class,
224 'name' => 'hidemyself',
225 'label' => 'rcfilters-filter-editsbyself-label',
226 'description' => 'rcfilters-filter-editsbyself-description',
227 // rcshowhidemine-show, rcshowhidemine-hide,
229 'showHideSuffix' => 'showhidemine',
231 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
232 &$query_options, &$join_conds
234 $actorQuery = ActorMigration
::newMigration()->getWhere( $dbr, 'rc_user', $ctx->getUser() );
235 $tables +
= $actorQuery['tables'];
236 $join_conds +
= $actorQuery['joins'];
237 $conds[] = 'NOT(' . $actorQuery['conds'] . ')';
239 'cssClassSuffix' => 'self',
240 'isRowApplicableCallable' => function ( $ctx, $rc ) {
241 return $ctx->getUser()->equals( $rc->getPerformer() );
245 'name' => 'hidebyothers',
246 'label' => 'rcfilters-filter-editsbyother-label',
247 'description' => 'rcfilters-filter-editsbyother-description',
249 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
250 &$query_options, &$join_conds
252 $actorQuery = ActorMigration
::newMigration()
253 ->getWhere( $dbr, 'rc_user', $ctx->getUser(), false );
254 $tables +
= $actorQuery['tables'];
255 $join_conds +
= $actorQuery['joins'];
256 $conds[] = $actorQuery['conds'];
258 'cssClassSuffix' => 'others',
259 'isRowApplicableCallable' => function ( $ctx, $rc ) {
260 return !$ctx->getUser()->equals( $rc->getPerformer() );
267 'name' => 'automated',
268 'title' => 'rcfilters-filtergroup-automated',
269 'class' => ChangesListBooleanFilterGroup
::class,
272 'name' => 'hidebots',
273 'label' => 'rcfilters-filter-bots-label',
274 'description' => 'rcfilters-filter-bots-description',
275 // rcshowhidebots-show, rcshowhidebots-hide,
277 'showHideSuffix' => 'showhidebots',
279 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
280 &$query_options, &$join_conds
282 $conds['rc_bot'] = 0;
284 'cssClassSuffix' => 'bot',
285 'isRowApplicableCallable' => function ( $ctx, $rc ) {
286 return $rc->getAttribute( 'rc_bot' );
290 'name' => 'hidehumans',
291 'label' => 'rcfilters-filter-humans-label',
292 'description' => 'rcfilters-filter-humans-description',
294 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
295 &$query_options, &$join_conds
297 $conds['rc_bot'] = 1;
299 'cssClassSuffix' => 'human',
300 'isRowApplicableCallable' => function ( $ctx, $rc ) {
301 return !$rc->getAttribute( 'rc_bot' );
307 // significance (conditional)
310 'name' => 'significance',
311 'title' => 'rcfilters-filtergroup-significance',
312 'class' => ChangesListBooleanFilterGroup
::class,
316 'name' => 'hideminor',
317 'label' => 'rcfilters-filter-minor-label',
318 'description' => 'rcfilters-filter-minor-description',
319 // rcshowhideminor-show, rcshowhideminor-hide,
321 'showHideSuffix' => 'showhideminor',
323 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
324 &$query_options, &$join_conds
326 $conds[] = 'rc_minor = 0';
328 'cssClassSuffix' => 'minor',
329 'isRowApplicableCallable' => function ( $ctx, $rc ) {
330 return $rc->getAttribute( 'rc_minor' );
334 'name' => 'hidemajor',
335 'label' => 'rcfilters-filter-major-label',
336 'description' => 'rcfilters-filter-major-description',
338 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
339 &$query_options, &$join_conds
341 $conds[] = 'rc_minor = 1';
343 'cssClassSuffix' => 'major',
344 'isRowApplicableCallable' => function ( $ctx, $rc ) {
345 return !$rc->getAttribute( 'rc_minor' );
352 'name' => 'lastRevision',
353 'title' => 'rcfilters-filtergroup-lastRevision',
354 'class' => ChangesListBooleanFilterGroup
::class,
358 'name' => 'hidelastrevision',
359 'label' => 'rcfilters-filter-lastrevision-label',
360 'description' => 'rcfilters-filter-lastrevision-description',
362 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
363 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
364 $conds[] = $dbr->makeList(
366 'rc_this_oldid <> page_latest',
367 'rc_type' => $nonRevisionTypes,
372 'cssClassSuffix' => 'last',
373 'isRowApplicableCallable' => function ( $ctx, $rc ) {
374 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
378 'name' => 'hidepreviousrevisions',
379 'label' => 'rcfilters-filter-previousrevision-label',
380 'description' => 'rcfilters-filter-previousrevision-description',
382 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
383 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
384 $conds[] = $dbr->makeList(
386 'rc_this_oldid = page_latest',
387 'rc_type' => $nonRevisionTypes,
392 'cssClassSuffix' => 'previous',
393 'isRowApplicableCallable' => function ( $ctx, $rc ) {
394 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
400 // With extensions, there can be change types that will not be hidden by any of these.
402 'name' => 'changeType',
403 'title' => 'rcfilters-filtergroup-changetype',
404 'class' => ChangesListBooleanFilterGroup
::class,
408 'name' => 'hidepageedits',
409 'label' => 'rcfilters-filter-pageedits-label',
410 'description' => 'rcfilters-filter-pageedits-description',
413 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
414 &$query_options, &$join_conds
416 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
418 'cssClassSuffix' => 'src-mw-edit',
419 'isRowApplicableCallable' => function ( $ctx, $rc ) {
420 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
424 'name' => 'hidenewpages',
425 'label' => 'rcfilters-filter-newpages-label',
426 'description' => 'rcfilters-filter-newpages-description',
429 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
430 &$query_options, &$join_conds
432 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
434 'cssClassSuffix' => 'src-mw-new',
435 'isRowApplicableCallable' => function ( $ctx, $rc ) {
436 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
440 // hidecategorization
444 'label' => 'rcfilters-filter-logactions-label',
445 'description' => 'rcfilters-filter-logactions-description',
448 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
449 &$query_options, &$join_conds
451 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
453 'cssClassSuffix' => 'src-mw-log',
454 'isRowApplicableCallable' => function ( $ctx, $rc ) {
455 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
463 $this->legacyReviewStatusFilterGroupDefinition
= [
465 'name' => 'legacyReviewStatus',
466 'title' => 'rcfilters-filtergroup-reviewstatus',
467 'class' => ChangesListBooleanFilterGroup
::class,
470 'name' => 'hidepatrolled',
471 // rcshowhidepatr-show, rcshowhidepatr-hide
473 'showHideSuffix' => 'showhidepatr',
475 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
476 &$query_options, &$join_conds
478 $conds['rc_patrolled'] = RecentChange
::PRC_UNPATROLLED
;
480 'isReplacedInStructuredUi' => true,
483 'name' => 'hideunpatrolled',
485 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
486 &$query_options, &$join_conds
488 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
;
490 'isReplacedInStructuredUi' => true,
496 $this->reviewStatusFilterGroupDefinition
= [
498 'name' => 'reviewStatus',
499 'title' => 'rcfilters-filtergroup-reviewstatus',
500 'class' => ChangesListStringOptionsFilterGroup
::class,
501 'isFullCoverage' => true,
505 'name' => 'unpatrolled',
506 'label' => 'rcfilters-filter-reviewstatus-unpatrolled-label',
507 'description' => 'rcfilters-filter-reviewstatus-unpatrolled-description',
508 'cssClassSuffix' => 'reviewstatus-unpatrolled',
509 'isRowApplicableCallable' => function ( $ctx, $rc ) {
510 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_UNPATROLLED
;
515 'label' => 'rcfilters-filter-reviewstatus-manual-label',
516 'description' => 'rcfilters-filter-reviewstatus-manual-description',
517 'cssClassSuffix' => 'reviewstatus-manual',
518 'isRowApplicableCallable' => function ( $ctx, $rc ) {
519 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_PATROLLED
;
524 'label' => 'rcfilters-filter-reviewstatus-auto-label',
525 'description' => 'rcfilters-filter-reviewstatus-auto-description',
526 'cssClassSuffix' => 'reviewstatus-auto',
527 'isRowApplicableCallable' => function ( $ctx, $rc ) {
528 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_AUTOPATROLLED
;
532 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
533 'queryCallable' => function ( $specialPageClassName, $ctx, $dbr,
534 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selected
536 if ( $selected === [] ) {
539 $rcPatrolledValues = [
540 'unpatrolled' => RecentChange
::PRC_UNPATROLLED
,
541 'manual' => RecentChange
::PRC_PATROLLED
,
542 'auto' => RecentChange
::PRC_AUTOPATROLLED
,
544 // e.g. rc_patrolled IN (0, 2)
545 $conds['rc_patrolled'] = array_map( function ( $s ) use ( $rcPatrolledValues ) {
546 return $rcPatrolledValues[ $s ];
552 $this->hideCategorizationFilterDefinition
= [
553 'name' => 'hidecategorization',
554 'label' => 'rcfilters-filter-categorization-label',
555 'description' => 'rcfilters-filter-categorization-description',
556 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
557 // wlshowhidecategorization
558 'showHideSuffix' => 'showhidecategorization',
561 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
562 &$query_options, &$join_conds
564 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
566 'cssClassSuffix' => 'src-mw-categorize',
567 'isRowApplicableCallable' => function ( $ctx, $rc ) {
568 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
574 * Check if filters are in conflict and guaranteed to return no results.
578 protected function areFiltersInConflict() {
579 $opts = $this->getOptions();
580 /** @var ChangesListFilterGroup $group */
581 foreach ( $this->getFilterGroups() as $group ) {
582 if ( $group->getConflictingGroups() ) {
585 " specifies conflicts with other groups but these are not supported yet."
589 /** @var ChangesListFilter $conflictingFilter */
590 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
591 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
596 /** @var ChangesListFilter $filter */
597 foreach ( $group->getFilters() as $filter ) {
598 /** @var ChangesListFilter $conflictingFilter */
599 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
601 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
602 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
616 * Main execution point
618 * @param string $subpage
620 public function execute( $subpage ) {
621 $this->rcSubpage
= $subpage;
623 $this->considerActionsForDefaultSavedQuery( $subpage );
625 $opts = $this->getOptions();
627 $rows = $this->getRows();
628 if ( $rows === false ) {
629 $rows = new FakeResultWrapper( [] );
632 // Used by Structured UI app to get results without MW chrome
633 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
634 $this->getOutput()->setArticleBodyOnly( true );
637 // Used by "live update" and "view newest" to check
638 // if there's new changes with minimal data transfer
639 if ( $this->getRequest()->getBool( 'peek' ) ) {
640 $code = $rows->numRows() > 0 ?
200 : 204;
641 $this->getOutput()->setStatusCode( $code );
643 if ( $this->getUser()->isAnon() !==
644 $this->getRequest()->getFuzzyBool( 'isAnon' )
646 $this->getOutput()->setStatusCode( 205 );
652 $batch = new LinkBatch
;
653 foreach ( $rows as $row ) {
654 $batch->add( NS_USER
, $row->rc_user_text
);
655 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
656 $batch->add( $row->rc_namespace
, $row->rc_title
);
657 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
658 $formatter = LogFormatter
::newFromRow( $row );
659 foreach ( $formatter->getPreloadTitles() as $title ) {
660 $batch->addObj( $title );
667 $this->outputHeader();
669 $this->webOutput( $rows, $opts );
672 } catch ( DBQueryTimeoutError
$timeoutException ) {
673 MWExceptionHandler
::logException( $timeoutException );
676 $this->outputHeader();
679 $this->getOutput()->setStatusCode( 500 );
680 $this->webOutputHeader( 0, $opts );
681 $this->outputTimeout();
684 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
685 // Clean up any bad page entries for titles showing up in RC
686 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
688 LoggerFactory
::getInstance( 'objectcache' )
692 $this->includeRcFiltersApp();
696 * Check whether or not the page should load defaults, and if so, whether
697 * a default saved query is relevant to be redirected to. If it is relevant,
698 * redirect properly with all necessary query parameters.
700 * @param string $subpage
702 protected function considerActionsForDefaultSavedQuery( $subpage ) {
703 if ( !$this->isStructuredFilterUiEnabled() ||
$this->including() ) {
707 $knownParams = call_user_func_array(
708 [ $this->getRequest(), 'getValues' ],
709 array_keys( $this->getOptions()->getAllValues() )
712 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
713 // we need to exclude several parameters we know should not be counted towards preventing
714 // the loading of defaults.
715 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
716 $knownParams = array_diff_key( $knownParams, $excludedParams );
719 // If there are NO known parameters in the URL request
720 // (that are not excluded) then we need to check into loading
721 // the default saved query
722 count( $knownParams ) === 0
724 // Get the saved queries data and parse it
725 $savedQueries = FormatJson
::decode(
726 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
730 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
731 // Only load queries that are 'version' 2, since those
732 // have parameter representation
733 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
734 $savedQueryDefaultID = $savedQueries[ 'default' ];
735 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
737 // Build the entire parameter list
738 $query = array_merge(
739 $defaultQuery[ 'params' ],
740 $defaultQuery[ 'highlights' ],
745 // Add to the query any parameters that we may have ignored before
746 // but are still valid and requested in the URL
747 $query = array_merge( $this->getRequest()->getValues(), $query );
748 unset( $query[ 'title' ] );
749 $this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) );
751 // There's a default, but the version is not 2, and the server can't
752 // actually recognize the query itself. This happens if it is before
753 // the conversion, so we need to tell the UI to reload saved query as
754 // it does the conversion to version 2
755 $this->getOutput()->addJsConfigVars(
756 'wgStructuredChangeFiltersDefaultSavedQueryExists',
760 // Add the class that tells the frontend it is still loading
762 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
769 * Include the modules and configuration for the RCFilters app.
770 * Conditional on the user having the feature enabled.
772 * If it is disabled, add a <body> class marking that
774 protected function includeRcFiltersApp() {
775 $out = $this->getOutput();
776 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
777 $jsData = $this->getStructuredFilterJsData();
780 foreach ( $jsData['messageKeys'] as $key ) {
781 $messages[$key] = $this->msg( $key )->plain();
784 $out->addBodyClasses( 'mw-rcfilters-enabled' );
787 ResourceLoader
::makeInlineScript(
788 ResourceLoader
::makeMessageSetScript( $messages ),
793 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
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
823 $out->addJsConfigVars(
824 'StructuredChangeFiltersLiveUpdatePollingRate',
825 $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
828 $out->addBodyClasses( 'mw-rcfilters-disabled' );
833 * Fetch the change tags list for the front end
835 * @return Array Tag data
837 protected function getChangeTagList() {
838 $cache = ObjectCache
::getMainWANInstance();
839 $context = $this->getContext();
840 return $cache->getWithSetCallback(
841 $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ),
842 $cache::TTL_MINUTE
* 10,
843 function () use ( $context ) {
844 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
845 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
847 // Hit counts disabled for perf reasons, see T169997
849 $tagStats = ChangeTags::tagUsageStatistics();
850 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
853 arsort( $tagHitCounts );
855 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
857 // Build the list and data
859 foreach ( $tagHitCounts as $tagName => $hits ) {
861 // Only get active tags
862 isset( $explicitlyDefinedTags[ $tagName ] ) ||
863 isset( $softwareActivatedTags[ $tagName ] )
867 'label' => Sanitizer
::stripAllTags(
868 ChangeTags
::tagDescription( $tagName, $context )
871 ChangeTags
::truncateTagDescription(
872 $tagName, self
::TAG_DESC_CHARACTER_LIMIT
, $context
874 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
880 // Instead of sorting by hit count (disabled, see above), sort by display name
881 usort( $result, function ( $a, $b ) {
882 return strcasecmp( $a['label'], $b['label'] );
894 * Add the "no results" message to the output
896 protected function outputNoResults() {
897 $this->getOutput()->addHTML(
898 '<div class="mw-changeslist-empty">' .
899 $this->msg( 'recentchanges-noresult' )->parse() .
905 * Add the "timeout" message to the output
907 protected function outputTimeout() {
908 $this->getOutput()->addHTML(
909 '<div class="mw-changeslist-empty mw-changeslist-timeout">' .
910 $this->msg( 'recentchanges-timeout' )->parse() .
916 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
918 * @return bool|IResultWrapper Result or false
920 public function getRows() {
921 $opts = $this->getOptions();
928 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
930 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
934 * Get the current FormOptions for this request
936 * @return FormOptions
938 public function getOptions() {
939 if ( $this->rcOptions
=== null ) {
940 $this->rcOptions
= $this->setup( $this->rcSubpage
);
943 return $this->rcOptions
;
947 * Register all filters and their groups (including those from hooks), plus handle
948 * conflicts and defaults.
950 * You might want to customize these in the same method, in subclasses. You can
951 * call getFilterGroup to access a group, and (on the group) getFilter to access a
952 * filter, then make necessary modfications to the filter or group (e.g. with
955 protected function registerFilters() {
956 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
958 // Make sure this is not being transcluded (we don't want to show this
959 // information to all users just because the user that saves the edit can
960 // patrol or is logged in)
961 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
962 $this->registerFiltersFromDefinitions( $this->legacyReviewStatusFilterGroupDefinition
);
963 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
966 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
968 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
969 $transformedHideCategorizationDef = $this->transformFilterDefinition(
970 $this->hideCategorizationFilterDefinition
973 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
975 $hideCategorization = new ChangesListBooleanFilter(
976 $transformedHideCategorizationDef
980 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
982 $unstructuredGroupDefinition =
983 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
984 $this->getCustomFilters()
986 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
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 * Get filter group definition from legacy custom filters
1072 * @param array $customFilters Custom filters from legacy hooks
1073 * @return array Group definition
1075 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
1076 // Special internal unstructured group
1077 $unstructuredGroupDefinition = [
1078 'name' => 'unstructured',
1079 'class' => ChangesListBooleanFilterGroup
::class,
1080 'priority' => -1, // Won't display in structured
1084 foreach ( $customFilters as $name => $params ) {
1085 $unstructuredGroupDefinition['filters'][] = [
1087 'showHide' => $params['msg'],
1088 'default' => $params['default'],
1092 return $unstructuredGroupDefinition;
1096 * @return array The legacy show/hide toggle filters
1098 protected function getLegacyShowHideFilters() {
1100 foreach ( $this->filterGroups
as $group ) {
1101 if ( $group instanceof ChangesListBooleanFilterGroup
) {
1102 foreach ( $group->getFilters() as $key => $filter ) {
1103 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1104 $filters[ $key ] = $filter;
1113 * Register all the filters, including legacy hook-driven ones.
1114 * Then create a FormOptions object with options as specified by the user
1116 * @param array $parameters
1118 * @return FormOptions
1120 public function setup( $parameters ) {
1121 $this->registerFilters();
1123 $opts = $this->getDefaultOptions();
1125 $opts = $this->fetchOptionsFromRequest( $opts );
1127 // Give precedence to subpage syntax
1128 if ( $parameters !== null ) {
1129 $this->parseParameters( $parameters, $opts );
1132 $this->validateOptions( $opts );
1138 * Get a FormOptions object containing the default options. By default, returns
1139 * some basic options. The filters listed explicitly here are overriden in this
1140 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1141 * and more) are structured. Structured filters are overriden in registerFilters.
1144 * @return FormOptions
1146 public function getDefaultOptions() {
1147 $opts = new FormOptions();
1148 $structuredUI = $this->isStructuredFilterUiEnabled();
1149 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1150 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1152 /** @var ChangesListFilterGroup $filterGroup */
1153 foreach ( $this->filterGroups
as $filterGroup ) {
1154 $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
1157 $opts->add( 'namespace', '', FormOptions
::STRING );
1158 $opts->add( 'invert', false );
1159 $opts->add( 'associated', false );
1160 $opts->add( 'urlversion', 1 );
1161 $opts->add( 'tagfilter', '' );
1163 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
1164 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
1166 $opts->add( 'from', '' );
1172 * Register a structured changes list filter group
1174 * @param ChangesListFilterGroup $group
1176 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
1177 $groupName = $group->getName();
1179 $this->filterGroups
[$groupName] = $group;
1183 * Gets the currently registered filters groups
1185 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1187 protected function getFilterGroups() {
1188 return $this->filterGroups
;
1192 * Gets a specified ChangesListFilterGroup by name
1194 * @param string $groupName Name of group
1196 * @return ChangesListFilterGroup|null Group, or null if not registered
1198 public function getFilterGroup( $groupName ) {
1199 return isset( $this->filterGroups
[$groupName] ) ?
1200 $this->filterGroups
[$groupName] :
1204 // Currently, this intentionally only includes filters that display
1205 // in the structured UI. This can be changed easily, though, if we want
1206 // to include data on filters that use the unstructured UI. messageKeys is a
1207 // special top-level value, with the value being an array of the message keys to
1208 // send to the client.
1210 * Gets structured filter information needed by JS
1212 * @return array Associative array
1213 * * array $return['groups'] Group data
1214 * * array $return['messageKeys'] Array of message keys
1216 public function getStructuredFilterJsData() {
1219 'messageKeys' => [],
1222 usort( $this->filterGroups
, function ( $a, $b ) {
1223 return $b->getPriority() - $a->getPriority();
1226 foreach ( $this->filterGroups
as $groupName => $group ) {
1227 $groupOutput = $group->getJsData( $this );
1228 if ( $groupOutput !== null ) {
1229 $output['messageKeys'] = array_merge(
1230 $output['messageKeys'],
1231 $groupOutput['messageKeys']
1234 unset( $groupOutput['messageKeys'] );
1235 $output['groups'][] = $groupOutput;
1243 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
1246 * @return array Map of filter URL param names to properties (msg/default)
1248 protected function getCustomFilters() {
1249 if ( $this->customFilters
=== null ) {
1250 $this->customFilters
= [];
1251 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
1254 return $this->customFilters
;
1258 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1260 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1262 * @param FormOptions $opts
1263 * @return FormOptions
1265 protected function fetchOptionsFromRequest( $opts ) {
1266 $opts->fetchValuesFromRequest( $this->getRequest() );
1272 * Process $par and put options found in $opts. Used when including the page.
1274 * @param string $par
1275 * @param FormOptions $opts
1277 public function parseParameters( $par, FormOptions
$opts ) {
1278 $stringParameterNameSet = [];
1279 $hideParameterNameSet = [];
1281 // URL parameters can be per-group, like 'userExpLevel',
1282 // or per-filter, like 'hideminor'.
1284 foreach ( $this->filterGroups
as $filterGroup ) {
1285 if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup
) {
1286 $stringParameterNameSet[$filterGroup->getName()] = true;
1287 } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1288 foreach ( $filterGroup->getFilters() as $filter ) {
1289 $hideParameterNameSet[$filter->getName()] = true;
1294 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1295 foreach ( $bits as $bit ) {
1297 if ( isset( $hideParameterNameSet[$bit] ) ) {
1298 // hidefoo => hidefoo=true
1300 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1301 // foo => hidefoo=false
1302 $opts["hide$bit"] = false;
1303 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1304 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1305 $opts[$m[1]] = $m[2];
1312 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1314 * @param FormOptions $opts
1316 public function validateOptions( FormOptions
$opts ) {
1317 $isContradictory = $this->fixContradictoryOptions( $opts );
1318 $isReplaced = $this->replaceOldOptions( $opts );
1320 if ( $isContradictory ||
$isReplaced ) {
1321 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1322 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1325 $opts->validateIntBounds( 'limit', 0, 5000 );
1326 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1330 * Fix invalid options by resetting pairs that should never appear together.
1332 * @param FormOptions $opts
1333 * @return bool True if any option was reset
1335 private function fixContradictoryOptions( FormOptions
$opts ) {
1336 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1338 foreach ( $this->filterGroups
as $filterGroup ) {
1339 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1340 $filters = $filterGroup->getFilters();
1342 if ( count( $filters ) === 1 ) {
1343 // legacy boolean filters should not be considered
1347 $allInGroupEnabled = array_reduce(
1349 function ( $carry, $filter ) use ( $opts ) {
1350 return $carry && $opts[ $filter->getName() ];
1352 /* initialValue */ count( $filters ) > 0
1355 if ( $allInGroupEnabled ) {
1356 foreach ( $filters as $filter ) {
1357 $opts[ $filter->getName() ] = false;
1369 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1372 * This is deprecated and may be removed.
1374 * @param FormOptions $opts
1375 * @return bool True if this change was mode
1377 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1378 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1379 $opts->reset( 'hideanons' );
1380 if ( !$opts['hidebots'] ) {
1381 $opts->reset( 'hideliu' );
1382 $opts['hidehumans'] = 1;
1392 * Replace old options with their structured UI equivalents
1394 * @param FormOptions $opts
1395 * @return bool True if the change was made
1397 public function replaceOldOptions( FormOptions
$opts ) {
1398 if ( !$this->isStructuredFilterUiEnabled() ) {
1404 // At this point 'hideanons' and 'hideliu' cannot be both true,
1405 // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
1406 if ( $opts[ 'hideanons' ] ) {
1407 $opts->reset( 'hideanons' );
1408 $opts[ 'userExpLevel' ] = 'registered';
1412 if ( $opts[ 'hideliu' ] ) {
1413 $opts->reset( 'hideliu' );
1414 $opts[ 'userExpLevel' ] = 'unregistered';
1418 if ( $this->getFilterGroup( 'legacyReviewStatus' ) ) {
1419 if ( $opts[ 'hidepatrolled' ] ) {
1420 $opts->reset( 'hidepatrolled' );
1421 $opts[ 'reviewStatus' ] = 'unpatrolled';
1425 if ( $opts[ 'hideunpatrolled' ] ) {
1426 $opts->reset( 'hideunpatrolled' );
1427 $opts[ 'reviewStatus' ] = implode(
1428 ChangesListStringOptionsFilterGroup
::SEPARATOR
,
1429 [ 'manual', 'auto' ]
1439 * Convert parameters values from true/false to 1/0
1440 * so they are not omitted by wfArrayToCgi()
1443 * @param array $params
1446 protected function convertParamsForLink( $params ) {
1447 foreach ( $params as &$value ) {
1448 if ( $value === false ) {
1457 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1458 * the user requested.
1460 * @param array &$tables Array of tables; see IDatabase::select $table
1461 * @param array &$fields Array of fields; see IDatabase::select $vars
1462 * @param array &$conds Array of conditions; see IDatabase::select $conds
1463 * @param array &$query_options Array of query options; see IDatabase::select $options
1464 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1465 * @param FormOptions $opts
1467 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1468 &$join_conds, FormOptions
$opts
1470 $dbr = $this->getDB();
1471 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1473 /** @var ChangesListFilterGroup $filterGroup */
1474 foreach ( $this->filterGroups
as $filterGroup ) {
1475 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1476 $query_options, $join_conds, $opts, $isStructuredUI );
1479 // Namespace filtering
1480 if ( $opts[ 'namespace' ] !== '' ) {
1481 $namespaces = explode( ';', $opts[ 'namespace' ] );
1483 if ( $opts[ 'associated' ] ) {
1484 $associatedNamespaces = array_map(
1486 return MWNamespace
::getAssociated( $ns );
1490 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1493 if ( count( $namespaces ) === 1 ) {
1494 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1495 $value = $dbr->addQuotes( reset( $namespaces ) );
1497 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1498 sort( $namespaces );
1499 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1501 $conds[] = "rc_namespace $operator $value";
1505 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1506 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1508 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1509 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
1510 $cutoff = $dbr->timestamp( $opts['from'] );
1512 $opts->reset( 'from' );
1515 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1521 * @param array $tables Array of tables; see IDatabase::select $table
1522 * @param array $fields Array of fields; see IDatabase::select $vars
1523 * @param array $conds Array of conditions; see IDatabase::select $conds
1524 * @param array $query_options Array of query options; see IDatabase::select $options
1525 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1526 * @param FormOptions $opts
1527 * @return bool|IResultWrapper Result or false
1529 protected function doMainQuery( $tables, $fields, $conds,
1530 $query_options, $join_conds, FormOptions
$opts
1532 $rcQuery = RecentChange
::getQueryInfo();
1533 $tables = array_merge( $tables, $rcQuery['tables'] );
1534 $fields = array_merge( $rcQuery['fields'], $fields );
1535 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
1537 ChangeTags
::modifyDisplayQuery(
1546 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1552 $dbr = $this->getDB();
1554 return $dbr->select(
1564 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1565 &$query_options, &$join_conds, $opts
1568 'ChangesListSpecialPageQuery',
1569 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1574 * Return a IDatabase object for reading
1578 protected function getDB() {
1579 return wfGetDB( DB_REPLICA
);
1583 * Send header output to the OutputPage object, only called if not using feeds
1585 * @param int $rowCount Number of database rows
1586 * @param FormOptions $opts
1588 private function webOutputHeader( $rowCount, $opts ) {
1589 if ( !$this->including() ) {
1590 $this->outputFeedLinks();
1591 $this->doHeader( $opts, $rowCount );
1596 * Send output to the OutputPage object, only called if not used feeds
1598 * @param IResultWrapper $rows Database rows
1599 * @param FormOptions $opts
1601 public function webOutput( $rows, $opts ) {
1602 $this->webOutputHeader( $rows->numRows(), $opts );
1604 $this->outputChangesList( $rows, $opts );
1608 * Output feed links.
1610 public function outputFeedLinks() {
1611 // nothing by default
1615 * Build and output the actual changes list.
1617 * @param IResultWrapper $rows Database rows
1618 * @param FormOptions $opts
1620 abstract public function outputChangesList( $rows, $opts );
1623 * Set the text to be displayed above the changes
1625 * @param FormOptions $opts
1626 * @param int $numRows Number of rows in the result to show after this header
1628 public function doHeader( $opts, $numRows ) {
1629 $this->setTopText( $opts );
1631 // @todo Lots of stuff should be done here.
1633 $this->setBottomText( $opts );
1637 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1638 * or similar methods to print the text.
1640 * @param FormOptions $opts
1642 public function setTopText( FormOptions
$opts ) {
1643 // nothing by default
1647 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1648 * or similar methods to print the text.
1650 * @param FormOptions $opts
1652 public function setBottomText( FormOptions
$opts ) {
1653 // nothing by default
1657 * Get options to be displayed in a form
1658 * @todo This should handle options returned by getDefaultOptions().
1659 * @todo Not called by anything in this class (but is in subclasses), should be
1660 * called by something… doHeader() maybe?
1662 * @param FormOptions $opts
1665 public function getExtraOptions( $opts ) {
1670 * Return the legend displayed within the fieldset
1674 public function makeLegend() {
1675 $context = $this->getContext();
1676 $user = $context->getUser();
1677 # The legend showing what the letters and stuff mean
1678 $legend = Html
::openElement( 'dl' ) . "\n";
1679 # Iterates through them and gets the messages for both letter and tooltip
1680 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1681 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1682 unset( $legendItems['unpatrolled'] );
1684 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1685 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1686 $letter = $item['letter'];
1687 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1689 $legend .= Html
::element( 'dt',
1690 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1692 Html
::rawElement( 'dd',
1693 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1694 $context->msg( $label )->parse()
1698 $legend .= Html
::rawElement( 'dt',
1699 [ 'class' => 'mw-plusminus-pos' ],
1700 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1702 $legend .= Html
::element(
1704 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1705 $context->msg( 'recentchanges-label-plusminus' )->text()
1707 $legend .= Html
::closeElement( 'dl' ) . "\n";
1709 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1710 $context->msg( 'rcfilters-legend-heading' )->parse() :
1711 $context->msg( 'recentchanges-legend-heading' )->parse();
1714 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1715 $collapsedClass = $collapsedState === 'collapsed' ?
' mw-collapsed' : '';
1718 '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
1720 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1727 * Add page-specific modules.
1729 protected function addModules() {
1730 $out = $this->getOutput();
1731 // Styles and behavior for the legend box (see makeLegend())
1732 $out->addModuleStyles( [
1733 'mediawiki.special.changeslist.legend',
1734 'mediawiki.special.changeslist',
1736 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1738 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
1739 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1740 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1744 protected function getGroupName() {
1749 * Filter on users' experience levels; this will not be called if nothing is
1752 * @param string $specialPageClassName Class name of current special page
1753 * @param IContextSource $context Context, for e.g. user
1754 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1755 * @param array &$tables Array of tables; see IDatabase::select $table
1756 * @param array &$fields Array of fields; see IDatabase::select $vars
1757 * @param array &$conds Array of conditions; see IDatabase::select $conds
1758 * @param array &$query_options Array of query options; see IDatabase::select $options
1759 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1760 * @param array $selectedExpLevels The allowed active values, sorted
1761 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1764 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1765 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1767 global $wgLearnerEdits,
1768 $wgExperiencedUserEdits,
1769 $wgLearnerMemberSince,
1770 $wgExperiencedUserMemberSince;
1774 // If all levels are selected, don't filter
1775 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1779 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1781 in_array( 'registered', $selectedExpLevels ) &&
1782 in_array( 'unregistered', $selectedExpLevels )
1787 $actorMigration = ActorMigration
::newMigration();
1788 $actorQuery = $actorMigration->getJoin( 'rc_user' );
1789 $tables +
= $actorQuery['tables'];
1790 $join_conds +
= $actorQuery['joins'];
1792 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1794 in_array( 'registered', $selectedExpLevels ) &&
1795 !in_array( 'unregistered', $selectedExpLevels )
1797 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1801 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1802 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1807 $join_conds['user'] = [ 'LEFT JOIN', $actorQuery['fields']['rc_user'] . ' = user_id' ];
1812 $secondsPerDay = 86400;
1813 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1814 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1816 $aboveNewcomer = $dbr->makeList(
1818 'user_editcount >= ' . intval( $wgLearnerEdits ),
1819 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1824 $aboveLearner = $dbr->makeList(
1826 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1827 'user_registration <= ' .
1828 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1835 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1836 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1837 $conditions[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1840 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1841 $conditions[] = "NOT ( $aboveNewcomer )";
1842 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1843 $conditions[] = $dbr->makeList(
1844 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1847 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1848 $conditions[] = $aboveLearner;
1849 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1850 $conditions[] = "NOT ( $aboveLearner )";
1851 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1852 $conditions[] = $dbr->makeList(
1853 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1856 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1857 $conditions[] = $aboveNewcomer;
1858 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1859 $conditions[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1862 if ( count( $conditions ) > 1 ) {
1863 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1864 } elseif ( count( $conditions ) === 1 ) {
1865 $conds[] = reset( $conditions );
1870 * Check whether the structured filter UI is enabled
1874 public function isStructuredFilterUiEnabled() {
1875 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1879 return static::checkStructuredFilterUiEnabled(
1886 * Check whether the structured filter UI is enabled by default (regardless of
1887 * this particular user's setting)
1891 public function isStructuredFilterUiEnabledByDefault() {
1892 if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
1893 return !$this->getUser()->getDefaultOption( 'rcenhancedfilters-disable' );
1895 return $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
1900 * Static method to check whether StructuredFilter UI is enabled for the given user
1903 * @param Config $config
1907 public static function checkStructuredFilterUiEnabled( Config
$config, User
$user ) {
1908 if ( $config->get( 'StructuredChangeFiltersShowPreference' ) ) {
1909 return !$user->getOption( 'rcenhancedfilters-disable' );
1911 return $user->getOption( 'rcenhancedfilters' );
1916 * Get the default value of the number of changes to display when loading
1922 public function getDefaultLimit() {
1923 return $this->getUser()->getIntOption( static::$limitPreferenceName );
1927 * Get the default value of the number of days to display when loading
1929 * Supports fractional values, and should be cast to a float.
1934 public function getDefaultDays() {
1935 return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );