268f0b099d0d51d9e1d86b1df1ffce36b15dad73
[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 $contradictorySets = [];
977
978 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
979
980 foreach ( $this->filterGroups as $filterGroup ) {
981 if ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
982 $filters = $filterGroup->getFilters();
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->reset( $filter->getName() );
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 /**
1029 * Convert parameters values from true/false to 1/0
1030 * so they are not omitted by wfArrayToCgi()
1031 * Bug 36524
1032 *
1033 * @param array $params
1034 * @return array
1035 */
1036 protected function convertParamsForLink( $params ) {
1037 foreach ( $params as &$value ) {
1038 if ( $value === false ) {
1039 $value = '0';
1040 }
1041 }
1042 unset( $value );
1043 return $params;
1044 }
1045
1046 /**
1047 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1048 * the user requested.
1049 *
1050 * @param array &$tables Array of tables; see IDatabase::select $table
1051 * @param array &$fields Array of fields; see IDatabase::select $vars
1052 * @param array &$conds Array of conditions; see IDatabase::select $conds
1053 * @param array &$query_options Array of query options; see IDatabase::select $options
1054 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1055 * @param FormOptions $opts
1056 */
1057 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1058 &$join_conds, FormOptions $opts ) {
1059
1060 $dbr = $this->getDB();
1061 $user = $this->getUser();
1062
1063 $context = $this->getContext();
1064 foreach ( $this->filterGroups as $filterGroup ) {
1065 // URL parameters can be per-group, like 'userExpLevel',
1066 // or per-filter, like 'hideminor'.
1067 if ( $filterGroup->isPerGroupRequestParameter() ) {
1068 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1069 $query_options, $join_conds, $opts[$filterGroup->getName()] );
1070 } else {
1071 foreach ( $filterGroup->getFilters() as $filter ) {
1072 if ( $opts[$filter->getName()] ) {
1073 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1074 $query_options, $join_conds );
1075 }
1076 }
1077 }
1078 }
1079
1080 // Namespace filtering
1081 if ( $opts[ 'namespace' ] !== '' ) {
1082 $namespaces = explode( ',', $opts[ 'namespace' ] );
1083
1084 if ( $opts[ 'associated' ] ) {
1085 $associatedNamespaces = array_map(
1086 function ( $ns ) {
1087 return MWNamespace::getAssociated( $ns );
1088 },
1089 $namespaces
1090 );
1091 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1092 }
1093
1094 if ( count( $namespaces ) === 1 ) {
1095 $operator = $opts[ 'invert' ] ? '!=' : '=';
1096 $value = $dbr->addQuotes( reset( $namespaces ) );
1097 } else {
1098 $operator = $opts[ 'invert' ] ? 'NOT IN' : 'IN';
1099 sort( $namespaces );
1100 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1101 }
1102 $conds[] = "rc_namespace $operator $value";
1103 }
1104 }
1105
1106 /**
1107 * Process the query
1108 *
1109 * @param array $tables Array of tables; see IDatabase::select $table
1110 * @param array $fields Array of fields; see IDatabase::select $vars
1111 * @param array $conds Array of conditions; see IDatabase::select $conds
1112 * @param array $query_options Array of query options; see IDatabase::select $options
1113 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1114 * @param FormOptions $opts
1115 * @return bool|ResultWrapper Result or false
1116 */
1117 protected function doMainQuery( $tables, $fields, $conds,
1118 $query_options, $join_conds, FormOptions $opts ) {
1119
1120 $tables[] = 'recentchanges';
1121 $fields = array_merge( RecentChange::selectFields(), $fields );
1122
1123 ChangeTags::modifyDisplayQuery(
1124 $tables,
1125 $fields,
1126 $conds,
1127 $join_conds,
1128 $query_options,
1129 ''
1130 );
1131
1132 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1133 $opts )
1134 ) {
1135 return false;
1136 }
1137
1138 $dbr = $this->getDB();
1139
1140 return $dbr->select(
1141 $tables,
1142 $fields,
1143 $conds,
1144 __METHOD__,
1145 $query_options,
1146 $join_conds
1147 );
1148 }
1149
1150 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1151 &$query_options, &$join_conds, $opts
1152 ) {
1153 return Hooks::run(
1154 'ChangesListSpecialPageQuery',
1155 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1156 );
1157 }
1158
1159 /**
1160 * Return a IDatabase object for reading
1161 *
1162 * @return IDatabase
1163 */
1164 protected function getDB() {
1165 return wfGetDB( DB_REPLICA );
1166 }
1167
1168 /**
1169 * Send output to the OutputPage object, only called if not used feeds
1170 *
1171 * @param ResultWrapper $rows Database rows
1172 * @param FormOptions $opts
1173 */
1174 public function webOutput( $rows, $opts ) {
1175 if ( !$this->including() ) {
1176 $this->outputFeedLinks();
1177 $this->doHeader( $opts, $rows->numRows() );
1178 }
1179
1180 $this->outputChangesList( $rows, $opts );
1181 }
1182
1183 /**
1184 * Output feed links.
1185 */
1186 public function outputFeedLinks() {
1187 // nothing by default
1188 }
1189
1190 /**
1191 * Build and output the actual changes list.
1192 *
1193 * @param ResultWrapper $rows Database rows
1194 * @param FormOptions $opts
1195 */
1196 abstract public function outputChangesList( $rows, $opts );
1197
1198 /**
1199 * Set the text to be displayed above the changes
1200 *
1201 * @param FormOptions $opts
1202 * @param int $numRows Number of rows in the result to show after this header
1203 */
1204 public function doHeader( $opts, $numRows ) {
1205 $this->setTopText( $opts );
1206
1207 // @todo Lots of stuff should be done here.
1208
1209 $this->setBottomText( $opts );
1210 }
1211
1212 /**
1213 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1214 * or similar methods to print the text.
1215 *
1216 * @param FormOptions $opts
1217 */
1218 public function setTopText( FormOptions $opts ) {
1219 // nothing by default
1220 }
1221
1222 /**
1223 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1224 * or similar methods to print the text.
1225 *
1226 * @param FormOptions $opts
1227 */
1228 public function setBottomText( FormOptions $opts ) {
1229 // nothing by default
1230 }
1231
1232 /**
1233 * Get options to be displayed in a form
1234 * @todo This should handle options returned by getDefaultOptions().
1235 * @todo Not called by anything in this class (but is in subclasses), should be
1236 * called by something… doHeader() maybe?
1237 *
1238 * @param FormOptions $opts
1239 * @return array
1240 */
1241 public function getExtraOptions( $opts ) {
1242 return [];
1243 }
1244
1245 /**
1246 * Return the legend displayed within the fieldset
1247 *
1248 * @return string
1249 */
1250 public function makeLegend() {
1251 $context = $this->getContext();
1252 $user = $context->getUser();
1253 # The legend showing what the letters and stuff mean
1254 $legend = Html::openElement( 'dl' ) . "\n";
1255 # Iterates through them and gets the messages for both letter and tooltip
1256 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1257 if ( !( $user->useRCPatrol() || $user->useNPPatrol() ) ) {
1258 unset( $legendItems['unpatrolled'] );
1259 }
1260 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1261 $label = isset( $item['legend'] ) ? $item['legend'] : $item['title'];
1262 $letter = $item['letter'];
1263 $cssClass = isset( $item['class'] ) ? $item['class'] : $key;
1264
1265 $legend .= Html::element( 'dt',
1266 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1267 ) . "\n" .
1268 Html::rawElement( 'dd',
1269 [ 'class' => Sanitizer::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1270 $context->msg( $label )->parse()
1271 ) . "\n";
1272 }
1273 # (+-123)
1274 $legend .= Html::rawElement( 'dt',
1275 [ 'class' => 'mw-plusminus-pos' ],
1276 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1277 ) . "\n";
1278 $legend .= Html::element(
1279 'dd',
1280 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1281 $context->msg( 'recentchanges-label-plusminus' )->text()
1282 ) . "\n";
1283 $legend .= Html::closeElement( 'dl' ) . "\n";
1284
1285 # Collapsibility
1286 $legend =
1287 '<div class="mw-changeslist-legend">' .
1288 $context->msg( 'recentchanges-legend-heading' )->parse() .
1289 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1290 '</div>';
1291
1292 return $legend;
1293 }
1294
1295 /**
1296 * Add page-specific modules.
1297 */
1298 protected function addModules() {
1299 $out = $this->getOutput();
1300 // Styles and behavior for the legend box (see makeLegend())
1301 $out->addModuleStyles( [
1302 'mediawiki.special.changeslist.legend',
1303 'mediawiki.special.changeslist',
1304 ] );
1305 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1306 }
1307
1308 protected function getGroupName() {
1309 return 'changes';
1310 }
1311
1312 /**
1313 * Filter on users' experience levels; this will not be called if nothing is
1314 * selected.
1315 *
1316 * @param string $specialPageClassName Class name of current special page
1317 * @param IContextSource $context Context, for e.g. user
1318 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1319 * @param array &$tables Array of tables; see IDatabase::select $table
1320 * @param array &$fields Array of fields; see IDatabase::select $vars
1321 * @param array &$conds Array of conditions; see IDatabase::select $conds
1322 * @param array &$query_options Array of query options; see IDatabase::select $options
1323 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1324 * @param array $selectedExpLevels The allowed active values, sorted
1325 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1326 * (optional)
1327 */
1328 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1329 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0 ) {
1330
1331 global $wgLearnerEdits,
1332 $wgExperiencedUserEdits,
1333 $wgLearnerMemberSince,
1334 $wgExperiencedUserMemberSince;
1335
1336 $LEVEL_COUNT = 3;
1337
1338 // If all levels are selected, all logged-in users are included (but no
1339 // anons), so we can short-circuit.
1340 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1341 $conds[] = 'rc_user != 0';
1342 return;
1343 }
1344
1345 $tables[] = 'user';
1346 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1347
1348 if ( $now === 0 ) {
1349 $now = time();
1350 }
1351 $secondsPerDay = 86400;
1352 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1353 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1354
1355 $aboveNewcomer = $dbr->makeList(
1356 [
1357 'user_editcount >= ' . intval( $wgLearnerEdits ),
1358 'user_registration <= ' . $dbr->timestamp( $learnerCutoff ),
1359 ],
1360 IDatabase::LIST_AND
1361 );
1362
1363 $aboveLearner = $dbr->makeList(
1364 [
1365 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1366 'user_registration <= ' . $dbr->timestamp( $experiencedUserCutoff ),
1367 ],
1368 IDatabase::LIST_AND
1369 );
1370
1371 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1372 $conds[] = "NOT ( $aboveNewcomer )";
1373 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1374 $conds[] = $dbr->makeList(
1375 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1376 IDatabase::LIST_AND
1377 );
1378 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1379 $conds[] = $aboveLearner;
1380 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1381 $conds[] = "NOT ( $aboveLearner )";
1382 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1383 $conds[] = $dbr->makeList(
1384 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1385 IDatabase::LIST_OR
1386 );
1387 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1388 $conds[] = $aboveNewcomer;
1389 }
1390 }
1391 }