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\ResultWrapper
;
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 $reviewStatusFilterGroupDefinition;
92 // Single filter registered conditionally
93 private $hideCategorizationFilterDefinition;
96 * Filter groups, and their contained filters
97 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
99 * @var array $filterGroups
101 protected $filterGroups = [];
103 public function __construct( $name, $restriction ) {
104 parent
::__construct( $name, $restriction );
106 $nonRevisionTypes = [ RC_LOG
];
107 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
109 $this->filterGroupDefinitions
= [
111 'name' => 'registration',
112 'title' => 'rcfilters-filtergroup-registration',
113 'class' => ChangesListBooleanFilterGroup
::class,
117 // rcshowhideliu-show, rcshowhideliu-hide,
119 'showHideSuffix' => 'showhideliu',
121 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
122 &$query_options, &$join_conds
124 $conds[] = 'rc_user = 0';
126 'isReplacedInStructuredUi' => true,
130 'name' => 'hideanons',
131 // rcshowhideanons-show, rcshowhideanons-hide,
133 'showHideSuffix' => 'showhideanons',
135 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
136 &$query_options, &$join_conds
138 $conds[] = 'rc_user != 0';
140 'isReplacedInStructuredUi' => true,
146 'name' => 'userExpLevel',
147 'title' => 'rcfilters-filtergroup-userExpLevel',
148 'class' => ChangesListStringOptionsFilterGroup
::class,
149 'isFullCoverage' => true,
152 'name' => 'unregistered',
153 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
154 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
155 'cssClassSuffix' => 'user-unregistered',
156 'isRowApplicableCallable' => function ( $ctx, $rc ) {
157 return !$rc->getAttribute( 'rc_user' );
161 'name' => 'registered',
162 'label' => 'rcfilters-filter-user-experience-level-registered-label',
163 'description' => 'rcfilters-filter-user-experience-level-registered-description',
164 'cssClassSuffix' => 'user-registered',
165 'isRowApplicableCallable' => function ( $ctx, $rc ) {
166 return $rc->getAttribute( 'rc_user' );
170 'name' => 'newcomer',
171 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
172 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
173 'cssClassSuffix' => 'user-newcomer',
174 'isRowApplicableCallable' => function ( $ctx, $rc ) {
175 $performer = $rc->getPerformer();
176 return $performer && $performer->isLoggedIn() &&
177 $performer->getExperienceLevel() === 'newcomer';
182 'label' => 'rcfilters-filter-user-experience-level-learner-label',
183 'description' => 'rcfilters-filter-user-experience-level-learner-description',
184 'cssClassSuffix' => 'user-learner',
185 'isRowApplicableCallable' => function ( $ctx, $rc ) {
186 $performer = $rc->getPerformer();
187 return $performer && $performer->isLoggedIn() &&
188 $performer->getExperienceLevel() === 'learner';
192 'name' => 'experienced',
193 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
194 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
195 'cssClassSuffix' => 'user-experienced',
196 'isRowApplicableCallable' => function ( $ctx, $rc ) {
197 $performer = $rc->getPerformer();
198 return $performer && $performer->isLoggedIn() &&
199 $performer->getExperienceLevel() === 'experienced';
203 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
204 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
208 'name' => 'authorship',
209 'title' => 'rcfilters-filtergroup-authorship',
210 'class' => ChangesListBooleanFilterGroup
::class,
213 'name' => 'hidemyself',
214 'label' => 'rcfilters-filter-editsbyself-label',
215 'description' => 'rcfilters-filter-editsbyself-description',
216 // rcshowhidemine-show, rcshowhidemine-hide,
218 'showHideSuffix' => 'showhidemine',
220 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
221 &$query_options, &$join_conds
223 $user = $ctx->getUser();
224 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
226 'cssClassSuffix' => 'self',
227 'isRowApplicableCallable' => function ( $ctx, $rc ) {
228 return $ctx->getUser()->equals( $rc->getPerformer() );
232 'name' => 'hidebyothers',
233 'label' => 'rcfilters-filter-editsbyother-label',
234 'description' => 'rcfilters-filter-editsbyother-description',
236 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
237 &$query_options, &$join_conds
239 $user = $ctx->getUser();
240 $conds[] = 'rc_user_text = ' . $dbr->addQuotes( $user->getName() );
242 'cssClassSuffix' => 'others',
243 'isRowApplicableCallable' => function ( $ctx, $rc ) {
244 return !$ctx->getUser()->equals( $rc->getPerformer() );
251 'name' => 'automated',
252 'title' => 'rcfilters-filtergroup-automated',
253 'class' => ChangesListBooleanFilterGroup
::class,
256 'name' => 'hidebots',
257 'label' => 'rcfilters-filter-bots-label',
258 'description' => 'rcfilters-filter-bots-description',
259 // rcshowhidebots-show, rcshowhidebots-hide,
261 'showHideSuffix' => 'showhidebots',
263 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
264 &$query_options, &$join_conds
266 $conds[] = 'rc_bot = 0';
268 'cssClassSuffix' => 'bot',
269 'isRowApplicableCallable' => function ( $ctx, $rc ) {
270 return $rc->getAttribute( 'rc_bot' );
274 'name' => 'hidehumans',
275 'label' => 'rcfilters-filter-humans-label',
276 'description' => 'rcfilters-filter-humans-description',
278 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
279 &$query_options, &$join_conds
281 $conds[] = 'rc_bot = 1';
283 'cssClassSuffix' => 'human',
284 'isRowApplicableCallable' => function ( $ctx, $rc ) {
285 return !$rc->getAttribute( 'rc_bot' );
291 // reviewStatus (conditional)
294 'name' => 'significance',
295 'title' => 'rcfilters-filtergroup-significance',
296 'class' => ChangesListBooleanFilterGroup
::class,
300 'name' => 'hideminor',
301 'label' => 'rcfilters-filter-minor-label',
302 'description' => 'rcfilters-filter-minor-description',
303 // rcshowhideminor-show, rcshowhideminor-hide,
305 'showHideSuffix' => 'showhideminor',
307 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
308 &$query_options, &$join_conds
310 $conds[] = 'rc_minor = 0';
312 'cssClassSuffix' => 'minor',
313 'isRowApplicableCallable' => function ( $ctx, $rc ) {
314 return $rc->getAttribute( 'rc_minor' );
318 'name' => 'hidemajor',
319 'label' => 'rcfilters-filter-major-label',
320 'description' => 'rcfilters-filter-major-description',
322 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
323 &$query_options, &$join_conds
325 $conds[] = 'rc_minor = 1';
327 'cssClassSuffix' => 'major',
328 'isRowApplicableCallable' => function ( $ctx, $rc ) {
329 return !$rc->getAttribute( 'rc_minor' );
336 'name' => 'lastRevision',
337 'title' => 'rcfilters-filtergroup-lastRevision',
338 'class' => ChangesListBooleanFilterGroup
::class,
342 'name' => 'hidelastrevision',
343 'label' => 'rcfilters-filter-lastrevision-label',
344 'description' => 'rcfilters-filter-lastrevision-description',
346 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
347 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
348 $conds[] = $dbr->makeList(
350 'rc_this_oldid <> page_latest',
351 'rc_type' => $nonRevisionTypes,
356 'cssClassSuffix' => 'last',
357 'isRowApplicableCallable' => function ( $ctx, $rc ) {
358 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
362 'name' => 'hidepreviousrevisions',
363 'label' => 'rcfilters-filter-previousrevision-label',
364 'description' => 'rcfilters-filter-previousrevision-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' => 'previous',
377 'isRowApplicableCallable' => function ( $ctx, $rc ) {
378 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
384 // With extensions, there can be change types that will not be hidden by any of these.
386 'name' => 'changeType',
387 'title' => 'rcfilters-filtergroup-changetype',
388 'class' => ChangesListBooleanFilterGroup
::class,
392 'name' => 'hidepageedits',
393 'label' => 'rcfilters-filter-pageedits-label',
394 'description' => 'rcfilters-filter-pageedits-description',
397 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
398 &$query_options, &$join_conds
400 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
402 'cssClassSuffix' => 'src-mw-edit',
403 'isRowApplicableCallable' => function ( $ctx, $rc ) {
404 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
408 'name' => 'hidenewpages',
409 'label' => 'rcfilters-filter-newpages-label',
410 'description' => 'rcfilters-filter-newpages-description',
413 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
414 &$query_options, &$join_conds
416 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
418 'cssClassSuffix' => 'src-mw-new',
419 'isRowApplicableCallable' => function ( $ctx, $rc ) {
420 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
424 // hidecategorization
428 'label' => 'rcfilters-filter-logactions-label',
429 'description' => 'rcfilters-filter-logactions-description',
432 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
433 &$query_options, &$join_conds
435 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
437 'cssClassSuffix' => 'src-mw-log',
438 'isRowApplicableCallable' => function ( $ctx, $rc ) {
439 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
447 $this->reviewStatusFilterGroupDefinition
= [
449 'name' => 'reviewStatus',
450 'title' => 'rcfilters-filtergroup-reviewstatus',
451 'class' => ChangesListBooleanFilterGroup
::class,
455 'name' => 'hidepatrolled',
456 'label' => 'rcfilters-filter-patrolled-label',
457 'description' => 'rcfilters-filter-patrolled-description',
458 // rcshowhidepatr-show, rcshowhidepatr-hide
460 'showHideSuffix' => 'showhidepatr',
462 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
463 &$query_options, &$join_conds
465 $conds[] = 'rc_patrolled = 0';
467 'cssClassSuffix' => 'patrolled',
468 'isRowApplicableCallable' => function ( $ctx, $rc ) {
469 return $rc->getAttribute( 'rc_patrolled' );
473 'name' => 'hideunpatrolled',
474 'label' => 'rcfilters-filter-unpatrolled-label',
475 'description' => 'rcfilters-filter-unpatrolled-description',
477 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
478 &$query_options, &$join_conds
480 $conds[] = 'rc_patrolled = 1';
482 'cssClassSuffix' => 'unpatrolled',
483 'isRowApplicableCallable' => function ( $ctx, $rc ) {
484 return !$rc->getAttribute( 'rc_patrolled' );
491 $this->hideCategorizationFilterDefinition
= [
492 'name' => 'hidecategorization',
493 'label' => 'rcfilters-filter-categorization-label',
494 'description' => 'rcfilters-filter-categorization-description',
495 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
496 // wlshowhidecategorization
497 'showHideSuffix' => 'showhidecategorization',
500 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
501 &$query_options, &$join_conds
503 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
505 'cssClassSuffix' => 'src-mw-categorize',
506 'isRowApplicableCallable' => function ( $ctx, $rc ) {
507 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
513 * Check if filters are in conflict and guaranteed to return no results.
517 protected function areFiltersInConflict() {
518 $opts = $this->getOptions();
519 /** @var ChangesListFilterGroup $group */
520 foreach ( $this->getFilterGroups() as $group ) {
521 if ( $group->getConflictingGroups() ) {
524 " specifies conflicts with other groups but these are not supported yet."
528 /** @var ChangesListFilter $conflictingFilter */
529 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
530 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
535 /** @var ChangesListFilter $filter */
536 foreach ( $group->getFilters() as $filter ) {
537 /** @var ChangesListFilter $conflictingFilter */
538 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
540 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
541 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
555 * Main execution point
557 * @param string $subpage
559 public function execute( $subpage ) {
560 $this->rcSubpage
= $subpage;
562 $this->considerActionsForDefaultSavedQuery( $subpage );
564 $opts = $this->getOptions();
566 $rows = $this->getRows();
567 if ( $rows === false ) {
568 $rows = new FakeResultWrapper( [] );
571 // Used by Structured UI app to get results without MW chrome
572 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
573 $this->getOutput()->setArticleBodyOnly( true );
576 // Used by "live update" and "view newest" to check
577 // if there's new changes with minimal data transfer
578 if ( $this->getRequest()->getBool( 'peek' ) ) {
579 $code = $rows->numRows() > 0 ?
200 : 204;
580 $this->getOutput()->setStatusCode( $code );
582 if ( $this->getUser()->isAnon() !==
583 $this->getRequest()->getFuzzyBool( 'isAnon' )
585 $this->getOutput()->setStatusCode( 205 );
591 $batch = new LinkBatch
;
592 foreach ( $rows as $row ) {
593 $batch->add( NS_USER
, $row->rc_user_text
);
594 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
595 $batch->add( $row->rc_namespace
, $row->rc_title
);
596 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
597 $formatter = LogFormatter
::newFromRow( $row );
598 foreach ( $formatter->getPreloadTitles() as $title ) {
599 $batch->addObj( $title );
606 $this->outputHeader();
608 $this->webOutput( $rows, $opts );
611 } catch ( DBQueryTimeoutError
$timeoutException ) {
612 MWExceptionHandler
::logException( $timeoutException );
615 $this->outputHeader();
618 $this->getOutput()->setStatusCode( 500 );
619 $this->webOutputHeader( 0, $opts );
620 $this->outputTimeout();
623 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
624 // Clean up any bad page entries for titles showing up in RC
625 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
627 LoggerFactory
::getInstance( 'objectcache' )
631 $this->includeRcFiltersApp();
635 * Check whether or not the page should load defaults, and if so, whether
636 * a default saved query is relevant to be redirected to. If it is relevant,
637 * redirect properly with all necessary query parameters.
639 * @param string $subpage
641 protected function considerActionsForDefaultSavedQuery( $subpage ) {
642 if ( !$this->isStructuredFilterUiEnabled() ||
$this->including() ) {
646 $knownParams = call_user_func_array(
647 [ $this->getRequest(), 'getValues' ],
648 array_keys( $this->getOptions()->getAllValues() )
651 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
652 // we need to exclude several parameters we know should not be counted towards preventing
653 // the loading of defaults.
654 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
655 $knownParams = array_diff_key( $knownParams, $excludedParams );
658 // If there are NO known parameters in the URL request
659 // (that are not excluded) then we need to check into loading
660 // the default saved query
661 count( $knownParams ) === 0
663 // Get the saved queries data and parse it
664 $savedQueries = FormatJson
::decode(
665 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
669 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
670 // Only load queries that are 'version' 2, since those
671 // have parameter representation
672 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
673 $savedQueryDefaultID = $savedQueries[ 'default' ];
674 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
676 // Build the entire parameter list
677 $query = array_merge(
678 $defaultQuery[ 'params' ],
679 $defaultQuery[ 'highlights' ],
684 // Add to the query any parameters that we may have ignored before
685 // but are still valid and requested in the URL
686 $query = array_merge( $this->getRequest()->getValues(), $query );
687 unset( $query[ 'title' ] );
688 $this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) );
690 // There's a default, but the version is not 2, and the server can't
691 // actually recognize the query itself. This happens if it is before
692 // the conversion, so we need to tell the UI to reload saved query as
693 // it does the conversion to version 2
694 $this->getOutput()->addJsConfigVars(
695 'wgStructuredChangeFiltersDefaultSavedQueryExists',
699 // Add the class that tells the frontend it is still loading
701 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
708 * Include the modules and configuration for the RCFilters app.
709 * Conditional on the user having the feature enabled.
711 * If it is disabled, add a <body> class marking that
713 protected function includeRcFiltersApp() {
714 $out = $this->getOutput();
715 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
716 $jsData = $this->getStructuredFilterJsData();
719 foreach ( $jsData['messageKeys'] as $key ) {
720 $messages[$key] = $this->msg( $key )->plain();
723 $out->addBodyClasses( 'mw-rcfilters-enabled' );
726 ResourceLoader
::makeInlineScript(
727 ResourceLoader
::makeMessageSetScript( $messages )
731 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
733 $out->addJsConfigVars(
734 'wgRCFiltersChangeTags',
735 $this->getChangeTagList()
737 $out->addJsConfigVars(
738 'StructuredChangeFiltersDisplayConfig',
740 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
741 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
742 'limitDefault' => $this->getDefaultLimit(),
743 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
744 'daysDefault' => $this->getDefaultDays(),
748 $out->addJsConfigVars(
749 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
750 static::$savedQueriesPreferenceName
752 $out->addJsConfigVars(
753 'wgStructuredChangeFiltersLimitPreferenceName',
754 static::$limitPreferenceName
756 $out->addJsConfigVars(
757 'wgStructuredChangeFiltersDaysPreferenceName',
758 static::$daysPreferenceName
761 $out->addJsConfigVars(
762 'StructuredChangeFiltersLiveUpdatePollingRate',
763 $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
766 $out->addBodyClasses( 'mw-rcfilters-disabled' );
771 * Fetch the change tags list for the front end
773 * @return Array Tag data
775 protected function getChangeTagList() {
776 $cache = ObjectCache
::getMainWANInstance();
777 $context = $this->getContext();
778 return $cache->getWithSetCallback(
779 $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ),
780 $cache::TTL_MINUTE
* 10,
781 function () use ( $context ) {
782 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
783 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
785 // Hit counts disabled for perf reasons, see T169997
787 $tagStats = ChangeTags::tagUsageStatistics();
788 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
791 arsort( $tagHitCounts );
793 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
795 // Build the list and data
797 foreach ( $tagHitCounts as $tagName => $hits ) {
799 // Only get active tags
800 isset( $explicitlyDefinedTags[ $tagName ] ) ||
801 isset( $softwareActivatedTags[ $tagName ] )
805 'label' => Sanitizer
::stripAllTags(
806 ChangeTags
::tagDescription( $tagName, $context )
809 ChangeTags
::truncateTagDescription(
810 $tagName, self
::TAG_DESC_CHARACTER_LIMIT
, $context
812 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
818 // Instead of sorting by hit count (disabled, see above), sort by display name
819 usort( $result, function ( $a, $b ) {
820 return strcasecmp( $a['label'], $b['label'] );
832 * Add the "no results" message to the output
834 protected function outputNoResults() {
835 $this->getOutput()->addHTML(
836 '<div class="mw-changeslist-empty">' .
837 $this->msg( 'recentchanges-noresult' )->parse() .
843 * Add the "timeout" message to the output
845 protected function outputTimeout() {
846 $this->getOutput()->addHTML(
847 '<div class="mw-changeslist-empty mw-changeslist-timeout">' .
848 $this->msg( 'recentchanges-timeout' )->parse() .
854 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
856 * @return bool|ResultWrapper Result or false
858 public function getRows() {
859 $opts = $this->getOptions();
866 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
868 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
872 * Get the current FormOptions for this request
874 * @return FormOptions
876 public function getOptions() {
877 if ( $this->rcOptions
=== null ) {
878 $this->rcOptions
= $this->setup( $this->rcSubpage
);
881 return $this->rcOptions
;
885 * Register all filters and their groups (including those from hooks), plus handle
886 * conflicts and defaults.
888 * You might want to customize these in the same method, in subclasses. You can
889 * call getFilterGroup to access a group, and (on the group) getFilter to access a
890 * filter, then make necessary modfications to the filter or group (e.g. with
893 protected function registerFilters() {
894 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
896 // Make sure this is not being transcluded (we don't want to show this
897 // information to all users just because the user that saves the edit can
898 // patrol or is logged in)
899 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
900 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
903 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
905 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
906 $transformedHideCategorizationDef = $this->transformFilterDefinition(
907 $this->hideCategorizationFilterDefinition
910 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
912 $hideCategorization = new ChangesListBooleanFilter(
913 $transformedHideCategorizationDef
917 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
919 $unstructuredGroupDefinition =
920 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
921 $this->getCustomFilters()
923 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
925 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
926 $registered = $userExperienceLevel->getFilter( 'registered' );
927 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
928 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
929 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
931 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
932 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
933 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
935 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
936 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
938 // categoryFilter is conditional; see registerFilters
939 if ( $categoryFilter !== null ) {
940 $hideMinorFilter->conflictsWith(
942 'rcfilters-hideminor-conflicts-typeofchange-global',
943 'rcfilters-hideminor-conflicts-typeofchange',
944 'rcfilters-typeofchange-conflicts-hideminor'
947 $hideMinorFilter->conflictsWith(
949 'rcfilters-hideminor-conflicts-typeofchange-global',
950 'rcfilters-hideminor-conflicts-typeofchange',
951 'rcfilters-typeofchange-conflicts-hideminor'
953 $hideMinorFilter->conflictsWith(
955 'rcfilters-hideminor-conflicts-typeofchange-global',
956 'rcfilters-hideminor-conflicts-typeofchange',
957 'rcfilters-typeofchange-conflicts-hideminor'
962 * Transforms filter definition to prepare it for constructor.
964 * See overrides of this method as well.
966 * @param array $filterDefinition Original filter definition
968 * @return array Transformed definition
970 protected function transformFilterDefinition( array $filterDefinition ) {
971 return $filterDefinition;
975 * Register filters from a definition object
977 * Array specifying groups and their filters; see Filter and
978 * ChangesListFilterGroup constructors.
980 * There is light processing to simplify core maintenance.
981 * @param array $definition
983 protected function registerFiltersFromDefinitions( array $definition ) {
984 $autoFillPriority = -1;
985 foreach ( $definition as $groupDefinition ) {
986 if ( !isset( $groupDefinition['priority'] ) ) {
987 $groupDefinition['priority'] = $autoFillPriority;
989 // If it's explicitly specified, start over the auto-fill
990 $autoFillPriority = $groupDefinition['priority'];
995 $className = $groupDefinition['class'];
996 unset( $groupDefinition['class'] );
998 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
999 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
1002 $this->registerFilterGroup( new $className( $groupDefinition ) );
1007 * Get filter group definition from legacy custom filters
1009 * @param array $customFilters Custom filters from legacy hooks
1010 * @return array Group definition
1012 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
1013 // Special internal unstructured group
1014 $unstructuredGroupDefinition = [
1015 'name' => 'unstructured',
1016 'class' => ChangesListBooleanFilterGroup
::class,
1017 'priority' => -1, // Won't display in structured
1021 foreach ( $customFilters as $name => $params ) {
1022 $unstructuredGroupDefinition['filters'][] = [
1024 'showHide' => $params['msg'],
1025 'default' => $params['default'],
1029 return $unstructuredGroupDefinition;
1033 * @return array The legacy show/hide toggle filters
1035 protected function getLegacyShowHideFilters() {
1037 foreach ( $this->filterGroups
as $group ) {
1038 if ( $group instanceof ChangesListBooleanFilterGroup
) {
1039 foreach ( $group->getFilters() as $key => $filter ) {
1040 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1041 $filters[ $key ] = $filter;
1050 * Register all the filters, including legacy hook-driven ones.
1051 * Then create a FormOptions object with options as specified by the user
1053 * @param array $parameters
1055 * @return FormOptions
1057 public function setup( $parameters ) {
1058 $this->registerFilters();
1060 $opts = $this->getDefaultOptions();
1062 $opts = $this->fetchOptionsFromRequest( $opts );
1064 // Give precedence to subpage syntax
1065 if ( $parameters !== null ) {
1066 $this->parseParameters( $parameters, $opts );
1069 $this->validateOptions( $opts );
1075 * Get a FormOptions object containing the default options. By default, returns
1076 * some basic options. The filters listed explicitly here are overriden in this
1077 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1078 * and more) are structured. Structured filters are overriden in registerFilters.
1081 * @return FormOptions
1083 public function getDefaultOptions() {
1084 $opts = new FormOptions();
1085 $structuredUI = $this->isStructuredFilterUiEnabled();
1086 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1087 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1089 /** @var ChangesListFilterGroup $filterGroup */
1090 foreach ( $this->filterGroups
as $filterGroup ) {
1091 $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
1094 $opts->add( 'namespace', '', FormOptions
::STRING );
1095 $opts->add( 'invert', false );
1096 $opts->add( 'associated', false );
1097 $opts->add( 'urlversion', 1 );
1098 $opts->add( 'tagfilter', '' );
1100 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
1101 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
1103 $opts->add( 'from', '' );
1109 * Register a structured changes list filter group
1111 * @param ChangesListFilterGroup $group
1113 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
1114 $groupName = $group->getName();
1116 $this->filterGroups
[$groupName] = $group;
1120 * Gets the currently registered filters groups
1122 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1124 protected function getFilterGroups() {
1125 return $this->filterGroups
;
1129 * Gets a specified ChangesListFilterGroup by name
1131 * @param string $groupName Name of group
1133 * @return ChangesListFilterGroup|null Group, or null if not registered
1135 public function getFilterGroup( $groupName ) {
1136 return isset( $this->filterGroups
[$groupName] ) ?
1137 $this->filterGroups
[$groupName] :
1141 // Currently, this intentionally only includes filters that display
1142 // in the structured UI. This can be changed easily, though, if we want
1143 // to include data on filters that use the unstructured UI. messageKeys is a
1144 // special top-level value, with the value being an array of the message keys to
1145 // send to the client.
1147 * Gets structured filter information needed by JS
1149 * @return array Associative array
1150 * * array $return['groups'] Group data
1151 * * array $return['messageKeys'] Array of message keys
1153 public function getStructuredFilterJsData() {
1156 'messageKeys' => [],
1159 usort( $this->filterGroups
, function ( $a, $b ) {
1160 return $b->getPriority() - $a->getPriority();
1163 foreach ( $this->filterGroups
as $groupName => $group ) {
1164 $groupOutput = $group->getJsData( $this );
1165 if ( $groupOutput !== null ) {
1166 $output['messageKeys'] = array_merge(
1167 $output['messageKeys'],
1168 $groupOutput['messageKeys']
1171 unset( $groupOutput['messageKeys'] );
1172 $output['groups'][] = $groupOutput;
1180 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
1183 * @return array Map of filter URL param names to properties (msg/default)
1185 protected function getCustomFilters() {
1186 if ( $this->customFilters
=== null ) {
1187 $this->customFilters
= [];
1188 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
1191 return $this->customFilters
;
1195 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1197 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1199 * @param FormOptions $opts
1200 * @return FormOptions
1202 protected function fetchOptionsFromRequest( $opts ) {
1203 $opts->fetchValuesFromRequest( $this->getRequest() );
1209 * Process $par and put options found in $opts. Used when including the page.
1211 * @param string $par
1212 * @param FormOptions $opts
1214 public function parseParameters( $par, FormOptions
$opts ) {
1215 $stringParameterNameSet = [];
1216 $hideParameterNameSet = [];
1218 // URL parameters can be per-group, like 'userExpLevel',
1219 // or per-filter, like 'hideminor'.
1221 foreach ( $this->filterGroups
as $filterGroup ) {
1222 if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup
) {
1223 $stringParameterNameSet[$filterGroup->getName()] = true;
1224 } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1225 foreach ( $filterGroup->getFilters() as $filter ) {
1226 $hideParameterNameSet[$filter->getName()] = true;
1231 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1232 foreach ( $bits as $bit ) {
1234 if ( isset( $hideParameterNameSet[$bit] ) ) {
1235 // hidefoo => hidefoo=true
1237 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1238 // foo => hidefoo=false
1239 $opts["hide$bit"] = false;
1240 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1241 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1242 $opts[$m[1]] = $m[2];
1249 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1251 * @param FormOptions $opts
1253 public function validateOptions( FormOptions
$opts ) {
1254 $isContradictory = $this->fixContradictoryOptions( $opts );
1255 $isReplaced = $this->replaceOldOptions( $opts );
1257 if ( $isContradictory ||
$isReplaced ) {
1258 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1259 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1262 $opts->validateIntBounds( 'limit', 0, 5000 );
1263 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1267 * Fix invalid options by resetting pairs that should never appear together.
1269 * @param FormOptions $opts
1270 * @return bool True if any option was reset
1272 private function fixContradictoryOptions( FormOptions
$opts ) {
1273 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1275 foreach ( $this->filterGroups
as $filterGroup ) {
1276 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1277 $filters = $filterGroup->getFilters();
1279 if ( count( $filters ) === 1 ) {
1280 // legacy boolean filters should not be considered
1284 $allInGroupEnabled = array_reduce(
1286 function ( $carry, $filter ) use ( $opts ) {
1287 return $carry && $opts[ $filter->getName() ];
1289 /* initialValue */ count( $filters ) > 0
1292 if ( $allInGroupEnabled ) {
1293 foreach ( $filters as $filter ) {
1294 $opts[ $filter->getName() ] = false;
1306 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1309 * This is deprecated and may be removed.
1311 * @param FormOptions $opts
1312 * @return bool True if this change was mode
1314 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1315 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1316 $opts->reset( 'hideanons' );
1317 if ( !$opts['hidebots'] ) {
1318 $opts->reset( 'hideliu' );
1319 $opts['hidehumans'] = 1;
1329 * Replace old options 'hideanons' or 'hideliu' with structured UI equivalent
1331 * @param FormOptions $opts
1332 * @return bool True if the change was made
1334 public function replaceOldOptions( FormOptions
$opts ) {
1335 if ( !$this->isStructuredFilterUiEnabled() ) {
1339 // At this point 'hideanons' and 'hideliu' cannot be both true,
1340 // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
1341 if ( $opts[ 'hideanons' ] ) {
1342 $opts->reset( 'hideanons' );
1343 $opts[ 'userExpLevel' ] = 'registered';
1347 if ( $opts[ 'hideliu' ] ) {
1348 $opts->reset( 'hideliu' );
1349 $opts[ 'userExpLevel' ] = 'unregistered';
1357 * Convert parameters values from true/false to 1/0
1358 * so they are not omitted by wfArrayToCgi()
1361 * @param array $params
1364 protected function convertParamsForLink( $params ) {
1365 foreach ( $params as &$value ) {
1366 if ( $value === false ) {
1375 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1376 * the user requested.
1378 * @param array &$tables Array of tables; see IDatabase::select $table
1379 * @param array &$fields Array of fields; see IDatabase::select $vars
1380 * @param array &$conds Array of conditions; see IDatabase::select $conds
1381 * @param array &$query_options Array of query options; see IDatabase::select $options
1382 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1383 * @param FormOptions $opts
1385 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1386 &$join_conds, FormOptions
$opts
1388 $dbr = $this->getDB();
1389 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1391 /** @var ChangesListFilterGroup $filterGroup */
1392 foreach ( $this->filterGroups
as $filterGroup ) {
1393 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1394 $query_options, $join_conds, $opts, $isStructuredUI );
1397 // Namespace filtering
1398 if ( $opts[ 'namespace' ] !== '' ) {
1399 $namespaces = explode( ';', $opts[ 'namespace' ] );
1401 if ( $opts[ 'associated' ] ) {
1402 $associatedNamespaces = array_map(
1404 return MWNamespace
::getAssociated( $ns );
1408 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1411 if ( count( $namespaces ) === 1 ) {
1412 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1413 $value = $dbr->addQuotes( reset( $namespaces ) );
1415 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1416 sort( $namespaces );
1417 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1419 $conds[] = "rc_namespace $operator $value";
1423 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1424 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1426 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1427 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
1428 $cutoff = $dbr->timestamp( $opts['from'] );
1430 $opts->reset( 'from' );
1433 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1439 * @param array $tables Array of tables; see IDatabase::select $table
1440 * @param array $fields Array of fields; see IDatabase::select $vars
1441 * @param array $conds Array of conditions; see IDatabase::select $conds
1442 * @param array $query_options Array of query options; see IDatabase::select $options
1443 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1444 * @param FormOptions $opts
1445 * @return bool|ResultWrapper Result or false
1447 protected function doMainQuery( $tables, $fields, $conds,
1448 $query_options, $join_conds, FormOptions
$opts
1450 $rcQuery = RecentChange
::getQueryInfo();
1451 $tables = array_merge( $tables, $rcQuery['tables'] );
1452 $fields = array_merge( $rcQuery['fields'], $fields );
1453 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
1455 ChangeTags
::modifyDisplayQuery(
1464 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1470 $dbr = $this->getDB();
1472 return $dbr->select(
1482 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1483 &$query_options, &$join_conds, $opts
1486 'ChangesListSpecialPageQuery',
1487 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1492 * Return a IDatabase object for reading
1496 protected function getDB() {
1497 return wfGetDB( DB_REPLICA
);
1501 * Send header output to the OutputPage object, only called if not using feeds
1503 * @param int $rowCount Number of database rows
1504 * @param FormOptions $opts
1506 private function webOutputHeader( $rowCount, $opts ) {
1507 if ( !$this->including() ) {
1508 $this->outputFeedLinks();
1509 $this->doHeader( $opts, $rowCount );
1514 * Send output to the OutputPage object, only called if not used feeds
1516 * @param ResultWrapper $rows Database rows
1517 * @param FormOptions $opts
1519 public function webOutput( $rows, $opts ) {
1520 $this->webOutputHeader( $rows->numRows(), $opts );
1522 $this->outputChangesList( $rows, $opts );
1526 * Output feed links.
1528 public function outputFeedLinks() {
1529 // nothing by default
1533 * Build and output the actual changes list.
1535 * @param ResultWrapper $rows Database rows
1536 * @param FormOptions $opts
1538 abstract public function outputChangesList( $rows, $opts );
1541 * Set the text to be displayed above the changes
1543 * @param FormOptions $opts
1544 * @param int $numRows Number of rows in the result to show after this header
1546 public function doHeader( $opts, $numRows ) {
1547 $this->setTopText( $opts );
1549 // @todo Lots of stuff should be done here.
1551 $this->setBottomText( $opts );
1555 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1556 * or similar methods to print the text.
1558 * @param FormOptions $opts
1560 public function setTopText( FormOptions
$opts ) {
1561 // nothing by default
1565 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1566 * or similar methods to print the text.
1568 * @param FormOptions $opts
1570 public function setBottomText( FormOptions
$opts ) {
1571 // nothing by default
1575 * Get options to be displayed in a form
1576 * @todo This should handle options returned by getDefaultOptions().
1577 * @todo Not called by anything in this class (but is in subclasses), should be
1578 * called by something… doHeader() maybe?
1580 * @param FormOptions $opts
1583 public function getExtraOptions( $opts ) {
1588 * Return the legend displayed within the fieldset
1592 public function makeLegend() {
1593 $context = $this->getContext();
1594 $user = $context->getUser();
1595 # The legend showing what the letters and stuff mean
1596 $legend = Html
::openElement( 'dl' ) . "\n";
1597 # Iterates through them and gets the messages for both letter and tooltip
1598 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1599 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1600 unset( $legendItems['unpatrolled'] );
1602 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1603 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1604 $letter = $item['letter'];
1605 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1607 $legend .= Html
::element( 'dt',
1608 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1610 Html
::rawElement( 'dd',
1611 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1612 $context->msg( $label )->parse()
1616 $legend .= Html
::rawElement( 'dt',
1617 [ 'class' => 'mw-plusminus-pos' ],
1618 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1620 $legend .= Html
::element(
1622 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1623 $context->msg( 'recentchanges-label-plusminus' )->text()
1625 $legend .= Html
::closeElement( 'dl' ) . "\n";
1627 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1628 $context->msg( 'rcfilters-legend-heading' )->parse() :
1629 $context->msg( 'recentchanges-legend-heading' )->parse();
1632 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1633 $collapsedClass = $collapsedState === 'collapsed' ?
' mw-collapsed' : '';
1636 '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
1638 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1645 * Add page-specific modules.
1647 protected function addModules() {
1648 $out = $this->getOutput();
1649 // Styles and behavior for the legend box (see makeLegend())
1650 $out->addModuleStyles( [
1651 'mediawiki.special.changeslist.legend',
1652 'mediawiki.special.changeslist',
1654 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1656 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
1657 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1658 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1662 protected function getGroupName() {
1667 * Filter on users' experience levels; this will not be called if nothing is
1670 * @param string $specialPageClassName Class name of current special page
1671 * @param IContextSource $context Context, for e.g. user
1672 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1673 * @param array &$tables Array of tables; see IDatabase::select $table
1674 * @param array &$fields Array of fields; see IDatabase::select $vars
1675 * @param array &$conds Array of conditions; see IDatabase::select $conds
1676 * @param array &$query_options Array of query options; see IDatabase::select $options
1677 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1678 * @param array $selectedExpLevels The allowed active values, sorted
1679 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1682 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1683 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1685 global $wgLearnerEdits,
1686 $wgExperiencedUserEdits,
1687 $wgLearnerMemberSince,
1688 $wgExperiencedUserMemberSince;
1692 // If all levels are selected, don't filter
1693 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1697 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1699 in_array( 'registered', $selectedExpLevels ) &&
1700 in_array( 'unregistered', $selectedExpLevels )
1705 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1707 in_array( 'registered', $selectedExpLevels ) &&
1708 !in_array( 'unregistered', $selectedExpLevels )
1710 $conds[] = 'rc_user != 0';
1714 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1715 $conds[] = 'rc_user = 0';
1720 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1725 $secondsPerDay = 86400;
1726 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1727 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1729 $aboveNewcomer = $dbr->makeList(
1731 'user_editcount >= ' . intval( $wgLearnerEdits ),
1732 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1737 $aboveLearner = $dbr->makeList(
1739 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1740 'user_registration <= ' .
1741 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1748 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1749 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1750 $conditions[] = 'rc_user = 0';
1753 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1754 $conditions[] = "NOT ( $aboveNewcomer )";
1755 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1756 $conditions[] = $dbr->makeList(
1757 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1760 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1761 $conditions[] = $aboveLearner;
1762 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1763 $conditions[] = "NOT ( $aboveLearner )";
1764 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1765 $conditions[] = $dbr->makeList(
1766 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1769 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1770 $conditions[] = $aboveNewcomer;
1771 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1772 $conditions[] = 'rc_user != 0';
1775 if ( count( $conditions ) > 1 ) {
1776 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1777 } elseif ( count( $conditions ) === 1 ) {
1778 $conds[] = reset( $conditions );
1783 * Check whether the structured filter UI is enabled
1787 public function isStructuredFilterUiEnabled() {
1788 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1792 return static::checkStructuredFilterUiEnabled(
1799 * Check whether the structured filter UI is enabled by default (regardless of
1800 * this particular user's setting)
1804 public function isStructuredFilterUiEnabledByDefault() {
1805 if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
1806 return !$this->getUser()->getDefaultOption( 'rcenhancedfilters-disable' );
1808 return $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
1813 * Static method to check whether StructuredFilter UI is enabled for the given user
1816 * @param Config $config
1820 public static function checkStructuredFilterUiEnabled( Config
$config, User
$user ) {
1821 if ( $config->get( 'StructuredChangeFiltersShowPreference' ) ) {
1822 return !$user->getOption( 'rcenhancedfilters-disable' );
1824 return $user->getOption( 'rcenhancedfilters' );
1829 * Get the default value of the number of changes to display when loading
1835 public function getDefaultLimit() {
1836 return $this->getUser()->getIntOption( static::$limitPreferenceName );
1840 * Get the default value of the number of days to display when loading
1842 * Supports fractional values, and should be cast to a float.
1847 public function getDefaultDays() {
1848 return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );