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
;
27 * Special page which uses a ChangesList to show query results.
28 * @todo Way too many public functions, most of them should be protected
30 * @ingroup SpecialPage
32 abstract class ChangesListSpecialPage
extends SpecialPage
{
36 /** @var FormOptions */
40 protected $customFilters;
42 // Order of both groups and filters is significant; first is top-most priority,
43 // descending from there.
44 // 'showHideSuffix' is a shortcut to and avoid spelling out
45 // details specific to subclasses here.
47 * Definition information for the filters and their groups
49 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
50 * However, priority is dynamically added for the core groups, to ease maintenance.
52 * Groups are displayed to the user in the structured UI. However, if necessary,
53 * all of the filters in a group can be configured to only display on the
54 * unstuctured UI, in which case you don't need a group title. This is done in
55 * getFilterGroupDefinitionFromLegacyCustomFilters, for example.
57 * @var array $filterGroupDefinitions
59 private $filterGroupDefinitions;
62 * Filter groups, and their contained filters
63 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
65 * @var array $filterGroups
67 protected $filterGroups = [];
69 public function __construct( $name, $restriction ) {
70 parent
::__construct( $name, $restriction );
72 $this->filterGroupDefinitions
= [
74 'name' => 'registration',
75 'title' => 'rcfilters-filtergroup-registration',
76 'class' => ChangesListBooleanFilterGroup
::class,
80 'label' => 'rcfilters-filter-registered-label',
81 'description' => 'rcfilters-filter-registered-description',
82 // rcshowhideliu-show, rcshowhideliu-hide,
84 'showHideSuffix' => 'showhideliu',
86 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
87 &$query_options, &$join_conds ) {
89 $conds[] = 'rc_user = 0';
91 'cssClassSuffix' => 'liu',
92 'isRowApplicableCallable' => function ( $ctx, $rc ) {
93 return $rc->getAttribute( 'rc_user' );
98 'name' => 'hideanons',
99 'label' => 'rcfilters-filter-unregistered-label',
100 'description' => 'rcfilters-filter-unregistered-description',
101 // rcshowhideanons-show, rcshowhideanons-hide,
103 'showHideSuffix' => 'showhideanons',
105 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
106 &$query_options, &$join_conds ) {
108 $conds[] = 'rc_user != 0';
110 'cssClassSuffix' => 'anon',
111 'isRowApplicableCallable' => function ( $ctx, $rc ) {
112 return !$rc->getAttribute( 'rc_user' );
119 'name' => 'userExpLevel',
120 'title' => 'rcfilters-filtergroup-userExpLevel',
121 'class' => ChangesListStringOptionsFilterGroup
::class,
122 // Excludes unregistered users
123 'isFullCoverage' => false,
126 'name' => 'newcomer',
127 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
128 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
129 'cssClassSuffix' => 'user-newcomer',
130 'isRowApplicableCallable' => function ( $ctx, $rc ) {
131 $performer = $rc->getPerformer();
132 return $performer && $performer->isLoggedIn() &&
133 $performer->getExperienceLevel() === 'newcomer';
138 'label' => 'rcfilters-filter-user-experience-level-learner-label',
139 'description' => 'rcfilters-filter-user-experience-level-learner-description',
140 'cssClassSuffix' => 'user-learner',
141 'isRowApplicableCallable' => function ( $ctx, $rc ) {
142 $performer = $rc->getPerformer();
143 return $performer && $performer->isLoggedIn() &&
144 $performer->getExperienceLevel() === 'learner';
148 'name' => 'experienced',
149 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
150 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
151 'cssClassSuffix' => 'user-experienced',
152 'isRowApplicableCallable' => function ( $ctx, $rc ) {
153 $performer = $rc->getPerformer();
154 return $performer && $performer->isLoggedIn() &&
155 $performer->getExperienceLevel() === 'experienced';
159 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
160 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
164 'name' => 'authorship',
165 'title' => 'rcfilters-filtergroup-authorship',
166 'class' => ChangesListBooleanFilterGroup
::class,
169 'name' => 'hidemyself',
170 'label' => 'rcfilters-filter-editsbyself-label',
171 'description' => 'rcfilters-filter-editsbyself-description',
172 // rcshowhidemine-show, rcshowhidemine-hide,
174 'showHideSuffix' => 'showhidemine',
176 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
177 &$query_options, &$join_conds ) {
179 $user = $ctx->getUser();
180 if ( $user->getId() ) {
181 $conds[] = 'rc_user != ' . $dbr->addQuotes( $user->getId() );
183 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
186 'cssClassSuffix' => 'self',
187 'isRowApplicableCallable' => function ( $ctx, $rc ) {
188 return $ctx->getUser()->equals( $rc->getPerformer() );
192 'name' => 'hidebyothers',
193 'label' => 'rcfilters-filter-editsbyother-label',
194 'description' => 'rcfilters-filter-editsbyother-description',
196 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
197 &$query_options, &$join_conds ) {
199 $user = $ctx->getUser();
200 if ( $user->getId() ) {
201 $conds[] = 'rc_user = ' . $dbr->addQuotes( $user->getId() );
203 $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' );
256 'name' => 'reviewStatus',
257 'title' => 'rcfilters-filtergroup-reviewstatus',
258 'class' => ChangesListBooleanFilterGroup
::class,
261 'name' => 'hidepatrolled',
262 'label' => 'rcfilters-filter-patrolled-label',
263 'description' => 'rcfilters-filter-patrolled-description',
264 // rcshowhidepatr-show, rcshowhidepatr-hide
266 'showHideSuffix' => 'showhidepatr',
268 'isAllowedCallable' => function ( $pageClassName, $context ) {
269 return $context->getUser()->useRCPatrol();
271 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
272 &$query_options, &$join_conds ) {
274 $conds[] = 'rc_patrolled = 0';
276 'cssClassSuffix' => 'patrolled',
277 'isRowApplicableCallable' => function ( $ctx, $rc ) {
278 return $rc->getAttribute( 'rc_patrolled' );
282 'name' => 'hideunpatrolled',
283 'label' => 'rcfilters-filter-unpatrolled-label',
284 'description' => 'rcfilters-filter-unpatrolled-description',
286 'isAllowedCallable' => function ( $pageClassName, $context ) {
287 return $context->getUser()->useRCPatrol();
289 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
290 &$query_options, &$join_conds ) {
292 $conds[] = 'rc_patrolled = 1';
294 'cssClassSuffix' => 'unpatrolled',
295 'isRowApplicableCallable' => function ( $ctx, $rc ) {
296 return !$rc->getAttribute( 'rc_patrolled' );
303 'name' => 'significance',
304 'title' => 'rcfilters-filtergroup-significance',
305 'class' => ChangesListBooleanFilterGroup
::class,
308 'name' => 'hideminor',
309 'label' => 'rcfilters-filter-minor-label',
310 'description' => 'rcfilters-filter-minor-description',
311 // rcshowhideminor-show, rcshowhideminor-hide,
313 'showHideSuffix' => 'showhideminor',
315 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
316 &$query_options, &$join_conds ) {
318 $conds[] = 'rc_minor = 0';
320 'cssClassSuffix' => 'minor',
321 'isRowApplicableCallable' => function ( $ctx, $rc ) {
322 return $rc->getAttribute( 'rc_minor' );
326 'name' => 'hidemajor',
327 'label' => 'rcfilters-filter-major-label',
328 'description' => 'rcfilters-filter-major-description',
330 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
331 &$query_options, &$join_conds ) {
333 $conds[] = 'rc_minor = 1';
335 'cssClassSuffix' => 'major',
336 'isRowApplicableCallable' => function ( $ctx, $rc ) {
337 return !$rc->getAttribute( 'rc_minor' );
343 // With extensions, there can be change types that will not be hidden by any of these.
345 'name' => 'changeType',
346 'title' => 'rcfilters-filtergroup-changetype',
347 'class' => ChangesListBooleanFilterGroup
::class,
350 'name' => 'hidepageedits',
351 'label' => 'rcfilters-filter-pageedits-label',
352 'description' => 'rcfilters-filter-pageedits-description',
354 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
355 &$query_options, &$join_conds ) {
357 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT
);
359 'cssClassSuffix' => 'src-mw-edit',
360 'isRowApplicableCallable' => function ( $ctx, $rc ) {
361 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_EDIT
;
365 'name' => 'hidenewpages',
366 'label' => 'rcfilters-filter-newpages-label',
367 'description' => 'rcfilters-filter-newpages-description',
369 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
370 &$query_options, &$join_conds ) {
372 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW
);
374 'cssClassSuffix' => 'src-mw-new',
375 'isRowApplicableCallable' => function ( $ctx, $rc ) {
376 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_NEW
;
380 'name' => 'hidecategorization',
381 'label' => 'rcfilters-filter-categorization-label',
382 'description' => 'rcfilters-filter-categorization-description',
383 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
384 // wlshowhidecategorization
385 'showHideSuffix' => 'showhidecategorization',
386 'isAllowedCallable' => function ( $pageClassName, $context ) {
387 return $context->getConfig()->get( 'RCWatchCategoryMembership' );
390 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
391 &$query_options, &$join_conds ) {
393 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
);
395 'cssClassSuffix' => 'src-mw-categorize',
396 'isRowApplicableCallable' => function ( $ctx, $rc ) {
397 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_CATEGORIZE
;
402 'label' => 'rcfilters-filter-logactions-label',
403 'description' => 'rcfilters-filter-logactions-description',
405 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
406 &$query_options, &$join_conds ) {
408 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG
);
410 'cssClassSuffix' => 'src-mw-log',
411 'isRowApplicableCallable' => function ( $ctx, $rc ) {
412 return $rc->getAttribute( 'rc_source' ) === RecentChange
::SRC_LOG
;
421 * Main execution point
423 * @param string $subpage
425 public function execute( $subpage ) {
426 $this->rcSubpage
= $subpage;
429 $this->outputHeader();
432 $rows = $this->getRows();
433 $opts = $this->getOptions();
434 if ( $rows === false ) {
435 if ( !$this->including() ) {
436 $this->doHeader( $opts, 0 );
437 $this->getOutput()->setStatusCode( 404 );
443 $batch = new LinkBatch
;
444 foreach ( $rows as $row ) {
445 $batch->add( NS_USER
, $row->rc_user_text
);
446 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
447 $batch->add( $row->rc_namespace
, $row->rc_title
);
448 if ( $row->rc_source
=== RecentChange
::SRC_LOG
) {
449 $formatter = LogFormatter
::newFromRow( $row );
450 foreach ( $formatter->getPreloadTitles() as $title ) {
451 $batch->addObj( $title );
457 $this->webOutput( $rows, $opts );
461 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
462 // Clean up any bad page entries for titles showing up in RC
463 DeferredUpdates
::addUpdate( new WANCacheReapUpdate(
465 LoggerFactory
::getInstance( 'objectcache' )
471 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
473 * @return bool|ResultWrapper Result or false
475 public function getRows() {
476 $opts = $this->getOptions();
483 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
485 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
489 * Get the current FormOptions for this request
491 * @return FormOptions
493 public function getOptions() {
494 if ( $this->rcOptions
=== null ) {
495 $this->rcOptions
= $this->setup( $this->rcSubpage
);
498 return $this->rcOptions
;
502 * Register all filters and their groups, plus conflicts
504 * You might want to customize these in the same method, in subclasses. You can
505 * call getFilterGroup to access a group, and (on the group) getFilter to access a
506 * filter, then make necessary modfications to the filter or group (e.g. with
509 protected function registerFilters() {
510 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions
);
512 Hooks
::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
514 $unstructuredGroupDefinition =
515 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
516 $this->getCustomFilters()
518 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
520 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
522 $registration = $this->getFilterGroup( 'registration' );
523 $anons = $registration->getFilter( 'hideanons' );
525 // This means there is a conflict between any item in user experience level
526 // being checked and only anons being *shown* (hideliu=1&hideanons=0 in the
527 // URL, or equivalent).
528 $userExperienceLevel->conflictsWith(
530 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered-global',
531 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered',
532 'rcfilters-filter-unregistered-conflicts-user-experience-level'
535 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
536 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
537 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
538 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
540 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
541 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
543 $hideMinorFilter->conflictsWith(
545 'rcfilters-hideminor-conflicts-typeofchange-global',
546 'rcfilters-hideminor-conflicts-typeofchange',
547 'rcfilters-typeofchange-conflicts-hideminor'
549 $hideMinorFilter->conflictsWith(
551 'rcfilters-hideminor-conflicts-typeofchange-global',
552 'rcfilters-hideminor-conflicts-typeofchange',
553 'rcfilters-typeofchange-conflicts-hideminor'
555 $hideMinorFilter->conflictsWith(
557 'rcfilters-hideminor-conflicts-typeofchange-global',
558 'rcfilters-hideminor-conflicts-typeofchange',
559 'rcfilters-typeofchange-conflicts-hideminor'
564 * Register filters from a definition object
566 * Array specifying groups and their filters; see Filter and
567 * ChangesListFilterGroup constructors.
569 * There is light processing to simplify core maintenance. See overrides
570 * of this method as well.
572 protected function registerFiltersFromDefinitions( array $definition ) {
574 foreach ( $definition as $groupDefinition ) {
575 $groupDefinition['priority'] = $priority;
578 $className = $groupDefinition['class'];
579 unset( $groupDefinition['class'] );
580 $this->registerFilterGroup( new $className( $groupDefinition ) );
585 * Get filter group definition from legacy custom filters
587 * @param array Custom filters from legacy hooks
588 * @return array Group definition
590 protected function getFilterGroupDefinitionFromLegacyCustomFilters( $customFilters ) {
591 // Special internal unstructured group
592 $unstructuredGroupDefinition = [
593 'name' => 'unstructured',
594 'class' => ChangesListBooleanFilterGroup
::class,
595 'priority' => -1, // Won't display in structured
599 foreach ( $customFilters as $name => $params ) {
600 $unstructuredGroupDefinition['filters'][] = [
602 'showHide' => $params['msg'],
603 'default' => $params['default'],
607 return $unstructuredGroupDefinition;
611 * Register all the filters, including legacy hook-driven ones.
612 * Then create a FormOptions object with options as specified by the user
614 * @param array $parameters
616 * @return FormOptions
618 public function setup( $parameters ) {
619 $this->registerFilters();
621 $opts = $this->getDefaultOptions();
623 $opts = $this->fetchOptionsFromRequest( $opts );
625 // Give precedence to subpage syntax
626 if ( $parameters !== null ) {
627 $this->parseParameters( $parameters, $opts );
630 $this->validateOptions( $opts );
636 * Get a FormOptions object containing the default options. By default, returns
637 * some basic options. The filters listed explicitly here are overriden in this
638 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
639 * and more) are structured. Structured filters are overriden in registerFilters.
642 * @return FormOptions
644 public function getDefaultOptions() {
645 $config = $this->getConfig();
646 $opts = new FormOptions();
649 foreach ( $this->filterGroups
as $filterGroup ) {
650 // URL parameters can be per-group, like 'userExpLevel',
651 // or per-filter, like 'hideminor'.
652 if ( $filterGroup->isPerGroupRequestParameter() ) {
653 $opts->add( $filterGroup->getName(), $filterGroup->getDefault() );
655 foreach ( $filterGroup->getFilters() as $filter ) {
656 $opts->add( $filter->getName(), $filter->getDefault() );
661 $opts->add( 'namespace', '', FormOptions
::INTNULL
);
662 $opts->add( 'invert', false );
663 $opts->add( 'associated', false );
669 * Register a structured changes list filter group
671 * @param ChangesListFilterGroup $group
673 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
674 $groupName = $group->getName();
676 $this->filterGroups
[$groupName] = $group;
680 * Gets the currently registered filters groups
682 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
684 protected function getFilterGroups() {
685 return $this->filterGroups
;
689 * Gets a specified ChangesListFilterGroup by name
691 * @param string $groupName Name of group
693 * @return ChangesListFilterGroup|null Group, or null if not registered
695 public function getFilterGroup( $groupName ) {
696 return isset( $this->filterGroups
[$groupName] ) ?
697 $this->filterGroups
[$groupName] :
701 // Currently, this intentionally only includes filters that display
702 // in the structured UI. This can be changed easily, though, if we want
703 // to include data on filters that use the unstructured UI. messageKeys is a
704 // special top-level value, with the value being an array of the message keys to
705 // send to the client.
707 * Gets structured filter information needed by JS
709 * @return array Associative array
710 * * array $return['groups'] Group data
711 * * array $return['messageKeys'] Array of message keys
713 public function getStructuredFilterJsData() {
719 $context = $this->getContext();
721 usort( $this->filterGroups
, function ( $a, $b ) {
722 return $b->getPriority() - $a->getPriority();
725 foreach ( $this->filterGroups
as $groupName => $group ) {
726 $groupOutput = $group->getJsData( $this );
727 if ( $groupOutput !== null ) {
728 $output['messageKeys'] = array_merge(
729 $output['messageKeys'],
730 $groupOutput['messageKeys']
733 unset( $groupOutput['messageKeys'] );
734 $output['groups'][] = $groupOutput;
742 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
745 * @return array Map of filter URL param names to properties (msg/default)
747 protected function getCustomFilters() {
748 if ( $this->customFilters
=== null ) {
749 $this->customFilters
= [];
750 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
753 return $this->customFilters
;
757 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
759 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
761 * @param FormOptions $opts
762 * @return FormOptions
764 protected function fetchOptionsFromRequest( $opts ) {
765 $opts->fetchValuesFromRequest( $this->getRequest() );
771 * Process $par and put options found in $opts. Used when including the page.
774 * @param FormOptions $opts
776 public function parseParameters( $par, FormOptions
$opts ) {
777 $stringParameterNameSet = [];
778 $hideParameterNameSet = [];
780 // URL parameters can be per-group, like 'userExpLevel',
781 // or per-filter, like 'hideminor'.
783 foreach ( $this->filterGroups
as $filterGroup ) {
784 if ( $filterGroup->isPerGroupRequestParameter() ) {
785 $stringParameterNameSet[$filterGroup->getName()] = true;
786 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup
::TYPE
) {
787 foreach ( $filterGroup->getFilters() as $filter ) {
788 $hideParameterNameSet[$filter->getName()] = true;
793 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
794 foreach ( $bits as $bit ) {
796 if ( isset( $hideParameterNameSet[$bit] ) ) {
797 // hidefoo => hidefoo=true
799 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
800 // foo => hidefoo=false
801 $opts["hide$bit"] = false;
802 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
803 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
804 $opts[$m[1]] = $m[2];
811 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
813 * @param FormOptions $opts
815 public function validateOptions( FormOptions
$opts ) {
816 // nothing by default
820 * Sets appropriate tables, fields, conditions, etc. depending on which filters
821 * the user requested.
823 * @param array &$tables Array of tables; see IDatabase::select $table
824 * @param array &$fields Array of fields; see IDatabase::select $vars
825 * @param array &$conds Array of conditions; see IDatabase::select $conds
826 * @param array &$query_options Array of query options; see IDatabase::select $options
827 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
828 * @param FormOptions $opts
830 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
831 &$join_conds, FormOptions
$opts ) {
833 $dbr = $this->getDB();
834 $user = $this->getUser();
836 $context = $this->getContext();
837 foreach ( $this->filterGroups
as $filterGroup ) {
838 // URL parameters can be per-group, like 'userExpLevel',
839 // or per-filter, like 'hideminor'.
840 if ( $filterGroup->isPerGroupRequestParameter() ) {
841 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
842 $query_options, $join_conds, $opts[$filterGroup->getName()] );
844 foreach ( $filterGroup->getFilters() as $filter ) {
845 if ( $opts[$filter->getName()] && $filter->isAllowed( $this ) ) {
846 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
847 $query_options, $join_conds );
853 // Namespace filtering
854 if ( $opts['namespace'] !== '' ) {
855 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
856 $operator = $opts['invert'] ?
'!=' : '=';
857 $boolean = $opts['invert'] ?
'AND' : 'OR';
859 // Namespace association (T4429)
860 if ( !$opts['associated'] ) {
861 $condition = "rc_namespace $operator $selectedNS";
863 // Also add the associated namespace
864 $associatedNS = $dbr->addQuotes(
865 MWNamespace
::getAssociated( $opts['namespace'] )
867 $condition = "(rc_namespace $operator $selectedNS "
869 . " rc_namespace $operator $associatedNS)";
872 $conds[] = $condition;
879 * @param array $tables Array of tables; see IDatabase::select $table
880 * @param array $fields Array of fields; see IDatabase::select $vars
881 * @param array $conds Array of conditions; see IDatabase::select $conds
882 * @param array $query_options Array of query options; see IDatabase::select $options
883 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
884 * @param FormOptions $opts
885 * @return bool|ResultWrapper Result or false
887 protected function doMainQuery( $tables, $fields, $conds,
888 $query_options, $join_conds, FormOptions
$opts ) {
890 $tables[] = 'recentchanges';
891 $fields = array_merge( RecentChange
::selectFields(), $fields );
893 ChangeTags
::modifyDisplayQuery(
902 // It makes no sense to hide both anons and logged-in users. When this occurs, try a guess on
903 // what the user meant and either show only bots or force anons to be shown.
907 // XXX: We're no longer doing this handling. To preserve back-compat, we need to complete
908 // T151873 (particularly the hideanons/hideliu/hidebots/hidehumans part) in conjunction
909 // with merging this.
911 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
917 $dbr = $this->getDB();
929 protected function runMainQueryHook( &$tables, &$fields, &$conds,
930 &$query_options, &$join_conds, $opts
933 'ChangesListSpecialPageQuery',
934 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
939 * Return a IDatabase object for reading
943 protected function getDB() {
944 return wfGetDB( DB_REPLICA
);
948 * Send output to the OutputPage object, only called if not used feeds
950 * @param ResultWrapper $rows Database rows
951 * @param FormOptions $opts
953 public function webOutput( $rows, $opts ) {
954 if ( !$this->including() ) {
955 $this->outputFeedLinks();
956 $this->doHeader( $opts, $rows->numRows() );
959 $this->outputChangesList( $rows, $opts );
965 public function outputFeedLinks() {
966 // nothing by default
970 * Build and output the actual changes list.
972 * @param ResultWrapper $rows Database rows
973 * @param FormOptions $opts
975 abstract public function outputChangesList( $rows, $opts );
978 * Set the text to be displayed above the changes
980 * @param FormOptions $opts
981 * @param int $numRows Number of rows in the result to show after this header
983 public function doHeader( $opts, $numRows ) {
984 $this->setTopText( $opts );
986 // @todo Lots of stuff should be done here.
988 $this->setBottomText( $opts );
992 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
993 * or similar methods to print the text.
995 * @param FormOptions $opts
997 public function setTopText( FormOptions
$opts ) {
998 // nothing by default
1002 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1003 * or similar methods to print the text.
1005 * @param FormOptions $opts
1007 public function setBottomText( FormOptions
$opts ) {
1008 // nothing by default
1012 * Get options to be displayed in a form
1013 * @todo This should handle options returned by getDefaultOptions().
1014 * @todo Not called by anything in this class (but is in subclasses), should be
1015 * called by something… doHeader() maybe?
1017 * @param FormOptions $opts
1020 public function getExtraOptions( $opts ) {
1025 * Return the legend displayed within the fieldset
1029 public function makeLegend() {
1030 $context = $this->getContext();
1031 $user = $context->getUser();
1032 # The legend showing what the letters and stuff mean
1033 $legend = Html
::openElement( 'dl' ) . "\n";
1034 # Iterates through them and gets the messages for both letter and tooltip
1035 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1036 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1037 unset( $legendItems['unpatrolled'] );
1039 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1040 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1041 $letter = $item['letter'];
1042 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1044 $legend .= Html
::element( 'dt',
1045 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1047 Html
::rawElement( 'dd',
1048 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1049 $context->msg( $label )->parse()
1053 $legend .= Html
::rawElement( 'dt',
1054 [ 'class' => 'mw-plusminus-pos' ],
1055 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1057 $legend .= Html
::element(
1059 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1060 $context->msg( 'recentchanges-label-plusminus' )->text()
1062 $legend .= Html
::closeElement( 'dl' ) . "\n";
1066 '<div class="mw-changeslist-legend">' .
1067 $context->msg( 'recentchanges-legend-heading' )->parse() .
1068 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1075 * Add page-specific modules.
1077 protected function addModules() {
1078 $out = $this->getOutput();
1079 // Styles and behavior for the legend box (see makeLegend())
1080 $out->addModuleStyles( [
1081 'mediawiki.special.changeslist.legend',
1082 'mediawiki.special.changeslist',
1084 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1087 protected function getGroupName() {
1092 * Filter on users' experience levels; this will not be called if nothing is
1095 * @param string $specialPageClassName Class name of current special page
1096 * @param IContextSource $context Context, for e.g. user
1097 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1098 * @param array &$tables Array of tables; see IDatabase::select $table
1099 * @param array &$fields Array of fields; see IDatabase::select $vars
1100 * @param array &$conds Array of conditions; see IDatabase::select $conds
1101 * @param array &$query_options Array of query options; see IDatabase::select $options
1102 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1103 * @param array $selectedExpLevels The allowed active values, sorted
1105 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1106 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels ) {
1108 global $wgLearnerEdits,
1109 $wgExperiencedUserEdits,
1110 $wgLearnerMemberSince,
1111 $wgExperiencedUserMemberSince;
1115 // If all levels are selected, all logged-in users are included (but no
1116 // anons), so we can short-circuit.
1117 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1118 $conds[] = 'rc_user != 0';
1123 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1126 $secondsPerDay = 86400;
1127 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1128 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1130 $aboveNewcomer = $dbr->makeList(
1132 'user_editcount >= ' . intval( $wgLearnerEdits ),
1133 'user_registration <= ' . $dbr->timestamp( $learnerCutoff ),
1138 $aboveLearner = $dbr->makeList(
1140 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1141 'user_registration <= ' . $dbr->timestamp( $experiencedUserCutoff ),
1146 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1147 $conds[] = "NOT ( $aboveNewcomer )";
1148 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1149 $conds[] = $dbr->makeList(
1150 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1153 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1154 $conds[] = $aboveLearner;
1155 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1156 $conds[] = "NOT ( $aboveLearner )";
1157 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1158 $conds[] = $dbr->makeList(
1159 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1162 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1163 $conds[] = $aboveNewcomer;