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'
537 * Register filters from a definition object
539 * Array specifying groups and their filters; see Filter and
540 * ChangesListFilterGroup constructors.
542 * There is light processing to simplify core maintenance. See overrides
543 * of this method as well.
545 protected function registerFiltersFromDefinitions( array $definition ) {
547 foreach ( $definition as $groupDefinition ) {
548 $groupDefinition['priority'] = $priority;
551 $className = $groupDefinition['class'];
552 unset( $groupDefinition['class'] );
553 $this->registerFilterGroup( new $className( $groupDefinition ) );
558 * Get filter group definition from legacy custom filters
560 * @param array Custom filters from legacy hooks
561 * @return array Group definition
563 protected function getFilterGroupDefinitionFromLegacyCustomFilters( $customFilters ) {
564 // Special internal unstructured group
565 $unstructuredGroupDefinition = [
566 'name' => 'unstructured',
567 'class' => ChangesListBooleanFilterGroup
::class,
568 'priority' => -1, // Won't display in structured
572 foreach ( $customFilters as $name => $params ) {
573 $unstructuredGroupDefinition['filters'][] = [
575 'showHide' => $params['msg'],
576 'default' => $params['default'],
580 return $unstructuredGroupDefinition;
584 * Register all the filters, including legacy hook-driven ones.
585 * Then create a FormOptions object with options as specified by the user
587 * @param array $parameters
589 * @return FormOptions
591 public function setup( $parameters ) {
592 $this->registerFilters();
594 $opts = $this->getDefaultOptions();
596 $opts = $this->fetchOptionsFromRequest( $opts );
598 // Give precedence to subpage syntax
599 if ( $parameters !== null ) {
600 $this->parseParameters( $parameters, $opts );
603 $this->validateOptions( $opts );
609 * Get a FormOptions object containing the default options. By default, returns
610 * some basic options. The filters listed explicitly here are overriden in this
611 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
612 * and more) are structured. Structured filters are overriden in registerFilters.
615 * @return FormOptions
617 public function getDefaultOptions() {
618 $config = $this->getConfig();
619 $opts = new FormOptions();
622 foreach ( $this->filterGroups
as $filterGroup ) {
623 // URL parameters can be per-group, like 'userExpLevel',
624 // or per-filter, like 'hideminor'.
625 if ( $filterGroup->isPerGroupRequestParameter() ) {
626 $opts->add( $filterGroup->getName(), $filterGroup->getDefault() );
628 foreach ( $filterGroup->getFilters() as $filter ) {
629 $opts->add( $filter->getName(), $filter->getDefault() );
634 $opts->add( 'namespace', '', FormOptions
::INTNULL
);
635 $opts->add( 'invert', false );
636 $opts->add( 'associated', false );
642 * Register a structured changes list filter group
644 * @param ChangesListFilterGroup $group
646 public function registerFilterGroup( ChangesListFilterGroup
$group ) {
647 $groupName = $group->getName();
649 $this->filterGroups
[$groupName] = $group;
653 * Gets the currently registered filters groups
655 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
657 protected function getFilterGroups() {
658 return $this->filterGroups
;
662 * Gets a specified ChangesListFilterGroup by name
664 * @param string $groupName Name of group
666 * @return ChangesListFilterGroup
668 public function getFilterGroup( $groupName ) {
669 return $this->filterGroups
[$groupName];
672 // Currently, this intentionally only includes filters that display
673 // in the structured UI. This can be changed easily, though, if we want
674 // to include data on filters that use the unstructured UI. messageKeys is a
675 // special top-level value, with the value being an array of the message keys to
676 // send to the client.
678 * Gets structured filter information needed by JS
680 * @return array Associative array
681 * * array $return['groups'] Group data
682 * * array $return['messageKeys'] Array of message keys
684 public function getStructuredFilterJsData() {
690 $context = $this->getContext();
692 usort( $this->filterGroups
, function ( $a, $b ) {
693 return $b->getPriority() - $a->getPriority();
696 foreach ( $this->filterGroups
as $groupName => $group ) {
697 $groupOutput = $group->getJsData( $this );
698 if ( $groupOutput !== null ) {
699 $output['messageKeys'] = array_merge(
700 $output['messageKeys'],
701 $groupOutput['messageKeys']
704 unset( $groupOutput['messageKeys'] );
705 $output['groups'][] = $groupOutput;
713 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
716 * @return array Map of filter URL param names to properties (msg/default)
718 protected function getCustomFilters() {
719 if ( $this->customFilters
=== null ) {
720 $this->customFilters
= [];
721 Hooks
::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters
], '1.29' );
724 return $this->customFilters
;
728 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
730 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
732 * @param FormOptions $opts
733 * @return FormOptions
735 protected function fetchOptionsFromRequest( $opts ) {
736 $opts->fetchValuesFromRequest( $this->getRequest() );
742 * Process $par and put options found in $opts. Used when including the page.
745 * @param FormOptions $opts
747 public function parseParameters( $par, FormOptions
$opts ) {
748 $stringParameterNameSet = [];
749 $hideParameterNameSet = [];
751 // URL parameters can be per-group, like 'userExpLevel',
752 // or per-filter, like 'hideminor'.
754 foreach ( $this->filterGroups
as $filterGroup ) {
755 if ( $filterGroup->isPerGroupRequestParameter() ) {
756 $stringParameterNameSet[$filterGroup->getName()] = true;
757 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup
::TYPE
) {
758 foreach ( $filterGroup->getFilters() as $filter ) {
759 $hideParameterNameSet[$filter->getName()] = true;
764 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
765 foreach ( $bits as $bit ) {
767 if ( isset( $hideParameterNameSet[$bit] ) ) {
768 // hidefoo => hidefoo=true
770 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
771 // foo => hidefoo=false
772 $opts["hide$bit"] = false;
773 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
774 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
775 $opts[$m[1]] = $m[2];
782 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
784 * @param FormOptions $opts
786 public function validateOptions( FormOptions
$opts ) {
787 // nothing by default
791 * Sets appropriate tables, fields, conditions, etc. depending on which filters
792 * the user requested.
794 * @param array &$tables Array of tables; see IDatabase::select $table
795 * @param array &$fields Array of fields; see IDatabase::select $vars
796 * @param array &$conds Array of conditions; see IDatabase::select $conds
797 * @param array &$query_options Array of query options; see IDatabase::select $options
798 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
799 * @param FormOptions $opts
801 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
802 &$join_conds, FormOptions
$opts ) {
804 $dbr = $this->getDB();
805 $user = $this->getUser();
807 $context = $this->getContext();
808 foreach ( $this->filterGroups
as $filterGroup ) {
809 // URL parameters can be per-group, like 'userExpLevel',
810 // or per-filter, like 'hideminor'.
811 if ( $filterGroup->isPerGroupRequestParameter() ) {
812 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
813 $query_options, $join_conds, $opts[$filterGroup->getName()] );
815 foreach ( $filterGroup->getFilters() as $filter ) {
816 if ( $opts[$filter->getName()] && $filter->isAllowed( $this ) ) {
817 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
818 $query_options, $join_conds );
824 // Namespace filtering
825 if ( $opts['namespace'] !== '' ) {
826 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
827 $operator = $opts['invert'] ?
'!=' : '=';
828 $boolean = $opts['invert'] ?
'AND' : 'OR';
830 // Namespace association (T4429)
831 if ( !$opts['associated'] ) {
832 $condition = "rc_namespace $operator $selectedNS";
834 // Also add the associated namespace
835 $associatedNS = $dbr->addQuotes(
836 MWNamespace
::getAssociated( $opts['namespace'] )
838 $condition = "(rc_namespace $operator $selectedNS "
840 . " rc_namespace $operator $associatedNS)";
843 $conds[] = $condition;
850 * @param array $tables Array of tables; see IDatabase::select $table
851 * @param array $fields Array of fields; see IDatabase::select $vars
852 * @param array $conds Array of conditions; see IDatabase::select $conds
853 * @param array $query_options Array of query options; see IDatabase::select $options
854 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
855 * @param FormOptions $opts
856 * @return bool|ResultWrapper Result or false
858 protected function doMainQuery( $tables, $fields, $conds,
859 $query_options, $join_conds, FormOptions
$opts ) {
861 $tables[] = 'recentchanges';
862 $fields = array_merge( RecentChange
::selectFields(), $fields );
864 ChangeTags
::modifyDisplayQuery(
873 // It makes no sense to hide both anons and logged-in users. When this occurs, try a guess on
874 // what the user meant and either show only bots or force anons to be shown.
878 // XXX: We're no longer doing this handling. To preserve back-compat, we need to complete
879 // T151873 (particularly the hideanons/hideliu/hidebots/hidehumans part) in conjunction
880 // with merging this.
882 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
888 $dbr = $this->getDB();
900 protected function runMainQueryHook( &$tables, &$fields, &$conds,
901 &$query_options, &$join_conds, $opts
904 'ChangesListSpecialPageQuery',
905 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
910 * Return a IDatabase object for reading
914 protected function getDB() {
915 return wfGetDB( DB_REPLICA
);
919 * Send output to the OutputPage object, only called if not used feeds
921 * @param ResultWrapper $rows Database rows
922 * @param FormOptions $opts
924 public function webOutput( $rows, $opts ) {
925 if ( !$this->including() ) {
926 $this->outputFeedLinks();
927 $this->doHeader( $opts, $rows->numRows() );
930 $this->outputChangesList( $rows, $opts );
936 public function outputFeedLinks() {
937 // nothing by default
941 * Build and output the actual changes list.
943 * @param ResultWrapper $rows Database rows
944 * @param FormOptions $opts
946 abstract public function outputChangesList( $rows, $opts );
949 * Set the text to be displayed above the changes
951 * @param FormOptions $opts
952 * @param int $numRows Number of rows in the result to show after this header
954 public function doHeader( $opts, $numRows ) {
955 $this->setTopText( $opts );
957 // @todo Lots of stuff should be done here.
959 $this->setBottomText( $opts );
963 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
964 * or similar methods to print the text.
966 * @param FormOptions $opts
968 public function setTopText( FormOptions
$opts ) {
969 // nothing by default
973 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
974 * or similar methods to print the text.
976 * @param FormOptions $opts
978 public function setBottomText( FormOptions
$opts ) {
979 // nothing by default
983 * Get options to be displayed in a form
984 * @todo This should handle options returned by getDefaultOptions().
985 * @todo Not called by anything in this class (but is in subclasses), should be
986 * called by something… doHeader() maybe?
988 * @param FormOptions $opts
991 public function getExtraOptions( $opts ) {
996 * Return the legend displayed within the fieldset
1000 public function makeLegend() {
1001 $context = $this->getContext();
1002 $user = $context->getUser();
1003 # The legend showing what the letters and stuff mean
1004 $legend = Html
::openElement( 'dl' ) . "\n";
1005 # Iterates through them and gets the messages for both letter and tooltip
1006 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1007 if ( !( $user->useRCPatrol() ||
$user->useNPPatrol() ) ) {
1008 unset( $legendItems['unpatrolled'] );
1010 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1011 $label = isset( $item['legend'] ) ?
$item['legend'] : $item['title'];
1012 $letter = $item['letter'];
1013 $cssClass = isset( $item['class'] ) ?
$item['class'] : $key;
1015 $legend .= Html
::element( 'dt',
1016 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1018 Html
::rawElement( 'dd',
1019 [ 'class' => Sanitizer
::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1020 $context->msg( $label )->parse()
1024 $legend .= Html
::rawElement( 'dt',
1025 [ 'class' => 'mw-plusminus-pos' ],
1026 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1028 $legend .= Html
::element(
1030 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1031 $context->msg( 'recentchanges-label-plusminus' )->text()
1033 $legend .= Html
::closeElement( 'dl' ) . "\n";
1037 '<div class="mw-changeslist-legend">' .
1038 $context->msg( 'recentchanges-legend-heading' )->parse() .
1039 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1046 * Add page-specific modules.
1048 protected function addModules() {
1049 $out = $this->getOutput();
1050 // Styles and behavior for the legend box (see makeLegend())
1051 $out->addModuleStyles( [
1052 'mediawiki.special.changeslist.legend',
1053 'mediawiki.special.changeslist',
1055 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1058 protected function getGroupName() {
1063 * Filter on users' experience levels; this will not be called if nothing is
1066 * @param string $specialPageClassName Class name of current special page
1067 * @param IContextSource $context Context, for e.g. user
1068 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1069 * @param array &$tables Array of tables; see IDatabase::select $table
1070 * @param array &$fields Array of fields; see IDatabase::select $vars
1071 * @param array &$conds Array of conditions; see IDatabase::select $conds
1072 * @param array &$query_options Array of query options; see IDatabase::select $options
1073 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1074 * @param array $selectedExpLevels The allowed active values, sorted
1076 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1077 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels ) {
1079 global $wgLearnerEdits,
1080 $wgExperiencedUserEdits,
1081 $wgLearnerMemberSince,
1082 $wgExperiencedUserMemberSince;
1086 // If all levels are selected, all logged-in users are included (but no
1087 // anons), so we can short-circuit.
1088 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1089 $conds[] = 'rc_user != 0';
1094 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1097 $secondsPerDay = 86400;
1098 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1099 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1101 $aboveNewcomer = $dbr->makeList(
1103 'user_editcount >= ' . intval( $wgLearnerEdits ),
1104 'user_registration <= ' . $dbr->timestamp( $learnerCutoff ),
1109 $aboveLearner = $dbr->makeList(
1111 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1112 'user_registration <= ' . $dbr->timestamp( $experiencedUserCutoff ),
1117 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1118 $conds[] = "NOT ( $aboveNewcomer )";
1119 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1120 $conds[] = $dbr->makeList(
1121 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1124 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1125 $conds[] = $aboveLearner;
1126 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1127 $conds[] = "NOT ( $aboveLearner )";
1128 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1129 $conds[] = $dbr->makeList(
1130 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1133 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1134 $conds[] = $aboveNewcomer;