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 $this->reviewStatusFilterGroupDefinition
= [
399 'name' => 'reviewStatus',
400 'title' => 'rcfilters-filtergroup-reviewstatus',
401 'class' => ChangesListBooleanFilterGroup
::class,
405 'name' => 'hidepatrolled',
406 'label' => 'rcfilters-filter-patrolled-label',
407 'description' => 'rcfilters-filter-patrolled-description',
408 // rcshowhidepatr-show, rcshowhidepatr-hide
410 'showHideSuffix' => 'showhidepatr',
412 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
413 &$query_options, &$join_conds ) {
415 $conds[] = 'rc_patrolled = 0';
417 'cssClassSuffix' => 'patrolled',
418 'isRowApplicableCallable' => function ( $ctx, $rc ) {
419 return $rc->getAttribute( 'rc_patrolled' );
423 'name' => 'hideunpatrolled',
424 'label' => 'rcfilters-filter-unpatrolled-label',
425 'description' => 'rcfilters-filter-unpatrolled-description',
427 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
428 &$query_options, &$join_conds ) {
430 $conds[] = 'rc_patrolled = 1';
432 'cssClassSuffix' => 'unpatrolled',
433 'isRowApplicableCallable' => function ( $ctx, $rc ) {
434 return !$rc->getAttribute( 'rc_patrolled' );
441 $this->hideCategorizationFilterDefinition
= [
442 'name' => 'hidecategorization',
443 'label' => 'rcfilters-filter-categorization-label',
444 'description' => 'rcfilters-filter-categorization-description',
445 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
446 // wlshowhidecategorization
447 'showHideSuffix' => 'showhidecategorization',
450 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
451 &$query_options, &$join_conds ) {
453 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
455 'cssClassSuffix' => 'src-mw-categorize',
456 'isRowApplicableCallable' => function ( $ctx, $rc ) {
457 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
463 * Check if filters are in conflict and guaranteed to return no results.
467 protected function areFiltersInConflict() {
468 $opts = $this->getOptions();
469 /** @var ChangesListFilterGroup $group */
470 foreach ( $this->getFilterGroups() as $group ) {
472 if ( $group->getConflictingGroups() ) {
475 " specifies conflicts with other groups but these are not supported yet."
479 /** @var ChangesListFilter $conflictingFilter */
480 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
481 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
486 /** @var ChangesListFilter $filter */
487 foreach ( $group->getFilters() as $filter ) {
489 /** @var ChangesListFilter $conflictingFilter */
490 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
492 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
493 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
507 * Main execution point
509 * @param string $subpage
511 public function execute( $subpage ) {
512 $this->rcSubpage
= $subpage;
515 $this->outputHeader();
518 $rows = $this->getRows();
519 $opts = $this->getOptions();
520 if ( $rows === false ) {
521 if ( !$this->including() ) {
522 $this->doHeader( $opts, 0 );
523 $this->outputNoResults();
524 $this->getOutput()->setStatusCode( 404 );
530 $batch = new LinkBatch
;
531 foreach ( $rows as $row ) {
532 $batch->add( NS_USER
, $row->rc_user_text
);
533 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
534 $batch->add( $row->rc_namespace
, $row->rc_title
);
535 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
536 $formatter = LogFormatter
::newFromRow( $row );
537 foreach ( $formatter->getPreloadTitles() as $title ) {
538 $batch->addObj( $title );
543 $this->webOutput( $rows, $opts );
547 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
548 // Clean up any bad page entries for titles showing up in RC
549 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
551 LoggerFactory
::getInstance( 'objectcache' )
557 * Add the "no results" message to the output
559 protected function outputNoResults() {
560 $this->getOutput()->addHTML(
561 '<div class="mw-changeslist-empty">' .
562 $this->msg( 'recentchanges-noresult' )->parse() .
568 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
570 * @return bool|ResultWrapper Result or false
572 public function getRows() {
573 $opts = $this->getOptions();
580 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
582 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
586 * Get the current FormOptions for this request
588 * @return FormOptions
590 public function getOptions() {
591 if ( $this->rcOptions
=== null ) {
592 $this->rcOptions
= $this->setup( $this->rcSubpage
);
595 return $this->rcOptions
;
599 * Register all filters and their groups (including those from hooks), plus handle
600 * conflicts and defaults.
602 * You might want to customize these in the same method, in subclasses. You can
603 * call getFilterGroup to access a group, and (on the group) getFilter to access a
604 * filter, then make necessary modfications to the filter or group (e.g. with
607 protected function registerFilters() {
608 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
610 // Make sure this is not being transcluded (we don't want to show this
611 // information to all users just because the user that saves the edit can
613 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
614 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition
);
617 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
619 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
620 $transformedHideCategorizationDef = $this->transformFilterDefinition(
621 $this->hideCategorizationFilterDefinition
624 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
626 $hideCategorization = new ChangesListBooleanFilter(
627 $transformedHideCategorizationDef
631 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
633 $unstructuredGroupDefinition =
634 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
635 $this->getCustomFilters()
637 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
639 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
641 $registration = $this->getFilterGroup( 'registration' );
642 $anons = $registration->getFilter( 'hideanons' );
644 // This means there is a conflict between any item in user experience level
645 // being checked and only anons being *shown* (hideliu=1&hideanons=0 in the
646 // URL, or equivalent).
647 $userExperienceLevel->conflictsWith(
649 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered-global',
650 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered',
651 'rcfilters-filter-unregistered-conflicts-user-experience-level'
654 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
655 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
656 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
658 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
659 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
661 // categoryFilter is conditional; see registerFilters
662 if ( $categoryFilter !== null ) {
663 $hideMinorFilter->conflictsWith(
665 'rcfilters-hideminor-conflicts-typeofchange-global',
666 'rcfilters-hideminor-conflicts-typeofchange',
667 'rcfilters-typeofchange-conflicts-hideminor'
670 $hideMinorFilter->conflictsWith(
672 'rcfilters-hideminor-conflicts-typeofchange-global',
673 'rcfilters-hideminor-conflicts-typeofchange',
674 'rcfilters-typeofchange-conflicts-hideminor'
676 $hideMinorFilter->conflictsWith(
678 'rcfilters-hideminor-conflicts-typeofchange-global',
679 'rcfilters-hideminor-conflicts-typeofchange',
680 'rcfilters-typeofchange-conflicts-hideminor'
685 * Transforms filter definition to prepare it for constructor.
687 * See overrides of this method as well.
689 * @param array $filterDefinition Original filter definition
691 * @return array Transformed definition
693 protected function transformFilterDefinition( array $filterDefinition ) {
694 return $filterDefinition;
698 * Register filters from a definition object
700 * Array specifying groups and their filters; see Filter and
701 * ChangesListFilterGroup constructors.
703 * There is light processing to simplify core maintenance.
705 protected function registerFiltersFromDefinitions( array $definition ) {
706 $autoFillPriority = -1;
707 foreach ( $definition as $groupDefinition ) {
708 if ( !isset( $groupDefinition['priority'] ) ) {
709 $groupDefinition['priority'] = $autoFillPriority;
711 // If it's explicitly specified, start over the auto-fill
712 $autoFillPriority = $groupDefinition['priority'];
717 $className = $groupDefinition['class'];
718 unset( $groupDefinition['class'] );
720 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
721 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
724 $this->registerFilterGroup( new $className( $groupDefinition ) );
729 * Get filter group definition from legacy custom filters
731 * @param array Custom filters from legacy hooks
732 * @return array Group definition
734 protected function getFilterGroupDefinitionFromLegacyCustomFilters( $customFilters ) {
735 // Special internal unstructured group
736 $unstructuredGroupDefinition = [
737 'name' => 'unstructured',
738 'class' => ChangesListBooleanFilterGroup
::class,
739 'priority' => -1, // Won't display in structured
743 foreach ( $customFilters as $name => $params ) {
744 $unstructuredGroupDefinition['filters'][] = [
746 'showHide' => $params['msg'],
747 'default' => $params['default'],
751 return $unstructuredGroupDefinition;
755 * Register all the filters, including legacy hook-driven ones.
756 * Then create a FormOptions object with options as specified by the user
758 * @param array $parameters
760 * @return FormOptions
762 public function setup( $parameters ) {
763 $this->registerFilters();
765 $opts = $this->getDefaultOptions();
767 $opts = $this->fetchOptionsFromRequest( $opts );
769 // Give precedence to subpage syntax
770 if ( $parameters !== null ) {
771 $this->parseParameters( $parameters, $opts );
774 $this->validateOptions( $opts );
780 * Get a FormOptions object containing the default options. By default, returns
781 * some basic options. The filters listed explicitly here are overriden in this
782 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
783 * and more) are structured. Structured filters are overriden in registerFilters.
786 * @return FormOptions
788 public function getDefaultOptions() {
789 $config = $this->getConfig();
790 $opts = new FormOptions();
791 $structuredUI = $this->getUser()->getOption( 'rcenhancedfilters' );
794 foreach ( $this->filterGroups
as $filterGroup ) {
795 // URL parameters can be per-group, like 'userExpLevel',
796 // or per-filter, like 'hideminor'.
797 if ( $filterGroup->isPerGroupRequestParameter() ) {
798 $opts->add( $filterGroup->getName(), $filterGroup->getDefault() );
800 foreach ( $filterGroup->getFilters() as $filter ) {
801 $opts->add( $filter->getName(), $filter->getDefault( $structuredUI ) );
806 $opts->add( 'namespace', '', FormOptions
::STRING );
807 $opts->add( 'invert', false );
808 $opts->add( 'associated', false );
814 * Register a structured changes list filter group
816 * @param ChangesListFilterGroup $group
818 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
819 $groupName = $group->getName();
821 $this->filterGroups
[$groupName] = $group;
825 * Gets the currently registered filters groups
827 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
829 protected function getFilterGroups() {
830 return $this->filterGroups
;
834 * Gets a specified ChangesListFilterGroup by name
836 * @param string $groupName Name of group
838 * @return ChangesListFilterGroup|null Group, or null if not registered
840 public function getFilterGroup( $groupName ) {
841 return isset( $this->filterGroups
[$groupName] ) ?
842 $this->filterGroups
[$groupName] :
846 // Currently, this intentionally only includes filters that display
847 // in the structured UI. This can be changed easily, though, if we want
848 // to include data on filters that use the unstructured UI. messageKeys is a
849 // special top-level value, with the value being an array of the message keys to
850 // send to the client.
852 * Gets structured filter information needed by JS
854 * @return array Associative array
855 * * array $return['groups'] Group data
856 * * array $return['messageKeys'] Array of message keys
858 public function getStructuredFilterJsData() {
864 $context = $this->getContext();
866 usort( $this->filterGroups
, function ( $a, $b ) {
867 return $b->getPriority() - $a->getPriority();
870 foreach ( $this->filterGroups
as $groupName => $group ) {
871 $groupOutput = $group->getJsData( $this );
872 if ( $groupOutput !== null ) {
873 $output['messageKeys'] = array_merge(
874 $output['messageKeys'],
875 $groupOutput['messageKeys']
878 unset( $groupOutput['messageKeys'] );
879 $output['groups'][] = $groupOutput;
887 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
890 * @return array Map of filter URL param names to properties (msg/default)
892 protected function getCustomFilters() {
893 if ( $this->customFilters
=== null ) {
894 $this->customFilters
= [];
895 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
898 return $this->customFilters
;
902 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
904 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
906 * @param FormOptions $opts
907 * @return FormOptions
909 protected function fetchOptionsFromRequest( $opts ) {
910 $opts->fetchValuesFromRequest( $this->getRequest() );
916 * Process $par and put options found in $opts. Used when including the page.
919 * @param FormOptions $opts
921 public function parseParameters( $par, FormOptions
$opts ) {
922 $stringParameterNameSet = [];
923 $hideParameterNameSet = [];
925 // URL parameters can be per-group, like 'userExpLevel',
926 // or per-filter, like 'hideminor'.
928 foreach ( $this->filterGroups
as $filterGroup ) {
929 if ( $filterGroup->isPerGroupRequestParameter() ) {
930 $stringParameterNameSet[$filterGroup->getName()] = true;
931 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup
::TYPE
) {
932 foreach ( $filterGroup->getFilters() as $filter ) {
933 $hideParameterNameSet[$filter->getName()] = true;
938 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
939 foreach ( $bits as $bit ) {
941 if ( isset( $hideParameterNameSet[$bit] ) ) {
942 // hidefoo => hidefoo=true
944 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
945 // foo => hidefoo=false
946 $opts["hide$bit"] = false;
947 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
948 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
949 $opts[$m[1]] = $m[2];
956 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
958 * @param FormOptions $opts
960 public function validateOptions( FormOptions
$opts ) {
961 // nothing by default
965 * Sets appropriate tables, fields, conditions, etc. depending on which filters
966 * the user requested.
968 * @param array &$tables Array of tables; see IDatabase::select $table
969 * @param array &$fields Array of fields; see IDatabase::select $vars
970 * @param array &$conds Array of conditions; see IDatabase::select $conds
971 * @param array &$query_options Array of query options; see IDatabase::select $options
972 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
973 * @param FormOptions $opts
975 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
976 &$join_conds, FormOptions
$opts ) {
978 $dbr = $this->getDB();
979 $user = $this->getUser();
981 $context = $this->getContext();
982 foreach ( $this->filterGroups
as $filterGroup ) {
983 // URL parameters can be per-group, like 'userExpLevel',
984 // or per-filter, like 'hideminor'.
985 if ( $filterGroup->isPerGroupRequestParameter() ) {
986 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
987 $query_options, $join_conds, $opts[$filterGroup->getName()] );
989 foreach ( $filterGroup->getFilters() as $filter ) {
990 if ( $opts[$filter->getName()] ) {
991 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
992 $query_options, $join_conds );
998 // Namespace filtering
999 if ( $opts[ 'namespace' ] !== '' ) {
1000 $namespaces = explode( ',', $opts[ 'namespace' ] );
1002 if ( $opts[ 'associated' ] ) {
1003 $associatedNamespaces = array_map(
1005 return MWNamespace
::getAssociated( $ns );
1009 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1012 if ( count( $namespaces ) === 1 ) {
1013 $operator = $opts[ 'invert' ] ?
'!=' : '=';
1014 $value = $dbr->addQuotes( reset( $namespaces ) );
1016 $operator = $opts[ 'invert' ] ?
'NOT IN' : 'IN';
1017 sort( $namespaces );
1018 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1020 $conds[] = "rc_namespace $operator $value";
1027 * @param array $tables Array of tables; see IDatabase::select $table
1028 * @param array $fields Array of fields; see IDatabase::select $vars
1029 * @param array $conds Array of conditions; see IDatabase::select $conds
1030 * @param array $query_options Array of query options; see IDatabase::select $options
1031 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1032 * @param FormOptions $opts
1033 * @return bool|ResultWrapper Result or false
1035 protected function doMainQuery( $tables, $fields, $conds,
1036 $query_options, $join_conds, FormOptions
$opts ) {
1038 $tables[] = 'recentchanges';
1039 $fields = array_merge( RecentChange
::selectFields(), $fields );
1041 ChangeTags
::modifyDisplayQuery(
1050 // It makes no sense to hide both anons and logged-in users. When this occurs, try a guess on
1051 // what the user meant and either show only bots or force anons to be shown.
1055 // XXX: We're no longer doing this handling. To preserve back-compat, we need to complete
1056 // T151873 (particularly the hideanons/hideliu/hidebots/hidehumans part) in conjunction
1057 // with merging this.
1059 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1065 $dbr = $this->getDB();
1067 return $dbr->select(
1077 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1078 &$query_options, &$join_conds, $opts
1081 'ChangesListSpecialPageQuery',
1082 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1087 * Return a IDatabase object for reading
1091 protected function getDB() {
1092 return wfGetDB( DB_REPLICA
);
1096 * Send output to the OutputPage object, only called if not used feeds
1098 * @param ResultWrapper $rows Database rows
1099 * @param FormOptions $opts
1101 public function webOutput( $rows, $opts ) {
1102 if ( !$this->including() ) {
1103 $this->outputFeedLinks();
1104 $this->doHeader( $opts, $rows->numRows() );
1107 $this->outputChangesList( $rows, $opts );
1111 * Output feed links.
1113 public function outputFeedLinks() {
1114 // nothing by default
1118 * Build and output the actual changes list.
1120 * @param ResultWrapper $rows Database rows
1121 * @param FormOptions $opts
1123 abstract public function outputChangesList( $rows, $opts );
1126 * Set the text to be displayed above the changes
1128 * @param FormOptions $opts
1129 * @param int $numRows Number of rows in the result to show after this header
1131 public function doHeader( $opts, $numRows ) {
1132 $this->setTopText( $opts );
1134 // @todo Lots of stuff should be done here.
1136 $this->setBottomText( $opts );
1140 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1141 * or similar methods to print the text.
1143 * @param FormOptions $opts
1145 public function setTopText( FormOptions
$opts ) {
1146 // nothing by default
1150 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1151 * or similar methods to print the text.
1153 * @param FormOptions $opts
1155 public function setBottomText( FormOptions
$opts ) {
1156 // nothing by default
1160 * Get options to be displayed in a form
1161 * @todo This should handle options returned by getDefaultOptions().
1162 * @todo Not called by anything in this class (but is in subclasses), should be
1163 * called by something… doHeader() maybe?
1165 * @param FormOptions $opts
1168 public function getExtraOptions( $opts ) {
1173 * Return the legend displayed within the fieldset
1177 public function makeLegend() {
1178 $context = $this->getContext();
1179 $user = $context->getUser();
1180 # The legend showing what the letters and stuff mean
1181 $legend = Html
::openElement( 'dl' ) . "\n";
1182 # Iterates through them and gets the messages for both letter and tooltip
1183 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1184 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1185 unset( $legendItems['unpatrolled'] );
1187 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1188 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1189 $letter = $item['letter'];
1190 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1192 $legend .= Html
::element( 'dt',
1193 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1195 Html
::rawElement( 'dd',
1196 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1197 $context->msg( $label )->parse()
1201 $legend .= Html
::rawElement( 'dt',
1202 [ 'class' => 'mw-plusminus-pos' ],
1203 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1205 $legend .= Html
::element(
1207 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1208 $context->msg( 'recentchanges-label-plusminus' )->text()
1210 $legend .= Html
::closeElement( 'dl' ) . "\n";
1214 '<div class="mw-changeslist-legend">' .
1215 $context->msg( 'recentchanges-legend-heading' )->parse() .
1216 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1223 * Add page-specific modules.
1225 protected function addModules() {
1226 $out = $this->getOutput();
1227 // Styles and behavior for the legend box (see makeLegend())
1228 $out->addModuleStyles( [
1229 'mediawiki.special.changeslist.legend',
1230 'mediawiki.special.changeslist',
1232 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1235 protected function getGroupName() {
1240 * Filter on users' experience levels; this will not be called if nothing is
1243 * @param string $specialPageClassName Class name of current special page
1244 * @param IContextSource $context Context, for e.g. user
1245 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1246 * @param array &$tables Array of tables; see IDatabase::select $table
1247 * @param array &$fields Array of fields; see IDatabase::select $vars
1248 * @param array &$conds Array of conditions; see IDatabase::select $conds
1249 * @param array &$query_options Array of query options; see IDatabase::select $options
1250 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1251 * @param array $selectedExpLevels The allowed active values, sorted
1253 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1254 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels ) {
1256 global $wgLearnerEdits,
1257 $wgExperiencedUserEdits,
1258 $wgLearnerMemberSince,
1259 $wgExperiencedUserMemberSince;
1263 // If all levels are selected, all logged-in users are included (but no
1264 // anons), so we can short-circuit.
1265 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1266 $conds[] = 'rc_user != 0';
1271 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1274 $secondsPerDay = 86400;
1275 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1276 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1278 $aboveNewcomer = $dbr->makeList(
1280 'user_editcount >= ' . intval( $wgLearnerEdits ),
1281 'user_registration <= ' . $dbr->timestamp( $learnerCutoff ),
1286 $aboveLearner = $dbr->makeList(
1288 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1289 'user_registration <= ' . $dbr->timestamp( $experiencedUserCutoff ),
1294 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1295 $conds[] = "NOT ( $aboveNewcomer )";
1296 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1297 $conds[] = $dbr->makeList(
1298 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1301 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1302 $conds[] = $aboveLearner;
1303 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1304 $conds[] = "NOT ( $aboveLearner )";
1305 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1306 $conds[] = $dbr->makeList(
1307 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1310 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1311 $conds[] = $aboveNewcomer;