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;
522 $rows = $this->getRows();
523 $opts = $this->getOptions();
524 if ( $rows === false ) {
525 $rows = new FakeResultWrapper( [] );
528 // Used by Structured UI app to get results without MW chrome
529 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
530 $this->getOutput()->setArticleBodyOnly( true );
533 // Used by "live update" and "view newest" to check
534 // if there's new changes with minimal data transfer
535 if ( $this->getRequest()->getBool( 'peek' ) ) {
536 $code = $rows->numRows() > 0 ?
200 : 304;
537 $this->getOutput()->setStatusCode( $code );
541 $batch = new LinkBatch
;
542 foreach ( $rows as $row ) {
543 $batch->add( NS_USER
, $row->rc_user_text
);
544 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
545 $batch->add( $row->rc_namespace
, $row->rc_title
);
546 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
547 $formatter = LogFormatter
::newFromRow( $row );
548 foreach ( $formatter->getPreloadTitles() as $title ) {
549 $batch->addObj( $title );
556 $this->outputHeader();
558 $this->webOutput( $rows, $opts );
562 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
563 // Clean up any bad page entries for titles showing up in RC
564 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
566 LoggerFactory
::getInstance( 'objectcache' )
570 $this->includeRcFiltersApp();
574 * Include the modules and configuration for the RCFilters app.
575 * Conditional on the user having the feature enabled.
577 protected function includeRcFiltersApp() {
578 if ( $this->isStructuredFilterUiEnabled() ) {
579 $out = $this->getOutput();
580 $jsData = $this->getStructuredFilterJsData();
583 foreach ( $jsData['messageKeys'] as $key ) {
584 $messages[$key] = $this->msg( $key )->plain();
588 ResourceLoader
::makeInlineScript(
589 ResourceLoader
::makeMessageSetScript( $messages )
593 $experimentalStructuredChangeFilters =
594 $this->getConfig()->get( 'StructuredChangeFiltersEnableExperimentalViews' );
596 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
597 $out->addJsConfigVars(
598 'wgStructuredChangeFiltersEnableExperimentalViews',
599 $experimentalStructuredChangeFilters
601 $out->addJsConfigVars(
602 'wgStructuredChangeFiltersEnableLiveUpdate',
603 $this->getConfig()->get( 'StructuredChangeFiltersEnableLiveUpdate' )
605 $out->addJsConfigVars(
606 'wgRCFiltersChangeTags',
607 $this->buildChangeTagList()
609 $out->addJsConfigVars(
610 'StructuredChangeFiltersDisplayConfig',
612 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
613 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
614 'limitDefault' => $this->getDefaultLimit(),
615 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
616 'daysDefault' => $this->getDefaultDays(),
623 * Fetch the change tags list for the front end
625 * @return Array Tag data
627 protected function buildChangeTagList() {
628 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
629 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
631 // Hit counts disabled for perf reasons, see T169997
633 $tagStats = ChangeTags::tagUsageStatistics();
634 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
637 arsort( $tagHitCounts );
639 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
641 // Build the list and data
643 foreach ( $tagHitCounts as $tagName => $hits ) {
645 // Only get active tags
646 isset( $explicitlyDefinedTags[ $tagName ] ) ||
647 isset( $softwareActivatedTags[ $tagName ] )
650 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $this->getContext() );
654 'label' => Sanitizer
::stripAllTags(
655 ChangeTags
::tagDescription( $tagName, $this->getContext() )
657 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
658 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
664 // Instead of sorting by hit count (disabled, see above), sort by display name
665 usort( $result, function ( $a, $b ) {
666 return strcasecmp( $a['label'], $b['label'] );
673 * Add the "no results" message to the output
675 protected function outputNoResults() {
676 $this->getOutput()->addHTML(
677 '<div class="mw-changeslist-empty">' .
678 $this->msg( 'recentchanges-noresult' )->parse() .
684 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
686 * @return bool|ResultWrapper Result or false
688 public function getRows() {
689 $opts = $this->getOptions();
696 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
698 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
702 * Get the current FormOptions for this request
704 * @return FormOptions
706 public function getOptions() {
707 if ( $this->rcOptions
=== null ) {
708 $this->rcOptions
= $this->setup( $this->rcSubpage
);
711 return $this->rcOptions
;
715 * Register all filters and their groups (including those from hooks), plus handle
716 * conflicts and defaults.
718 * You might want to customize these in the same method, in subclasses. You can
719 * call getFilterGroup to access a group, and (on the group) getFilter to access a
720 * filter, then make necessary modfications to the filter or group (e.g. with
723 protected function registerFilters() {
724 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
726 // Make sure this is not being transcluded (we don't want to show this
727 // information to all users just because the user that saves the edit can
728 // patrol or is logged in)
729 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
730 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
733 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
735 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
736 $transformedHideCategorizationDef = $this->transformFilterDefinition(
737 $this->hideCategorizationFilterDefinition
740 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
742 $hideCategorization = new ChangesListBooleanFilter(
743 $transformedHideCategorizationDef
747 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
749 $unstructuredGroupDefinition =
750 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
751 $this->getCustomFilters()
753 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
755 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
756 $registered = $userExperienceLevel->getFilter( 'registered' );
757 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
758 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
759 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
761 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
762 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
763 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
765 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
766 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
768 // categoryFilter is conditional; see registerFilters
769 if ( $categoryFilter !== null ) {
770 $hideMinorFilter->conflictsWith(
772 'rcfilters-hideminor-conflicts-typeofchange-global',
773 'rcfilters-hideminor-conflicts-typeofchange',
774 'rcfilters-typeofchange-conflicts-hideminor'
777 $hideMinorFilter->conflictsWith(
779 'rcfilters-hideminor-conflicts-typeofchange-global',
780 'rcfilters-hideminor-conflicts-typeofchange',
781 'rcfilters-typeofchange-conflicts-hideminor'
783 $hideMinorFilter->conflictsWith(
785 'rcfilters-hideminor-conflicts-typeofchange-global',
786 'rcfilters-hideminor-conflicts-typeofchange',
787 'rcfilters-typeofchange-conflicts-hideminor'
792 * Transforms filter definition to prepare it for constructor.
794 * See overrides of this method as well.
796 * @param array $filterDefinition Original filter definition
798 * @return array Transformed definition
800 protected function transformFilterDefinition( array $filterDefinition ) {
801 return $filterDefinition;
805 * Register filters from a definition object
807 * Array specifying groups and their filters; see Filter and
808 * ChangesListFilterGroup constructors.
810 * There is light processing to simplify core maintenance.
812 protected function registerFiltersFromDefinitions( array $definition ) {
813 $autoFillPriority = -1;
814 foreach ( $definition as $groupDefinition ) {
815 if ( !isset( $groupDefinition['priority'] ) ) {
816 $groupDefinition['priority'] = $autoFillPriority;
818 // If it's explicitly specified, start over the auto-fill
819 $autoFillPriority = $groupDefinition['priority'];
824 $className = $groupDefinition['class'];
825 unset( $groupDefinition['class'] );
827 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
828 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
831 $this->registerFilterGroup( new $className( $groupDefinition ) );
836 * Get filter group definition from legacy custom filters
838 * @param array $customFilters Custom filters from legacy hooks
839 * @return array Group definition
841 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
842 // Special internal unstructured group
843 $unstructuredGroupDefinition = [
844 'name' => 'unstructured',
845 'class' => ChangesListBooleanFilterGroup
::class,
846 'priority' => -1, // Won't display in structured
850 foreach ( $customFilters as $name => $params ) {
851 $unstructuredGroupDefinition['filters'][] = [
853 'showHide' => $params['msg'],
854 'default' => $params['default'],
858 return $unstructuredGroupDefinition;
862 * Register all the filters, including legacy hook-driven ones.
863 * Then create a FormOptions object with options as specified by the user
865 * @param array $parameters
867 * @return FormOptions
869 public function setup( $parameters ) {
870 $this->registerFilters();
872 $opts = $this->getDefaultOptions();
874 $opts = $this->fetchOptionsFromRequest( $opts );
876 // Give precedence to subpage syntax
877 if ( $parameters !== null ) {
878 $this->parseParameters( $parameters, $opts );
881 $this->validateOptions( $opts );
887 * Get a FormOptions object containing the default options. By default, returns
888 * some basic options. The filters listed explicitly here are overriden in this
889 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
890 * and more) are structured. Structured filters are overriden in registerFilters.
893 * @return FormOptions
895 public function getDefaultOptions() {
896 $opts = new FormOptions();
897 $structuredUI = $this->isStructuredFilterUiEnabled();
898 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
899 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
902 /** @var ChangesListFilterGroup $filterGroup */
903 foreach ( $this->filterGroups
as $filterGroup ) {
904 // URL parameters can be per-group, like 'userExpLevel',
905 // or per-filter, like 'hideminor'.
906 if ( $filterGroup->isPerGroupRequestParameter() ) {
907 $opts->add( $filterGroup->getName(), $useDefaults ?
$filterGroup->getDefault() : '' );
909 /** @var ChangesListBooleanFilter $filter */
910 foreach ( $filterGroup->getFilters() as $filter ) {
911 $opts->add( $filter->getName(), $useDefaults ?
$filter->getDefault( $structuredUI ) : false );
916 $opts->add( 'namespace', '', FormOptions
::STRING );
917 $opts->add( 'invert', false );
918 $opts->add( 'associated', false );
919 $opts->add( 'urlversion', 1 );
920 $opts->add( 'tagfilter', '' );
926 * Register a structured changes list filter group
928 * @param ChangesListFilterGroup $group
930 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
931 $groupName = $group->getName();
933 $this->filterGroups
[$groupName] = $group;
937 * Gets the currently registered filters groups
939 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
941 protected function getFilterGroups() {
942 return $this->filterGroups
;
946 * Gets a specified ChangesListFilterGroup by name
948 * @param string $groupName Name of group
950 * @return ChangesListFilterGroup|null Group, or null if not registered
952 public function getFilterGroup( $groupName ) {
953 return isset( $this->filterGroups
[$groupName] ) ?
954 $this->filterGroups
[$groupName] :
958 // Currently, this intentionally only includes filters that display
959 // in the structured UI. This can be changed easily, though, if we want
960 // to include data on filters that use the unstructured UI. messageKeys is a
961 // special top-level value, with the value being an array of the message keys to
962 // send to the client.
964 * Gets structured filter information needed by JS
966 * @return array Associative array
967 * * array $return['groups'] Group data
968 * * array $return['messageKeys'] Array of message keys
970 public function getStructuredFilterJsData() {
976 usort( $this->filterGroups
, function ( $a, $b ) {
977 return $b->getPriority() - $a->getPriority();
980 foreach ( $this->filterGroups
as $groupName => $group ) {
981 $groupOutput = $group->getJsData( $this );
982 if ( $groupOutput !== null ) {
983 $output['messageKeys'] = array_merge(
984 $output['messageKeys'],
985 $groupOutput['messageKeys']
988 unset( $groupOutput['messageKeys'] );
989 $output['groups'][] = $groupOutput;
997 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
1000 * @return array Map of filter URL param names to properties (msg/default)
1002 protected function getCustomFilters() {
1003 if ( $this->customFilters
=== null ) {
1004 $this->customFilters
= [];
1005 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
1008 return $this->customFilters
;
1012 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1014 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1016 * @param FormOptions $opts
1017 * @return FormOptions
1019 protected function fetchOptionsFromRequest( $opts ) {
1020 $opts->fetchValuesFromRequest( $this->getRequest() );
1026 * Process $par and put options found in $opts. Used when including the page.
1028 * @param string $par
1029 * @param FormOptions $opts
1031 public function parseParameters( $par, FormOptions
$opts ) {
1032 $stringParameterNameSet = [];
1033 $hideParameterNameSet = [];
1035 // URL parameters can be per-group, like 'userExpLevel',
1036 // or per-filter, like 'hideminor'.
1038 foreach ( $this->filterGroups
as $filterGroup ) {
1039 if ( $filterGroup->isPerGroupRequestParameter() ) {
1040 $stringParameterNameSet[$filterGroup->getName()] = true;
1041 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup
::TYPE
) {
1042 foreach ( $filterGroup->getFilters() as $filter ) {
1043 $hideParameterNameSet[$filter->getName()] = true;
1048 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1049 foreach ( $bits as $bit ) {
1051 if ( isset( $hideParameterNameSet[$bit] ) ) {
1052 // hidefoo => hidefoo=true
1054 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1055 // foo => hidefoo=false
1056 $opts["hide$bit"] = false;
1057 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1058 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1059 $opts[$m[1]] = $m[2];
1066 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1068 * @param FormOptions $opts
1070 public function validateOptions( FormOptions
$opts ) {
1071 if ( $this->fixContradictoryOptions( $opts ) ) {
1072 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1073 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1078 * Fix invalid options by resetting pairs that should never appear together.
1080 * @param FormOptions $opts
1081 * @return bool True if any option was reset
1083 private function fixContradictoryOptions( FormOptions
$opts ) {
1084 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1086 foreach ( $this->filterGroups
as $filterGroup ) {
1087 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
1088 $filters = $filterGroup->getFilters();
1090 if ( count( $filters ) === 1 ) {
1091 // legacy boolean filters should not be considered
1095 $allInGroupEnabled = array_reduce(
1097 function ( $carry, $filter ) use ( $opts ) {
1098 return $carry && $opts[ $filter->getName() ];
1100 /* initialValue */ count( $filters ) > 0
1103 if ( $allInGroupEnabled ) {
1104 foreach ( $filters as $filter ) {
1105 $opts[ $filter->getName() ] = false;
1117 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1120 * This is deprecated and may be removed.
1122 * @param FormOptions $opts
1123 * @return bool True if this change was mode
1125 private function fixBackwardsCompatibilityOptions( FormOptions
$opts ) {
1126 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1127 $opts->reset( 'hideanons' );
1128 if ( !$opts['hidebots'] ) {
1129 $opts->reset( 'hideliu' );
1130 $opts['hidehumans'] = 1;
1140 * Convert parameters values from true/false to 1/0
1141 * so they are not omitted by wfArrayToCgi()
1144 * @param array $params
1147 protected function convertParamsForLink( $params ) {
1148 foreach ( $params as &$value ) {
1149 if ( $value === false ) {
1158 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1159 * the user requested.
1161 * @param array &$tables Array of tables; see IDatabase::select $table
1162 * @param array &$fields Array of fields; see IDatabase::select $vars
1163 * @param array &$conds Array of conditions; see IDatabase::select $conds
1164 * @param array &$query_options Array of query options; see IDatabase::select $options
1165 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1166 * @param FormOptions $opts
1168 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1169 &$join_conds, FormOptions
$opts
1171 $dbr = $this->getDB();
1172 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1174 foreach ( $this->filterGroups
as $filterGroup ) {
1175 // URL parameters can be per-group, like 'userExpLevel',
1176 // or per-filter, like 'hideminor'.
1177 if ( $filterGroup->isPerGroupRequestParameter() ) {
1178 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1179 $query_options, $join_conds, $opts[$filterGroup->getName()] );
1181 foreach ( $filterGroup->getFilters() as $filter ) {
1182 if ( $filter->isActive( $opts, $isStructuredUI ) ) {
1183 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1184 $query_options, $join_conds );
1190 // Namespace filtering
1191 if ( $opts[ 'namespace' ] !== '' ) {
1192 $namespaces = explode( ';', $opts[ 'namespace' ] );
1194 if ( $opts[ 'associated' ] ) {
1195 $associatedNamespaces = array_map(
1197 return MWNamespace
::getAssociated( $ns );
1201 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1204 if ( count( $namespaces ) === 1 ) {
1205 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1206 $value = $dbr->addQuotes( reset( $namespaces ) );
1208 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1209 sort( $namespaces );
1210 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1212 $conds[] = "rc_namespace $operator $value";
1219 * @param array $tables Array of tables; see IDatabase::select $table
1220 * @param array $fields Array of fields; see IDatabase::select $vars
1221 * @param array $conds Array of conditions; see IDatabase::select $conds
1222 * @param array $query_options Array of query options; see IDatabase::select $options
1223 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1224 * @param FormOptions $opts
1225 * @return bool|ResultWrapper Result or false
1227 protected function doMainQuery( $tables, $fields, $conds,
1228 $query_options, $join_conds, FormOptions
$opts
1230 $tables[] = 'recentchanges';
1231 $fields = array_merge( RecentChange
::selectFields(), $fields );
1233 ChangeTags
::modifyDisplayQuery(
1242 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1248 $dbr = $this->getDB();
1250 return $dbr->select(
1260 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1261 &$query_options, &$join_conds, $opts
1264 'ChangesListSpecialPageQuery',
1265 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1270 * Return a IDatabase object for reading
1274 protected function getDB() {
1275 return wfGetDB( DB_REPLICA
);
1279 * Send output to the OutputPage object, only called if not used feeds
1281 * @param ResultWrapper $rows Database rows
1282 * @param FormOptions $opts
1284 public function webOutput( $rows, $opts ) {
1285 if ( !$this->including() ) {
1286 $this->outputFeedLinks();
1287 $this->doHeader( $opts, $rows->numRows() );
1290 $this->outputChangesList( $rows, $opts );
1294 * Output feed links.
1296 public function outputFeedLinks() {
1297 // nothing by default
1301 * Build and output the actual changes list.
1303 * @param ResultWrapper $rows Database rows
1304 * @param FormOptions $opts
1306 abstract public function outputChangesList( $rows, $opts );
1309 * Set the text to be displayed above the changes
1311 * @param FormOptions $opts
1312 * @param int $numRows Number of rows in the result to show after this header
1314 public function doHeader( $opts, $numRows ) {
1315 $this->setTopText( $opts );
1317 // @todo Lots of stuff should be done here.
1319 $this->setBottomText( $opts );
1323 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1324 * or similar methods to print the text.
1326 * @param FormOptions $opts
1328 public function setTopText( FormOptions
$opts ) {
1329 // nothing by default
1333 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1334 * or similar methods to print the text.
1336 * @param FormOptions $opts
1338 public function setBottomText( FormOptions
$opts ) {
1339 // nothing by default
1343 * Get options to be displayed in a form
1344 * @todo This should handle options returned by getDefaultOptions().
1345 * @todo Not called by anything in this class (but is in subclasses), should be
1346 * called by something… doHeader() maybe?
1348 * @param FormOptions $opts
1351 public function getExtraOptions( $opts ) {
1356 * Return the legend displayed within the fieldset
1360 public function makeLegend() {
1361 $context = $this->getContext();
1362 $user = $context->getUser();
1363 # The legend showing what the letters and stuff mean
1364 $legend = Html
::openElement( 'dl' ) . "\n";
1365 # Iterates through them and gets the messages for both letter and tooltip
1366 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1367 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1368 unset( $legendItems['unpatrolled'] );
1370 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1371 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1372 $letter = $item['letter'];
1373 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1375 $legend .= Html
::element( 'dt',
1376 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1378 Html
::rawElement( 'dd',
1379 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1380 $context->msg( $label )->parse()
1384 $legend .= Html
::rawElement( 'dt',
1385 [ 'class' => 'mw-plusminus-pos' ],
1386 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1388 $legend .= Html
::element(
1390 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1391 $context->msg( 'recentchanges-label-plusminus' )->text()
1393 $legend .= Html
::closeElement( 'dl' ) . "\n";
1395 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1396 $context->msg( 'rcfilters-legend-heading' )->parse() :
1397 $context->msg( 'recentchanges-legend-heading' )->parse();
1401 '<div class="mw-changeslist-legend">' .
1403 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1410 * Add page-specific modules.
1412 protected function addModules() {
1413 $out = $this->getOutput();
1414 // Styles and behavior for the legend box (see makeLegend())
1415 $out->addModuleStyles( [
1416 'mediawiki.special.changeslist.legend',
1417 'mediawiki.special.changeslist',
1419 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1421 if ( $this->isStructuredFilterUiEnabled() ) {
1422 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1423 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1427 protected function getGroupName() {
1432 * Filter on users' experience levels; this will not be called if nothing is
1435 * @param string $specialPageClassName Class name of current special page
1436 * @param IContextSource $context Context, for e.g. user
1437 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1438 * @param array &$tables Array of tables; see IDatabase::select $table
1439 * @param array &$fields Array of fields; see IDatabase::select $vars
1440 * @param array &$conds Array of conditions; see IDatabase::select $conds
1441 * @param array &$query_options Array of query options; see IDatabase::select $options
1442 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1443 * @param array $selectedExpLevels The allowed active values, sorted
1444 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1447 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1448 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1450 global $wgLearnerEdits,
1451 $wgExperiencedUserEdits,
1452 $wgLearnerMemberSince,
1453 $wgExperiencedUserMemberSince;
1457 // If all levels are selected, don't filter
1458 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1462 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1464 in_array( 'registered', $selectedExpLevels ) &&
1465 in_array( 'unregistered', $selectedExpLevels )
1470 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1472 in_array( 'registered', $selectedExpLevels ) &&
1473 !in_array( 'unregistered', $selectedExpLevels )
1475 $conds[] = 'rc_user != 0';
1479 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1480 $conds[] = 'rc_user = 0';
1485 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1490 $secondsPerDay = 86400;
1491 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1492 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1494 $aboveNewcomer = $dbr->makeList(
1496 'user_editcount >= ' . intval( $wgLearnerEdits ),
1497 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1502 $aboveLearner = $dbr->makeList(
1504 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1505 'user_registration <= ' .
1506 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1513 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1514 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1515 $conditions[] = 'rc_user = 0';
1518 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1519 $conditions[] = "NOT ( $aboveNewcomer )";
1520 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1521 $conditions[] = $dbr->makeList(
1522 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1525 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1526 $conditions[] = $aboveLearner;
1527 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1528 $conditions[] = "NOT ( $aboveLearner )";
1529 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1530 $conditions[] = $dbr->makeList(
1531 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1534 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1535 $conditions[] = $aboveNewcomer;
1536 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1537 $conditions[] = 'rc_user != 0';
1540 if ( count( $conditions ) > 1 ) {
1541 $conds[] = $dbr->makeList( $conditions, IDatabase
::LIST_OR
);
1542 } elseif ( count( $conditions ) === 1 ) {
1543 $conds[] = reset( $conditions );
1548 * Check whether the structured filter UI is enabled
1552 public function isStructuredFilterUiEnabled() {
1553 return $this->getUser()->getOption( 'rcenhancedfilters' );
1556 abstract function getDefaultLimit();
1558 abstract function getDefaultDays();