Add (hacky) check for webm audio 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 if ( $group->getConflictingGroups() ) {
474 wfLogWarning(
475 $group->getName() .
476 " specifies conflicts with other groups but these are not supported yet."
477 );
478 }
479
480 /** @var ChangesListFilter $conflictingFilter */
481 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
482 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
483 return true;
484 }
485 }
486
487 /** @var ChangesListFilter $filter */
488 foreach ( $group->getFilters() as $filter ) {
489 /** @var ChangesListFilter $conflictingFilter */
490 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
491 if (
492 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
493 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
494 ) {
495 return true;
496 }
497 }
498
499 }
500
501 }
502
503 return false;
504 }
505
506 /**
507 * Main execution point
508 *
509 * @param string $subpage
510 */
511 public function execute( $subpage ) {
512 $this->rcSubpage = $subpage;
513
514 $this->setHeaders();
515 $this->outputHeader();
516 $this->addModules();
517
518 $rows = $this->getRows();
519 $opts = $this->getOptions();
520 if ( $rows === false ) {
521 if ( !$this->including() ) {
522 $this->doHeader( $opts, 0 );
523 $this->outputNoResults();
524 $this->getOutput()->setStatusCode( 404 );
525 }
526
527 return;
528 }
529
530 $batch = new LinkBatch;
531 foreach ( $rows as $row ) {
532 $batch->add( NS_USER, $row->rc_user_text );
533 $batch->add( NS_USER_TALK, $row->rc_user_text );
534 $batch->add( $row->rc_namespace, $row->rc_title );
535 if ( $row->rc_source === RecentChange::SRC_LOG ) {
536 $formatter = LogFormatter::newFromRow( $row );
537 foreach ( $formatter->getPreloadTitles() as $title ) {
538 $batch->addObj( $title );
539 }
540 }
541 }
542 $batch->execute();
543 $this->webOutput( $rows, $opts );
544
545 $rows->free();
546
547 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
548 // Clean up any bad page entries for titles showing up in RC
549 DeferredUpdates::addUpdate( new WANCacheReapUpdate(
550 $this->getDB(),
551 LoggerFactory::getInstance( 'objectcache' )
552 ) );
553 }
554 }
555
556 /**
557 * Add the "no results" message to the output
558 */
559 protected function outputNoResults() {
560 $this->getOutput()->addHTML(
561 '<div class="mw-changeslist-empty">' .
562 $this->msg( 'recentchanges-noresult' )->parse() .
563 '</div>'
564 );
565 }
566
567 /**
568 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
569 *
570 * @return bool|ResultWrapper Result or false
571 */
572 public function getRows() {
573 $opts = $this->getOptions();
574
575 $tables = [];
576 $fields = [];
577 $conds = [];
578 $query_options = [];
579 $join_conds = [];
580 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
581
582 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
583 }
584
585 /**
586 * Get the current FormOptions for this request
587 *
588 * @return FormOptions
589 */
590 public function getOptions() {
591 if ( $this->rcOptions === null ) {
592 $this->rcOptions = $this->setup( $this->rcSubpage );
593 }
594
595 return $this->rcOptions;
596 }
597
598 /**
599 * Register all filters and their groups (including those from hooks), plus handle
600 * conflicts and defaults.
601 *
602 * You might want to customize these in the same method, in subclasses. You can
603 * call getFilterGroup to access a group, and (on the group) getFilter to access a
604 * filter, then make necessary modfications to the filter or group (e.g. with
605 * setDefault).
606 */
607 protected function registerFilters() {
608 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions );
609
610 // Make sure this is not being transcluded (we don't want to show this
611 // information to all users just because the user that saves the edit can
612 // patrol or is logged in)
613 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
614 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition );
615 }
616
617 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
618
619 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
620 $transformedHideCategorizationDef = $this->transformFilterDefinition(
621 $this->hideCategorizationFilterDefinition
622 );
623
624 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
625
626 $hideCategorization = new ChangesListBooleanFilter(
627 $transformedHideCategorizationDef
628 );
629 }
630
631 Hooks::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
632
633 $unstructuredGroupDefinition =
634 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
635 $this->getCustomFilters()
636 );
637 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
638
639 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
640
641 $registration = $this->getFilterGroup( 'registration' );
642 $anons = $registration->getFilter( 'hideanons' );
643
644 // This means there is a conflict between any item in user experience level
645 // being checked and only anons being *shown* (hideliu=1&hideanons=0 in the
646 // URL, or equivalent).
647 $userExperienceLevel->conflictsWith(
648 $anons,
649 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered-global',
650 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered',
651 'rcfilters-filter-unregistered-conflicts-user-experience-level'
652 );
653
654 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
655 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
656 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
657
658 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
659 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
660
661 // categoryFilter is conditional; see registerFilters
662 if ( $categoryFilter !== null ) {
663 $hideMinorFilter->conflictsWith(
664 $categoryFilter,
665 'rcfilters-hideminor-conflicts-typeofchange-global',
666 'rcfilters-hideminor-conflicts-typeofchange',
667 'rcfilters-typeofchange-conflicts-hideminor'
668 );
669 }
670 $hideMinorFilter->conflictsWith(
671 $logactionsFilter,
672 'rcfilters-hideminor-conflicts-typeofchange-global',
673 'rcfilters-hideminor-conflicts-typeofchange',
674 'rcfilters-typeofchange-conflicts-hideminor'
675 );
676 $hideMinorFilter->conflictsWith(
677 $pagecreationFilter,
678 'rcfilters-hideminor-conflicts-typeofchange-global',
679 'rcfilters-hideminor-conflicts-typeofchange',
680 'rcfilters-typeofchange-conflicts-hideminor'
681 );
682 }
683
684 /**
685 * Transforms filter definition to prepare it for constructor.
686 *
687 * See overrides of this method as well.
688 *
689 * @param array $filterDefinition Original filter definition
690 *
691 * @return array Transformed definition
692 */
693 protected function transformFilterDefinition( array $filterDefinition ) {
694 return $filterDefinition;
695 }
696
697 /**
698 * Register filters from a definition object
699 *
700 * Array specifying groups and their filters; see Filter and
701 * ChangesListFilterGroup constructors.
702 *
703 * There is light processing to simplify core maintenance.
704 */
705 protected function registerFiltersFromDefinitions( array $definition ) {
706 $autoFillPriority = -1;
707 foreach ( $definition as $groupDefinition ) {
708 if ( !isset( $groupDefinition['priority'] ) ) {
709 $groupDefinition['priority'] = $autoFillPriority;
710 } else {
711 // If it's explicitly specified, start over the auto-fill
712 $autoFillPriority = $groupDefinition['priority'];
713 }
714
715 $autoFillPriority--;
716
717 $className = $groupDefinition['class'];
718 unset( $groupDefinition['class'] );
719
720 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
721 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
722 }
723
724 $this->registerFilterGroup( new $className( $groupDefinition ) );
725 }
726 }
727
728 /**
729 * Get filter group definition from legacy custom filters
730 *
731 * @param array $customFilters Custom filters from legacy hooks
732 * @return array Group definition
733 */
734 protected function getFilterGroupDefinitionFromLegacyCustomFilters( array $customFilters ) {
735 // Special internal unstructured group
736 $unstructuredGroupDefinition = [
737 'name' => 'unstructured',
738 'class' => ChangesListBooleanFilterGroup::class,
739 'priority' => -1, // Won't display in structured
740 'filters' => [],
741 ];
742
743 foreach ( $customFilters as $name => $params ) {
744 $unstructuredGroupDefinition['filters'][] = [
745 'name' => $name,
746 'showHide' => $params['msg'],
747 'default' => $params['default'],
748 ];
749 }
750
751 return $unstructuredGroupDefinition;
752 }
753
754 /**
755 * Register all the filters, including legacy hook-driven ones.
756 * Then create a FormOptions object with options as specified by the user
757 *
758 * @param array $parameters
759 *
760 * @return FormOptions
761 */
762 public function setup( $parameters ) {
763 $this->registerFilters();
764
765 $opts = $this->getDefaultOptions();
766
767 $opts = $this->fetchOptionsFromRequest( $opts );
768
769 // Give precedence to subpage syntax
770 if ( $parameters !== null ) {
771 $this->parseParameters( $parameters, $opts );
772 }
773
774 $this->validateOptions( $opts );
775
776 return $opts;
777 }
778
779 /**
780 * Get a FormOptions object containing the default options. By default, returns
781 * some basic options. The filters listed explicitly here are overriden in this
782 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
783 * and more) are structured. Structured filters are overriden in registerFilters.
784 * not here.
785 *
786 * @return FormOptions
787 */
788 public function getDefaultOptions() {
789 $config = $this->getConfig();
790 $opts = new FormOptions();
791 $structuredUI = $this->getUser()->getOption( 'rcenhancedfilters' );
792 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
793 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
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(), $useDefaults ? $filterGroup->getDefault() : '' );
801 } else {
802 foreach ( $filterGroup->getFilters() as $filter ) {
803 $opts->add( $filter->getName(), $useDefaults ? $filter->getDefault( $structuredUI ) : false );
804 }
805 }
806 }
807
808 $opts->add( 'namespace', '', FormOptions::STRING );
809 $opts->add( 'invert', false );
810 $opts->add( 'associated', false );
811 $opts->add( 'urlversion', 1 );
812
813 return $opts;
814 }
815
816 /**
817 * Register a structured changes list filter group
818 *
819 * @param ChangesListFilterGroup $group
820 */
821 public function registerFilterGroup( ChangesListFilterGroup $group ) {
822 $groupName = $group->getName();
823
824 $this->filterGroups[$groupName] = $group;
825 }
826
827 /**
828 * Gets the currently registered filters groups
829 *
830 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
831 */
832 protected function getFilterGroups() {
833 return $this->filterGroups;
834 }
835
836 /**
837 * Gets a specified ChangesListFilterGroup by name
838 *
839 * @param string $groupName Name of group
840 *
841 * @return ChangesListFilterGroup|null Group, or null if not registered
842 */
843 public function getFilterGroup( $groupName ) {
844 return isset( $this->filterGroups[$groupName] ) ?
845 $this->filterGroups[$groupName] :
846 null;
847 }
848
849 // Currently, this intentionally only includes filters that display
850 // in the structured UI. This can be changed easily, though, if we want
851 // to include data on filters that use the unstructured UI. messageKeys is a
852 // special top-level value, with the value being an array of the message keys to
853 // send to the client.
854 /**
855 * Gets structured filter information needed by JS
856 *
857 * @return array Associative array
858 * * array $return['groups'] Group data
859 * * array $return['messageKeys'] Array of message keys
860 */
861 public function getStructuredFilterJsData() {
862 $output = [
863 'groups' => [],
864 'messageKeys' => [],
865 ];
866
867 $context = $this->getContext();
868
869 usort( $this->filterGroups, function ( $a, $b ) {
870 return $b->getPriority() - $a->getPriority();
871 } );
872
873 foreach ( $this->filterGroups as $groupName => $group ) {
874 $groupOutput = $group->getJsData( $this );
875 if ( $groupOutput !== null ) {
876 $output['messageKeys'] = array_merge(
877 $output['messageKeys'],
878 $groupOutput['messageKeys']
879 );
880
881 unset( $groupOutput['messageKeys'] );
882 $output['groups'][] = $groupOutput;
883 }
884 }
885
886 return $output;
887 }
888
889 /**
890 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
891 * hook.
892 *
893 * @return array Map of filter URL param names to properties (msg/default)
894 */
895 protected function getCustomFilters() {
896 if ( $this->customFilters === null ) {
897 $this->customFilters = [];
898 Hooks::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters ], '1.29' );
899 }
900
901 return $this->customFilters;
902 }
903
904 /**
905 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
906 *
907 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
908 *
909 * @param FormOptions $opts
910 * @return FormOptions
911 */
912 protected function fetchOptionsFromRequest( $opts ) {
913 $opts->fetchValuesFromRequest( $this->getRequest() );
914
915 return $opts;
916 }
917
918 /**
919 * Process $par and put options found in $opts. Used when including the page.
920 *
921 * @param string $par
922 * @param FormOptions $opts
923 */
924 public function parseParameters( $par, FormOptions $opts ) {
925 $stringParameterNameSet = [];
926 $hideParameterNameSet = [];
927
928 // URL parameters can be per-group, like 'userExpLevel',
929 // or per-filter, like 'hideminor'.
930
931 foreach ( $this->filterGroups as $filterGroup ) {
932 if ( $filterGroup->isPerGroupRequestParameter() ) {
933 $stringParameterNameSet[$filterGroup->getName()] = true;
934 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup::TYPE ) {
935 foreach ( $filterGroup->getFilters() as $filter ) {
936 $hideParameterNameSet[$filter->getName()] = true;
937 }
938 }
939 }
940
941 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
942 foreach ( $bits as $bit ) {
943 $m = [];
944 if ( isset( $hideParameterNameSet[$bit] ) ) {
945 // hidefoo => hidefoo=true
946 $opts[$bit] = true;
947 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
948 // foo => hidefoo=false
949 $opts["hide$bit"] = false;
950 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
951 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
952 $opts[$m[1]] = $m[2];
953 }
954 }
955 }
956 }
957
958 /**
959 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
960 *
961 * @param FormOptions $opts
962 */
963 public function validateOptions( FormOptions $opts ) {
964 if ( $this->fixContradictoryOptions( $opts ) ) {
965 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
966 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
967 }
968 }
969
970 /**
971 * Fix invalid options by resetting pairs that should never appear together.
972 *
973 * @param FormOptions $opts
974 * @return bool True if any option was reset
975 */
976 private function fixContradictoryOptions( FormOptions $opts ) {
977 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
978
979 foreach ( $this->filterGroups as $filterGroup ) {
980 if ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
981 $filters = $filterGroup->getFilters();
982
983 if ( count( $filters ) === 1 ) {
984 // legacy boolean filters should not be considered
985 continue;
986 }
987
988 $allInGroupEnabled = array_reduce(
989 $filters,
990 function ( $carry, $filter ) use ( $opts ) {
991 return $carry && $opts[ $filter->getName() ];
992 },
993 /* initialValue */ count( $filters ) > 0
994 );
995
996 if ( $allInGroupEnabled ) {
997 foreach ( $filters as $filter ) {
998 $opts[ $filter->getName() ] = false;
999 }
1000
1001 $fixed = true;
1002 }
1003 }
1004 }
1005
1006 return $fixed;
1007 }
1008
1009 /**
1010 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1011 * compatibility.
1012 *
1013 * This is deprecated and may be removed.
1014 *
1015 * @param FormOptions $opts
1016 * @return bool True if this change was mode
1017 */
1018 private function fixBackwardsCompatibilityOptions( FormOptions $opts ) {
1019 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1020 $opts->reset( 'hideanons' );
1021 if ( !$opts['hidebots'] ) {
1022 $opts->reset( 'hideliu' );
1023 $opts['hidehumans'] = 1;
1024 }
1025
1026 return true;
1027 }
1028
1029 return false;
1030 }
1031
1032 /**
1033 * Convert parameters values from true/false to 1/0
1034 * so they are not omitted by wfArrayToCgi()
1035 * Bug 36524
1036 *
1037 * @param array $params
1038 * @return array
1039 */
1040 protected function convertParamsForLink( $params ) {
1041 foreach ( $params as &$value ) {
1042 if ( $value === false ) {
1043 $value = '0';
1044 }
1045 }
1046 unset( $value );
1047 return $params;
1048 }
1049
1050 /**
1051 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1052 * the user requested.
1053 *
1054 * @param array &$tables Array of tables; see IDatabase::select $table
1055 * @param array &$fields Array of fields; see IDatabase::select $vars
1056 * @param array &$conds Array of conditions; see IDatabase::select $conds
1057 * @param array &$query_options Array of query options; see IDatabase::select $options
1058 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1059 * @param FormOptions $opts
1060 */
1061 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1062 &$join_conds, FormOptions $opts
1063 ) {
1064 $dbr = $this->getDB();
1065 $user = $this->getUser();
1066
1067 $context = $this->getContext();
1068 foreach ( $this->filterGroups as $filterGroup ) {
1069 // URL parameters can be per-group, like 'userExpLevel',
1070 // or per-filter, like 'hideminor'.
1071 if ( $filterGroup->isPerGroupRequestParameter() ) {
1072 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1073 $query_options, $join_conds, $opts[$filterGroup->getName()] );
1074 } else {
1075 foreach ( $filterGroup->getFilters() as $filter ) {
1076 if ( $opts[$filter->getName()] ) {
1077 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1078 $query_options, $join_conds );
1079 }
1080 }
1081 }
1082 }
1083
1084 // Namespace filtering
1085 if ( $opts[ 'namespace' ] !== '' ) {
1086 $namespaces = explode( ';', $opts[ 'namespace' ] );
1087
1088 if ( $opts[ 'associated' ] ) {
1089 $associatedNamespaces = array_map(
1090 function ( $ns ) {
1091 return MWNamespace::getAssociated( $ns );
1092 },
1093 $namespaces
1094 );
1095 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1096 }
1097
1098 if ( count( $namespaces ) === 1 ) {
1099 $operator = $opts[ 'invert' ] ? '!=' : '=';
1100 $value = $dbr->addQuotes( reset( $namespaces ) );
1101 } else {
1102 $operator = $opts[ 'invert' ] ? 'NOT IN' : 'IN';
1103 sort( $namespaces );
1104 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1105 }
1106 $conds[] = "rc_namespace $operator $value";
1107 }
1108 }
1109
1110 /**
1111 * Process the query
1112 *
1113 * @param array $tables Array of tables; see IDatabase::select $table
1114 * @param array $fields Array of fields; see IDatabase::select $vars
1115 * @param array $conds Array of conditions; see IDatabase::select $conds
1116 * @param array $query_options Array of query options; see IDatabase::select $options
1117 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1118 * @param FormOptions $opts
1119 * @return bool|ResultWrapper Result or false
1120 */
1121 protected function doMainQuery( $tables, $fields, $conds,
1122 $query_options, $join_conds, FormOptions $opts
1123 ) {
1124 $tables[] = 'recentchanges';
1125 $fields = array_merge( RecentChange::selectFields(), $fields );
1126
1127 ChangeTags::modifyDisplayQuery(
1128 $tables,
1129 $fields,
1130 $conds,
1131 $join_conds,
1132 $query_options,
1133 ''
1134 );
1135
1136 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1137 $opts )
1138 ) {
1139 return false;
1140 }
1141
1142 $dbr = $this->getDB();
1143
1144 return $dbr->select(
1145 $tables,
1146 $fields,
1147 $conds,
1148 __METHOD__,
1149 $query_options,
1150 $join_conds
1151 );
1152 }
1153
1154 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1155 &$query_options, &$join_conds, $opts
1156 ) {
1157 return Hooks::run(
1158 'ChangesListSpecialPageQuery',
1159 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1160 );
1161 }
1162
1163 /**
1164 * Return a IDatabase object for reading
1165 *
1166 * @return IDatabase
1167 */
1168 protected function getDB() {
1169 return wfGetDB( DB_REPLICA );
1170 }
1171
1172 /**
1173 * Send output to the OutputPage object, only called if not used feeds
1174 *
1175 * @param ResultWrapper $rows Database rows
1176 * @param FormOptions $opts
1177 */
1178 public function webOutput( $rows, $opts ) {
1179 if ( !$this->including() ) {
1180 $this->outputFeedLinks();
1181 $this->doHeader( $opts, $rows->numRows() );
1182 }
1183
1184 $this->outputChangesList( $rows, $opts );
1185 }
1186
1187 /**
1188 * Output feed links.
1189 */
1190 public function outputFeedLinks() {
1191 // nothing by default
1192 }
1193
1194 /**
1195 * Build and output the actual changes list.
1196 *
1197 * @param ResultWrapper $rows Database rows
1198 * @param FormOptions $opts
1199 */
1200 abstract public function outputChangesList( $rows, $opts );
1201
1202 /**
1203 * Set the text to be displayed above the changes
1204 *
1205 * @param FormOptions $opts
1206 * @param int $numRows Number of rows in the result to show after this header
1207 */
1208 public function doHeader( $opts, $numRows ) {
1209 $this->setTopText( $opts );
1210
1211 // @todo Lots of stuff should be done here.
1212
1213 $this->setBottomText( $opts );
1214 }
1215
1216 /**
1217 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1218 * or similar methods to print the text.
1219 *
1220 * @param FormOptions $opts
1221 */
1222 public function setTopText( FormOptions $opts ) {
1223 // nothing by default
1224 }
1225
1226 /**
1227 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1228 * or similar methods to print the text.
1229 *
1230 * @param FormOptions $opts
1231 */
1232 public function setBottomText( FormOptions $opts ) {
1233 // nothing by default
1234 }
1235
1236 /**
1237 * Get options to be displayed in a form
1238 * @todo This should handle options returned by getDefaultOptions().
1239 * @todo Not called by anything in this class (but is in subclasses), should be
1240 * called by something… doHeader() maybe?
1241 *
1242 * @param FormOptions $opts
1243 * @return array
1244 */
1245 public function getExtraOptions( $opts ) {
1246 return [];
1247 }
1248
1249 /**
1250 * Return the legend displayed within the fieldset
1251 *
1252 * @return string
1253 */
1254 public function makeLegend() {
1255 $context = $this->getContext();
1256 $user = $context->getUser();
1257 # The legend showing what the letters and stuff mean
1258 $legend = Html::openElement( 'dl' ) . "\n";
1259 # Iterates through them and gets the messages for both letter and tooltip
1260 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1261 if ( !( $user->useRCPatrol() || $user->useNPPatrol() ) ) {
1262 unset( $legendItems['unpatrolled'] );
1263 }
1264 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1265 $label = isset( $item['legend'] ) ? $item['legend'] : $item['title'];
1266 $letter = $item['letter'];
1267 $cssClass = isset( $item['class'] ) ? $item['class'] : $key;
1268
1269 $legend .= Html::element( 'dt',
1270 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1271 ) . "\n" .
1272 Html::rawElement( 'dd',
1273 [ 'class' => Sanitizer::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1274 $context->msg( $label )->parse()
1275 ) . "\n";
1276 }
1277 # (+-123)
1278 $legend .= Html::rawElement( 'dt',
1279 [ 'class' => 'mw-plusminus-pos' ],
1280 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1281 ) . "\n";
1282 $legend .= Html::element(
1283 'dd',
1284 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1285 $context->msg( 'recentchanges-label-plusminus' )->text()
1286 ) . "\n";
1287 $legend .= Html::closeElement( 'dl' ) . "\n";
1288
1289 # Collapsibility
1290 $legend =
1291 '<div class="mw-changeslist-legend">' .
1292 $context->msg( 'recentchanges-legend-heading' )->parse() .
1293 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1294 '</div>';
1295
1296 return $legend;
1297 }
1298
1299 /**
1300 * Add page-specific modules.
1301 */
1302 protected function addModules() {
1303 $out = $this->getOutput();
1304 // Styles and behavior for the legend box (see makeLegend())
1305 $out->addModuleStyles( [
1306 'mediawiki.special.changeslist.legend',
1307 'mediawiki.special.changeslist',
1308 ] );
1309 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1310 }
1311
1312 protected function getGroupName() {
1313 return 'changes';
1314 }
1315
1316 /**
1317 * Filter on users' experience levels; this will not be called if nothing is
1318 * selected.
1319 *
1320 * @param string $specialPageClassName Class name of current special page
1321 * @param IContextSource $context Context, for e.g. user
1322 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1323 * @param array &$tables Array of tables; see IDatabase::select $table
1324 * @param array &$fields Array of fields; see IDatabase::select $vars
1325 * @param array &$conds Array of conditions; see IDatabase::select $conds
1326 * @param array &$query_options Array of query options; see IDatabase::select $options
1327 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1328 * @param array $selectedExpLevels The allowed active values, sorted
1329 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1330 * (optional)
1331 */
1332 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1333 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1334 ) {
1335 global $wgLearnerEdits,
1336 $wgExperiencedUserEdits,
1337 $wgLearnerMemberSince,
1338 $wgExperiencedUserMemberSince;
1339
1340 $LEVEL_COUNT = 3;
1341
1342 // If all levels are selected, all logged-in users are included (but no
1343 // anons), so we can short-circuit.
1344 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1345 $conds[] = 'rc_user != 0';
1346 return;
1347 }
1348
1349 $tables[] = 'user';
1350 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1351
1352 if ( $now === 0 ) {
1353 $now = time();
1354 }
1355 $secondsPerDay = 86400;
1356 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1357 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1358
1359 $aboveNewcomer = $dbr->makeList(
1360 [
1361 'user_editcount >= ' . intval( $wgLearnerEdits ),
1362 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1363 ],
1364 IDatabase::LIST_AND
1365 );
1366
1367 $aboveLearner = $dbr->makeList(
1368 [
1369 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1370 'user_registration <= ' .
1371 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1372 ],
1373 IDatabase::LIST_AND
1374 );
1375
1376 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1377 $conds[] = "NOT ( $aboveNewcomer )";
1378 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1379 $conds[] = $dbr->makeList(
1380 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1381 IDatabase::LIST_AND
1382 );
1383 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1384 $conds[] = $aboveLearner;
1385 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1386 $conds[] = "NOT ( $aboveLearner )";
1387 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1388 $conds[] = $dbr->makeList(
1389 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1390 IDatabase::LIST_OR
1391 );
1392 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1393 $conds[] = $aboveNewcomer;
1394 }
1395 }
1396 }