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