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\ResultWrapper
;
25 use Wikimedia\Rdbms\FakeResultWrapper
;
26 use Wikimedia\Rdbms\IDatabase
;
29 * Special page which uses a ChangesList to show query results.
30 * @todo Way too many public functions, most of them should be protected
32 * @ingroup SpecialPage
34 abstract class ChangesListSpecialPage
extends SpecialPage
{
38 /** @var FormOptions */
42 protected $customFilters;
44 // Order of both groups and filters is significant; first is top-most priority,
45 // descending from there.
46 // 'showHideSuffix' is a shortcut to and avoid spelling out
47 // details specific to subclasses here.
49 * Definition information for the filters and their groups
51 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
52 * However, priority is dynamically added for the core groups, to ease maintenance.
54 * Groups are displayed to the user in the structured UI. However, if necessary,
55 * all of the filters in a group can be configured to only display on the
56 * unstuctured UI, in which case you don't need a group title. This is done in
57 * getFilterGroupDefinitionFromLegacyCustomFilters, for example.
59 * @var array $filterGroupDefinitions
61 private $filterGroupDefinitions;
63 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
64 // that is registered conditionally.
65 private $reviewStatusFilterGroupDefinition;
67 // Single filter registered conditionally
68 private $hideCategorizationFilterDefinition;
71 * Filter groups, and their contained filters
72 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
74 * @var array $filterGroups
76 protected $filterGroups = [];
78 public function __construct( $name, $restriction ) {
79 parent
::__construct( $name, $restriction );
81 $this->filterGroupDefinitions
= [
83 'name' => 'registration',
84 'title' => 'rcfilters-filtergroup-registration',
85 'class' => ChangesListBooleanFilterGroup
::class,
89 // rcshowhideliu-show, rcshowhideliu-hide,
91 'showHideSuffix' => 'showhideliu',
93 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
94 &$query_options, &$join_conds
96 $conds[] = 'rc_user = 0';
98 'isReplacedInStructuredUi' => true,
102 'name' => 'hideanons',
103 // rcshowhideanons-show, rcshowhideanons-hide,
105 'showHideSuffix' => 'showhideanons',
107 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
108 &$query_options, &$join_conds
110 $conds[] = 'rc_user != 0';
112 'isReplacedInStructuredUi' => true,
118 'name' => 'userExpLevel',
119 'title' => 'rcfilters-filtergroup-userExpLevel',
120 'class' => ChangesListStringOptionsFilterGroup
::class,
121 'isFullCoverage' => true,
124 'name' => 'unregistered',
125 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
126 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
127 'cssClassSuffix' => 'user-unregistered',
128 'isRowApplicableCallable' => function ( $ctx, $rc ) {
129 return !$rc->getAttribute( 'rc_user' );
133 'name' => 'registered',
134 'label' => 'rcfilters-filter-user-experience-level-registered-label',
135 'description' => 'rcfilters-filter-user-experience-level-registered-description',
136 'cssClassSuffix' => 'user-registered',
137 'isRowApplicableCallable' => function ( $ctx, $rc ) {
138 return $rc->getAttribute( 'rc_user' );
142 'name' => 'newcomer',
143 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
144 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
145 'cssClassSuffix' => 'user-newcomer',
146 'isRowApplicableCallable' => function ( $ctx, $rc ) {
147 $performer = $rc->getPerformer();
148 return $performer && $performer->isLoggedIn() &&
149 $performer->getExperienceLevel() === 'newcomer';
154 'label' => 'rcfilters-filter-user-experience-level-learner-label',
155 'description' => 'rcfilters-filter-user-experience-level-learner-description',
156 'cssClassSuffix' => 'user-learner',
157 'isRowApplicableCallable' => function ( $ctx, $rc ) {
158 $performer = $rc->getPerformer();
159 return $performer && $performer->isLoggedIn() &&
160 $performer->getExperienceLevel() === 'learner';
164 'name' => 'experienced',
165 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
166 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
167 'cssClassSuffix' => 'user-experienced',
168 'isRowApplicableCallable' => function ( $ctx, $rc ) {
169 $performer = $rc->getPerformer();
170 return $performer && $performer->isLoggedIn() &&
171 $performer->getExperienceLevel() === 'experienced';
175 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
176 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
180 'name' => 'authorship',
181 'title' => 'rcfilters-filtergroup-authorship',
182 'class' => ChangesListBooleanFilterGroup
::class,
185 'name' => 'hidemyself',
186 'label' => 'rcfilters-filter-editsbyself-label',
187 'description' => 'rcfilters-filter-editsbyself-description',
188 // rcshowhidemine-show, rcshowhidemine-hide,
190 'showHideSuffix' => 'showhidemine',
192 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
193 &$query_options, &$join_conds
195 $user = $ctx->getUser();
196 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
198 'cssClassSuffix' => 'self',
199 'isRowApplicableCallable' => function ( $ctx, $rc ) {
200 return $ctx->getUser()->equals( $rc->getPerformer() );
204 'name' => 'hidebyothers',
205 'label' => 'rcfilters-filter-editsbyother-label',
206 'description' => 'rcfilters-filter-editsbyother-description',
208 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
209 &$query_options, &$join_conds
211 $user = $ctx->getUser();
212 $conds[] = 'rc_user_text = ' . $dbr->addQuotes( $user->getName() );
214 'cssClassSuffix' => 'others',
215 'isRowApplicableCallable' => function ( $ctx, $rc ) {
216 return !$ctx->getUser()->equals( $rc->getPerformer() );
223 'name' => 'automated',
224 'title' => 'rcfilters-filtergroup-automated',
225 'class' => ChangesListBooleanFilterGroup
::class,
228 'name' => 'hidebots',
229 'label' => 'rcfilters-filter-bots-label',
230 'description' => 'rcfilters-filter-bots-description',
231 // rcshowhidebots-show, rcshowhidebots-hide,
233 'showHideSuffix' => 'showhidebots',
235 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
236 &$query_options, &$join_conds
238 $conds[] = 'rc_bot = 0';
240 'cssClassSuffix' => 'bot',
241 'isRowApplicableCallable' => function ( $ctx, $rc ) {
242 return $rc->getAttribute( 'rc_bot' );
246 'name' => 'hidehumans',
247 'label' => 'rcfilters-filter-humans-label',
248 'description' => 'rcfilters-filter-humans-description',
250 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
251 &$query_options, &$join_conds
253 $conds[] = 'rc_bot = 1';
255 'cssClassSuffix' => 'human',
256 'isRowApplicableCallable' => function ( $ctx, $rc ) {
257 return !$rc->getAttribute( 'rc_bot' );
263 // reviewStatus (conditional)
266 'name' => 'significance',
267 'title' => 'rcfilters-filtergroup-significance',
268 'class' => ChangesListBooleanFilterGroup
::class,
272 'name' => 'hideminor',
273 'label' => 'rcfilters-filter-minor-label',
274 'description' => 'rcfilters-filter-minor-description',
275 // rcshowhideminor-show, rcshowhideminor-hide,
277 'showHideSuffix' => 'showhideminor',
279 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
280 &$query_options, &$join_conds
282 $conds[] = 'rc_minor = 0';
284 'cssClassSuffix' => 'minor',
285 'isRowApplicableCallable' => function ( $ctx, $rc ) {
286 return $rc->getAttribute( 'rc_minor' );
290 'name' => 'hidemajor',
291 'label' => 'rcfilters-filter-major-label',
292 'description' => 'rcfilters-filter-major-description',
294 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
295 &$query_options, &$join_conds
297 $conds[] = 'rc_minor = 1';
299 'cssClassSuffix' => 'major',
300 'isRowApplicableCallable' => function ( $ctx, $rc ) {
301 return !$rc->getAttribute( 'rc_minor' );
308 'name' => 'lastRevision',
309 'title' => 'rcfilters-filtergroup-lastRevision',
310 'class' => ChangesListBooleanFilterGroup
::class,
314 'name' => 'hidelastrevision',
315 'label' => 'rcfilters-filter-lastrevision-label',
316 'description' => 'rcfilters-filter-lastrevision-description',
318 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
319 &$query_options, &$join_conds ) {
320 $conds[] = 'rc_this_oldid <> page_latest';
322 'cssClassSuffix' => 'last',
323 'isRowApplicableCallable' => function ( $ctx, $rc ) {
324 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
328 'name' => 'hidepreviousrevisions',
329 'label' => 'rcfilters-filter-previousrevision-label',
330 'description' => 'rcfilters-filter-previousrevision-description',
332 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
333 &$query_options, &$join_conds ) {
334 $conds[] = 'rc_this_oldid = page_latest';
336 'cssClassSuffix' => 'previous',
337 'isRowApplicableCallable' => function ( $ctx, $rc ) {
338 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
344 // With extensions, there can be change types that will not be hidden by any of these.
346 'name' => 'changeType',
347 'title' => 'rcfilters-filtergroup-changetype',
348 'class' => ChangesListBooleanFilterGroup
::class,
352 'name' => 'hidepageedits',
353 'label' => 'rcfilters-filter-pageedits-label',
354 'description' => 'rcfilters-filter-pageedits-description',
357 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
358 &$query_options, &$join_conds
360 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
362 'cssClassSuffix' => 'src-mw-edit',
363 'isRowApplicableCallable' => function ( $ctx, $rc ) {
364 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
368 'name' => 'hidenewpages',
369 'label' => 'rcfilters-filter-newpages-label',
370 'description' => 'rcfilters-filter-newpages-description',
373 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
374 &$query_options, &$join_conds
376 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
378 'cssClassSuffix' => 'src-mw-new',
379 'isRowApplicableCallable' => function ( $ctx, $rc ) {
380 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
384 // hidecategorization
388 'label' => 'rcfilters-filter-logactions-label',
389 'description' => 'rcfilters-filter-logactions-description',
392 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
393 &$query_options, &$join_conds
395 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
397 'cssClassSuffix' => 'src-mw-log',
398 'isRowApplicableCallable' => function ( $ctx, $rc ) {
399 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
407 $this->reviewStatusFilterGroupDefinition
= [
409 'name' => 'reviewStatus',
410 'title' => 'rcfilters-filtergroup-reviewstatus',
411 'class' => ChangesListBooleanFilterGroup
::class,
415 'name' => 'hidepatrolled',
416 'label' => 'rcfilters-filter-patrolled-label',
417 'description' => 'rcfilters-filter-patrolled-description',
418 // rcshowhidepatr-show, rcshowhidepatr-hide
420 'showHideSuffix' => 'showhidepatr',
422 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
423 &$query_options, &$join_conds
425 $conds[] = 'rc_patrolled = 0';
427 'cssClassSuffix' => 'patrolled',
428 'isRowApplicableCallable' => function ( $ctx, $rc ) {
429 return $rc->getAttribute( 'rc_patrolled' );
433 'name' => 'hideunpatrolled',
434 'label' => 'rcfilters-filter-unpatrolled-label',
435 'description' => 'rcfilters-filter-unpatrolled-description',
437 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
438 &$query_options, &$join_conds
440 $conds[] = 'rc_patrolled = 1';
442 'cssClassSuffix' => 'unpatrolled',
443 'isRowApplicableCallable' => function ( $ctx, $rc ) {
444 return !$rc->getAttribute( 'rc_patrolled' );
451 $this->hideCategorizationFilterDefinition
= [
452 'name' => 'hidecategorization',
453 'label' => 'rcfilters-filter-categorization-label',
454 'description' => 'rcfilters-filter-categorization-description',
455 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
456 // wlshowhidecategorization
457 'showHideSuffix' => 'showhidecategorization',
460 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
461 &$query_options, &$join_conds
463 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
465 'cssClassSuffix' => 'src-mw-categorize',
466 'isRowApplicableCallable' => function ( $ctx, $rc ) {
467 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
473 * Check if filters are in conflict and guaranteed to return no results.
477 protected function areFiltersInConflict() {
478 $opts = $this->getOptions();
479 /** @var ChangesListFilterGroup $group */
480 foreach ( $this->getFilterGroups() as $group ) {
481 if ( $group->getConflictingGroups() ) {
484 " specifies conflicts with other groups but these are not supported yet."
488 /** @var ChangesListFilter $conflictingFilter */
489 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
490 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
495 /** @var ChangesListFilter $filter */
496 foreach ( $group->getFilters() as $filter ) {
497 /** @var ChangesListFilter $conflictingFilter */
498 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
500 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
501 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
515 * Main execution point
517 * @param string $subpage
519 public function execute( $subpage ) {
520 $this->rcSubpage
= $subpage;
523 $this->outputHeader();
526 $rows = $this->getRows();
527 $opts = $this->getOptions();
528 if ( $rows === false ) {
529 $rows = new FakeResultWrapper( [] );
532 $batch = new LinkBatch
;
533 foreach ( $rows as $row ) {
534 $batch->add( NS_USER
, $row->rc_user_text
);
535 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
536 $batch->add( $row->rc_namespace
, $row->rc_title
);
537 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
538 $formatter = LogFormatter
::newFromRow( $row );
539 foreach ( $formatter->getPreloadTitles() as $title ) {
540 $batch->addObj( $title );
545 $this->webOutput( $rows, $opts );
549 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
550 // Clean up any bad page entries for titles showing up in RC
551 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
553 LoggerFactory
::getInstance( 'objectcache' )
557 $this->includeRcFiltersApp();
561 * Include the modules and configuration for the RCFilters app.
562 * Conditional on the user having the feature enabled.
564 protected function includeRcFiltersApp() {
565 if ( $this->isStructuredFilterUiEnabled() ) {
566 $out = $this->getOutput();
567 $jsData = $this->getStructuredFilterJsData();
570 foreach ( $jsData['messageKeys'] as $key ) {
571 $messages[$key] = $this->msg( $key )->plain();
575 ResourceLoader
::makeInlineScript(
576 ResourceLoader
::makeMessageSetScript( $messages )
580 $experimentalStructuredChangeFilters =
581 $this->getConfig()->get( 'StructuredChangeFiltersEnableExperimentalViews' );
583 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
584 $out->addJsConfigVars(
585 'wgStructuredChangeFiltersEnableExperimentalViews',
586 $experimentalStructuredChangeFilters
588 $out->addJsConfigVars(
589 'wgStructuredChangeFiltersEnableLiveUpdate',
590 $this->getConfig()->get( 'StructuredChangeFiltersEnableLiveUpdate' )
592 $out->addJsConfigVars(
593 'wgRCFiltersChangeTags',
594 $this->buildChangeTagList()
596 $out->addJsConfigVars(
597 'StructuredChangeFiltersDisplayConfig',
599 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
600 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
601 'limitDefault' => $this->getDefaultLimit(),
602 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
603 'daysDefault' => $this->getDefaultDays(),
610 * Fetch the change tags list for the front end
612 * @return Array Tag data
614 protected function buildChangeTagList() {
615 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
616 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
618 // Hit counts disabled for perf reasons, see T169997
620 $tagStats = ChangeTags::tagUsageStatistics();
621 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
624 arsort( $tagHitCounts );
626 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
628 // Build the list and data
630 foreach ( $tagHitCounts as $tagName => $hits ) {
632 // Only get active tags
633 isset( $explicitlyDefinedTags[ $tagName ] ) ||
634 isset( $softwareActivatedTags[ $tagName ] )
637 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $this->getContext() );
641 'label' => Sanitizer
::stripAllTags(
642 ChangeTags
::tagDescription( $tagName, $this->getContext() )
644 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
645 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
651 // Instead of sorting by hit count (disabled, see above), sort by display name
652 usort( $result, function ( $a, $b ) {
653 return strcasecmp( $a['label'], $b['label'] );
660 * Add the "no results" message to the output
662 protected function outputNoResults() {
663 $this->getOutput()->addHTML(
664 '<div class="mw-changeslist-empty">' .
665 $this->msg( 'recentchanges-noresult' )->parse() .
671 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
673 * @return bool|ResultWrapper Result or false
675 public function getRows() {
676 $opts = $this->getOptions();
683 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
685 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
689 * Get the current FormOptions for this request
691 * @return FormOptions
693 public function getOptions() {
694 if ( $this->rcOptions
=== null ) {
695 $this->rcOptions
= $this->setup( $this->rcSubpage
);
698 return $this->rcOptions
;
702 * Register all filters and their groups (including those from hooks), plus handle
703 * conflicts and defaults.
705 * You might want to customize these in the same method, in subclasses. You can
706 * call getFilterGroup to access a group, and (on the group) getFilter to access a
707 * filter, then make necessary modfications to the filter or group (e.g. with
710 protected function registerFilters() {
711 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
713 // Make sure this is not being transcluded (we don't want to show this
714 // information to all users just because the user that saves the edit can
715 // patrol or is logged in)
716 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
717 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
720 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
722 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
723 $transformedHideCategorizationDef = $this->transformFilterDefinition(
724 $this->hideCategorizationFilterDefinition
727 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
729 $hideCategorization = new ChangesListBooleanFilter(
730 $transformedHideCategorizationDef
734 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
736 $unstructuredGroupDefinition =
737 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
738 $this->getCustomFilters()
740 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
742 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
743 $registered = $userExperienceLevel->getFilter( 'registered' );
744 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
745 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
746 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
748 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
749 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
750 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
752 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
753 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
755 // categoryFilter is conditional; see registerFilters
756 if ( $categoryFilter !== null ) {
757 $hideMinorFilter->conflictsWith(
759 'rcfilters-hideminor-conflicts-typeofchange-global',
760 'rcfilters-hideminor-conflicts-typeofchange',
761 'rcfilters-typeofchange-conflicts-hideminor'
764 $hideMinorFilter->conflictsWith(
766 'rcfilters-hideminor-conflicts-typeofchange-global',
767 'rcfilters-hideminor-conflicts-typeofchange',
768 'rcfilters-typeofchange-conflicts-hideminor'
770 $hideMinorFilter->conflictsWith(
772 'rcfilters-hideminor-conflicts-typeofchange-global',
773 'rcfilters-hideminor-conflicts-typeofchange',
774 'rcfilters-typeofchange-conflicts-hideminor'
779 * Transforms filter definition to prepare it for constructor.
781 * See overrides of this method as well.
783 * @param array $filterDefinition Original filter definition
785 * @return array Transformed definition
787 protected function transformFilterDefinition( array $filterDefinition ) {
788 return $filterDefinition;
792 * Register filters from a definition object
794 * Array specifying groups and their filters; see Filter and
795 * ChangesListFilterGroup constructors.
797 * There is light processing to simplify core maintenance.
799 protected function registerFiltersFromDefinitions( array $definition ) {
800 $autoFillPriority = -1;
801 foreach ( $definition as $groupDefinition ) {
802 if ( !isset( $groupDefinition['priority'] ) ) {
803 $groupDefinition['priority'] = $autoFillPriority;
805 // If it's explicitly specified, start over the auto-fill
806 $autoFillPriority = $groupDefinition['priority'];
811 $className = $groupDefinition['class'];
812 unset( $groupDefinition['class'] );
814 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
815 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
818 $this->registerFilterGroup( new $className( $groupDefinition ) );
823 * Get filter group definition from legacy custom filters
825 * @param array $customFilters Custom filters from legacy hooks
826 * @return array Group definition
828 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
829 // Special internal unstructured group
830 $unstructuredGroupDefinition = [
831 'name' => 'unstructured',
832 'class' => ChangesListBooleanFilterGroup
::class,
833 'priority' => -1, // Won't display in structured
837 foreach ( $customFilters as $name => $params ) {
838 $unstructuredGroupDefinition['filters'][] = [
840 'showHide' => $params['msg'],
841 'default' => $params['default'],
845 return $unstructuredGroupDefinition;
849 * Register all the filters, including legacy hook-driven ones.
850 * Then create a FormOptions object with options as specified by the user
852 * @param array $parameters
854 * @return FormOptions
856 public function setup( $parameters ) {
857 $this->registerFilters();
859 $opts = $this->getDefaultOptions();
861 $opts = $this->fetchOptionsFromRequest( $opts );
863 // Give precedence to subpage syntax
864 if ( $parameters !== null ) {
865 $this->parseParameters( $parameters, $opts );
868 $this->validateOptions( $opts );
874 * Get a FormOptions object containing the default options. By default, returns
875 * some basic options. The filters listed explicitly here are overriden in this
876 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
877 * and more) are structured. Structured filters are overriden in registerFilters.
880 * @return FormOptions
882 public function getDefaultOptions() {
883 $opts = new FormOptions();
884 $structuredUI = $this->isStructuredFilterUiEnabled();
885 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
886 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
889 /** @var ChangesListFilterGroup $filterGroup */
890 foreach ( $this->filterGroups
as $filterGroup ) {
891 // URL parameters can be per-group, like 'userExpLevel',
892 // or per-filter, like 'hideminor'.
893 if ( $filterGroup->isPerGroupRequestParameter() ) {
894 $opts->add( $filterGroup->getName(), $useDefaults ?
$filterGroup->getDefault() : '' );
896 /** @var ChangesListBooleanFilter $filter */
897 foreach ( $filterGroup->getFilters() as $filter ) {
898 $opts->add( $filter->getName(), $useDefaults ?
$filter->getDefault( $structuredUI ) : false );
903 $opts->add( 'namespace', '', FormOptions
::STRING );
904 $opts->add( 'invert', false );
905 $opts->add( 'associated', false );
906 $opts->add( 'urlversion', 1 );
907 $opts->add( 'tagfilter', '' );
913 * Register a structured changes list filter group
915 * @param ChangesListFilterGroup $group
917 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
918 $groupName = $group->getName();
920 $this->filterGroups
[$groupName] = $group;
924 * Gets the currently registered filters groups
926 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
928 protected function getFilterGroups() {
929 return $this->filterGroups
;
933 * Gets a specified ChangesListFilterGroup by name
935 * @param string $groupName Name of group
937 * @return ChangesListFilterGroup|null Group, or null if not registered
939 public function getFilterGroup( $groupName ) {
940 return isset( $this->filterGroups
[$groupName] ) ?
941 $this->filterGroups
[$groupName] :
945 // Currently, this intentionally only includes filters that display
946 // in the structured UI. This can be changed easily, though, if we want
947 // to include data on filters that use the unstructured UI. messageKeys is a
948 // special top-level value, with the value being an array of the message keys to
949 // send to the client.
951 * Gets structured filter information needed by JS
953 * @return array Associative array
954 * * array $return['groups'] Group data
955 * * array $return['messageKeys'] Array of message keys
957 public function getStructuredFilterJsData() {
963 usort( $this->filterGroups
, function ( $a, $b ) {
964 return $b->getPriority() - $a->getPriority();
967 foreach ( $this->filterGroups
as $groupName => $group ) {
968 $groupOutput = $group->getJsData( $this );
969 if ( $groupOutput !== null ) {
970 $output['messageKeys'] = array_merge(
971 $output['messageKeys'],
972 $groupOutput['messageKeys']
975 unset( $groupOutput['messageKeys'] );
976 $output['groups'][] = $groupOutput;
984 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
987 * @return array Map of filter URL param names to properties (msg/default)
989 protected function getCustomFilters() {
990 if ( $this->customFilters
=== null ) {
991 $this->customFilters
= [];
992 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
995 return $this->customFilters
;
999 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1001 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1003 * @param FormOptions $opts
1004 * @return FormOptions
1006 protected function fetchOptionsFromRequest( $opts ) {
1007 $opts->fetchValuesFromRequest( $this->getRequest() );
1013 * Process $par and put options found in $opts. Used when including the page.
1015 * @param string $par
1016 * @param FormOptions $opts
1018 public function parseParameters( $par, FormOptions
$opts ) {
1019 $stringParameterNameSet = [];
1020 $hideParameterNameSet = [];
1022 // URL parameters can be per-group, like 'userExpLevel',
1023 // or per-filter, like 'hideminor'.
1025 foreach ( $this->filterGroups
as $filterGroup ) {
1026 if ( $filterGroup->isPerGroupRequestParameter() ) {
1027 $stringParameterNameSet[$filterGroup->getName()] = true;
1028 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup
::TYPE
) {
1029 foreach ( $filterGroup->getFilters() as $filter ) {
1030 $hideParameterNameSet[$filter->getName()] = true;
1035 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1036 foreach ( $bits as $bit ) {
1038 if ( isset( $hideParameterNameSet[$bit] ) ) {
1039 // hidefoo => hidefoo=true
1041 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1042 // foo => hidefoo=false
1043 $opts["hide$bit"] = false;
1044 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1045 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1046 $opts[$m[1]] = $m[2];
1053 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1055 * @param FormOptions $opts
1057 public function validateOptions( FormOptions
$opts ) {
1058 if ( $this->fixContradictoryOptions( $opts ) ) {
1059 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1060 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1065 * Fix invalid options by resetting pairs that should never appear together.
1067 * @param FormOptions $opts
1068 * @return bool True if any option was reset
1070 private function fixContradictoryOptions( FormOptions
$opts ) {
1071 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1073 foreach ( $this->filterGroups
as $filterGroup ) {
1074 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1075 $filters = $filterGroup->getFilters();
1077 if ( count( $filters ) === 1 ) {
1078 // legacy boolean filters should not be considered
1082 $allInGroupEnabled = array_reduce(
1084 function ( $carry, $filter ) use ( $opts ) {
1085 return $carry && $opts[ $filter->getName() ];
1087 /* initialValue */ count( $filters ) > 0
1090 if ( $allInGroupEnabled ) {
1091 foreach ( $filters as $filter ) {
1092 $opts[ $filter->getName() ] = false;
1104 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1107 * This is deprecated and may be removed.
1109 * @param FormOptions $opts
1110 * @return bool True if this change was mode
1112 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1113 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1114 $opts->reset( 'hideanons' );
1115 if ( !$opts['hidebots'] ) {
1116 $opts->reset( 'hideliu' );
1117 $opts['hidehumans'] = 1;
1127 * Convert parameters values from true/false to 1/0
1128 * so they are not omitted by wfArrayToCgi()
1131 * @param array $params
1134 protected function convertParamsForLink( $params ) {
1135 foreach ( $params as &$value ) {
1136 if ( $value === false ) {
1145 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1146 * the user requested.
1148 * @param array &$tables Array of tables; see IDatabase::select $table
1149 * @param array &$fields Array of fields; see IDatabase::select $vars
1150 * @param array &$conds Array of conditions; see IDatabase::select $conds
1151 * @param array &$query_options Array of query options; see IDatabase::select $options
1152 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1153 * @param FormOptions $opts
1155 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1156 &$join_conds, FormOptions
$opts
1158 $dbr = $this->getDB();
1159 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1161 foreach ( $this->filterGroups
as $filterGroup ) {
1162 // URL parameters can be per-group, like 'userExpLevel',
1163 // or per-filter, like 'hideminor'.
1164 if ( $filterGroup->isPerGroupRequestParameter() ) {
1165 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1166 $query_options, $join_conds, $opts[$filterGroup->getName()] );
1168 foreach ( $filterGroup->getFilters() as $filter ) {
1169 if ( $filter->isActive( $opts, $isStructuredUI ) ) {
1170 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1171 $query_options, $join_conds );
1177 // Namespace filtering
1178 if ( $opts[ 'namespace' ] !== '' ) {
1179 $namespaces = explode( ';', $opts[ 'namespace' ] );
1181 if ( $opts[ 'associated' ] ) {
1182 $associatedNamespaces = array_map(
1184 return MWNamespace
::getAssociated( $ns );
1188 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1191 if ( count( $namespaces ) === 1 ) {
1192 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1193 $value = $dbr->addQuotes( reset( $namespaces ) );
1195 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1196 sort( $namespaces );
1197 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1199 $conds[] = "rc_namespace $operator $value";
1206 * @param array $tables Array of tables; see IDatabase::select $table
1207 * @param array $fields Array of fields; see IDatabase::select $vars
1208 * @param array $conds Array of conditions; see IDatabase::select $conds
1209 * @param array $query_options Array of query options; see IDatabase::select $options
1210 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1211 * @param FormOptions $opts
1212 * @return bool|ResultWrapper Result or false
1214 protected function doMainQuery( $tables, $fields, $conds,
1215 $query_options, $join_conds, FormOptions
$opts
1217 $tables[] = 'recentchanges';
1218 $fields = array_merge( RecentChange
::selectFields(), $fields );
1220 ChangeTags
::modifyDisplayQuery(
1229 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1235 $dbr = $this->getDB();
1237 return $dbr->select(
1247 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1248 &$query_options, &$join_conds, $opts
1251 'ChangesListSpecialPageQuery',
1252 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1257 * Return a IDatabase object for reading
1261 protected function getDB() {
1262 return wfGetDB( DB_REPLICA
);
1266 * Send output to the OutputPage object, only called if not used feeds
1268 * @param ResultWrapper $rows Database rows
1269 * @param FormOptions $opts
1271 public function webOutput( $rows, $opts ) {
1272 if ( !$this->including() ) {
1273 $this->outputFeedLinks();
1274 $this->doHeader( $opts, $rows->numRows() );
1277 $this->outputChangesList( $rows, $opts );
1281 * Output feed links.
1283 public function outputFeedLinks() {
1284 // nothing by default
1288 * Build and output the actual changes list.
1290 * @param ResultWrapper $rows Database rows
1291 * @param FormOptions $opts
1293 abstract public function outputChangesList( $rows, $opts );
1296 * Set the text to be displayed above the changes
1298 * @param FormOptions $opts
1299 * @param int $numRows Number of rows in the result to show after this header
1301 public function doHeader( $opts, $numRows ) {
1302 $this->setTopText( $opts );
1304 // @todo Lots of stuff should be done here.
1306 $this->setBottomText( $opts );
1310 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1311 * or similar methods to print the text.
1313 * @param FormOptions $opts
1315 public function setTopText( FormOptions
$opts ) {
1316 // nothing by default
1320 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1321 * or similar methods to print the text.
1323 * @param FormOptions $opts
1325 public function setBottomText( FormOptions
$opts ) {
1326 // nothing by default
1330 * Get options to be displayed in a form
1331 * @todo This should handle options returned by getDefaultOptions().
1332 * @todo Not called by anything in this class (but is in subclasses), should be
1333 * called by something… doHeader() maybe?
1335 * @param FormOptions $opts
1338 public function getExtraOptions( $opts ) {
1343 * Return the legend displayed within the fieldset
1347 public function makeLegend() {
1348 $context = $this->getContext();
1349 $user = $context->getUser();
1350 # The legend showing what the letters and stuff mean
1351 $legend = Html
::openElement( 'dl' ) . "\n";
1352 # Iterates through them and gets the messages for both letter and tooltip
1353 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1354 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1355 unset( $legendItems['unpatrolled'] );
1357 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1358 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1359 $letter = $item['letter'];
1360 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1362 $legend .= Html
::element( 'dt',
1363 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1365 Html
::rawElement( 'dd',
1366 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1367 $context->msg( $label )->parse()
1371 $legend .= Html
::rawElement( 'dt',
1372 [ 'class' => 'mw-plusminus-pos' ],
1373 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1375 $legend .= Html
::element(
1377 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1378 $context->msg( 'recentchanges-label-plusminus' )->text()
1380 $legend .= Html
::closeElement( 'dl' ) . "\n";
1382 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1383 $context->msg( 'rcfilters-legend-heading' )->parse() :
1384 $context->msg( 'recentchanges-legend-heading' )->parse();
1388 '<div class="mw-changeslist-legend">' .
1390 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1397 * Add page-specific modules.
1399 protected function addModules() {
1400 $out = $this->getOutput();
1401 // Styles and behavior for the legend box (see makeLegend())
1402 $out->addModuleStyles( [
1403 'mediawiki.special.changeslist.legend',
1404 'mediawiki.special.changeslist',
1406 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1408 if ( $this->isStructuredFilterUiEnabled() ) {
1409 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1410 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1414 protected function getGroupName() {
1419 * Filter on users' experience levels; this will not be called if nothing is
1422 * @param string $specialPageClassName Class name of current special page
1423 * @param IContextSource $context Context, for e.g. user
1424 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1425 * @param array &$tables Array of tables; see IDatabase::select $table
1426 * @param array &$fields Array of fields; see IDatabase::select $vars
1427 * @param array &$conds Array of conditions; see IDatabase::select $conds
1428 * @param array &$query_options Array of query options; see IDatabase::select $options
1429 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1430 * @param array $selectedExpLevels The allowed active values, sorted
1431 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1434 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1435 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1437 global $wgLearnerEdits,
1438 $wgExperiencedUserEdits,
1439 $wgLearnerMemberSince,
1440 $wgExperiencedUserMemberSince;
1444 // If all levels are selected, don't filter
1445 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1449 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1451 in_array( 'registered', $selectedExpLevels ) &&
1452 in_array( 'unregistered', $selectedExpLevels )
1457 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1459 in_array( 'registered', $selectedExpLevels ) &&
1460 !in_array( 'unregistered', $selectedExpLevels )
1462 $conds[] = 'rc_user != 0';
1466 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1467 $conds[] = 'rc_user = 0';
1472 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1477 $secondsPerDay = 86400;
1478 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1479 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1481 $aboveNewcomer = $dbr->makeList(
1483 'user_editcount >= ' . intval( $wgLearnerEdits ),
1484 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1489 $aboveLearner = $dbr->makeList(
1491 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1492 'user_registration <= ' .
1493 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1500 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1501 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1502 $conditions[] = 'rc_user = 0';
1505 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1506 $conditions[] = "NOT ( $aboveNewcomer )";
1507 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1508 $conditions[] = $dbr->makeList(
1509 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1512 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1513 $conditions[] = $aboveLearner;
1514 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1515 $conditions[] = "NOT ( $aboveLearner )";
1516 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1517 $conditions[] = $dbr->makeList(
1518 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1521 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1522 $conditions[] = $aboveNewcomer;
1523 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1524 $conditions[] = 'rc_user != 0';
1527 if ( count( $conditions ) > 1 ) {
1528 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1529 } elseif ( count( $conditions ) === 1 ) {
1530 $conds[] = reset( $conditions );
1535 * Check whether the structured filter UI is enabled
1539 public function isStructuredFilterUiEnabled() {
1540 return $this->getUser()->getOption( 'rcenhancedfilters' );
1543 abstract function getDefaultLimit();
1545 abstract function getDefaultDays();