Merge "RCFilters: Reduce saved queries items height"
[lhc/web/wiklou.git] / includes / specialpage / ChangesListSpecialPage.php
1 <?php
2 /**
3 * Special page which uses a ChangesList to show query results.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23 use MediaWiki\Logger\LoggerFactory;
24 use Wikimedia\Rdbms\ResultWrapper;
25 use Wikimedia\Rdbms\FakeResultWrapper;
26 use Wikimedia\Rdbms\IDatabase;
27
28 /**
29 * Special page which uses a ChangesList to show query results.
30 * @todo Way too many public functions, most of them should be protected
31 *
32 * @ingroup SpecialPage
33 */
34 abstract class ChangesListSpecialPage extends SpecialPage {
35 /** @var string */
36 protected $rcSubpage;
37
38 /** @var FormOptions */
39 protected $rcOptions;
40
41 /** @var array */
42 protected $customFilters;
43
44 // Order of both groups and filters is significant; first is top-most priority,
45 // descending from there.
46 // 'showHideSuffix' is a shortcut to and avoid spelling out
47 // details specific to subclasses here.
48 /**
49 * Definition information for the filters and their groups
50 *
51 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
52 * However, priority is dynamically added for the core groups, to ease maintenance.
53 *
54 * Groups are displayed to the user in the structured UI. However, if necessary,
55 * all of the filters in a group can be configured to only display on the
56 * unstuctured UI, in which case you don't need a group title. This is done in
57 * getFilterGroupDefinitionFromLegacyCustomFilters, for example.
58 *
59 * @var array $filterGroupDefinitions
60 */
61 private $filterGroupDefinitions;
62
63 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
64 // that is registered conditionally.
65 private $reviewStatusFilterGroupDefinition;
66
67 // Single filter registered conditionally
68 private $hideCategorizationFilterDefinition;
69
70 /**
71 * Filter groups, and their contained filters
72 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
73 *
74 * @var array $filterGroups
75 */
76 protected $filterGroups = [];
77
78 public function __construct( $name, $restriction ) {
79 parent::__construct( $name, $restriction );
80
81 $this->filterGroupDefinitions = [
82 [
83 'name' => 'registration',
84 'title' => 'rcfilters-filtergroup-registration',
85 'class' => ChangesListBooleanFilterGroup::class,
86 'filters' => [
87 [
88 'name' => 'hideliu',
89 'label' => 'rcfilters-filter-registered-label',
90 'description' => 'rcfilters-filter-registered-description',
91 // rcshowhideliu-show, rcshowhideliu-hide,
92 // wlshowhideliu
93 'showHideSuffix' => 'showhideliu',
94 'default' => false,
95 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
96 &$query_options, &$join_conds
97 ) {
98 $conds[] = 'rc_user = 0';
99 },
100 'cssClassSuffix' => 'liu',
101 'isRowApplicableCallable' => function ( $ctx, $rc ) {
102 return $rc->getAttribute( 'rc_user' );
103 },
104
105 ],
106 [
107 'name' => 'hideanons',
108 'label' => 'rcfilters-filter-unregistered-label',
109 'description' => 'rcfilters-filter-unregistered-description',
110 // rcshowhideanons-show, rcshowhideanons-hide,
111 // wlshowhideanons
112 'showHideSuffix' => 'showhideanons',
113 'default' => false,
114 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
115 &$query_options, &$join_conds
116 ) {
117 $conds[] = 'rc_user != 0';
118 },
119 'cssClassSuffix' => 'anon',
120 'isRowApplicableCallable' => function ( $ctx, $rc ) {
121 return !$rc->getAttribute( 'rc_user' );
122 },
123 ]
124 ],
125 ],
126
127 [
128 'name' => 'userExpLevel',
129 'title' => 'rcfilters-filtergroup-userExpLevel',
130 'class' => ChangesListStringOptionsFilterGroup::class,
131 // Excludes unregistered users
132 'isFullCoverage' => false,
133 'filters' => [
134 [
135 'name' => 'newcomer',
136 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
137 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
138 'cssClassSuffix' => 'user-newcomer',
139 'isRowApplicableCallable' => function ( $ctx, $rc ) {
140 $performer = $rc->getPerformer();
141 return $performer && $performer->isLoggedIn() &&
142 $performer->getExperienceLevel() === 'newcomer';
143 }
144 ],
145 [
146 'name' => 'learner',
147 'label' => 'rcfilters-filter-user-experience-level-learner-label',
148 'description' => 'rcfilters-filter-user-experience-level-learner-description',
149 'cssClassSuffix' => 'user-learner',
150 'isRowApplicableCallable' => function ( $ctx, $rc ) {
151 $performer = $rc->getPerformer();
152 return $performer && $performer->isLoggedIn() &&
153 $performer->getExperienceLevel() === 'learner';
154 },
155 ],
156 [
157 'name' => 'experienced',
158 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
159 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
160 'cssClassSuffix' => 'user-experienced',
161 'isRowApplicableCallable' => function ( $ctx, $rc ) {
162 $performer = $rc->getPerformer();
163 return $performer && $performer->isLoggedIn() &&
164 $performer->getExperienceLevel() === 'experienced';
165 },
166 ]
167 ],
168 'default' => ChangesListStringOptionsFilterGroup::NONE,
169 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
170 ],
171
172 [
173 'name' => 'authorship',
174 'title' => 'rcfilters-filtergroup-authorship',
175 'class' => ChangesListBooleanFilterGroup::class,
176 'filters' => [
177 [
178 'name' => 'hidemyself',
179 'label' => 'rcfilters-filter-editsbyself-label',
180 'description' => 'rcfilters-filter-editsbyself-description',
181 // rcshowhidemine-show, rcshowhidemine-hide,
182 // wlshowhidemine
183 'showHideSuffix' => 'showhidemine',
184 'default' => false,
185 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
186 &$query_options, &$join_conds
187 ) {
188 $user = $ctx->getUser();
189 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
190 },
191 'cssClassSuffix' => 'self',
192 'isRowApplicableCallable' => function ( $ctx, $rc ) {
193 return $ctx->getUser()->equals( $rc->getPerformer() );
194 },
195 ],
196 [
197 'name' => 'hidebyothers',
198 'label' => 'rcfilters-filter-editsbyother-label',
199 'description' => 'rcfilters-filter-editsbyother-description',
200 'default' => false,
201 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
202 &$query_options, &$join_conds
203 ) {
204 $user = $ctx->getUser();
205 $conds[] = 'rc_user_text = ' . $dbr->addQuotes( $user->getName() );
206 },
207 'cssClassSuffix' => 'others',
208 'isRowApplicableCallable' => function ( $ctx, $rc ) {
209 return !$ctx->getUser()->equals( $rc->getPerformer() );
210 },
211 ]
212 ]
213 ],
214
215 [
216 'name' => 'automated',
217 'title' => 'rcfilters-filtergroup-automated',
218 'class' => ChangesListBooleanFilterGroup::class,
219 'filters' => [
220 [
221 'name' => 'hidebots',
222 'label' => 'rcfilters-filter-bots-label',
223 'description' => 'rcfilters-filter-bots-description',
224 // rcshowhidebots-show, rcshowhidebots-hide,
225 // wlshowhidebots
226 'showHideSuffix' => 'showhidebots',
227 'default' => false,
228 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
229 &$query_options, &$join_conds
230 ) {
231 $conds[] = 'rc_bot = 0';
232 },
233 'cssClassSuffix' => 'bot',
234 'isRowApplicableCallable' => function ( $ctx, $rc ) {
235 return $rc->getAttribute( 'rc_bot' );
236 },
237 ],
238 [
239 'name' => 'hidehumans',
240 'label' => 'rcfilters-filter-humans-label',
241 'description' => 'rcfilters-filter-humans-description',
242 'default' => false,
243 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
244 &$query_options, &$join_conds
245 ) {
246 $conds[] = 'rc_bot = 1';
247 },
248 'cssClassSuffix' => 'human',
249 'isRowApplicableCallable' => function ( $ctx, $rc ) {
250 return !$rc->getAttribute( 'rc_bot' );
251 },
252 ]
253 ]
254 ],
255
256 // reviewStatus (conditional)
257
258 [
259 'name' => 'significance',
260 'title' => 'rcfilters-filtergroup-significance',
261 'class' => ChangesListBooleanFilterGroup::class,
262 'priority' => -6,
263 'filters' => [
264 [
265 'name' => 'hideminor',
266 'label' => 'rcfilters-filter-minor-label',
267 'description' => 'rcfilters-filter-minor-description',
268 // rcshowhideminor-show, rcshowhideminor-hide,
269 // wlshowhideminor
270 'showHideSuffix' => 'showhideminor',
271 'default' => false,
272 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
273 &$query_options, &$join_conds
274 ) {
275 $conds[] = 'rc_minor = 0';
276 },
277 'cssClassSuffix' => 'minor',
278 'isRowApplicableCallable' => function ( $ctx, $rc ) {
279 return $rc->getAttribute( 'rc_minor' );
280 }
281 ],
282 [
283 'name' => 'hidemajor',
284 'label' => 'rcfilters-filter-major-label',
285 'description' => 'rcfilters-filter-major-description',
286 'default' => false,
287 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
288 &$query_options, &$join_conds
289 ) {
290 $conds[] = 'rc_minor = 1';
291 },
292 'cssClassSuffix' => 'major',
293 'isRowApplicableCallable' => function ( $ctx, $rc ) {
294 return !$rc->getAttribute( 'rc_minor' );
295 }
296 ]
297 ]
298 ],
299
300 [
301 'name' => 'lastRevision',
302 'title' => 'rcfilters-filtergroup-lastRevision',
303 'class' => ChangesListBooleanFilterGroup::class,
304 'priority' => -7,
305 'filters' => [
306 [
307 'name' => 'hidelastrevision',
308 'label' => 'rcfilters-filter-lastrevision-label',
309 'description' => 'rcfilters-filter-lastrevision-description',
310 'default' => false,
311 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
312 &$query_options, &$join_conds ) {
313 $conds[] = 'rc_this_oldid <> page_latest';
314 },
315 'cssClassSuffix' => 'last',
316 'isRowApplicableCallable' => function ( $ctx, $rc ) {
317 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
318 }
319 ],
320 [
321 'name' => 'hidepreviousrevisions',
322 'label' => 'rcfilters-filter-previousrevision-label',
323 'description' => 'rcfilters-filter-previousrevision-description',
324 'default' => false,
325 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
326 &$query_options, &$join_conds ) {
327 $conds[] = 'rc_this_oldid = page_latest';
328 },
329 'cssClassSuffix' => 'previous',
330 'isRowApplicableCallable' => function ( $ctx, $rc ) {
331 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
332 }
333 ]
334 ]
335 ],
336
337 // With extensions, there can be change types that will not be hidden by any of these.
338 [
339 'name' => 'changeType',
340 'title' => 'rcfilters-filtergroup-changetype',
341 'class' => ChangesListBooleanFilterGroup::class,
342 'priority' => -8,
343 'filters' => [
344 [
345 'name' => 'hidepageedits',
346 'label' => 'rcfilters-filter-pageedits-label',
347 'description' => 'rcfilters-filter-pageedits-description',
348 'default' => false,
349 'priority' => -2,
350 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
351 &$query_options, &$join_conds
352 ) {
353 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT );
354 },
355 'cssClassSuffix' => 'src-mw-edit',
356 'isRowApplicableCallable' => function ( $ctx, $rc ) {
357 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_EDIT;
358 },
359 ],
360 [
361 'name' => 'hidenewpages',
362 'label' => 'rcfilters-filter-newpages-label',
363 'description' => 'rcfilters-filter-newpages-description',
364 'default' => false,
365 'priority' => -3,
366 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
367 &$query_options, &$join_conds
368 ) {
369 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW );
370 },
371 'cssClassSuffix' => 'src-mw-new',
372 'isRowApplicableCallable' => function ( $ctx, $rc ) {
373 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_NEW;
374 },
375 ],
376
377 // hidecategorization
378
379 [
380 'name' => 'hidelog',
381 'label' => 'rcfilters-filter-logactions-label',
382 'description' => 'rcfilters-filter-logactions-description',
383 'default' => false,
384 'priority' => -5,
385 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
386 &$query_options, &$join_conds
387 ) {
388 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG );
389 },
390 'cssClassSuffix' => 'src-mw-log',
391 'isRowApplicableCallable' => function ( $ctx, $rc ) {
392 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_LOG;
393 }
394 ],
395 ],
396 ],
397
398 ];
399
400 $this->reviewStatusFilterGroupDefinition = [
401 [
402 'name' => 'reviewStatus',
403 'title' => 'rcfilters-filtergroup-reviewstatus',
404 'class' => ChangesListBooleanFilterGroup::class,
405 'priority' => -5,
406 'filters' => [
407 [
408 'name' => 'hidepatrolled',
409 'label' => 'rcfilters-filter-patrolled-label',
410 'description' => 'rcfilters-filter-patrolled-description',
411 // rcshowhidepatr-show, rcshowhidepatr-hide
412 // wlshowhidepatr
413 'showHideSuffix' => 'showhidepatr',
414 'default' => false,
415 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
416 &$query_options, &$join_conds
417 ) {
418 $conds[] = 'rc_patrolled = 0';
419 },
420 'cssClassSuffix' => 'patrolled',
421 'isRowApplicableCallable' => function ( $ctx, $rc ) {
422 return $rc->getAttribute( 'rc_patrolled' );
423 },
424 ],
425 [
426 'name' => 'hideunpatrolled',
427 'label' => 'rcfilters-filter-unpatrolled-label',
428 'description' => 'rcfilters-filter-unpatrolled-description',
429 'default' => false,
430 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
431 &$query_options, &$join_conds
432 ) {
433 $conds[] = 'rc_patrolled = 1';
434 },
435 'cssClassSuffix' => 'unpatrolled',
436 'isRowApplicableCallable' => function ( $ctx, $rc ) {
437 return !$rc->getAttribute( 'rc_patrolled' );
438 },
439 ],
440 ],
441 ]
442 ];
443
444 $this->hideCategorizationFilterDefinition = [
445 'name' => 'hidecategorization',
446 'label' => 'rcfilters-filter-categorization-label',
447 'description' => 'rcfilters-filter-categorization-description',
448 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
449 // wlshowhidecategorization
450 'showHideSuffix' => 'showhidecategorization',
451 'default' => false,
452 'priority' => -4,
453 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
454 &$query_options, &$join_conds
455 ) {
456 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE );
457 },
458 'cssClassSuffix' => 'src-mw-categorize',
459 'isRowApplicableCallable' => function ( $ctx, $rc ) {
460 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_CATEGORIZE;
461 },
462 ];
463 }
464
465 /**
466 * Check if filters are in conflict and guaranteed to return no results.
467 *
468 * @return bool
469 */
470 protected function areFiltersInConflict() {
471 $opts = $this->getOptions();
472 /** @var ChangesListFilterGroup $group */
473 foreach ( $this->getFilterGroups() as $group ) {
474 if ( $group->getConflictingGroups() ) {
475 wfLogWarning(
476 $group->getName() .
477 " specifies conflicts with other groups but these are not supported yet."
478 );
479 }
480
481 /** @var ChangesListFilter $conflictingFilter */
482 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
483 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
484 return true;
485 }
486 }
487
488 /** @var ChangesListFilter $filter */
489 foreach ( $group->getFilters() as $filter ) {
490 /** @var ChangesListFilter $conflictingFilter */
491 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
492 if (
493 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
494 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
495 ) {
496 return true;
497 }
498 }
499
500 }
501
502 }
503
504 return false;
505 }
506
507 /**
508 * Main execution point
509 *
510 * @param string $subpage
511 */
512 public function execute( $subpage ) {
513 $this->rcSubpage = $subpage;
514
515 $this->setHeaders();
516 $this->outputHeader();
517 $this->addModules();
518
519 $rows = $this->getRows();
520 $opts = $this->getOptions();
521 if ( $rows === false ) {
522 $rows = new FakeResultWrapper( [] );
523 }
524
525 $batch = new LinkBatch;
526 foreach ( $rows as $row ) {
527 $batch->add( NS_USER, $row->rc_user_text );
528 $batch->add( NS_USER_TALK, $row->rc_user_text );
529 $batch->add( $row->rc_namespace, $row->rc_title );
530 if ( $row->rc_source === RecentChange::SRC_LOG ) {
531 $formatter = LogFormatter::newFromRow( $row );
532 foreach ( $formatter->getPreloadTitles() as $title ) {
533 $batch->addObj( $title );
534 }
535 }
536 }
537 $batch->execute();
538 $this->webOutput( $rows, $opts );
539
540 $rows->free();
541
542 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
543 // Clean up any bad page entries for titles showing up in RC
544 DeferredUpdates::addUpdate( new WANCacheReapUpdate(
545 $this->getDB(),
546 LoggerFactory::getInstance( 'objectcache' )
547 ) );
548 }
549 }
550
551 /**
552 * Add the "no results" message to the output
553 */
554 protected function outputNoResults() {
555 $this->getOutput()->addHTML(
556 '<div class="mw-changeslist-empty">' .
557 $this->msg( 'recentchanges-noresult' )->parse() .
558 '</div>'
559 );
560 }
561
562 /**
563 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
564 *
565 * @return bool|ResultWrapper Result or false
566 */
567 public function getRows() {
568 $opts = $this->getOptions();
569
570 $tables = [];
571 $fields = [];
572 $conds = [];
573 $query_options = [];
574 $join_conds = [];
575 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
576
577 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
578 }
579
580 /**
581 * Get the current FormOptions for this request
582 *
583 * @return FormOptions
584 */
585 public function getOptions() {
586 if ( $this->rcOptions === null ) {
587 $this->rcOptions = $this->setup( $this->rcSubpage );
588 }
589
590 return $this->rcOptions;
591 }
592
593 /**
594 * Register all filters and their groups (including those from hooks), plus handle
595 * conflicts and defaults.
596 *
597 * You might want to customize these in the same method, in subclasses. You can
598 * call getFilterGroup to access a group, and (on the group) getFilter to access a
599 * filter, then make necessary modfications to the filter or group (e.g. with
600 * setDefault).
601 */
602 protected function registerFilters() {
603 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions );
604
605 // Make sure this is not being transcluded (we don't want to show this
606 // information to all users just because the user that saves the edit can
607 // patrol or is logged in)
608 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
609 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition );
610 }
611
612 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
613
614 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
615 $transformedHideCategorizationDef = $this->transformFilterDefinition(
616 $this->hideCategorizationFilterDefinition
617 );
618
619 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
620
621 $hideCategorization = new ChangesListBooleanFilter(
622 $transformedHideCategorizationDef
623 );
624 }
625
626 Hooks::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
627
628 $unstructuredGroupDefinition =
629 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
630 $this->getCustomFilters()
631 );
632 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
633
634 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
635
636 $registration = $this->getFilterGroup( 'registration' );
637 $anons = $registration->getFilter( 'hideanons' );
638
639 // This means there is a conflict between any item in user experience level
640 // being checked and only anons being *shown* (hideliu=1&hideanons=0 in the
641 // URL, or equivalent).
642 $userExperienceLevel->conflictsWith(
643 $anons,
644 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered-global',
645 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered',
646 'rcfilters-filter-unregistered-conflicts-user-experience-level'
647 );
648
649 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
650 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
651 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
652
653 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
654 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
655
656 // categoryFilter is conditional; see registerFilters
657 if ( $categoryFilter !== null ) {
658 $hideMinorFilter->conflictsWith(
659 $categoryFilter,
660 'rcfilters-hideminor-conflicts-typeofchange-global',
661 'rcfilters-hideminor-conflicts-typeofchange',
662 'rcfilters-typeofchange-conflicts-hideminor'
663 );
664 }
665 $hideMinorFilter->conflictsWith(
666 $logactionsFilter,
667 'rcfilters-hideminor-conflicts-typeofchange-global',
668 'rcfilters-hideminor-conflicts-typeofchange',
669 'rcfilters-typeofchange-conflicts-hideminor'
670 );
671 $hideMinorFilter->conflictsWith(
672 $pagecreationFilter,
673 'rcfilters-hideminor-conflicts-typeofchange-global',
674 'rcfilters-hideminor-conflicts-typeofchange',
675 'rcfilters-typeofchange-conflicts-hideminor'
676 );
677 }
678
679 /**
680 * Transforms filter definition to prepare it for constructor.
681 *
682 * See overrides of this method as well.
683 *
684 * @param array $filterDefinition Original filter definition
685 *
686 * @return array Transformed definition
687 */
688 protected function transformFilterDefinition( array $filterDefinition ) {
689 return $filterDefinition;
690 }
691
692 /**
693 * Register filters from a definition object
694 *
695 * Array specifying groups and their filters; see Filter and
696 * ChangesListFilterGroup constructors.
697 *
698 * There is light processing to simplify core maintenance.
699 */
700 protected function registerFiltersFromDefinitions( array $definition ) {
701 $autoFillPriority = -1;
702 foreach ( $definition as $groupDefinition ) {
703 if ( !isset( $groupDefinition['priority'] ) ) {
704 $groupDefinition['priority'] = $autoFillPriority;
705 } else {
706 // If it's explicitly specified, start over the auto-fill
707 $autoFillPriority = $groupDefinition['priority'];
708 }
709
710 $autoFillPriority--;
711
712 $className = $groupDefinition['class'];
713 unset( $groupDefinition['class'] );
714
715 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
716 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
717 }
718
719 $this->registerFilterGroup( new $className( $groupDefinition ) );
720 }
721 }
722
723 /**
724 * Get filter group definition from legacy custom filters
725 *
726 * @param array $customFilters Custom filters from legacy hooks
727 * @return array Group definition
728 */
729 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
730 // Special internal unstructured group
731 $unstructuredGroupDefinition = [
732 'name' => 'unstructured',
733 'class' => ChangesListBooleanFilterGroup::class,
734 'priority' => -1, // Won't display in structured
735 'filters' => [],
736 ];
737
738 foreach ( $customFilters as $name => $params ) {
739 $unstructuredGroupDefinition['filters'][] = [
740 'name' => $name,
741 'showHide' => $params['msg'],
742 'default' => $params['default'],
743 ];
744 }
745
746 return $unstructuredGroupDefinition;
747 }
748
749 /**
750 * Register all the filters, including legacy hook-driven ones.
751 * Then create a FormOptions object with options as specified by the user
752 *
753 * @param array $parameters
754 *
755 * @return FormOptions
756 */
757 public function setup( $parameters ) {
758 $this->registerFilters();
759
760 $opts = $this->getDefaultOptions();
761
762 $opts = $this->fetchOptionsFromRequest( $opts );
763
764 // Give precedence to subpage syntax
765 if ( $parameters !== null ) {
766 $this->parseParameters( $parameters, $opts );
767 }
768
769 $this->validateOptions( $opts );
770
771 return $opts;
772 }
773
774 /**
775 * Get a FormOptions object containing the default options. By default, returns
776 * some basic options. The filters listed explicitly here are overriden in this
777 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
778 * and more) are structured. Structured filters are overriden in registerFilters.
779 * not here.
780 *
781 * @return FormOptions
782 */
783 public function getDefaultOptions() {
784 $config = $this->getConfig();
785 $opts = new FormOptions();
786 $structuredUI = $this->getUser()->getOption( 'rcenhancedfilters' );
787 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
788 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
789
790 // Add all filters
791 foreach ( $this->filterGroups as $filterGroup ) {
792 // URL parameters can be per-group, like 'userExpLevel',
793 // or per-filter, like 'hideminor'.
794 if ( $filterGroup->isPerGroupRequestParameter() ) {
795 $opts->add( $filterGroup->getName(), $useDefaults ? $filterGroup->getDefault() : '' );
796 } else {
797 foreach ( $filterGroup->getFilters() as $filter ) {
798 $opts->add( $filter->getName(), $useDefaults ? $filter->getDefault( $structuredUI ) : false );
799 }
800 }
801 }
802
803 $opts->add( 'namespace', '', FormOptions::STRING );
804 $opts->add( 'invert', false );
805 $opts->add( 'associated', false );
806 $opts->add( 'urlversion', 1 );
807
808 return $opts;
809 }
810
811 /**
812 * Register a structured changes list filter group
813 *
814 * @param ChangesListFilterGroup $group
815 */
816 public function registerFilterGroup( ChangesListFilterGroup $group ) {
817 $groupName = $group->getName();
818
819 $this->filterGroups[$groupName] = $group;
820 }
821
822 /**
823 * Gets the currently registered filters groups
824 *
825 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
826 */
827 protected function getFilterGroups() {
828 return $this->filterGroups;
829 }
830
831 /**
832 * Gets a specified ChangesListFilterGroup by name
833 *
834 * @param string $groupName Name of group
835 *
836 * @return ChangesListFilterGroup|null Group, or null if not registered
837 */
838 public function getFilterGroup( $groupName ) {
839 return isset( $this->filterGroups[$groupName] ) ?
840 $this->filterGroups[$groupName] :
841 null;
842 }
843
844 // Currently, this intentionally only includes filters that display
845 // in the structured UI. This can be changed easily, though, if we want
846 // to include data on filters that use the unstructured UI. messageKeys is a
847 // special top-level value, with the value being an array of the message keys to
848 // send to the client.
849 /**
850 * Gets structured filter information needed by JS
851 *
852 * @return array Associative array
853 * * array $return['groups'] Group data
854 * * array $return['messageKeys'] Array of message keys
855 */
856 public function getStructuredFilterJsData() {
857 $output = [
858 'groups' => [],
859 'messageKeys' => [],
860 ];
861
862 $context = $this->getContext();
863
864 usort( $this->filterGroups, function ( $a, $b ) {
865 return $b->getPriority() - $a->getPriority();
866 } );
867
868 foreach ( $this->filterGroups as $groupName => $group ) {
869 $groupOutput = $group->getJsData( $this );
870 if ( $groupOutput !== null ) {
871 $output['messageKeys'] = array_merge(
872 $output['messageKeys'],
873 $groupOutput['messageKeys']
874 );
875
876 unset( $groupOutput['messageKeys'] );
877 $output['groups'][] = $groupOutput;
878 }
879 }
880
881 return $output;
882 }
883
884 /**
885 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
886 * hook.
887 *
888 * @return array Map of filter URL param names to properties (msg/default)
889 */
890 protected function getCustomFilters() {
891 if ( $this->customFilters === null ) {
892 $this->customFilters = [];
893 Hooks::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters ], '1.29' );
894 }
895
896 return $this->customFilters;
897 }
898
899 /**
900 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
901 *
902 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
903 *
904 * @param FormOptions $opts
905 * @return FormOptions
906 */
907 protected function fetchOptionsFromRequest( $opts ) {
908 $opts->fetchValuesFromRequest( $this->getRequest() );
909
910 return $opts;
911 }
912
913 /**
914 * Process $par and put options found in $opts. Used when including the page.
915 *
916 * @param string $par
917 * @param FormOptions $opts
918 */
919 public function parseParameters( $par, FormOptions $opts ) {
920 $stringParameterNameSet = [];
921 $hideParameterNameSet = [];
922
923 // URL parameters can be per-group, like 'userExpLevel',
924 // or per-filter, like 'hideminor'.
925
926 foreach ( $this->filterGroups as $filterGroup ) {
927 if ( $filterGroup->isPerGroupRequestParameter() ) {
928 $stringParameterNameSet[$filterGroup->getName()] = true;
929 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup::TYPE ) {
930 foreach ( $filterGroup->getFilters() as $filter ) {
931 $hideParameterNameSet[$filter->getName()] = true;
932 }
933 }
934 }
935
936 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
937 foreach ( $bits as $bit ) {
938 $m = [];
939 if ( isset( $hideParameterNameSet[$bit] ) ) {
940 // hidefoo => hidefoo=true
941 $opts[$bit] = true;
942 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
943 // foo => hidefoo=false
944 $opts["hide$bit"] = false;
945 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
946 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
947 $opts[$m[1]] = $m[2];
948 }
949 }
950 }
951 }
952
953 /**
954 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
955 *
956 * @param FormOptions $opts
957 */
958 public function validateOptions( FormOptions $opts ) {
959 if ( $this->fixContradictoryOptions( $opts ) ) {
960 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
961 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
962 }
963 }
964
965 /**
966 * Fix invalid options by resetting pairs that should never appear together.
967 *
968 * @param FormOptions $opts
969 * @return bool True if any option was reset
970 */
971 private function fixContradictoryOptions( FormOptions $opts ) {
972 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
973
974 foreach ( $this->filterGroups as $filterGroup ) {
975 if ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
976 $filters = $filterGroup->getFilters();
977
978 if ( count( $filters ) === 1 ) {
979 // legacy boolean filters should not be considered
980 continue;
981 }
982
983 $allInGroupEnabled = array_reduce(
984 $filters,
985 function ( $carry, $filter ) use ( $opts ) {
986 return $carry && $opts[ $filter->getName() ];
987 },
988 /* initialValue */ count( $filters ) > 0
989 );
990
991 if ( $allInGroupEnabled ) {
992 foreach ( $filters as $filter ) {
993 $opts[ $filter->getName() ] = false;
994 }
995
996 $fixed = true;
997 }
998 }
999 }
1000
1001 return $fixed;
1002 }
1003
1004 /**
1005 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1006 * compatibility.
1007 *
1008 * This is deprecated and may be removed.
1009 *
1010 * @param FormOptions $opts
1011 * @return bool True if this change was mode
1012 */
1013 private function fixBackwardsCompatibilityOptions( FormOptions $opts ) {
1014 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1015 $opts->reset( 'hideanons' );
1016 if ( !$opts['hidebots'] ) {
1017 $opts->reset( 'hideliu' );
1018 $opts['hidehumans'] = 1;
1019 }
1020
1021 return true;
1022 }
1023
1024 return false;
1025 }
1026
1027 /**
1028 * Convert parameters values from true/false to 1/0
1029 * so they are not omitted by wfArrayToCgi()
1030 * Bug 36524
1031 *
1032 * @param array $params
1033 * @return array
1034 */
1035 protected function convertParamsForLink( $params ) {
1036 foreach ( $params as &$value ) {
1037 if ( $value === false ) {
1038 $value = '0';
1039 }
1040 }
1041 unset( $value );
1042 return $params;
1043 }
1044
1045 /**
1046 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1047 * the user requested.
1048 *
1049 * @param array &$tables Array of tables; see IDatabase::select $table
1050 * @param array &$fields Array of fields; see IDatabase::select $vars
1051 * @param array &$conds Array of conditions; see IDatabase::select $conds
1052 * @param array &$query_options Array of query options; see IDatabase::select $options
1053 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1054 * @param FormOptions $opts
1055 */
1056 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1057 &$join_conds, FormOptions $opts
1058 ) {
1059 $dbr = $this->getDB();
1060 $user = $this->getUser();
1061
1062 $context = $this->getContext();
1063 foreach ( $this->filterGroups as $filterGroup ) {
1064 // URL parameters can be per-group, like 'userExpLevel',
1065 // or per-filter, like 'hideminor'.
1066 if ( $filterGroup->isPerGroupRequestParameter() ) {
1067 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1068 $query_options, $join_conds, $opts[$filterGroup->getName()] );
1069 } else {
1070 foreach ( $filterGroup->getFilters() as $filter ) {
1071 if ( $opts[$filter->getName()] ) {
1072 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1073 $query_options, $join_conds );
1074 }
1075 }
1076 }
1077 }
1078
1079 // Namespace filtering
1080 if ( $opts[ 'namespace' ] !== '' ) {
1081 $namespaces = explode( ';', $opts[ 'namespace' ] );
1082
1083 if ( $opts[ 'associated' ] ) {
1084 $associatedNamespaces = array_map(
1085 function ( $ns ) {
1086 return MWNamespace::getAssociated( $ns );
1087 },
1088 $namespaces
1089 );
1090 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1091 }
1092
1093 if ( count( $namespaces ) === 1 ) {
1094 $operator = $opts[ 'invert' ] ? '!=' : '=';
1095 $value = $dbr->addQuotes( reset( $namespaces ) );
1096 } else {
1097 $operator = $opts[ 'invert' ] ? 'NOT IN' : 'IN';
1098 sort( $namespaces );
1099 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1100 }
1101 $conds[] = "rc_namespace $operator $value";
1102 }
1103 }
1104
1105 /**
1106 * Process the query
1107 *
1108 * @param array $tables Array of tables; see IDatabase::select $table
1109 * @param array $fields Array of fields; see IDatabase::select $vars
1110 * @param array $conds Array of conditions; see IDatabase::select $conds
1111 * @param array $query_options Array of query options; see IDatabase::select $options
1112 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1113 * @param FormOptions $opts
1114 * @return bool|ResultWrapper Result or false
1115 */
1116 protected function doMainQuery( $tables, $fields, $conds,
1117 $query_options, $join_conds, FormOptions $opts
1118 ) {
1119 $tables[] = 'recentchanges';
1120 $fields = array_merge( RecentChange::selectFields(), $fields );
1121
1122 ChangeTags::modifyDisplayQuery(
1123 $tables,
1124 $fields,
1125 $conds,
1126 $join_conds,
1127 $query_options,
1128 ''
1129 );
1130
1131 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1132 $opts )
1133 ) {
1134 return false;
1135 }
1136
1137 $dbr = $this->getDB();
1138
1139 return $dbr->select(
1140 $tables,
1141 $fields,
1142 $conds,
1143 __METHOD__,
1144 $query_options,
1145 $join_conds
1146 );
1147 }
1148
1149 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1150 &$query_options, &$join_conds, $opts
1151 ) {
1152 return Hooks::run(
1153 'ChangesListSpecialPageQuery',
1154 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1155 );
1156 }
1157
1158 /**
1159 * Return a IDatabase object for reading
1160 *
1161 * @return IDatabase
1162 */
1163 protected function getDB() {
1164 return wfGetDB( DB_REPLICA );
1165 }
1166
1167 /**
1168 * Send output to the OutputPage object, only called if not used feeds
1169 *
1170 * @param ResultWrapper $rows Database rows
1171 * @param FormOptions $opts
1172 */
1173 public function webOutput( $rows, $opts ) {
1174 if ( !$this->including() ) {
1175 $this->outputFeedLinks();
1176 $this->doHeader( $opts, $rows->numRows() );
1177 }
1178
1179 $this->outputChangesList( $rows, $opts );
1180 }
1181
1182 /**
1183 * Output feed links.
1184 */
1185 public function outputFeedLinks() {
1186 // nothing by default
1187 }
1188
1189 /**
1190 * Build and output the actual changes list.
1191 *
1192 * @param ResultWrapper $rows Database rows
1193 * @param FormOptions $opts
1194 */
1195 abstract public function outputChangesList( $rows, $opts );
1196
1197 /**
1198 * Set the text to be displayed above the changes
1199 *
1200 * @param FormOptions $opts
1201 * @param int $numRows Number of rows in the result to show after this header
1202 */
1203 public function doHeader( $opts, $numRows ) {
1204 $this->setTopText( $opts );
1205
1206 // @todo Lots of stuff should be done here.
1207
1208 $this->setBottomText( $opts );
1209 }
1210
1211 /**
1212 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1213 * or similar methods to print the text.
1214 *
1215 * @param FormOptions $opts
1216 */
1217 public function setTopText( FormOptions $opts ) {
1218 // nothing by default
1219 }
1220
1221 /**
1222 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1223 * or similar methods to print the text.
1224 *
1225 * @param FormOptions $opts
1226 */
1227 public function setBottomText( FormOptions $opts ) {
1228 // nothing by default
1229 }
1230
1231 /**
1232 * Get options to be displayed in a form
1233 * @todo This should handle options returned by getDefaultOptions().
1234 * @todo Not called by anything in this class (but is in subclasses), should be
1235 * called by something… doHeader() maybe?
1236 *
1237 * @param FormOptions $opts
1238 * @return array
1239 */
1240 public function getExtraOptions( $opts ) {
1241 return [];
1242 }
1243
1244 /**
1245 * Return the legend displayed within the fieldset
1246 *
1247 * @return string
1248 */
1249 public function makeLegend() {
1250 $context = $this->getContext();
1251 $user = $context->getUser();
1252 # The legend showing what the letters and stuff mean
1253 $legend = Html::openElement( 'dl' ) . "\n";
1254 # Iterates through them and gets the messages for both letter and tooltip
1255 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1256 if ( !( $user->useRCPatrol() || $user->useNPPatrol() ) ) {
1257 unset( $legendItems['unpatrolled'] );
1258 }
1259 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1260 $label = isset( $item['legend'] ) ? $item['legend'] : $item['title'];
1261 $letter = $item['letter'];
1262 $cssClass = isset( $item['class'] ) ? $item['class'] : $key;
1263
1264 $legend .= Html::element( 'dt',
1265 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1266 ) . "\n" .
1267 Html::rawElement( 'dd',
1268 [ 'class' => Sanitizer::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1269 $context->msg( $label )->parse()
1270 ) . "\n";
1271 }
1272 # (+-123)
1273 $legend .= Html::rawElement( 'dt',
1274 [ 'class' => 'mw-plusminus-pos' ],
1275 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1276 ) . "\n";
1277 $legend .= Html::element(
1278 'dd',
1279 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1280 $context->msg( 'recentchanges-label-plusminus' )->text()
1281 ) . "\n";
1282 $legend .= Html::closeElement( 'dl' ) . "\n";
1283
1284 # Collapsibility
1285 $legendHeading = $this->getUser()->getOption(
1286 'rcenhancedfilters'
1287 ) ?
1288 $context->msg( 'rcfilters-legend-heading' )->parse() :
1289 $context->msg( 'recentchanges-legend-heading' )->parse();
1290 $legend =
1291 '<div class="mw-changeslist-legend">' .
1292 $legendHeading .
1293 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1294 '</div>';
1295
1296 return $legend;
1297 }
1298
1299 /**
1300 * Add page-specific modules.
1301 */
1302 protected function addModules() {
1303 $out = $this->getOutput();
1304 // Styles and behavior for the legend box (see makeLegend())
1305 $out->addModuleStyles( [
1306 'mediawiki.special.changeslist.legend',
1307 'mediawiki.special.changeslist',
1308 ] );
1309 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1310 }
1311
1312 protected function getGroupName() {
1313 return 'changes';
1314 }
1315
1316 /**
1317 * Filter on users' experience levels; this will not be called if nothing is
1318 * selected.
1319 *
1320 * @param string $specialPageClassName Class name of current special page
1321 * @param IContextSource $context Context, for e.g. user
1322 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1323 * @param array &$tables Array of tables; see IDatabase::select $table
1324 * @param array &$fields Array of fields; see IDatabase::select $vars
1325 * @param array &$conds Array of conditions; see IDatabase::select $conds
1326 * @param array &$query_options Array of query options; see IDatabase::select $options
1327 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1328 * @param array $selectedExpLevels The allowed active values, sorted
1329 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1330 * (optional)
1331 */
1332 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1333 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1334 ) {
1335 global $wgLearnerEdits,
1336 $wgExperiencedUserEdits,
1337 $wgLearnerMemberSince,
1338 $wgExperiencedUserMemberSince;
1339
1340 $LEVEL_COUNT = 3;
1341
1342 // If all levels are selected, all logged-in users are included (but no
1343 // anons), so we can short-circuit.
1344 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1345 $conds[] = 'rc_user != 0';
1346 return;
1347 }
1348
1349 $tables[] = 'user';
1350 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1351
1352 if ( $now === 0 ) {
1353 $now = time();
1354 }
1355 $secondsPerDay = 86400;
1356 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1357 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1358
1359 $aboveNewcomer = $dbr->makeList(
1360 [
1361 'user_editcount >= ' . intval( $wgLearnerEdits ),
1362 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1363 ],
1364 IDatabase::LIST_AND
1365 );
1366
1367 $aboveLearner = $dbr->makeList(
1368 [
1369 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1370 'user_registration <= ' .
1371 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1372 ],
1373 IDatabase::LIST_AND
1374 );
1375
1376 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1377 $conds[] = "NOT ( $aboveNewcomer )";
1378 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1379 $conds[] = $dbr->makeList(
1380 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1381 IDatabase::LIST_AND
1382 );
1383 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1384 $conds[] = $aboveLearner;
1385 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1386 $conds[] = "NOT ( $aboveLearner )";
1387 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1388 $conds[] = $dbr->makeList(
1389 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1390 IDatabase::LIST_OR
1391 );
1392 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1393 $conds[] = $aboveNewcomer;
1394 }
1395 }
1396 }