Merge "Change delimiter for multiple namespaces and tags"
[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
795 // Add all filters
796 foreach ( $this->filterGroups as $filterGroup ) {
797 // URL parameters can be per-group, like 'userExpLevel',
798 // or per-filter, like 'hideminor'.
799 if ( $filterGroup->isPerGroupRequestParameter() ) {
800 $opts->add( $filterGroup->getName(), $filterGroup->getDefault() );
801 } else {
802 foreach ( $filterGroup->getFilters() as $filter ) {
803 $opts->add( $filter->getName(), $filter->getDefault( $structuredUI ) );
804 }
805 }
806 }
807
808 $opts->add( 'namespace', '', FormOptions::STRING );
809 $opts->add( 'invert', false );
810 $opts->add( 'associated', false );
811
812 return $opts;
813 }
814
815 /**
816 * Register a structured changes list filter group
817 *
818 * @param ChangesListFilterGroup $group
819 */
820 public function registerFilterGroup( ChangesListFilterGroup $group ) {
821 $groupName = $group->getName();
822
823 $this->filterGroups[$groupName] = $group;
824 }
825
826 /**
827 * Gets the currently registered filters groups
828 *
829 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
830 */
831 protected function getFilterGroups() {
832 return $this->filterGroups;
833 }
834
835 /**
836 * Gets a specified ChangesListFilterGroup by name
837 *
838 * @param string $groupName Name of group
839 *
840 * @return ChangesListFilterGroup|null Group, or null if not registered
841 */
842 public function getFilterGroup( $groupName ) {
843 return isset( $this->filterGroups[$groupName] ) ?
844 $this->filterGroups[$groupName] :
845 null;
846 }
847
848 // Currently, this intentionally only includes filters that display
849 // in the structured UI. This can be changed easily, though, if we want
850 // to include data on filters that use the unstructured UI. messageKeys is a
851 // special top-level value, with the value being an array of the message keys to
852 // send to the client.
853 /**
854 * Gets structured filter information needed by JS
855 *
856 * @return array Associative array
857 * * array $return['groups'] Group data
858 * * array $return['messageKeys'] Array of message keys
859 */
860 public function getStructuredFilterJsData() {
861 $output = [
862 'groups' => [],
863 'messageKeys' => [],
864 ];
865
866 $context = $this->getContext();
867
868 usort( $this->filterGroups, function ( $a, $b ) {
869 return $b->getPriority() - $a->getPriority();
870 } );
871
872 foreach ( $this->filterGroups as $groupName => $group ) {
873 $groupOutput = $group->getJsData( $this );
874 if ( $groupOutput !== null ) {
875 $output['messageKeys'] = array_merge(
876 $output['messageKeys'],
877 $groupOutput['messageKeys']
878 );
879
880 unset( $groupOutput['messageKeys'] );
881 $output['groups'][] = $groupOutput;
882 }
883 }
884
885 return $output;
886 }
887
888 /**
889 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
890 * hook.
891 *
892 * @return array Map of filter URL param names to properties (msg/default)
893 */
894 protected function getCustomFilters() {
895 if ( $this->customFilters === null ) {
896 $this->customFilters = [];
897 Hooks::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters ], '1.29' );
898 }
899
900 return $this->customFilters;
901 }
902
903 /**
904 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
905 *
906 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
907 *
908 * @param FormOptions $opts
909 * @return FormOptions
910 */
911 protected function fetchOptionsFromRequest( $opts ) {
912 $opts->fetchValuesFromRequest( $this->getRequest() );
913
914 return $opts;
915 }
916
917 /**
918 * Process $par and put options found in $opts. Used when including the page.
919 *
920 * @param string $par
921 * @param FormOptions $opts
922 */
923 public function parseParameters( $par, FormOptions $opts ) {
924 $stringParameterNameSet = [];
925 $hideParameterNameSet = [];
926
927 // URL parameters can be per-group, like 'userExpLevel',
928 // or per-filter, like 'hideminor'.
929
930 foreach ( $this->filterGroups as $filterGroup ) {
931 if ( $filterGroup->isPerGroupRequestParameter() ) {
932 $stringParameterNameSet[$filterGroup->getName()] = true;
933 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup::TYPE ) {
934 foreach ( $filterGroup->getFilters() as $filter ) {
935 $hideParameterNameSet[$filter->getName()] = true;
936 }
937 }
938 }
939
940 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
941 foreach ( $bits as $bit ) {
942 $m = [];
943 if ( isset( $hideParameterNameSet[$bit] ) ) {
944 // hidefoo => hidefoo=true
945 $opts[$bit] = true;
946 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
947 // foo => hidefoo=false
948 $opts["hide$bit"] = false;
949 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
950 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
951 $opts[$m[1]] = $m[2];
952 }
953 }
954 }
955 }
956
957 /**
958 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
959 *
960 * @param FormOptions $opts
961 */
962 public function validateOptions( FormOptions $opts ) {
963 if ( $this->fixContradictoryOptions( $opts ) ) {
964 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
965 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
966 }
967 }
968
969 /**
970 * Fix invalid options by resetting pairs that should never appear together.
971 *
972 * @param FormOptions $opts
973 * @return bool True if any option was reset
974 */
975 private function fixContradictoryOptions( FormOptions $opts ) {
976 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
977
978 foreach ( $this->filterGroups as $filterGroup ) {
979 if ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
980 $filters = $filterGroup->getFilters();
981
982 if ( count( $filters ) === 1 ) {
983 // legacy boolean filters should not be considered
984 continue;
985 }
986
987 $allInGroupEnabled = array_reduce(
988 $filters,
989 function ( $carry, $filter ) use ( $opts ) {
990 return $carry && $opts[ $filter->getName() ];
991 },
992 /* initialValue */ count( $filters ) > 0
993 );
994
995 if ( $allInGroupEnabled ) {
996 foreach ( $filters as $filter ) {
997 $opts[ $filter->getName() ] = false;
998 }
999
1000 $fixed = true;
1001 }
1002 }
1003 }
1004
1005 return $fixed;
1006 }
1007
1008 /**
1009 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1010 * compatibility.
1011 *
1012 * This is deprecated and may be removed.
1013 *
1014 * @param FormOptions $opts
1015 * @return bool True if this change was mode
1016 */
1017 private function fixBackwardsCompatibilityOptions( FormOptions $opts ) {
1018 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1019 $opts->reset( 'hideanons' );
1020 if ( !$opts['hidebots'] ) {
1021 $opts->reset( 'hideliu' );
1022 $opts['hidehumans'] = 1;
1023 }
1024
1025 return true;
1026 }
1027
1028 return false;
1029 }
1030
1031 /**
1032 * Convert parameters values from true/false to 1/0
1033 * so they are not omitted by wfArrayToCgi()
1034 * Bug 36524
1035 *
1036 * @param array $params
1037 * @return array
1038 */
1039 protected function convertParamsForLink( $params ) {
1040 foreach ( $params as &$value ) {
1041 if ( $value === false ) {
1042 $value = '0';
1043 }
1044 }
1045 unset( $value );
1046 return $params;
1047 }
1048
1049 /**
1050 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1051 * the user requested.
1052 *
1053 * @param array &$tables Array of tables; see IDatabase::select $table
1054 * @param array &$fields Array of fields; see IDatabase::select $vars
1055 * @param array &$conds Array of conditions; see IDatabase::select $conds
1056 * @param array &$query_options Array of query options; see IDatabase::select $options
1057 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1058 * @param FormOptions $opts
1059 */
1060 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1061 &$join_conds, FormOptions $opts ) {
1062
1063 $dbr = $this->getDB();
1064 $user = $this->getUser();
1065
1066 $context = $this->getContext();
1067 foreach ( $this->filterGroups as $filterGroup ) {
1068 // URL parameters can be per-group, like 'userExpLevel',
1069 // or per-filter, like 'hideminor'.
1070 if ( $filterGroup->isPerGroupRequestParameter() ) {
1071 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1072 $query_options, $join_conds, $opts[$filterGroup->getName()] );
1073 } else {
1074 foreach ( $filterGroup->getFilters() as $filter ) {
1075 if ( $opts[$filter->getName()] ) {
1076 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1077 $query_options, $join_conds );
1078 }
1079 }
1080 }
1081 }
1082
1083 // Namespace filtering
1084 if ( $opts[ 'namespace' ] !== '' ) {
1085 $namespaces = explode( ';', $opts[ 'namespace' ] );
1086
1087 if ( $opts[ 'associated' ] ) {
1088 $associatedNamespaces = array_map(
1089 function ( $ns ) {
1090 return MWNamespace::getAssociated( $ns );
1091 },
1092 $namespaces
1093 );
1094 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1095 }
1096
1097 if ( count( $namespaces ) === 1 ) {
1098 $operator = $opts[ 'invert' ] ? '!=' : '=';
1099 $value = $dbr->addQuotes( reset( $namespaces ) );
1100 } else {
1101 $operator = $opts[ 'invert' ] ? 'NOT IN' : 'IN';
1102 sort( $namespaces );
1103 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1104 }
1105 $conds[] = "rc_namespace $operator $value";
1106 }
1107 }
1108
1109 /**
1110 * Process the query
1111 *
1112 * @param array $tables Array of tables; see IDatabase::select $table
1113 * @param array $fields Array of fields; see IDatabase::select $vars
1114 * @param array $conds Array of conditions; see IDatabase::select $conds
1115 * @param array $query_options Array of query options; see IDatabase::select $options
1116 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1117 * @param FormOptions $opts
1118 * @return bool|ResultWrapper Result or false
1119 */
1120 protected function doMainQuery( $tables, $fields, $conds,
1121 $query_options, $join_conds, FormOptions $opts ) {
1122
1123 $tables[] = 'recentchanges';
1124 $fields = array_merge( RecentChange::selectFields(), $fields );
1125
1126 ChangeTags::modifyDisplayQuery(
1127 $tables,
1128 $fields,
1129 $conds,
1130 $join_conds,
1131 $query_options,
1132 ''
1133 );
1134
1135 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1136 $opts )
1137 ) {
1138 return false;
1139 }
1140
1141 $dbr = $this->getDB();
1142
1143 return $dbr->select(
1144 $tables,
1145 $fields,
1146 $conds,
1147 __METHOD__,
1148 $query_options,
1149 $join_conds
1150 );
1151 }
1152
1153 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1154 &$query_options, &$join_conds, $opts
1155 ) {
1156 return Hooks::run(
1157 'ChangesListSpecialPageQuery',
1158 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1159 );
1160 }
1161
1162 /**
1163 * Return a IDatabase object for reading
1164 *
1165 * @return IDatabase
1166 */
1167 protected function getDB() {
1168 return wfGetDB( DB_REPLICA );
1169 }
1170
1171 /**
1172 * Send output to the OutputPage object, only called if not used feeds
1173 *
1174 * @param ResultWrapper $rows Database rows
1175 * @param FormOptions $opts
1176 */
1177 public function webOutput( $rows, $opts ) {
1178 if ( !$this->including() ) {
1179 $this->outputFeedLinks();
1180 $this->doHeader( $opts, $rows->numRows() );
1181 }
1182
1183 $this->outputChangesList( $rows, $opts );
1184 }
1185
1186 /**
1187 * Output feed links.
1188 */
1189 public function outputFeedLinks() {
1190 // nothing by default
1191 }
1192
1193 /**
1194 * Build and output the actual changes list.
1195 *
1196 * @param ResultWrapper $rows Database rows
1197 * @param FormOptions $opts
1198 */
1199 abstract public function outputChangesList( $rows, $opts );
1200
1201 /**
1202 * Set the text to be displayed above the changes
1203 *
1204 * @param FormOptions $opts
1205 * @param int $numRows Number of rows in the result to show after this header
1206 */
1207 public function doHeader( $opts, $numRows ) {
1208 $this->setTopText( $opts );
1209
1210 // @todo Lots of stuff should be done here.
1211
1212 $this->setBottomText( $opts );
1213 }
1214
1215 /**
1216 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1217 * or similar methods to print the text.
1218 *
1219 * @param FormOptions $opts
1220 */
1221 public function setTopText( FormOptions $opts ) {
1222 // nothing by default
1223 }
1224
1225 /**
1226 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1227 * or similar methods to print the text.
1228 *
1229 * @param FormOptions $opts
1230 */
1231 public function setBottomText( FormOptions $opts ) {
1232 // nothing by default
1233 }
1234
1235 /**
1236 * Get options to be displayed in a form
1237 * @todo This should handle options returned by getDefaultOptions().
1238 * @todo Not called by anything in this class (but is in subclasses), should be
1239 * called by something… doHeader() maybe?
1240 *
1241 * @param FormOptions $opts
1242 * @return array
1243 */
1244 public function getExtraOptions( $opts ) {
1245 return [];
1246 }
1247
1248 /**
1249 * Return the legend displayed within the fieldset
1250 *
1251 * @return string
1252 */
1253 public function makeLegend() {
1254 $context = $this->getContext();
1255 $user = $context->getUser();
1256 # The legend showing what the letters and stuff mean
1257 $legend = Html::openElement( 'dl' ) . "\n";
1258 # Iterates through them and gets the messages for both letter and tooltip
1259 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1260 if ( !( $user->useRCPatrol() || $user->useNPPatrol() ) ) {
1261 unset( $legendItems['unpatrolled'] );
1262 }
1263 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1264 $label = isset( $item['legend'] ) ? $item['legend'] : $item['title'];
1265 $letter = $item['letter'];
1266 $cssClass = isset( $item['class'] ) ? $item['class'] : $key;
1267
1268 $legend .= Html::element( 'dt',
1269 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1270 ) . "\n" .
1271 Html::rawElement( 'dd',
1272 [ 'class' => Sanitizer::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1273 $context->msg( $label )->parse()
1274 ) . "\n";
1275 }
1276 # (+-123)
1277 $legend .= Html::rawElement( 'dt',
1278 [ 'class' => 'mw-plusminus-pos' ],
1279 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1280 ) . "\n";
1281 $legend .= Html::element(
1282 'dd',
1283 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1284 $context->msg( 'recentchanges-label-plusminus' )->text()
1285 ) . "\n";
1286 $legend .= Html::closeElement( 'dl' ) . "\n";
1287
1288 # Collapsibility
1289 $legend =
1290 '<div class="mw-changeslist-legend">' .
1291 $context->msg( 'recentchanges-legend-heading' )->parse() .
1292 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1293 '</div>';
1294
1295 return $legend;
1296 }
1297
1298 /**
1299 * Add page-specific modules.
1300 */
1301 protected function addModules() {
1302 $out = $this->getOutput();
1303 // Styles and behavior for the legend box (see makeLegend())
1304 $out->addModuleStyles( [
1305 'mediawiki.special.changeslist.legend',
1306 'mediawiki.special.changeslist',
1307 ] );
1308 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1309 }
1310
1311 protected function getGroupName() {
1312 return 'changes';
1313 }
1314
1315 /**
1316 * Filter on users' experience levels; this will not be called if nothing is
1317 * selected.
1318 *
1319 * @param string $specialPageClassName Class name of current special page
1320 * @param IContextSource $context Context, for e.g. user
1321 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1322 * @param array &$tables Array of tables; see IDatabase::select $table
1323 * @param array &$fields Array of fields; see IDatabase::select $vars
1324 * @param array &$conds Array of conditions; see IDatabase::select $conds
1325 * @param array &$query_options Array of query options; see IDatabase::select $options
1326 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1327 * @param array $selectedExpLevels The allowed active values, sorted
1328 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1329 * (optional)
1330 */
1331 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1332 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0 ) {
1333
1334 global $wgLearnerEdits,
1335 $wgExperiencedUserEdits,
1336 $wgLearnerMemberSince,
1337 $wgExperiencedUserMemberSince;
1338
1339 $LEVEL_COUNT = 3;
1340
1341 // If all levels are selected, all logged-in users are included (but no
1342 // anons), so we can short-circuit.
1343 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1344 $conds[] = 'rc_user != 0';
1345 return;
1346 }
1347
1348 $tables[] = 'user';
1349 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1350
1351 if ( $now === 0 ) {
1352 $now = time();
1353 }
1354 $secondsPerDay = 86400;
1355 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1356 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1357
1358 $aboveNewcomer = $dbr->makeList(
1359 [
1360 'user_editcount >= ' . intval( $wgLearnerEdits ),
1361 'user_registration <= ' . $dbr->timestamp( $learnerCutoff ),
1362 ],
1363 IDatabase::LIST_AND
1364 );
1365
1366 $aboveLearner = $dbr->makeList(
1367 [
1368 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1369 'user_registration <= ' . $dbr->timestamp( $experiencedUserCutoff ),
1370 ],
1371 IDatabase::LIST_AND
1372 );
1373
1374 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1375 $conds[] = "NOT ( $aboveNewcomer )";
1376 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1377 $conds[] = $dbr->makeList(
1378 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1379 IDatabase::LIST_AND
1380 );
1381 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1382 $conds[] = $aboveLearner;
1383 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1384 $conds[] = "NOT ( $aboveLearner )";
1385 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1386 $conds[] = $dbr->makeList(
1387 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1388 IDatabase::LIST_OR
1389 );
1390 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1391 $conds[] = $aboveNewcomer;
1392 }
1393 }
1394 }