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
24 use MediaWiki\Logger\LoggerFactory
;
25 use MediaWiki\MediaWikiServices
;
26 use Wikimedia\Rdbms\DBQueryTimeoutError
;
27 use Wikimedia\Rdbms\IResultWrapper
;
28 use Wikimedia\Rdbms\FakeResultWrapper
;
29 use Wikimedia\Rdbms\IDatabase
;
32 * Special page which uses a ChangesList to show query results.
33 * @todo Way too many public functions, most of them should be protected
35 * @ingroup SpecialPage
37 abstract class ChangesListSpecialPage
extends SpecialPage
{
39 * Maximum length of a tag description in UTF-8 characters.
40 * Longer descriptions will be truncated.
42 const TAG_DESC_CHARACTER_LIMIT
= 120;
45 * Preference name for saved queries. Subclasses that use saved queries should override this.
48 protected static $savedQueriesPreferenceName;
51 * Preference name for 'days'. Subclasses should override this.
54 protected static $daysPreferenceName;
57 * Preference name for 'limit'. Subclasses should override this.
60 protected static $limitPreferenceName;
63 * Preference name for collapsing the active filter display. Subclasses should override this.
66 protected static $collapsedPreferenceName;
71 /** @var FormOptions */
74 // Order of both groups and filters is significant; first is top-most priority,
75 // descending from there.
76 // 'showHideSuffix' is a shortcut to and avoid spelling out
77 // details specific to subclasses here.
79 * Definition information for the filters and their groups
81 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
82 * However, priority is dynamically added for the core groups, to ease maintenance.
84 * Groups are displayed to the user in the structured UI. However, if necessary,
85 * all of the filters in a group can be configured to only display on the
86 * unstuctured UI, in which case you don't need a group title.
88 * @var array $filterGroupDefinitions
90 private $filterGroupDefinitions;
92 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
93 // that is registered conditionally.
94 private $legacyReviewStatusFilterGroupDefinition;
96 // Single filter group registered conditionally
97 private $reviewStatusFilterGroupDefinition;
99 // Single filter group registered conditionally
100 private $hideCategorizationFilterDefinition;
103 * Filter groups, and their contained filters
104 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
106 * @var array $filterGroups
108 protected $filterGroups = [];
110 public function __construct( $name, $restriction ) {
111 parent
::__construct( $name, $restriction );
113 $nonRevisionTypes = [ RC_LOG
];
114 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
116 $this->filterGroupDefinitions
= [
118 'name' => 'registration',
119 'title' => 'rcfilters-filtergroup-registration',
120 'class' => ChangesListBooleanFilterGroup
::class,
124 // rcshowhideliu-show, rcshowhideliu-hide,
126 'showHideSuffix' => 'showhideliu',
128 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
129 &$query_options, &$join_conds
131 $actorMigration = ActorMigration
::newMigration();
132 $actorQuery = $actorMigration->getJoin( 'rc_user' );
133 $tables +
= $actorQuery['tables'];
134 $join_conds +
= $actorQuery['joins'];
135 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
137 'isReplacedInStructuredUi' => true,
141 'name' => 'hideanons',
142 // rcshowhideanons-show, rcshowhideanons-hide,
144 'showHideSuffix' => 'showhideanons',
146 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
147 &$query_options, &$join_conds
149 $actorMigration = ActorMigration
::newMigration();
150 $actorQuery = $actorMigration->getJoin( 'rc_user' );
151 $tables +
= $actorQuery['tables'];
152 $join_conds +
= $actorQuery['joins'];
153 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
155 'isReplacedInStructuredUi' => true,
161 'name' => 'userExpLevel',
162 'title' => 'rcfilters-filtergroup-user-experience-level',
163 'class' => ChangesListStringOptionsFilterGroup
::class,
164 'isFullCoverage' => true,
167 'name' => 'unregistered',
168 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
169 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
170 'cssClassSuffix' => 'user-unregistered',
171 'isRowApplicableCallable' => function ( $ctx, $rc ) {
172 return !$rc->getAttribute( 'rc_user' );
176 'name' => 'registered',
177 'label' => 'rcfilters-filter-user-experience-level-registered-label',
178 'description' => 'rcfilters-filter-user-experience-level-registered-description',
179 'cssClassSuffix' => 'user-registered',
180 'isRowApplicableCallable' => function ( $ctx, $rc ) {
181 return $rc->getAttribute( 'rc_user' );
185 'name' => 'newcomer',
186 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
187 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
188 'cssClassSuffix' => 'user-newcomer',
189 'isRowApplicableCallable' => function ( $ctx, $rc ) {
190 $performer = $rc->getPerformer();
191 return $performer && $performer->isLoggedIn() &&
192 $performer->getExperienceLevel() === 'newcomer';
197 'label' => 'rcfilters-filter-user-experience-level-learner-label',
198 'description' => 'rcfilters-filter-user-experience-level-learner-description',
199 'cssClassSuffix' => 'user-learner',
200 'isRowApplicableCallable' => function ( $ctx, $rc ) {
201 $performer = $rc->getPerformer();
202 return $performer && $performer->isLoggedIn() &&
203 $performer->getExperienceLevel() === 'learner';
207 'name' => 'experienced',
208 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
209 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
210 'cssClassSuffix' => 'user-experienced',
211 'isRowApplicableCallable' => function ( $ctx, $rc ) {
212 $performer = $rc->getPerformer();
213 return $performer && $performer->isLoggedIn() &&
214 $performer->getExperienceLevel() === 'experienced';
218 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
219 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
223 'name' => 'authorship',
224 'title' => 'rcfilters-filtergroup-authorship',
225 'class' => ChangesListBooleanFilterGroup
::class,
228 'name' => 'hidemyself',
229 'label' => 'rcfilters-filter-editsbyself-label',
230 'description' => 'rcfilters-filter-editsbyself-description',
231 // rcshowhidemine-show, rcshowhidemine-hide,
233 'showHideSuffix' => 'showhidemine',
235 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
236 &$query_options, &$join_conds
238 $actorQuery = ActorMigration
::newMigration()->getWhere( $dbr, 'rc_user', $ctx->getUser() );
239 $tables +
= $actorQuery['tables'];
240 $join_conds +
= $actorQuery['joins'];
241 $conds[] = 'NOT(' . $actorQuery['conds'] . ')';
243 'cssClassSuffix' => 'self',
244 'isRowApplicableCallable' => function ( $ctx, $rc ) {
245 return $ctx->getUser()->equals( $rc->getPerformer() );
249 'name' => 'hidebyothers',
250 'label' => 'rcfilters-filter-editsbyother-label',
251 'description' => 'rcfilters-filter-editsbyother-description',
253 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
254 &$query_options, &$join_conds
256 $actorQuery = ActorMigration
::newMigration()
257 ->getWhere( $dbr, 'rc_user', $ctx->getUser(), false );
258 $tables +
= $actorQuery['tables'];
259 $join_conds +
= $actorQuery['joins'];
260 $conds[] = $actorQuery['conds'];
262 'cssClassSuffix' => 'others',
263 'isRowApplicableCallable' => function ( $ctx, $rc ) {
264 return !$ctx->getUser()->equals( $rc->getPerformer() );
271 'name' => 'automated',
272 'title' => 'rcfilters-filtergroup-automated',
273 'class' => ChangesListBooleanFilterGroup
::class,
276 'name' => 'hidebots',
277 'label' => 'rcfilters-filter-bots-label',
278 'description' => 'rcfilters-filter-bots-description',
279 // rcshowhidebots-show, rcshowhidebots-hide,
281 'showHideSuffix' => 'showhidebots',
283 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
284 &$query_options, &$join_conds
286 $conds['rc_bot'] = 0;
288 'cssClassSuffix' => 'bot',
289 'isRowApplicableCallable' => function ( $ctx, $rc ) {
290 return $rc->getAttribute( 'rc_bot' );
294 'name' => 'hidehumans',
295 'label' => 'rcfilters-filter-humans-label',
296 'description' => 'rcfilters-filter-humans-description',
298 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
299 &$query_options, &$join_conds
301 $conds['rc_bot'] = 1;
303 'cssClassSuffix' => 'human',
304 'isRowApplicableCallable' => function ( $ctx, $rc ) {
305 return !$rc->getAttribute( 'rc_bot' );
311 // significance (conditional)
314 'name' => 'significance',
315 'title' => 'rcfilters-filtergroup-significance',
316 'class' => ChangesListBooleanFilterGroup
::class,
320 'name' => 'hideminor',
321 'label' => 'rcfilters-filter-minor-label',
322 'description' => 'rcfilters-filter-minor-description',
323 // rcshowhideminor-show, rcshowhideminor-hide,
325 'showHideSuffix' => 'showhideminor',
327 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
328 &$query_options, &$join_conds
330 $conds[] = 'rc_minor = 0';
332 'cssClassSuffix' => 'minor',
333 'isRowApplicableCallable' => function ( $ctx, $rc ) {
334 return $rc->getAttribute( 'rc_minor' );
338 'name' => 'hidemajor',
339 'label' => 'rcfilters-filter-major-label',
340 'description' => 'rcfilters-filter-major-description',
342 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
343 &$query_options, &$join_conds
345 $conds[] = 'rc_minor = 1';
347 'cssClassSuffix' => 'major',
348 'isRowApplicableCallable' => function ( $ctx, $rc ) {
349 return !$rc->getAttribute( 'rc_minor' );
356 'name' => 'lastRevision',
357 'title' => 'rcfilters-filtergroup-lastrevision',
358 'class' => ChangesListBooleanFilterGroup
::class,
362 'name' => 'hidelastrevision',
363 'label' => 'rcfilters-filter-lastrevision-label',
364 'description' => 'rcfilters-filter-lastrevision-description',
366 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
367 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
368 $conds[] = $dbr->makeList(
370 'rc_this_oldid <> page_latest',
371 'rc_type' => $nonRevisionTypes,
376 'cssClassSuffix' => 'last',
377 'isRowApplicableCallable' => function ( $ctx, $rc ) {
378 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
382 'name' => 'hidepreviousrevisions',
383 'label' => 'rcfilters-filter-previousrevision-label',
384 'description' => 'rcfilters-filter-previousrevision-description',
386 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
387 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
388 $conds[] = $dbr->makeList(
390 'rc_this_oldid = page_latest',
391 'rc_type' => $nonRevisionTypes,
396 'cssClassSuffix' => 'previous',
397 'isRowApplicableCallable' => function ( $ctx, $rc ) {
398 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
404 // With extensions, there can be change types that will not be hidden by any of these.
406 'name' => 'changeType',
407 'title' => 'rcfilters-filtergroup-changetype',
408 'class' => ChangesListBooleanFilterGroup
::class,
412 'name' => 'hidepageedits',
413 'label' => 'rcfilters-filter-pageedits-label',
414 'description' => 'rcfilters-filter-pageedits-description',
417 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
418 &$query_options, &$join_conds
420 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
422 'cssClassSuffix' => 'src-mw-edit',
423 'isRowApplicableCallable' => function ( $ctx, $rc ) {
424 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
428 'name' => 'hidenewpages',
429 'label' => 'rcfilters-filter-newpages-label',
430 'description' => 'rcfilters-filter-newpages-description',
433 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
434 &$query_options, &$join_conds
436 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
438 'cssClassSuffix' => 'src-mw-new',
439 'isRowApplicableCallable' => function ( $ctx, $rc ) {
440 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
444 // hidecategorization
448 'label' => 'rcfilters-filter-logactions-label',
449 'description' => 'rcfilters-filter-logactions-description',
452 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
453 &$query_options, &$join_conds
455 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
457 'cssClassSuffix' => 'src-mw-log',
458 'isRowApplicableCallable' => function ( $ctx, $rc ) {
459 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
467 $this->legacyReviewStatusFilterGroupDefinition
= [
469 'name' => 'legacyReviewStatus',
470 'title' => 'rcfilters-filtergroup-reviewstatus',
471 'class' => ChangesListBooleanFilterGroup
::class,
474 'name' => 'hidepatrolled',
475 // rcshowhidepatr-show, rcshowhidepatr-hide
477 'showHideSuffix' => 'showhidepatr',
479 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
480 &$query_options, &$join_conds
482 $conds['rc_patrolled'] = RecentChange
::PRC_UNPATROLLED
;
484 'isReplacedInStructuredUi' => true,
487 'name' => 'hideunpatrolled',
489 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
490 &$query_options, &$join_conds
492 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
;
494 'isReplacedInStructuredUi' => true,
500 $this->reviewStatusFilterGroupDefinition
= [
502 'name' => 'reviewStatus',
503 'title' => 'rcfilters-filtergroup-reviewstatus',
504 'class' => ChangesListStringOptionsFilterGroup
::class,
505 'isFullCoverage' => true,
509 'name' => 'unpatrolled',
510 'label' => 'rcfilters-filter-reviewstatus-unpatrolled-label',
511 'description' => 'rcfilters-filter-reviewstatus-unpatrolled-description',
512 'cssClassSuffix' => 'reviewstatus-unpatrolled',
513 'isRowApplicableCallable' => function ( $ctx, $rc ) {
514 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_UNPATROLLED
;
519 'label' => 'rcfilters-filter-reviewstatus-manual-label',
520 'description' => 'rcfilters-filter-reviewstatus-manual-description',
521 'cssClassSuffix' => 'reviewstatus-manual',
522 'isRowApplicableCallable' => function ( $ctx, $rc ) {
523 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_PATROLLED
;
528 'label' => 'rcfilters-filter-reviewstatus-auto-label',
529 'description' => 'rcfilters-filter-reviewstatus-auto-description',
530 'cssClassSuffix' => 'reviewstatus-auto',
531 'isRowApplicableCallable' => function ( $ctx, $rc ) {
532 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_AUTOPATROLLED
;
536 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
537 'queryCallable' => function ( $specialPageClassName, $ctx, $dbr,
538 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selected
540 if ( $selected === [] ) {
543 $rcPatrolledValues = [
544 'unpatrolled' => RecentChange
::PRC_UNPATROLLED
,
545 'manual' => RecentChange
::PRC_PATROLLED
,
546 'auto' => RecentChange
::PRC_AUTOPATROLLED
,
548 // e.g. rc_patrolled IN (0, 2)
549 $conds['rc_patrolled'] = array_map( function ( $s ) use ( $rcPatrolledValues ) {
550 return $rcPatrolledValues[ $s ];
556 $this->hideCategorizationFilterDefinition
= [
557 'name' => 'hidecategorization',
558 'label' => 'rcfilters-filter-categorization-label',
559 'description' => 'rcfilters-filter-categorization-description',
560 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
561 // wlshowhidecategorization
562 'showHideSuffix' => 'showhidecategorization',
565 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
566 &$query_options, &$join_conds
568 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
570 'cssClassSuffix' => 'src-mw-categorize',
571 'isRowApplicableCallable' => function ( $ctx, $rc ) {
572 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
578 * Check if filters are in conflict and guaranteed to return no results.
582 protected function areFiltersInConflict() {
583 $opts = $this->getOptions();
584 /** @var ChangesListFilterGroup $group */
585 foreach ( $this->getFilterGroups() as $group ) {
586 if ( $group->getConflictingGroups() ) {
589 " specifies conflicts with other groups but these are not supported yet."
593 /** @var ChangesListFilter $conflictingFilter */
594 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
595 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
600 /** @var ChangesListFilter $filter */
601 foreach ( $group->getFilters() as $filter ) {
602 /** @var ChangesListFilter $conflictingFilter */
603 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
605 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
606 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
620 * @param string|null $subpage
622 public function execute( $subpage ) {
623 $this->rcSubpage
= $subpage;
625 $this->considerActionsForDefaultSavedQuery( $subpage );
627 $opts = $this->getOptions();
629 $rows = $this->getRows();
630 if ( $rows === false ) {
631 $rows = new FakeResultWrapper( [] );
634 // Used by Structured UI app to get results without MW chrome
635 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
636 $this->getOutput()->setArticleBodyOnly( true );
639 // Used by "live update" and "view newest" to check
640 // if there's new changes with minimal data transfer
641 if ( $this->getRequest()->getBool( 'peek' ) ) {
642 $code = $rows->numRows() > 0 ?
200 : 204;
643 $this->getOutput()->setStatusCode( $code );
645 if ( $this->getUser()->isAnon() !==
646 $this->getRequest()->getFuzzyBool( 'isAnon' )
648 $this->getOutput()->setStatusCode( 205 );
654 $batch = new LinkBatch
;
655 foreach ( $rows as $row ) {
656 $batch->add( NS_USER
, $row->rc_user_text
);
657 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
658 $batch->add( $row->rc_namespace
, $row->rc_title
);
659 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
660 $formatter = LogFormatter
::newFromRow( $row );
661 foreach ( $formatter->getPreloadTitles() as $title ) {
662 $batch->addObj( $title );
669 $this->outputHeader();
671 $this->webOutput( $rows, $opts );
674 } catch ( DBQueryTimeoutError
$timeoutException ) {
675 MWExceptionHandler
::logException( $timeoutException );
678 $this->outputHeader();
681 $this->getOutput()->setStatusCode( 500 );
682 $this->webOutputHeader( 0, $opts );
683 $this->outputTimeout();
686 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
687 // Clean up any bad page entries for titles showing up in RC
688 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
690 LoggerFactory
::getInstance( 'objectcache' )
694 $this->includeRcFiltersApp();
698 * Check whether or not the page should load defaults, and if so, whether
699 * a default saved query is relevant to be redirected to. If it is relevant,
700 * redirect properly with all necessary query parameters.
702 * @param string $subpage
704 protected function considerActionsForDefaultSavedQuery( $subpage ) {
705 if ( !$this->isStructuredFilterUiEnabled() ||
$this->including() ) {
709 $knownParams = $this->getRequest()->getValues(
710 ...array_keys( $this->getOptions()->getAllValues() )
713 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
714 // we need to exclude several parameters we know should not be counted towards preventing
715 // the loading of defaults.
716 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
717 $knownParams = array_diff_key( $knownParams, $excludedParams );
720 // If there are NO known parameters in the URL request
721 // (that are not excluded) then we need to check into loading
722 // the default saved query
723 count( $knownParams ) === 0
725 // Get the saved queries data and parse it
726 $savedQueries = FormatJson
::decode(
727 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
731 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
732 // Only load queries that are 'version' 2, since those
733 // have parameter representation
734 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
735 $savedQueryDefaultID = $savedQueries[ 'default' ];
736 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
738 // Build the entire parameter list
739 $query = array_merge(
740 $defaultQuery[ 'params' ],
741 $defaultQuery[ 'highlights' ],
746 // Add to the query any parameters that we may have ignored before
747 // but are still valid and requested in the URL
748 $query = array_merge( $this->getRequest()->getValues(), $query );
749 unset( $query[ 'title' ] );
750 $this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) );
752 // There's a default, but the version is not 2, and the server can't
753 // actually recognize the query itself. This happens if it is before
754 // the conversion, so we need to tell the UI to reload saved query as
755 // it does the conversion to version 2
756 $this->getOutput()->addJsConfigVars(
757 'wgStructuredChangeFiltersDefaultSavedQueryExists',
761 // Add the class that tells the frontend it is still loading
763 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
770 * Include the modules and configuration for the RCFilters app.
771 * Conditional on the user having the feature enabled.
773 * If it is disabled, add a <body> class marking that
775 protected function includeRcFiltersApp() {
776 $out = $this->getOutput();
777 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
778 $jsData = $this->getStructuredFilterJsData();
780 foreach ( $jsData['messageKeys'] as $key ) {
781 $messages[$key] = $this->msg( $key )->plain();
784 $out->addBodyClasses( 'mw-rcfilters-enabled' );
785 $collapsed = $this->getUser()->getBoolOption( static::$collapsedPreferenceName );
787 $out->addBodyClasses( 'mw-rcfilters-collapsed' );
790 // These config and message exports should be moved into a ResourceLoader data module (T201574)
791 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
792 $out->addJsConfigVars( 'wgStructuredChangeFiltersMessages', $messages );
793 $out->addJsConfigVars( 'wgStructuredChangeFiltersCollapsedState', $collapsed );
795 $out->addJsConfigVars(
796 'StructuredChangeFiltersDisplayConfig',
798 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
799 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
800 'limitDefault' => $this->getDefaultLimit(),
801 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
802 'daysDefault' => $this->getDefaultDays(),
806 $out->addJsConfigVars(
807 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
808 static::$savedQueriesPreferenceName
810 $out->addJsConfigVars(
811 'wgStructuredChangeFiltersLimitPreferenceName',
812 static::$limitPreferenceName
814 $out->addJsConfigVars(
815 'wgStructuredChangeFiltersDaysPreferenceName',
816 static::$daysPreferenceName
818 $out->addJsConfigVars(
819 'wgStructuredChangeFiltersCollapsedPreferenceName',
820 static::$collapsedPreferenceName
823 $out->addBodyClasses( 'mw-rcfilters-disabled' );
828 * Get config vars to export with the mediawiki.rcfilters.filters.ui module.
830 * @param ResourceLoaderContext $context
833 public static function getRcFiltersConfigVars( ResourceLoaderContext
$context ) {
835 'RCFiltersChangeTags' => self
::getChangeTagList( $context ),
836 'StructuredChangeFiltersEditWatchlistUrl' =>
837 SpecialPage
::getTitleFor( 'EditWatchlist' )->getLocalURL()
842 * Fetch the change tags list for the front end
844 * @param ResourceLoaderContext $context
845 * @return array Tag data
847 protected static function getChangeTagList( ResourceLoaderContext
$context ) {
848 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
849 return $cache->getWithSetCallback(
850 $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage() ),
851 $cache::TTL_MINUTE
* 10,
852 function () use ( $context ) {
853 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
854 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
856 $tagStats = ChangeTags
::tagUsageStatistics();
857 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
859 // Sort by hits (disabled for now)
860 //arsort( $tagHitCounts );
862 // HACK work around ChangeTags::truncateTagDescription() requiring a RequestContext
863 $fakeContext = RequestContext
::newExtraneousContext( Title
::newFromText( 'Dwimmerlaik' ) );
864 $fakeContext->setLanguage( Language
::factory( $context->getLanguage() ) );
866 // Build the list and data
868 foreach ( $tagHitCounts as $tagName => $hits ) {
871 // Only get active tags
872 isset( $explicitlyDefinedTags[ $tagName ] ) ||
873 isset( $softwareActivatedTags[ $tagName ] )
875 // Only get tags with more than 0 hits
880 'label' => Sanitizer
::stripAllTags(
881 ChangeTags
::tagDescription( $tagName, $context )
884 ChangeTags
::truncateTagDescription(
886 self
::TAG_DESC_CHARACTER_LIMIT
,
889 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
895 // Instead of sorting by hit count (disabled, see above), sort by display name
896 usort( $result, function ( $a, $b ) {
897 return strcasecmp( $a['label'], $b['label'] );
909 * Add the "no results" message to the output
911 protected function outputNoResults() {
912 $this->getOutput()->addHTML(
913 '<div class="mw-changeslist-empty">' .
914 $this->msg( 'recentchanges-noresult' )->parse() .
920 * Add the "timeout" message to the output
922 protected function outputTimeout() {
923 $this->getOutput()->addHTML(
924 '<div class="mw-changeslist-empty mw-changeslist-timeout">' .
925 $this->msg( 'recentchanges-timeout' )->parse() .
931 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
933 * @return bool|IResultWrapper Result or false
935 public function getRows() {
936 $opts = $this->getOptions();
943 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
945 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
949 * Get the current FormOptions for this request
951 * @return FormOptions
953 public function getOptions() {
954 if ( $this->rcOptions
=== null ) {
955 $this->rcOptions
= $this->setup( $this->rcSubpage
);
958 return $this->rcOptions
;
962 * Register all filters and their groups (including those from hooks), plus handle
963 * conflicts and defaults.
965 * You might want to customize these in the same method, in subclasses. You can
966 * call getFilterGroup to access a group, and (on the group) getFilter to access a
967 * filter, then make necessary modfications to the filter or group (e.g. with
970 protected function registerFilters() {
971 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
973 // Make sure this is not being transcluded (we don't want to show this
974 // information to all users just because the user that saves the edit can
975 // patrol or is logged in)
976 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
977 $this->registerFiltersFromDefinitions( $this->legacyReviewStatusFilterGroupDefinition
);
978 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
981 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
983 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
984 $transformedHideCategorizationDef = $this->transformFilterDefinition(
985 $this->hideCategorizationFilterDefinition
988 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
990 $hideCategorization = new ChangesListBooleanFilter(
991 $transformedHideCategorizationDef
995 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
997 $this->registerFiltersFromDefinitions( [] );
999 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
1000 $registered = $userExperienceLevel->getFilter( 'registered' );
1001 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
1002 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
1003 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
1005 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
1006 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
1007 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
1009 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
1010 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
1012 // categoryFilter is conditional; see registerFilters
1013 if ( $categoryFilter !== null ) {
1014 $hideMinorFilter->conflictsWith(
1016 'rcfilters-hideminor-conflicts-typeofchange-global',
1017 'rcfilters-hideminor-conflicts-typeofchange',
1018 'rcfilters-typeofchange-conflicts-hideminor'
1021 $hideMinorFilter->conflictsWith(
1023 'rcfilters-hideminor-conflicts-typeofchange-global',
1024 'rcfilters-hideminor-conflicts-typeofchange',
1025 'rcfilters-typeofchange-conflicts-hideminor'
1027 $hideMinorFilter->conflictsWith(
1028 $pagecreationFilter,
1029 'rcfilters-hideminor-conflicts-typeofchange-global',
1030 'rcfilters-hideminor-conflicts-typeofchange',
1031 'rcfilters-typeofchange-conflicts-hideminor'
1036 * Transforms filter definition to prepare it for constructor.
1038 * See overrides of this method as well.
1040 * @param array $filterDefinition Original filter definition
1042 * @return array Transformed definition
1044 protected function transformFilterDefinition( array $filterDefinition ) {
1045 return $filterDefinition;
1049 * Register filters from a definition object
1051 * Array specifying groups and their filters; see Filter and
1052 * ChangesListFilterGroup constructors.
1054 * There is light processing to simplify core maintenance.
1055 * @param array $definition
1056 * @phan-param array<int,array{class:string}> $definition
1058 protected function registerFiltersFromDefinitions( array $definition ) {
1059 $autoFillPriority = -1;
1060 foreach ( $definition as $groupDefinition ) {
1061 if ( !isset( $groupDefinition['priority'] ) ) {
1062 $groupDefinition['priority'] = $autoFillPriority;
1064 // If it's explicitly specified, start over the auto-fill
1065 $autoFillPriority = $groupDefinition['priority'];
1068 $autoFillPriority--;
1070 $className = $groupDefinition['class'];
1071 unset( $groupDefinition['class'] );
1073 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
1074 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
1077 $this->registerFilterGroup( new $className( $groupDefinition ) );
1082 * @return array The legacy show/hide toggle filters
1084 protected function getLegacyShowHideFilters() {
1086 foreach ( $this->filterGroups
as $group ) {
1087 if ( $group instanceof ChangesListBooleanFilterGroup
) {
1088 foreach ( $group->getFilters() as $key => $filter ) {
1089 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1090 $filters[ $key ] = $filter;
1099 * Register all the filters, including legacy hook-driven ones.
1100 * Then create a FormOptions object with options as specified by the user
1102 * @param array $parameters
1104 * @return FormOptions
1106 public function setup( $parameters ) {
1107 $this->registerFilters();
1109 $opts = $this->getDefaultOptions();
1111 $opts = $this->fetchOptionsFromRequest( $opts );
1113 // Give precedence to subpage syntax
1114 if ( $parameters !== null ) {
1115 $this->parseParameters( $parameters, $opts );
1118 $this->validateOptions( $opts );
1124 * Get a FormOptions object containing the default options. By default, returns
1125 * some basic options. The filters listed explicitly here are overriden in this
1126 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1127 * and more) are structured. Structured filters are overriden in registerFilters.
1130 * @return FormOptions
1132 public function getDefaultOptions() {
1133 $opts = new FormOptions();
1134 $structuredUI = $this->isStructuredFilterUiEnabled();
1135 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1136 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1138 /** @var ChangesListFilterGroup $filterGroup */
1139 foreach ( $this->filterGroups
as $filterGroup ) {
1140 $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
1143 $opts->add( 'namespace', '', FormOptions
::STRING );
1144 $opts->add( 'invert', false );
1145 $opts->add( 'associated', false );
1146 $opts->add( 'urlversion', 1 );
1147 $opts->add( 'tagfilter', '' );
1149 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
1150 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
1152 $opts->add( 'from', '' );
1158 * Register a structured changes list filter group
1160 * @param ChangesListFilterGroup $group
1162 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
1163 $groupName = $group->getName();
1165 $this->filterGroups
[$groupName] = $group;
1169 * Gets the currently registered filters groups
1171 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1173 protected function getFilterGroups() {
1174 return $this->filterGroups
;
1178 * Gets a specified ChangesListFilterGroup by name
1180 * @param string $groupName Name of group
1182 * @return ChangesListFilterGroup|null Group, or null if not registered
1184 public function getFilterGroup( $groupName ) {
1185 return $this->filterGroups
[$groupName] ??
null;
1188 // Currently, this intentionally only includes filters that display
1189 // in the structured UI. This can be changed easily, though, if we want
1190 // to include data on filters that use the unstructured UI. messageKeys is a
1191 // special top-level value, with the value being an array of the message keys to
1192 // send to the client.
1195 * Gets structured filter information needed by JS
1197 * @return array Associative array
1198 * * array $return['groups'] Group data
1199 * * array $return['messageKeys'] Array of message keys
1201 public function getStructuredFilterJsData() {
1204 'messageKeys' => [],
1207 usort( $this->filterGroups
, function ( $a, $b ) {
1208 return $b->getPriority() <=> $a->getPriority();
1211 foreach ( $this->filterGroups
as $groupName => $group ) {
1212 $groupOutput = $group->getJsData( $this );
1213 if ( $groupOutput !== null ) {
1214 $output['messageKeys'] = array_merge(
1215 $output['messageKeys'],
1216 $groupOutput['messageKeys']
1219 unset( $groupOutput['messageKeys'] );
1220 $output['groups'][] = $groupOutput;
1228 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1230 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1232 * @param FormOptions $opts
1233 * @return FormOptions
1235 protected function fetchOptionsFromRequest( $opts ) {
1236 $opts->fetchValuesFromRequest( $this->getRequest() );
1242 * Process $par and put options found in $opts. Used when including the page.
1244 * @param string $par
1245 * @param FormOptions $opts
1247 public function parseParameters( $par, FormOptions
$opts ) {
1248 $stringParameterNameSet = [];
1249 $hideParameterNameSet = [];
1251 // URL parameters can be per-group, like 'userExpLevel',
1252 // or per-filter, like 'hideminor'.
1254 foreach ( $this->filterGroups
as $filterGroup ) {
1255 if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup
) {
1256 $stringParameterNameSet[$filterGroup->getName()] = true;
1257 } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1258 foreach ( $filterGroup->getFilters() as $filter ) {
1259 $hideParameterNameSet[$filter->getName()] = true;
1264 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1265 foreach ( $bits as $bit ) {
1267 if ( isset( $hideParameterNameSet[$bit] ) ) {
1268 // hidefoo => hidefoo=true
1270 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1271 // foo => hidefoo=false
1272 $opts["hide$bit"] = false;
1273 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1274 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1275 $opts[$m[1]] = $m[2];
1282 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1284 * @param FormOptions $opts
1286 public function validateOptions( FormOptions
$opts ) {
1287 $isContradictory = $this->fixContradictoryOptions( $opts );
1288 $isReplaced = $this->replaceOldOptions( $opts );
1290 if ( $isContradictory ||
$isReplaced ) {
1291 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1292 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1295 $opts->validateIntBounds( 'limit', 0, 5000 );
1296 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1300 * Fix invalid options by resetting pairs that should never appear together.
1302 * @param FormOptions $opts
1303 * @return bool True if any option was reset
1305 private function fixContradictoryOptions( FormOptions
$opts ) {
1306 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1308 foreach ( $this->filterGroups
as $filterGroup ) {
1309 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1310 $filters = $filterGroup->getFilters();
1312 if ( count( $filters ) === 1 ) {
1313 // legacy boolean filters should not be considered
1317 $allInGroupEnabled = array_reduce(
1319 function ( $carry, $filter ) use ( $opts ) {
1320 return $carry && $opts[ $filter->getName() ];
1322 /* initialValue */ count( $filters ) > 0
1325 if ( $allInGroupEnabled ) {
1326 foreach ( $filters as $filter ) {
1327 $opts[ $filter->getName() ] = false;
1339 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1342 * This is deprecated and may be removed.
1344 * @param FormOptions $opts
1345 * @return bool True if this change was mode
1347 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1348 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1349 $opts->reset( 'hideanons' );
1350 if ( !$opts['hidebots'] ) {
1351 $opts->reset( 'hideliu' );
1352 $opts['hidehumans'] = 1;
1362 * Replace old options with their structured UI equivalents
1364 * @param FormOptions $opts
1365 * @return bool True if the change was made
1367 public function replaceOldOptions( FormOptions
$opts ) {
1368 if ( !$this->isStructuredFilterUiEnabled() ) {
1374 // At this point 'hideanons' and 'hideliu' cannot be both true,
1375 // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
1376 if ( $opts[ 'hideanons' ] ) {
1377 $opts->reset( 'hideanons' );
1378 $opts[ 'userExpLevel' ] = 'registered';
1382 if ( $opts[ 'hideliu' ] ) {
1383 $opts->reset( 'hideliu' );
1384 $opts[ 'userExpLevel' ] = 'unregistered';
1388 if ( $this->getFilterGroup( 'legacyReviewStatus' ) ) {
1389 if ( $opts[ 'hidepatrolled' ] ) {
1390 $opts->reset( 'hidepatrolled' );
1391 $opts[ 'reviewStatus' ] = 'unpatrolled';
1395 if ( $opts[ 'hideunpatrolled' ] ) {
1396 $opts->reset( 'hideunpatrolled' );
1397 $opts[ 'reviewStatus' ] = implode(
1398 ChangesListStringOptionsFilterGroup
::SEPARATOR
,
1399 [ 'manual', 'auto' ]
1409 * Convert parameters values from true/false to 1/0
1410 * so they are not omitted by wfArrayToCgi()
1413 * @param array $params
1416 protected function convertParamsForLink( $params ) {
1417 foreach ( $params as &$value ) {
1418 if ( $value === false ) {
1427 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1428 * the user requested.
1430 * @param array &$tables Array of tables; see IDatabase::select $table
1431 * @param array &$fields Array of fields; see IDatabase::select $vars
1432 * @param array &$conds Array of conditions; see IDatabase::select $conds
1433 * @param array &$query_options Array of query options; see IDatabase::select $options
1434 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1435 * @param FormOptions $opts
1437 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1438 &$join_conds, FormOptions
$opts
1440 $dbr = $this->getDB();
1441 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1443 /** @var ChangesListFilterGroup $filterGroup */
1444 foreach ( $this->filterGroups
as $filterGroup ) {
1445 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1446 $query_options, $join_conds, $opts, $isStructuredUI );
1449 // Namespace filtering
1450 if ( $opts[ 'namespace' ] !== '' ) {
1451 $namespaces = explode( ';', $opts[ 'namespace' ] );
1453 if ( $opts[ 'associated' ] ) {
1454 $associatedNamespaces = array_map(
1456 return MediaWikiServices
::getInstance()->getNamespaceInfo()->
1457 getAssociated( $ns );
1461 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1464 if ( count( $namespaces ) === 1 ) {
1465 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1466 $value = $dbr->addQuotes( reset( $namespaces ) );
1468 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1469 sort( $namespaces );
1470 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1472 $conds[] = "rc_namespace $operator $value";
1476 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1477 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1479 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1480 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
1481 $cutoff = $dbr->timestamp( $opts['from'] );
1483 $opts->reset( 'from' );
1486 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1492 * @param array $tables Array of tables; see IDatabase::select $table
1493 * @param array $fields Array of fields; see IDatabase::select $vars
1494 * @param array $conds Array of conditions; see IDatabase::select $conds
1495 * @param array $query_options Array of query options; see IDatabase::select $options
1496 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1497 * @param FormOptions $opts
1498 * @return bool|IResultWrapper Result or false
1500 protected function doMainQuery( $tables, $fields, $conds,
1501 $query_options, $join_conds, FormOptions
$opts
1503 $rcQuery = RecentChange
::getQueryInfo();
1504 $tables = array_merge( $tables, $rcQuery['tables'] );
1505 $fields = array_merge( $rcQuery['fields'], $fields );
1506 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
1508 ChangeTags
::modifyDisplayQuery(
1517 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1523 $dbr = $this->getDB();
1525 return $dbr->select(
1535 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1536 &$query_options, &$join_conds, $opts
1539 'ChangesListSpecialPageQuery',
1540 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1545 * Return a IDatabase object for reading
1549 protected function getDB() {
1550 return wfGetDB( DB_REPLICA
);
1554 * Send header output to the OutputPage object, only called if not using feeds
1556 * @param int $rowCount Number of database rows
1557 * @param FormOptions $opts
1559 private function webOutputHeader( $rowCount, $opts ) {
1560 if ( !$this->including() ) {
1561 $this->outputFeedLinks();
1562 $this->doHeader( $opts, $rowCount );
1567 * Send output to the OutputPage object, only called if not used feeds
1569 * @param IResultWrapper $rows Database rows
1570 * @param FormOptions $opts
1572 public function webOutput( $rows, $opts ) {
1573 $this->webOutputHeader( $rows->numRows(), $opts );
1575 $this->outputChangesList( $rows, $opts );
1579 * Output feed links.
1581 public function outputFeedLinks() {
1582 // nothing by default
1586 * Build and output the actual changes list.
1588 * @param IResultWrapper $rows Database rows
1589 * @param FormOptions $opts
1591 abstract public function outputChangesList( $rows, $opts );
1594 * Set the text to be displayed above the changes
1596 * @param FormOptions $opts
1597 * @param int $numRows Number of rows in the result to show after this header
1599 public function doHeader( $opts, $numRows ) {
1600 $this->setTopText( $opts );
1602 // @todo Lots of stuff should be done here.
1604 $this->setBottomText( $opts );
1608 * Send the text to be displayed before the options.
1609 * Should use $this->getOutput()->addWikiTextAsInterface()
1610 * or similar methods to print the text.
1612 * @param FormOptions $opts
1614 public function setTopText( FormOptions
$opts ) {
1615 // nothing by default
1619 * Send the text to be displayed after the options.
1620 * Should use $this->getOutput()->addWikiTextAsInterface()
1621 * or similar methods to print the text.
1623 * @param FormOptions $opts
1625 public function setBottomText( FormOptions
$opts ) {
1626 // nothing by default
1630 * Get options to be displayed in a form
1631 * @todo This should handle options returned by getDefaultOptions().
1632 * @todo Not called by anything in this class (but is in subclasses), should be
1633 * called by something… doHeader() maybe?
1635 * @param FormOptions $opts
1638 public function getExtraOptions( $opts ) {
1643 * Return the legend displayed within the fieldset
1647 public function makeLegend() {
1648 $context = $this->getContext();
1649 $user = $context->getUser();
1650 # The legend showing what the letters and stuff mean
1651 $legend = Html
::openElement( 'dl' ) . "\n";
1652 # Iterates through them and gets the messages for both letter and tooltip
1653 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1654 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1655 unset( $legendItems['unpatrolled'] );
1657 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1658 $label = $item['legend'] ??
$item['title'];
1659 $letter = $item['letter'];
1660 $cssClass = $item['class'] ??
$key;
1662 $legend .= Html
::element( 'dt',
1663 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1665 Html
::rawElement( 'dd',
1666 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1667 $context->msg( $label )->parse()
1671 $legend .= Html
::rawElement( 'dt',
1672 [ 'class' => 'mw-plusminus-pos' ],
1673 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1675 $legend .= Html
::element(
1677 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1678 $context->msg( 'recentchanges-label-plusminus' )->text()
1680 $legend .= Html
::closeElement( 'dl' ) . "\n";
1682 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1683 $context->msg( 'rcfilters-legend-heading' )->parse() :
1684 $context->msg( 'recentchanges-legend-heading' )->parse();
1687 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1688 $collapsedClass = $collapsedState === 'collapsed' ?
' mw-collapsed' : '';
1691 '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
1693 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1700 * Add page-specific modules.
1702 protected function addModules() {
1703 $out = $this->getOutput();
1704 // Styles and behavior for the legend box (see makeLegend())
1705 $out->addModuleStyles( [
1706 'mediawiki.interface.helpers.styles',
1707 'mediawiki.special.changeslist.legend',
1708 'mediawiki.special.changeslist',
1710 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1712 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
1713 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1714 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1718 protected function getGroupName() {
1723 * Filter on users' experience levels; this will not be called if nothing is
1726 * @param string $specialPageClassName Class name of current special page
1727 * @param IContextSource $context Context, for e.g. user
1728 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1729 * @param array &$tables Array of tables; see IDatabase::select $table
1730 * @param array &$fields Array of fields; see IDatabase::select $vars
1731 * @param array &$conds Array of conditions; see IDatabase::select $conds
1732 * @param array &$query_options Array of query options; see IDatabase::select $options
1733 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1734 * @param array $selectedExpLevels The allowed active values, sorted
1735 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1738 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1739 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1741 global $wgLearnerEdits,
1742 $wgExperiencedUserEdits,
1743 $wgLearnerMemberSince,
1744 $wgExperiencedUserMemberSince;
1748 // If all levels are selected, don't filter
1749 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1753 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1755 in_array( 'registered', $selectedExpLevels ) &&
1756 in_array( 'unregistered', $selectedExpLevels )
1761 $actorMigration = ActorMigration
::newMigration();
1762 $actorQuery = $actorMigration->getJoin( 'rc_user' );
1763 $tables +
= $actorQuery['tables'];
1764 $join_conds +
= $actorQuery['joins'];
1766 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1768 in_array( 'registered', $selectedExpLevels ) &&
1769 !in_array( 'unregistered', $selectedExpLevels )
1771 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1775 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1776 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1781 $join_conds['user'] = [ 'LEFT JOIN', $actorQuery['fields']['rc_user'] . ' = user_id' ];
1786 $secondsPerDay = 86400;
1787 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1788 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1790 $aboveNewcomer = $dbr->makeList(
1792 'user_editcount >= ' . intval( $wgLearnerEdits ),
1793 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1798 $aboveLearner = $dbr->makeList(
1800 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1801 'user_registration <= ' .
1802 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1809 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1810 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1811 $conditions[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1814 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1815 $conditions[] = "NOT ( $aboveNewcomer )";
1816 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1817 $conditions[] = $dbr->makeList(
1818 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1821 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1822 $conditions[] = $aboveLearner;
1823 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1824 $conditions[] = "NOT ( $aboveLearner )";
1825 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1826 $conditions[] = $dbr->makeList(
1827 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1830 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1831 $conditions[] = $aboveNewcomer;
1832 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1833 $conditions[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1836 if ( count( $conditions ) > 1 ) {
1837 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1838 } elseif ( count( $conditions ) === 1 ) {
1839 $conds[] = reset( $conditions );
1844 * Check whether the structured filter UI is enabled
1848 public function isStructuredFilterUiEnabled() {
1849 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1853 return static::checkStructuredFilterUiEnabled( $this->getUser() );
1857 * Static method to check whether StructuredFilter UI is enabled for the given user
1863 public static function checkStructuredFilterUiEnabled( $user ) {
1864 if ( $user instanceof Config
) {
1865 wfDeprecated( __METHOD__
. ' with Config argument', '1.34' );
1866 $user = func_get_arg( 1 );
1868 return !$user->getOption( 'rcenhancedfilters-disable' );
1872 * Get the default value of the number of changes to display when loading
1878 public function getDefaultLimit() {
1879 return $this->getUser()->getIntOption( static::$limitPreferenceName );
1883 * Get the default value of the number of days to display when loading
1885 * Supports fractional values, and should be cast to a float.
1890 public function getDefaultDays() {
1891 return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );