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\IDatabase
;
28 * Special page which uses a ChangesList to show query results.
29 * @todo Way too many public functions, most of them should be protected
31 * @ingroup SpecialPage
33 abstract class ChangesListSpecialPage
extends SpecialPage
{
37 /** @var FormOptions */
41 protected $customFilters;
43 // Order of both groups and filters is significant; first is top-most priority,
44 // descending from there.
45 // 'showHideSuffix' is a shortcut to and avoid spelling out
46 // details specific to subclasses here.
48 * Definition information for the filters and their groups
50 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
51 * However, priority is dynamically added for the core groups, to ease maintenance.
53 * Groups are displayed to the user in the structured UI. However, if necessary,
54 * all of the filters in a group can be configured to only display on the
55 * unstuctured UI, in which case you don't need a group title. This is done in
56 * getFilterGroupDefinitionFromLegacyCustomFilters, for example.
58 * @var array $filterGroupDefinitions
60 private $filterGroupDefinitions;
62 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
63 // that is registered conditionally.
64 private $reviewStatusFilterGroupDefinition;
66 // Single filter registered conditionally
67 private $hideCategorizationFilterDefinition;
70 * Filter groups, and their contained filters
71 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
73 * @var array $filterGroups
75 protected $filterGroups = [];
77 public function __construct( $name, $restriction ) {
78 parent
::__construct( $name, $restriction );
80 $this->filterGroupDefinitions
= [
82 'name' => 'registration',
83 'title' => 'rcfilters-filtergroup-registration',
84 'class' => ChangesListBooleanFilterGroup
::class,
88 'label' => 'rcfilters-filter-registered-label',
89 'description' => 'rcfilters-filter-registered-description',
90 // rcshowhideliu-show, rcshowhideliu-hide,
92 'showHideSuffix' => 'showhideliu',
94 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
95 &$query_options, &$join_conds ) {
97 $conds[] = 'rc_user = 0';
99 'cssClassSuffix' => 'liu',
100 'isRowApplicableCallable' => function ( $ctx, $rc ) {
101 return $rc->getAttribute( 'rc_user' );
106 'name' => 'hideanons',
107 'label' => 'rcfilters-filter-unregistered-label',
108 'description' => 'rcfilters-filter-unregistered-description',
109 // rcshowhideanons-show, rcshowhideanons-hide,
111 'showHideSuffix' => 'showhideanons',
113 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
114 &$query_options, &$join_conds ) {
116 $conds[] = 'rc_user != 0';
118 'cssClassSuffix' => 'anon',
119 'isRowApplicableCallable' => function ( $ctx, $rc ) {
120 return !$rc->getAttribute( 'rc_user' );
127 'name' => 'userExpLevel',
128 'title' => 'rcfilters-filtergroup-userExpLevel',
129 'class' => ChangesListStringOptionsFilterGroup
::class,
130 // Excludes unregistered users
131 'isFullCoverage' => false,
134 'name' => 'newcomer',
135 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
136 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
137 'cssClassSuffix' => 'user-newcomer',
138 'isRowApplicableCallable' => function ( $ctx, $rc ) {
139 $performer = $rc->getPerformer();
140 return $performer && $performer->isLoggedIn() &&
141 $performer->getExperienceLevel() === 'newcomer';
146 'label' => 'rcfilters-filter-user-experience-level-learner-label',
147 'description' => 'rcfilters-filter-user-experience-level-learner-description',
148 'cssClassSuffix' => 'user-learner',
149 'isRowApplicableCallable' => function ( $ctx, $rc ) {
150 $performer = $rc->getPerformer();
151 return $performer && $performer->isLoggedIn() &&
152 $performer->getExperienceLevel() === 'learner';
156 'name' => 'experienced',
157 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
158 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
159 'cssClassSuffix' => 'user-experienced',
160 'isRowApplicableCallable' => function ( $ctx, $rc ) {
161 $performer = $rc->getPerformer();
162 return $performer && $performer->isLoggedIn() &&
163 $performer->getExperienceLevel() === 'experienced';
167 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
168 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
172 'name' => 'authorship',
173 'title' => 'rcfilters-filtergroup-authorship',
174 'class' => ChangesListBooleanFilterGroup
::class,
177 'name' => 'hidemyself',
178 'label' => 'rcfilters-filter-editsbyself-label',
179 'description' => 'rcfilters-filter-editsbyself-description',
180 // rcshowhidemine-show, rcshowhidemine-hide,
182 'showHideSuffix' => 'showhidemine',
184 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
185 &$query_options, &$join_conds ) {
187 $user = $ctx->getUser();
188 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
190 'cssClassSuffix' => 'self',
191 'isRowApplicableCallable' => function ( $ctx, $rc ) {
192 return $ctx->getUser()->equals( $rc->getPerformer() );
196 'name' => 'hidebyothers',
197 'label' => 'rcfilters-filter-editsbyother-label',
198 'description' => 'rcfilters-filter-editsbyother-description',
200 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
201 &$query_options, &$join_conds ) {
203 $user = $ctx->getUser();
204 $conds[] = 'rc_user_text = ' . $dbr->addQuotes( $user->getName() );
206 'cssClassSuffix' => 'others',
207 'isRowApplicableCallable' => function ( $ctx, $rc ) {
208 return !$ctx->getUser()->equals( $rc->getPerformer() );
215 'name' => 'automated',
216 'title' => 'rcfilters-filtergroup-automated',
217 'class' => ChangesListBooleanFilterGroup
::class,
220 'name' => 'hidebots',
221 'label' => 'rcfilters-filter-bots-label',
222 'description' => 'rcfilters-filter-bots-description',
223 // rcshowhidebots-show, rcshowhidebots-hide,
225 'showHideSuffix' => 'showhidebots',
227 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
228 &$query_options, &$join_conds ) {
230 $conds[] = 'rc_bot = 0';
232 'cssClassSuffix' => 'bot',
233 'isRowApplicableCallable' => function ( $ctx, $rc ) {
234 return $rc->getAttribute( 'rc_bot' );
238 'name' => 'hidehumans',
239 'label' => 'rcfilters-filter-humans-label',
240 'description' => 'rcfilters-filter-humans-description',
242 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
243 &$query_options, &$join_conds ) {
245 $conds[] = 'rc_bot = 1';
247 'cssClassSuffix' => 'human',
248 'isRowApplicableCallable' => function ( $ctx, $rc ) {
249 return !$rc->getAttribute( 'rc_bot' );
255 // reviewStatus (conditional)
258 'name' => 'lastRevision',
259 'title' => 'rcfilters-filtergroup-lastRevision',
260 'class' => ChangesListBooleanFilterGroup
::class,
264 'name' => 'hidelastrevision',
265 'label' => 'rcfilters-filter-lastrevision-label',
266 'description' => 'rcfilters-filter-lastrevision-description',
268 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
269 &$query_options, &$join_conds ) {
270 $conds[] = 'rc_this_oldid <> page_latest';
272 'cssClassSuffix' => 'last',
273 'isRowApplicableCallable' => function ( $ctx, $rc ) {
274 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
278 'name' => 'hidepreviousrevisions',
279 'label' => 'rcfilters-filter-previousrevision-label',
280 'description' => 'rcfilters-filter-previousrevision-description',
282 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
283 &$query_options, &$join_conds ) {
284 $conds[] = 'rc_this_oldid = page_latest';
286 'cssClassSuffix' => 'previous',
287 'isRowApplicableCallable' => function ( $ctx, $rc ) {
288 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
295 'name' => 'significance',
296 'title' => 'rcfilters-filtergroup-significance',
297 'class' => ChangesListBooleanFilterGroup
::class,
301 'name' => 'hideminor',
302 'label' => 'rcfilters-filter-minor-label',
303 'description' => 'rcfilters-filter-minor-description',
304 // rcshowhideminor-show, rcshowhideminor-hide,
306 'showHideSuffix' => 'showhideminor',
308 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
309 &$query_options, &$join_conds ) {
311 $conds[] = 'rc_minor = 0';
313 'cssClassSuffix' => 'minor',
314 'isRowApplicableCallable' => function ( $ctx, $rc ) {
315 return $rc->getAttribute( 'rc_minor' );
319 'name' => 'hidemajor',
320 'label' => 'rcfilters-filter-major-label',
321 'description' => 'rcfilters-filter-major-description',
323 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
324 &$query_options, &$join_conds ) {
326 $conds[] = 'rc_minor = 1';
328 'cssClassSuffix' => 'major',
329 'isRowApplicableCallable' => function ( $ctx, $rc ) {
330 return !$rc->getAttribute( 'rc_minor' );
336 // With extensions, there can be change types that will not be hidden by any of these.
338 'name' => 'changeType',
339 'title' => 'rcfilters-filtergroup-changetype',
340 'class' => ChangesListBooleanFilterGroup
::class,
343 'name' => 'hidepageedits',
344 'label' => 'rcfilters-filter-pageedits-label',
345 'description' => 'rcfilters-filter-pageedits-description',
348 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
349 &$query_options, &$join_conds ) {
351 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
353 'cssClassSuffix' => 'src-mw-edit',
354 'isRowApplicableCallable' => function ( $ctx, $rc ) {
355 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
359 'name' => 'hidenewpages',
360 'label' => 'rcfilters-filter-newpages-label',
361 'description' => 'rcfilters-filter-newpages-description',
364 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
365 &$query_options, &$join_conds ) {
367 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
369 'cssClassSuffix' => 'src-mw-new',
370 'isRowApplicableCallable' => function ( $ctx, $rc ) {
371 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
375 // hidecategorization
379 'label' => 'rcfilters-filter-logactions-label',
380 'description' => 'rcfilters-filter-logactions-description',
383 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
384 &$query_options, &$join_conds ) {
386 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
388 'cssClassSuffix' => 'src-mw-log',
389 'isRowApplicableCallable' => function ( $ctx, $rc ) {
390 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
397 'name' => 'watchlist',
398 'title' => 'rcfilters-filtergroup-watchlist',
399 'class' => ChangesListStringOptionsFilterGroup
::class,
400 'isFullCoverage' => true,
404 'label' => 'rcfilters-filter-watchlist-watched-label',
405 'description' => 'rcfilters-filter-watchlist-watched-description',
406 'cssClassSuffix' => 'watched',
407 'isRowApplicableCallable' => function ( $ctx, $rc ) {
408 return $rc->getAttribute( 'wl_user' );
412 'name' => 'watchednew',
413 'label' => 'rcfilters-filter-watchlist-watchednew-label',
414 'description' => 'rcfilters-filter-watchlist-watchednew-description',
415 'cssClassSuffix' => 'watchednew',
416 'isRowApplicableCallable' => function ( $ctx, $rc ) {
417 return $rc->getAttribute( 'wl_user' ) &&
418 $rc->getAttribute( 'rc_timestamp' ) > $rc->getAttribute( 'wl_notificationtimestamp' );
422 'name' => 'notwatched',
423 'label' => 'rcfilters-filter-watchlist-notwatched-label',
424 'description' => 'rcfilters-filter-watchlist-notwatched-description',
425 'cssClassSuffix' => 'notwatched',
426 'isRowApplicableCallable' => function ( $ctx, $rc ) {
427 return $rc->getAttribute( 'wl_user' ) === null;
431 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
432 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
433 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
434 sort( $selectedValues );
435 $notwatchedCond = 'wl_user IS NULL';
436 $watchedCond = 'wl_user IS NOT NULL';
437 $newCond = 'rc_timestamp >= wl_notificationtimestamp';
439 if ( $selectedValues === [ 'notwatched' ] ) {
440 $conds[] = $notwatchedCond;
444 if ( $selectedValues === [ 'watched' ] ) {
445 $conds[] = $watchedCond;
449 if ( $selectedValues === [ 'watchednew' ] ) {
450 $conds[] = $dbr->makeList( [
457 if ( $selectedValues === [ 'notwatched', 'watched' ] ) {
462 if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) {
463 $conds[] = $dbr->makeList( [
473 if ( $selectedValues === [ 'watched', 'watchednew' ] ) {
474 $conds[] = $watchedCond;
478 if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) {
486 $this->reviewStatusFilterGroupDefinition
= [
488 'name' => 'reviewStatus',
489 'title' => 'rcfilters-filtergroup-reviewstatus',
490 'class' => ChangesListBooleanFilterGroup
::class,
494 'name' => 'hidepatrolled',
495 'label' => 'rcfilters-filter-patrolled-label',
496 'description' => 'rcfilters-filter-patrolled-description',
497 // rcshowhidepatr-show, rcshowhidepatr-hide
499 'showHideSuffix' => 'showhidepatr',
501 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
502 &$query_options, &$join_conds ) {
504 $conds[] = 'rc_patrolled = 0';
506 'cssClassSuffix' => 'patrolled',
507 'isRowApplicableCallable' => function ( $ctx, $rc ) {
508 return $rc->getAttribute( 'rc_patrolled' );
512 'name' => 'hideunpatrolled',
513 'label' => 'rcfilters-filter-unpatrolled-label',
514 'description' => 'rcfilters-filter-unpatrolled-description',
516 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
517 &$query_options, &$join_conds ) {
519 $conds[] = 'rc_patrolled = 1';
521 'cssClassSuffix' => 'unpatrolled',
522 'isRowApplicableCallable' => function ( $ctx, $rc ) {
523 return !$rc->getAttribute( 'rc_patrolled' );
530 $this->hideCategorizationFilterDefinition
= [
531 'name' => 'hidecategorization',
532 'label' => 'rcfilters-filter-categorization-label',
533 'description' => 'rcfilters-filter-categorization-description',
534 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
535 // wlshowhidecategorization
536 'showHideSuffix' => 'showhidecategorization',
539 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
540 &$query_options, &$join_conds ) {
542 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
544 'cssClassSuffix' => 'src-mw-categorize',
545 'isRowApplicableCallable' => function ( $ctx, $rc ) {
546 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
552 * Check if filters are in conflict and guaranteed to return no results.
556 protected function areFiltersInConflict() {
557 $opts = $this->getOptions();
558 /** @var ChangesListFilterGroup $group */
559 foreach ( $this->getFilterGroups() as $group ) {
561 if ( $group->getConflictingGroups() ) {
564 " specifies conflicts with other groups but these are not supported yet."
568 /** @var ChangesListFilter $conflictingFilter */
569 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
570 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
575 /** @var ChangesListFilter $filter */
576 foreach ( $group->getFilters() as $filter ) {
578 /** @var ChangesListFilter $conflictingFilter */
579 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
581 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
582 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
596 * Main execution point
598 * @param string $subpage
600 public function execute( $subpage ) {
601 $this->rcSubpage
= $subpage;
604 $this->outputHeader();
607 $rows = $this->getRows();
608 $opts = $this->getOptions();
609 if ( $rows === false ) {
610 if ( !$this->including() ) {
611 $this->doHeader( $opts, 0 );
612 $this->outputNoResults();
613 $this->getOutput()->setStatusCode( 404 );
619 $batch = new LinkBatch
;
620 foreach ( $rows as $row ) {
621 $batch->add( NS_USER
, $row->rc_user_text
);
622 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
623 $batch->add( $row->rc_namespace
, $row->rc_title
);
624 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
625 $formatter = LogFormatter
::newFromRow( $row );
626 foreach ( $formatter->getPreloadTitles() as $title ) {
627 $batch->addObj( $title );
632 $this->webOutput( $rows, $opts );
636 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
637 // Clean up any bad page entries for titles showing up in RC
638 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
640 LoggerFactory
::getInstance( 'objectcache' )
646 * Add the "no results" message to the output
648 protected function outputNoResults() {
649 $this->getOutput()->addHTML(
650 '<div class="mw-changeslist-empty">' .
651 $this->msg( 'recentchanges-noresult' )->parse() .
657 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
659 * @return bool|ResultWrapper Result or false
661 public function getRows() {
662 $opts = $this->getOptions();
669 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
671 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
675 * Get the current FormOptions for this request
677 * @return FormOptions
679 public function getOptions() {
680 if ( $this->rcOptions
=== null ) {
681 $this->rcOptions
= $this->setup( $this->rcSubpage
);
684 return $this->rcOptions
;
688 * Register all filters and their groups (including those from hooks), plus handle
689 * conflicts and defaults.
691 * You might want to customize these in the same method, in subclasses. You can
692 * call getFilterGroup to access a group, and (on the group) getFilter to access a
693 * filter, then make necessary modfications to the filter or group (e.g. with
696 protected function registerFilters() {
697 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
699 // Make sure this is not being transcluded (we don't want to show this
700 // information to all users just because the user that saves the edit can
702 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
703 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
706 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
708 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
709 $transformedHideCategorizationDef = $this->transformFilterDefinition(
710 $this->hideCategorizationFilterDefinition
713 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
715 $hideCategorization = new ChangesListBooleanFilter(
716 $transformedHideCategorizationDef
720 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
722 $unstructuredGroupDefinition =
723 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
724 $this->getCustomFilters()
726 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
728 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
730 $registration = $this->getFilterGroup( 'registration' );
731 $anons = $registration->getFilter( 'hideanons' );
733 // This means there is a conflict between any item in user experience level
734 // being checked and only anons being *shown* (hideliu=1&hideanons=0 in the
735 // URL, or equivalent).
736 $userExperienceLevel->conflictsWith(
738 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered-global',
739 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered',
740 'rcfilters-filter-unregistered-conflicts-user-experience-level'
743 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
744 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
745 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
747 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
748 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
750 // categoryFilter is conditional; see registerFilters
751 if ( $categoryFilter !== null ) {
752 $hideMinorFilter->conflictsWith(
754 'rcfilters-hideminor-conflicts-typeofchange-global',
755 'rcfilters-hideminor-conflicts-typeofchange',
756 'rcfilters-typeofchange-conflicts-hideminor'
759 $hideMinorFilter->conflictsWith(
761 'rcfilters-hideminor-conflicts-typeofchange-global',
762 'rcfilters-hideminor-conflicts-typeofchange',
763 'rcfilters-typeofchange-conflicts-hideminor'
765 $hideMinorFilter->conflictsWith(
767 'rcfilters-hideminor-conflicts-typeofchange-global',
768 'rcfilters-hideminor-conflicts-typeofchange',
769 'rcfilters-typeofchange-conflicts-hideminor'
772 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
773 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
774 $watchlistGroup->getFilter( 'watchednew' )
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 Custom filters from legacy hooks
826 * @return array Group definition
828 protected function getFilterGroupDefinitionFromLegacyCustomFilters( $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 $config = $this->getConfig();
884 $opts = new FormOptions();
885 $structuredUI = $this->getUser()->getOption( 'rcenhancedfilters' );
888 foreach ( $this->filterGroups
as $filterGroup ) {
889 // URL parameters can be per-group, like 'userExpLevel',
890 // or per-filter, like 'hideminor'.
891 if ( $filterGroup->isPerGroupRequestParameter() ) {
892 $opts->add( $filterGroup->getName(), $filterGroup->getDefault() );
894 foreach ( $filterGroup->getFilters() as $filter ) {
895 $opts->add( $filter->getName(), $filter->getDefault( $structuredUI ) );
900 $opts->add( 'namespace', '', FormOptions
::INTNULL
);
901 $opts->add( 'invert', false );
902 $opts->add( 'associated', false );
908 * Register a structured changes list filter group
910 * @param ChangesListFilterGroup $group
912 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
913 $groupName = $group->getName();
915 $this->filterGroups
[$groupName] = $group;
919 * Gets the currently registered filters groups
921 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
923 protected function getFilterGroups() {
924 return $this->filterGroups
;
928 * Gets a specified ChangesListFilterGroup by name
930 * @param string $groupName Name of group
932 * @return ChangesListFilterGroup|null Group, or null if not registered
934 public function getFilterGroup( $groupName ) {
935 return isset( $this->filterGroups
[$groupName] ) ?
936 $this->filterGroups
[$groupName] :
940 // Currently, this intentionally only includes filters that display
941 // in the structured UI. This can be changed easily, though, if we want
942 // to include data on filters that use the unstructured UI. messageKeys is a
943 // special top-level value, with the value being an array of the message keys to
944 // send to the client.
946 * Gets structured filter information needed by JS
948 * @return array Associative array
949 * * array $return['groups'] Group data
950 * * array $return['messageKeys'] Array of message keys
952 public function getStructuredFilterJsData() {
958 $context = $this->getContext();
960 usort( $this->filterGroups
, function ( $a, $b ) {
961 return $b->getPriority() - $a->getPriority();
964 foreach ( $this->filterGroups
as $groupName => $group ) {
965 $groupOutput = $group->getJsData( $this );
966 if ( $groupOutput !== null ) {
967 $output['messageKeys'] = array_merge(
968 $output['messageKeys'],
969 $groupOutput['messageKeys']
972 unset( $groupOutput['messageKeys'] );
973 $output['groups'][] = $groupOutput;
981 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
984 * @return array Map of filter URL param names to properties (msg/default)
986 protected function getCustomFilters() {
987 if ( $this->customFilters
=== null ) {
988 $this->customFilters
= [];
989 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
992 return $this->customFilters
;
996 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
998 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1000 * @param FormOptions $opts
1001 * @return FormOptions
1003 protected function fetchOptionsFromRequest( $opts ) {
1004 $opts->fetchValuesFromRequest( $this->getRequest() );
1010 * Process $par and put options found in $opts. Used when including the page.
1012 * @param string $par
1013 * @param FormOptions $opts
1015 public function parseParameters( $par, FormOptions
$opts ) {
1016 $stringParameterNameSet = [];
1017 $hideParameterNameSet = [];
1019 // URL parameters can be per-group, like 'userExpLevel',
1020 // or per-filter, like 'hideminor'.
1022 foreach ( $this->filterGroups
as $filterGroup ) {
1023 if ( $filterGroup->isPerGroupRequestParameter() ) {
1024 $stringParameterNameSet[$filterGroup->getName()] = true;
1025 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup
::TYPE
) {
1026 foreach ( $filterGroup->getFilters() as $filter ) {
1027 $hideParameterNameSet[$filter->getName()] = true;
1032 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1033 foreach ( $bits as $bit ) {
1035 if ( isset( $hideParameterNameSet[$bit] ) ) {
1036 // hidefoo => hidefoo=true
1038 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1039 // foo => hidefoo=false
1040 $opts["hide$bit"] = false;
1041 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1042 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1043 $opts[$m[1]] = $m[2];
1050 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1052 * @param FormOptions $opts
1054 public function validateOptions( FormOptions
$opts ) {
1055 // nothing by default
1059 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1060 * the user requested.
1062 * @param array &$tables Array of tables; see IDatabase::select $table
1063 * @param array &$fields Array of fields; see IDatabase::select $vars
1064 * @param array &$conds Array of conditions; see IDatabase::select $conds
1065 * @param array &$query_options Array of query options; see IDatabase::select $options
1066 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1067 * @param FormOptions $opts
1069 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1070 &$join_conds, FormOptions
$opts ) {
1072 $dbr = $this->getDB();
1073 $user = $this->getUser();
1075 $context = $this->getContext();
1076 foreach ( $this->filterGroups
as $filterGroup ) {
1077 // URL parameters can be per-group, like 'userExpLevel',
1078 // or per-filter, like 'hideminor'.
1079 if ( $filterGroup->isPerGroupRequestParameter() ) {
1080 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1081 $query_options, $join_conds, $opts[$filterGroup->getName()] );
1083 foreach ( $filterGroup->getFilters() as $filter ) {
1084 if ( $opts[$filter->getName()] ) {
1085 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1086 $query_options, $join_conds );
1092 // Namespace filtering
1093 if ( $opts['namespace'] !== '' ) {
1094 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
1095 $operator = $opts['invert'] ?
'!=' : '=';
1096 $boolean = $opts['invert'] ?
'AND' : 'OR';
1098 // Namespace association (T4429)
1099 if ( !$opts['associated'] ) {
1100 $condition = "rc_namespace $operator $selectedNS";
1102 // Also add the associated namespace
1103 $associatedNS = $dbr->addQuotes(
1104 MWNamespace
::getAssociated( $opts['namespace'] )
1106 $condition = "(rc_namespace $operator $selectedNS "
1108 . " rc_namespace $operator $associatedNS)";
1111 $conds[] = $condition;
1118 * @param array $tables Array of tables; see IDatabase::select $table
1119 * @param array $fields Array of fields; see IDatabase::select $vars
1120 * @param array $conds Array of conditions; see IDatabase::select $conds
1121 * @param array $query_options Array of query options; see IDatabase::select $options
1122 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1123 * @param FormOptions $opts
1124 * @return bool|ResultWrapper Result or false
1126 protected function doMainQuery( $tables, $fields, $conds,
1127 $query_options, $join_conds, FormOptions
$opts ) {
1129 $tables[] = 'recentchanges';
1130 $fields = array_merge( RecentChange
::selectFields(), $fields );
1132 ChangeTags
::modifyDisplayQuery(
1141 // It makes no sense to hide both anons and logged-in users. When this occurs, try a guess on
1142 // what the user meant and either show only bots or force anons to be shown.
1146 // XXX: We're no longer doing this handling. To preserve back-compat, we need to complete
1147 // T151873 (particularly the hideanons/hideliu/hidebots/hidehumans part) in conjunction
1148 // with merging this.
1150 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1156 $dbr = $this->getDB();
1158 return $dbr->select(
1168 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1169 &$query_options, &$join_conds, $opts
1172 'ChangesListSpecialPageQuery',
1173 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1178 * Return a IDatabase object for reading
1182 protected function getDB() {
1183 return wfGetDB( DB_REPLICA
);
1187 * Send output to the OutputPage object, only called if not used feeds
1189 * @param ResultWrapper $rows Database rows
1190 * @param FormOptions $opts
1192 public function webOutput( $rows, $opts ) {
1193 if ( !$this->including() ) {
1194 $this->outputFeedLinks();
1195 $this->doHeader( $opts, $rows->numRows() );
1198 $this->outputChangesList( $rows, $opts );
1202 * Output feed links.
1204 public function outputFeedLinks() {
1205 // nothing by default
1209 * Build and output the actual changes list.
1211 * @param ResultWrapper $rows Database rows
1212 * @param FormOptions $opts
1214 abstract public function outputChangesList( $rows, $opts );
1217 * Set the text to be displayed above the changes
1219 * @param FormOptions $opts
1220 * @param int $numRows Number of rows in the result to show after this header
1222 public function doHeader( $opts, $numRows ) {
1223 $this->setTopText( $opts );
1225 // @todo Lots of stuff should be done here.
1227 $this->setBottomText( $opts );
1231 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1232 * or similar methods to print the text.
1234 * @param FormOptions $opts
1236 public function setTopText( FormOptions
$opts ) {
1237 // nothing by default
1241 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1242 * or similar methods to print the text.
1244 * @param FormOptions $opts
1246 public function setBottomText( FormOptions
$opts ) {
1247 // nothing by default
1251 * Get options to be displayed in a form
1252 * @todo This should handle options returned by getDefaultOptions().
1253 * @todo Not called by anything in this class (but is in subclasses), should be
1254 * called by something… doHeader() maybe?
1256 * @param FormOptions $opts
1259 public function getExtraOptions( $opts ) {
1264 * Return the legend displayed within the fieldset
1268 public function makeLegend() {
1269 $context = $this->getContext();
1270 $user = $context->getUser();
1271 # The legend showing what the letters and stuff mean
1272 $legend = Html
::openElement( 'dl' ) . "\n";
1273 # Iterates through them and gets the messages for both letter and tooltip
1274 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1275 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1276 unset( $legendItems['unpatrolled'] );
1278 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1279 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1280 $letter = $item['letter'];
1281 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1283 $legend .= Html
::element( 'dt',
1284 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1286 Html
::rawElement( 'dd',
1287 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1288 $context->msg( $label )->parse()
1292 $legend .= Html
::rawElement( 'dt',
1293 [ 'class' => 'mw-plusminus-pos' ],
1294 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1296 $legend .= Html
::element(
1298 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1299 $context->msg( 'recentchanges-label-plusminus' )->text()
1301 $legend .= Html
::closeElement( 'dl' ) . "\n";
1305 '<div class="mw-changeslist-legend">' .
1306 $context->msg( 'recentchanges-legend-heading' )->parse() .
1307 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1314 * Add page-specific modules.
1316 protected function addModules() {
1317 $out = $this->getOutput();
1318 // Styles and behavior for the legend box (see makeLegend())
1319 $out->addModuleStyles( [
1320 'mediawiki.special.changeslist.legend',
1321 'mediawiki.special.changeslist',
1323 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1326 protected function getGroupName() {
1331 * Filter on users' experience levels; this will not be called if nothing is
1334 * @param string $specialPageClassName Class name of current special page
1335 * @param IContextSource $context Context, for e.g. user
1336 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1337 * @param array &$tables Array of tables; see IDatabase::select $table
1338 * @param array &$fields Array of fields; see IDatabase::select $vars
1339 * @param array &$conds Array of conditions; see IDatabase::select $conds
1340 * @param array &$query_options Array of query options; see IDatabase::select $options
1341 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1342 * @param array $selectedExpLevels The allowed active values, sorted
1344 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1345 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0 ) {
1347 global $wgLearnerEdits,
1348 $wgExperiencedUserEdits,
1349 $wgLearnerMemberSince,
1350 $wgExperiencedUserMemberSince;
1354 // If all levels are selected, all logged-in users are included (but no
1355 // anons), so we can short-circuit.
1356 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1357 $conds[] = 'rc_user != 0';
1362 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1367 $secondsPerDay = 86400;
1368 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1369 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1371 $aboveNewcomer = $dbr->makeList(
1373 'user_editcount >= ' . intval( $wgLearnerEdits ),
1374 'user_registration <= ' . $dbr->timestamp( $learnerCutoff ),
1379 $aboveLearner = $dbr->makeList(
1381 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1382 'user_registration <= ' . $dbr->timestamp( $experiencedUserCutoff ),
1387 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1388 $conds[] = "NOT ( $aboveNewcomer )";
1389 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1390 $conds[] = $dbr->makeList(
1391 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1394 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1395 $conds[] = $aboveLearner;
1396 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1397 $conds[] = "NOT ( $aboveLearner )";
1398 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1399 $conds[] = $dbr->makeList(
1400 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1403 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1404 $conds[] = $aboveNewcomer;