Merge "ApiSandbox: Specify a $overlay for menu-using widgets"
[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' => 'lastRevision',
259 'title' => 'rcfilters-filtergroup-lastRevision',
260 'class' => ChangesListBooleanFilterGroup::class,
261 'priority' => -7,
262 'filters' => [
263 [
264 'name' => 'hidelastrevision',
265 'label' => 'rcfilters-filter-lastrevision-label',
266 'description' => 'rcfilters-filter-lastrevision-description',
267 'default' => false,
268 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
269 &$query_options, &$join_conds ) {
270 $conds[] = 'rc_this_oldid <> page_latest';
271 },
272 'cssClassSuffix' => 'last',
273 'isRowApplicableCallable' => function ( $ctx, $rc ) {
274 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
275 }
276 ],
277 [
278 'name' => 'hidepreviousrevisions',
279 'label' => 'rcfilters-filter-previousrevision-label',
280 'description' => 'rcfilters-filter-previousrevision-description',
281 'default' => false,
282 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
283 &$query_options, &$join_conds ) {
284 $conds[] = 'rc_this_oldid = page_latest';
285 },
286 'cssClassSuffix' => 'previous',
287 'isRowApplicableCallable' => function ( $ctx, $rc ) {
288 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
289 }
290 ]
291 ]
292 ],
293
294 [
295 'name' => 'significance',
296 'title' => 'rcfilters-filtergroup-significance',
297 'class' => ChangesListBooleanFilterGroup::class,
298 'priority' => -6,
299 'filters' => [
300 [
301 'name' => 'hideminor',
302 'label' => 'rcfilters-filter-minor-label',
303 'description' => 'rcfilters-filter-minor-description',
304 // rcshowhideminor-show, rcshowhideminor-hide,
305 // wlshowhideminor
306 'showHideSuffix' => 'showhideminor',
307 'default' => false,
308 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
309 &$query_options, &$join_conds ) {
310
311 $conds[] = 'rc_minor = 0';
312 },
313 'cssClassSuffix' => 'minor',
314 'isRowApplicableCallable' => function ( $ctx, $rc ) {
315 return $rc->getAttribute( 'rc_minor' );
316 }
317 ],
318 [
319 'name' => 'hidemajor',
320 'label' => 'rcfilters-filter-major-label',
321 'description' => 'rcfilters-filter-major-description',
322 'default' => false,
323 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
324 &$query_options, &$join_conds ) {
325
326 $conds[] = 'rc_minor = 1';
327 },
328 'cssClassSuffix' => 'major',
329 'isRowApplicableCallable' => function ( $ctx, $rc ) {
330 return !$rc->getAttribute( 'rc_minor' );
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 'filters' => [
342 [
343 'name' => 'hidepageedits',
344 'label' => 'rcfilters-filter-pageedits-label',
345 'description' => 'rcfilters-filter-pageedits-description',
346 'default' => false,
347 'priority' => -2,
348 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
349 &$query_options, &$join_conds ) {
350
351 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT );
352 },
353 'cssClassSuffix' => 'src-mw-edit',
354 'isRowApplicableCallable' => function ( $ctx, $rc ) {
355 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_EDIT;
356 },
357 ],
358 [
359 'name' => 'hidenewpages',
360 'label' => 'rcfilters-filter-newpages-label',
361 'description' => 'rcfilters-filter-newpages-description',
362 'default' => false,
363 'priority' => -3,
364 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
365 &$query_options, &$join_conds ) {
366
367 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW );
368 },
369 'cssClassSuffix' => 'src-mw-new',
370 'isRowApplicableCallable' => function ( $ctx, $rc ) {
371 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_NEW;
372 },
373 ],
374
375 // hidecategorization
376
377 [
378 'name' => 'hidelog',
379 'label' => 'rcfilters-filter-logactions-label',
380 'description' => 'rcfilters-filter-logactions-description',
381 'default' => false,
382 'priority' => -5,
383 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
384 &$query_options, &$join_conds ) {
385
386 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG );
387 },
388 'cssClassSuffix' => 'src-mw-log',
389 'isRowApplicableCallable' => function ( $ctx, $rc ) {
390 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_LOG;
391 }
392 ],
393 ],
394 ],
395
396 [
397 'name' => 'watchlist',
398 'title' => 'rcfilters-filtergroup-watchlist',
399 'class' => ChangesListStringOptionsFilterGroup::class,
400 'isFullCoverage' => true,
401 'filters' => [
402 [
403 'name' => 'watched',
404 'label' => 'rcfilters-filter-watchlist-watched-label',
405 'description' => 'rcfilters-filter-watchlist-watched-description',
406 'cssClassSuffix' => 'watched',
407 'isRowApplicableCallable' => function ( $ctx, $rc ) {
408 return $rc->getAttribute( 'wl_user' );
409 }
410 ],
411 [
412 'name' => 'watchednew',
413 'label' => 'rcfilters-filter-watchlist-watchednew-label',
414 'description' => 'rcfilters-filter-watchlist-watchednew-description',
415 'cssClassSuffix' => 'watchednew',
416 'isRowApplicableCallable' => function ( $ctx, $rc ) {
417 return $rc->getAttribute( 'wl_user' ) &&
418 $rc->getAttribute( 'rc_timestamp' ) &&
419 $rc->getAttribute( 'wl_notificationtimestamp' ) &&
420 $rc->getAttribute( 'rc_timestamp' ) >= $rc->getAttribute( 'wl_notificationtimestamp' );
421 },
422 ],
423 [
424 'name' => 'notwatched',
425 'label' => 'rcfilters-filter-watchlist-notwatched-label',
426 'description' => 'rcfilters-filter-watchlist-notwatched-description',
427 'cssClassSuffix' => 'notwatched',
428 'isRowApplicableCallable' => function ( $ctx, $rc ) {
429 return $rc->getAttribute( 'wl_user' ) === null;
430 },
431 ]
432 ],
433 'default' => ChangesListStringOptionsFilterGroup::NONE,
434 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
435 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
436 sort( $selectedValues );
437 $notwatchedCond = 'wl_user IS NULL';
438 $watchedCond = 'wl_user IS NOT NULL';
439 $newCond = 'rc_timestamp >= wl_notificationtimestamp';
440
441 if ( $selectedValues === [ 'notwatched' ] ) {
442 $conds[] = $notwatchedCond;
443 return;
444 }
445
446 if ( $selectedValues === [ 'watched' ] ) {
447 $conds[] = $watchedCond;
448 return;
449 }
450
451 if ( $selectedValues === [ 'watchednew' ] ) {
452 $conds[] = $dbr->makeList( [
453 $watchedCond,
454 $newCond
455 ], LIST_AND );
456 return;
457 }
458
459 if ( $selectedValues === [ 'notwatched', 'watched' ] ) {
460 // no filters
461 return;
462 }
463
464 if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) {
465 $conds[] = $dbr->makeList( [
466 $notwatchedCond,
467 $dbr->makeList( [
468 $watchedCond,
469 $newCond
470 ], LIST_AND )
471 ], LIST_OR );
472 return;
473 }
474
475 if ( $selectedValues === [ 'watched', 'watchednew' ] ) {
476 $conds[] = $watchedCond;
477 return;
478 }
479
480 if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) {
481 // no filters
482 return;
483 }
484 },
485 ],
486 ];
487
488 $this->reviewStatusFilterGroupDefinition = [
489 [
490 'name' => 'reviewStatus',
491 'title' => 'rcfilters-filtergroup-reviewstatus',
492 'class' => ChangesListBooleanFilterGroup::class,
493 'priority' => -5,
494 'filters' => [
495 [
496 'name' => 'hidepatrolled',
497 'label' => 'rcfilters-filter-patrolled-label',
498 'description' => 'rcfilters-filter-patrolled-description',
499 // rcshowhidepatr-show, rcshowhidepatr-hide
500 // wlshowhidepatr
501 'showHideSuffix' => 'showhidepatr',
502 'default' => false,
503 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
504 &$query_options, &$join_conds ) {
505
506 $conds[] = 'rc_patrolled = 0';
507 },
508 'cssClassSuffix' => 'patrolled',
509 'isRowApplicableCallable' => function ( $ctx, $rc ) {
510 return $rc->getAttribute( 'rc_patrolled' );
511 },
512 ],
513 [
514 'name' => 'hideunpatrolled',
515 'label' => 'rcfilters-filter-unpatrolled-label',
516 'description' => 'rcfilters-filter-unpatrolled-description',
517 'default' => false,
518 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
519 &$query_options, &$join_conds ) {
520
521 $conds[] = 'rc_patrolled = 1';
522 },
523 'cssClassSuffix' => 'unpatrolled',
524 'isRowApplicableCallable' => function ( $ctx, $rc ) {
525 return !$rc->getAttribute( 'rc_patrolled' );
526 },
527 ],
528 ],
529 ]
530 ];
531
532 $this->hideCategorizationFilterDefinition = [
533 'name' => 'hidecategorization',
534 'label' => 'rcfilters-filter-categorization-label',
535 'description' => 'rcfilters-filter-categorization-description',
536 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
537 // wlshowhidecategorization
538 'showHideSuffix' => 'showhidecategorization',
539 'default' => false,
540 'priority' => -4,
541 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
542 &$query_options, &$join_conds ) {
543
544 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE );
545 },
546 'cssClassSuffix' => 'src-mw-categorize',
547 'isRowApplicableCallable' => function ( $ctx, $rc ) {
548 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_CATEGORIZE;
549 },
550 ];
551 }
552
553 /**
554 * Check if filters are in conflict and guaranteed to return no results.
555 *
556 * @return bool
557 */
558 protected function areFiltersInConflict() {
559 $opts = $this->getOptions();
560 /** @var ChangesListFilterGroup $group */
561 foreach ( $this->getFilterGroups() as $group ) {
562
563 if ( $group->getConflictingGroups() ) {
564 wfLogWarning(
565 $group->getName() .
566 " specifies conflicts with other groups but these are not supported yet."
567 );
568 }
569
570 /** @var ChangesListFilter $conflictingFilter */
571 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
572 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
573 return true;
574 }
575 }
576
577 /** @var ChangesListFilter $filter */
578 foreach ( $group->getFilters() as $filter ) {
579
580 /** @var ChangesListFilter $conflictingFilter */
581 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
582 if (
583 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
584 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
585 ) {
586 return true;
587 }
588 }
589
590 }
591
592 }
593
594 return false;
595 }
596
597 /**
598 * Main execution point
599 *
600 * @param string $subpage
601 */
602 public function execute( $subpage ) {
603 $this->rcSubpage = $subpage;
604
605 $this->setHeaders();
606 $this->outputHeader();
607 $this->addModules();
608
609 $rows = $this->getRows();
610 $opts = $this->getOptions();
611 if ( $rows === false ) {
612 if ( !$this->including() ) {
613 $this->doHeader( $opts, 0 );
614 $this->outputNoResults();
615 $this->getOutput()->setStatusCode( 404 );
616 }
617
618 return;
619 }
620
621 $batch = new LinkBatch;
622 foreach ( $rows as $row ) {
623 $batch->add( NS_USER, $row->rc_user_text );
624 $batch->add( NS_USER_TALK, $row->rc_user_text );
625 $batch->add( $row->rc_namespace, $row->rc_title );
626 if ( $row->rc_source === RecentChange::SRC_LOG ) {
627 $formatter = LogFormatter::newFromRow( $row );
628 foreach ( $formatter->getPreloadTitles() as $title ) {
629 $batch->addObj( $title );
630 }
631 }
632 }
633 $batch->execute();
634 $this->webOutput( $rows, $opts );
635
636 $rows->free();
637
638 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
639 // Clean up any bad page entries for titles showing up in RC
640 DeferredUpdates::addUpdate( new WANCacheReapUpdate(
641 $this->getDB(),
642 LoggerFactory::getInstance( 'objectcache' )
643 ) );
644 }
645 }
646
647 /**
648 * Add the "no results" message to the output
649 */
650 protected function outputNoResults() {
651 $this->getOutput()->addHTML(
652 '<div class="mw-changeslist-empty">' .
653 $this->msg( 'recentchanges-noresult' )->parse() .
654 '</div>'
655 );
656 }
657
658 /**
659 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
660 *
661 * @return bool|ResultWrapper Result or false
662 */
663 public function getRows() {
664 $opts = $this->getOptions();
665
666 $tables = [];
667 $fields = [];
668 $conds = [];
669 $query_options = [];
670 $join_conds = [];
671 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
672
673 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
674 }
675
676 /**
677 * Get the current FormOptions for this request
678 *
679 * @return FormOptions
680 */
681 public function getOptions() {
682 if ( $this->rcOptions === null ) {
683 $this->rcOptions = $this->setup( $this->rcSubpage );
684 }
685
686 return $this->rcOptions;
687 }
688
689 /**
690 * Register all filters and their groups (including those from hooks), plus handle
691 * conflicts and defaults.
692 *
693 * You might want to customize these in the same method, in subclasses. You can
694 * call getFilterGroup to access a group, and (on the group) getFilter to access a
695 * filter, then make necessary modfications to the filter or group (e.g. with
696 * setDefault).
697 */
698 protected function registerFilters() {
699 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions );
700
701 // Make sure this is not being transcluded (we don't want to show this
702 // information to all users just because the user that saves the edit can
703 // patrol)
704 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
705 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition );
706 }
707
708 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
709
710 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
711 $transformedHideCategorizationDef = $this->transformFilterDefinition(
712 $this->hideCategorizationFilterDefinition
713 );
714
715 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
716
717 $hideCategorization = new ChangesListBooleanFilter(
718 $transformedHideCategorizationDef
719 );
720 }
721
722 Hooks::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
723
724 $unstructuredGroupDefinition =
725 $this->getFilterGroupDefinitionFromLegacyCustomFilters(
726 $this->getCustomFilters()
727 );
728 $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] );
729
730 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
731
732 $registration = $this->getFilterGroup( 'registration' );
733 $anons = $registration->getFilter( 'hideanons' );
734
735 // This means there is a conflict between any item in user experience level
736 // being checked and only anons being *shown* (hideliu=1&hideanons=0 in the
737 // URL, or equivalent).
738 $userExperienceLevel->conflictsWith(
739 $anons,
740 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered-global',
741 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered',
742 'rcfilters-filter-unregistered-conflicts-user-experience-level'
743 );
744
745 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
746 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
747 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
748
749 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
750 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
751
752 // categoryFilter is conditional; see registerFilters
753 if ( $categoryFilter !== null ) {
754 $hideMinorFilter->conflictsWith(
755 $categoryFilter,
756 'rcfilters-hideminor-conflicts-typeofchange-global',
757 'rcfilters-hideminor-conflicts-typeofchange',
758 'rcfilters-typeofchange-conflicts-hideminor'
759 );
760 }
761 $hideMinorFilter->conflictsWith(
762 $logactionsFilter,
763 'rcfilters-hideminor-conflicts-typeofchange-global',
764 'rcfilters-hideminor-conflicts-typeofchange',
765 'rcfilters-typeofchange-conflicts-hideminor'
766 );
767 $hideMinorFilter->conflictsWith(
768 $pagecreationFilter,
769 'rcfilters-hideminor-conflicts-typeofchange-global',
770 'rcfilters-hideminor-conflicts-typeofchange',
771 'rcfilters-typeofchange-conflicts-hideminor'
772 );
773
774 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
775 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
776 $watchlistGroup->getFilter( 'watchednew' )
777 );
778 }
779
780 /**
781 * Transforms filter definition to prepare it for constructor.
782 *
783 * See overrides of this method as well.
784 *
785 * @param array $filterDefinition Original filter definition
786 *
787 * @return array Transformed definition
788 */
789 protected function transformFilterDefinition( array $filterDefinition ) {
790 return $filterDefinition;
791 }
792
793 /**
794 * Register filters from a definition object
795 *
796 * Array specifying groups and their filters; see Filter and
797 * ChangesListFilterGroup constructors.
798 *
799 * There is light processing to simplify core maintenance.
800 */
801 protected function registerFiltersFromDefinitions( array $definition ) {
802 $autoFillPriority = -1;
803 foreach ( $definition as $groupDefinition ) {
804 if ( !isset( $groupDefinition['priority'] ) ) {
805 $groupDefinition['priority'] = $autoFillPriority;
806 } else {
807 // If it's explicitly specified, start over the auto-fill
808 $autoFillPriority = $groupDefinition['priority'];
809 }
810
811 $autoFillPriority--;
812
813 $className = $groupDefinition['class'];
814 unset( $groupDefinition['class'] );
815
816 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
817 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
818 }
819
820 $this->registerFilterGroup( new $className( $groupDefinition ) );
821 }
822 }
823
824 /**
825 * Get filter group definition from legacy custom filters
826 *
827 * @param array Custom filters from legacy hooks
828 * @return array Group definition
829 */
830 protected function getFilterGroupDefinitionFromLegacyCustomFilters( $customFilters ) {
831 // Special internal unstructured group
832 $unstructuredGroupDefinition = [
833 'name' => 'unstructured',
834 'class' => ChangesListBooleanFilterGroup::class,
835 'priority' => -1, // Won't display in structured
836 'filters' => [],
837 ];
838
839 foreach ( $customFilters as $name => $params ) {
840 $unstructuredGroupDefinition['filters'][] = [
841 'name' => $name,
842 'showHide' => $params['msg'],
843 'default' => $params['default'],
844 ];
845 }
846
847 return $unstructuredGroupDefinition;
848 }
849
850 /**
851 * Register all the filters, including legacy hook-driven ones.
852 * Then create a FormOptions object with options as specified by the user
853 *
854 * @param array $parameters
855 *
856 * @return FormOptions
857 */
858 public function setup( $parameters ) {
859 $this->registerFilters();
860
861 $opts = $this->getDefaultOptions();
862
863 $opts = $this->fetchOptionsFromRequest( $opts );
864
865 // Give precedence to subpage syntax
866 if ( $parameters !== null ) {
867 $this->parseParameters( $parameters, $opts );
868 }
869
870 $this->validateOptions( $opts );
871
872 return $opts;
873 }
874
875 /**
876 * Get a FormOptions object containing the default options. By default, returns
877 * some basic options. The filters listed explicitly here are overriden in this
878 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
879 * and more) are structured. Structured filters are overriden in registerFilters.
880 * not here.
881 *
882 * @return FormOptions
883 */
884 public function getDefaultOptions() {
885 $config = $this->getConfig();
886 $opts = new FormOptions();
887 $structuredUI = $this->getUser()->getOption( 'rcenhancedfilters' );
888
889 // Add all filters
890 foreach ( $this->filterGroups as $filterGroup ) {
891 // URL parameters can be per-group, like 'userExpLevel',
892 // or per-filter, like 'hideminor'.
893 if ( $filterGroup->isPerGroupRequestParameter() ) {
894 $opts->add( $filterGroup->getName(), $filterGroup->getDefault() );
895 } else {
896 foreach ( $filterGroup->getFilters() as $filter ) {
897 $opts->add( $filter->getName(), $filter->getDefault( $structuredUI ) );
898 }
899 }
900 }
901
902 $opts->add( 'namespace', '', FormOptions::STRING );
903 $opts->add( 'invert', false );
904 $opts->add( 'associated', false );
905
906 return $opts;
907 }
908
909 /**
910 * Register a structured changes list filter group
911 *
912 * @param ChangesListFilterGroup $group
913 */
914 public function registerFilterGroup( ChangesListFilterGroup $group ) {
915 $groupName = $group->getName();
916
917 $this->filterGroups[$groupName] = $group;
918 }
919
920 /**
921 * Gets the currently registered filters groups
922 *
923 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
924 */
925 protected function getFilterGroups() {
926 return $this->filterGroups;
927 }
928
929 /**
930 * Gets a specified ChangesListFilterGroup by name
931 *
932 * @param string $groupName Name of group
933 *
934 * @return ChangesListFilterGroup|null Group, or null if not registered
935 */
936 public function getFilterGroup( $groupName ) {
937 return isset( $this->filterGroups[$groupName] ) ?
938 $this->filterGroups[$groupName] :
939 null;
940 }
941
942 // Currently, this intentionally only includes filters that display
943 // in the structured UI. This can be changed easily, though, if we want
944 // to include data on filters that use the unstructured UI. messageKeys is a
945 // special top-level value, with the value being an array of the message keys to
946 // send to the client.
947 /**
948 * Gets structured filter information needed by JS
949 *
950 * @return array Associative array
951 * * array $return['groups'] Group data
952 * * array $return['messageKeys'] Array of message keys
953 */
954 public function getStructuredFilterJsData() {
955 $output = [
956 'groups' => [],
957 'messageKeys' => [],
958 ];
959
960 $context = $this->getContext();
961
962 usort( $this->filterGroups, function ( $a, $b ) {
963 return $b->getPriority() - $a->getPriority();
964 } );
965
966 foreach ( $this->filterGroups as $groupName => $group ) {
967 $groupOutput = $group->getJsData( $this );
968 if ( $groupOutput !== null ) {
969 $output['messageKeys'] = array_merge(
970 $output['messageKeys'],
971 $groupOutput['messageKeys']
972 );
973
974 unset( $groupOutput['messageKeys'] );
975 $output['groups'][] = $groupOutput;
976 }
977 }
978
979 return $output;
980 }
981
982 /**
983 * Get custom show/hide filters using deprecated ChangesListSpecialPageFilters
984 * hook.
985 *
986 * @return array Map of filter URL param names to properties (msg/default)
987 */
988 protected function getCustomFilters() {
989 if ( $this->customFilters === null ) {
990 $this->customFilters = [];
991 Hooks::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters ], '1.29' );
992 }
993
994 return $this->customFilters;
995 }
996
997 /**
998 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
999 *
1000 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1001 *
1002 * @param FormOptions $opts
1003 * @return FormOptions
1004 */
1005 protected function fetchOptionsFromRequest( $opts ) {
1006 $opts->fetchValuesFromRequest( $this->getRequest() );
1007
1008 return $opts;
1009 }
1010
1011 /**
1012 * Process $par and put options found in $opts. Used when including the page.
1013 *
1014 * @param string $par
1015 * @param FormOptions $opts
1016 */
1017 public function parseParameters( $par, FormOptions $opts ) {
1018 $stringParameterNameSet = [];
1019 $hideParameterNameSet = [];
1020
1021 // URL parameters can be per-group, like 'userExpLevel',
1022 // or per-filter, like 'hideminor'.
1023
1024 foreach ( $this->filterGroups as $filterGroup ) {
1025 if ( $filterGroup->isPerGroupRequestParameter() ) {
1026 $stringParameterNameSet[$filterGroup->getName()] = true;
1027 } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup::TYPE ) {
1028 foreach ( $filterGroup->getFilters() as $filter ) {
1029 $hideParameterNameSet[$filter->getName()] = true;
1030 }
1031 }
1032 }
1033
1034 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1035 foreach ( $bits as $bit ) {
1036 $m = [];
1037 if ( isset( $hideParameterNameSet[$bit] ) ) {
1038 // hidefoo => hidefoo=true
1039 $opts[$bit] = true;
1040 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1041 // foo => hidefoo=false
1042 $opts["hide$bit"] = false;
1043 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1044 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1045 $opts[$m[1]] = $m[2];
1046 }
1047 }
1048 }
1049 }
1050
1051 /**
1052 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1053 *
1054 * @param FormOptions $opts
1055 */
1056 public function validateOptions( FormOptions $opts ) {
1057 // nothing by default
1058 }
1059
1060 /**
1061 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1062 * the user requested.
1063 *
1064 * @param array &$tables Array of tables; see IDatabase::select $table
1065 * @param array &$fields Array of fields; see IDatabase::select $vars
1066 * @param array &$conds Array of conditions; see IDatabase::select $conds
1067 * @param array &$query_options Array of query options; see IDatabase::select $options
1068 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1069 * @param FormOptions $opts
1070 */
1071 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1072 &$join_conds, FormOptions $opts ) {
1073
1074 $dbr = $this->getDB();
1075 $user = $this->getUser();
1076
1077 $context = $this->getContext();
1078 foreach ( $this->filterGroups as $filterGroup ) {
1079 // URL parameters can be per-group, like 'userExpLevel',
1080 // or per-filter, like 'hideminor'.
1081 if ( $filterGroup->isPerGroupRequestParameter() ) {
1082 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1083 $query_options, $join_conds, $opts[$filterGroup->getName()] );
1084 } else {
1085 foreach ( $filterGroup->getFilters() as $filter ) {
1086 if ( $opts[$filter->getName()] ) {
1087 $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1088 $query_options, $join_conds );
1089 }
1090 }
1091 }
1092 }
1093
1094 // Namespace filtering
1095 if ( $opts[ 'namespace' ] !== '' ) {
1096 $namespaces = explode( ',', $opts[ 'namespace' ] );
1097
1098 if ( $opts[ 'associated' ] ) {
1099 $associatedNamespaces = array_map(
1100 function ( $ns ) {
1101 return MWNamespace::getAssociated( $ns );
1102 },
1103 $namespaces
1104 );
1105 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1106 }
1107
1108 if ( count( $namespaces ) === 1 ) {
1109 $operator = $opts[ 'invert' ] ? '!=' : '=';
1110 $value = $dbr->addQuotes( reset( $namespaces ) );
1111 } else {
1112 $operator = $opts[ 'invert' ] ? 'NOT IN' : 'IN';
1113 sort( $namespaces );
1114 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1115 }
1116 $conds[] = "rc_namespace $operator $value";
1117 }
1118 }
1119
1120 /**
1121 * Process the query
1122 *
1123 * @param array $tables Array of tables; see IDatabase::select $table
1124 * @param array $fields Array of fields; see IDatabase::select $vars
1125 * @param array $conds Array of conditions; see IDatabase::select $conds
1126 * @param array $query_options Array of query options; see IDatabase::select $options
1127 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1128 * @param FormOptions $opts
1129 * @return bool|ResultWrapper Result or false
1130 */
1131 protected function doMainQuery( $tables, $fields, $conds,
1132 $query_options, $join_conds, FormOptions $opts ) {
1133
1134 $tables[] = 'recentchanges';
1135 $fields = array_merge( RecentChange::selectFields(), $fields );
1136
1137 ChangeTags::modifyDisplayQuery(
1138 $tables,
1139 $fields,
1140 $conds,
1141 $join_conds,
1142 $query_options,
1143 ''
1144 );
1145
1146 // It makes no sense to hide both anons and logged-in users. When this occurs, try a guess on
1147 // what the user meant and either show only bots or force anons to be shown.
1148
1149 // -------
1150
1151 // XXX: We're no longer doing this handling. To preserve back-compat, we need to complete
1152 // T151873 (particularly the hideanons/hideliu/hidebots/hidehumans part) in conjunction
1153 // with merging this.
1154
1155 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1156 $opts )
1157 ) {
1158 return false;
1159 }
1160
1161 $dbr = $this->getDB();
1162
1163 return $dbr->select(
1164 $tables,
1165 $fields,
1166 $conds,
1167 __METHOD__,
1168 $query_options,
1169 $join_conds
1170 );
1171 }
1172
1173 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1174 &$query_options, &$join_conds, $opts
1175 ) {
1176 return Hooks::run(
1177 'ChangesListSpecialPageQuery',
1178 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1179 );
1180 }
1181
1182 /**
1183 * Return a IDatabase object for reading
1184 *
1185 * @return IDatabase
1186 */
1187 protected function getDB() {
1188 return wfGetDB( DB_REPLICA );
1189 }
1190
1191 /**
1192 * Send output to the OutputPage object, only called if not used feeds
1193 *
1194 * @param ResultWrapper $rows Database rows
1195 * @param FormOptions $opts
1196 */
1197 public function webOutput( $rows, $opts ) {
1198 if ( !$this->including() ) {
1199 $this->outputFeedLinks();
1200 $this->doHeader( $opts, $rows->numRows() );
1201 }
1202
1203 $this->outputChangesList( $rows, $opts );
1204 }
1205
1206 /**
1207 * Output feed links.
1208 */
1209 public function outputFeedLinks() {
1210 // nothing by default
1211 }
1212
1213 /**
1214 * Build and output the actual changes list.
1215 *
1216 * @param ResultWrapper $rows Database rows
1217 * @param FormOptions $opts
1218 */
1219 abstract public function outputChangesList( $rows, $opts );
1220
1221 /**
1222 * Set the text to be displayed above the changes
1223 *
1224 * @param FormOptions $opts
1225 * @param int $numRows Number of rows in the result to show after this header
1226 */
1227 public function doHeader( $opts, $numRows ) {
1228 $this->setTopText( $opts );
1229
1230 // @todo Lots of stuff should be done here.
1231
1232 $this->setBottomText( $opts );
1233 }
1234
1235 /**
1236 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
1237 * or similar methods to print the text.
1238 *
1239 * @param FormOptions $opts
1240 */
1241 public function setTopText( FormOptions $opts ) {
1242 // nothing by default
1243 }
1244
1245 /**
1246 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
1247 * or similar methods to print the text.
1248 *
1249 * @param FormOptions $opts
1250 */
1251 public function setBottomText( FormOptions $opts ) {
1252 // nothing by default
1253 }
1254
1255 /**
1256 * Get options to be displayed in a form
1257 * @todo This should handle options returned by getDefaultOptions().
1258 * @todo Not called by anything in this class (but is in subclasses), should be
1259 * called by something… doHeader() maybe?
1260 *
1261 * @param FormOptions $opts
1262 * @return array
1263 */
1264 public function getExtraOptions( $opts ) {
1265 return [];
1266 }
1267
1268 /**
1269 * Return the legend displayed within the fieldset
1270 *
1271 * @return string
1272 */
1273 public function makeLegend() {
1274 $context = $this->getContext();
1275 $user = $context->getUser();
1276 # The legend showing what the letters and stuff mean
1277 $legend = Html::openElement( 'dl' ) . "\n";
1278 # Iterates through them and gets the messages for both letter and tooltip
1279 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1280 if ( !( $user->useRCPatrol() || $user->useNPPatrol() ) ) {
1281 unset( $legendItems['unpatrolled'] );
1282 }
1283 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1284 $label = isset( $item['legend'] ) ? $item['legend'] : $item['title'];
1285 $letter = $item['letter'];
1286 $cssClass = isset( $item['class'] ) ? $item['class'] : $key;
1287
1288 $legend .= Html::element( 'dt',
1289 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1290 ) . "\n" .
1291 Html::rawElement( 'dd',
1292 [ 'class' => Sanitizer::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1293 $context->msg( $label )->parse()
1294 ) . "\n";
1295 }
1296 # (+-123)
1297 $legend .= Html::rawElement( 'dt',
1298 [ 'class' => 'mw-plusminus-pos' ],
1299 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1300 ) . "\n";
1301 $legend .= Html::element(
1302 'dd',
1303 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1304 $context->msg( 'recentchanges-label-plusminus' )->text()
1305 ) . "\n";
1306 $legend .= Html::closeElement( 'dl' ) . "\n";
1307
1308 # Collapsibility
1309 $legend =
1310 '<div class="mw-changeslist-legend">' .
1311 $context->msg( 'recentchanges-legend-heading' )->parse() .
1312 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1313 '</div>';
1314
1315 return $legend;
1316 }
1317
1318 /**
1319 * Add page-specific modules.
1320 */
1321 protected function addModules() {
1322 $out = $this->getOutput();
1323 // Styles and behavior for the legend box (see makeLegend())
1324 $out->addModuleStyles( [
1325 'mediawiki.special.changeslist.legend',
1326 'mediawiki.special.changeslist',
1327 ] );
1328 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1329 }
1330
1331 protected function getGroupName() {
1332 return 'changes';
1333 }
1334
1335 /**
1336 * Filter on users' experience levels; this will not be called if nothing is
1337 * selected.
1338 *
1339 * @param string $specialPageClassName Class name of current special page
1340 * @param IContextSource $context Context, for e.g. user
1341 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1342 * @param array &$tables Array of tables; see IDatabase::select $table
1343 * @param array &$fields Array of fields; see IDatabase::select $vars
1344 * @param array &$conds Array of conditions; see IDatabase::select $conds
1345 * @param array &$query_options Array of query options; see IDatabase::select $options
1346 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1347 * @param array $selectedExpLevels The allowed active values, sorted
1348 */
1349 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1350 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0 ) {
1351
1352 global $wgLearnerEdits,
1353 $wgExperiencedUserEdits,
1354 $wgLearnerMemberSince,
1355 $wgExperiencedUserMemberSince;
1356
1357 $LEVEL_COUNT = 3;
1358
1359 // If all levels are selected, all logged-in users are included (but no
1360 // anons), so we can short-circuit.
1361 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1362 $conds[] = 'rc_user != 0';
1363 return;
1364 }
1365
1366 $tables[] = 'user';
1367 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
1368
1369 if ( $now === 0 ) {
1370 $now = time();
1371 }
1372 $secondsPerDay = 86400;
1373 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1374 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1375
1376 $aboveNewcomer = $dbr->makeList(
1377 [
1378 'user_editcount >= ' . intval( $wgLearnerEdits ),
1379 'user_registration <= ' . $dbr->timestamp( $learnerCutoff ),
1380 ],
1381 IDatabase::LIST_AND
1382 );
1383
1384 $aboveLearner = $dbr->makeList(
1385 [
1386 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1387 'user_registration <= ' . $dbr->timestamp( $experiencedUserCutoff ),
1388 ],
1389 IDatabase::LIST_AND
1390 );
1391
1392 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1393 $conds[] = "NOT ( $aboveNewcomer )";
1394 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1395 $conds[] = $dbr->makeList(
1396 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1397 IDatabase::LIST_AND
1398 );
1399 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1400 $conds[] = $aboveLearner;
1401 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1402 $conds[] = "NOT ( $aboveLearner )";
1403 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1404 $conds[] = $dbr->makeList(
1405 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1406 IDatabase::LIST_OR
1407 );
1408 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1409 $conds[] = $aboveNewcomer;
1410 }
1411 }
1412 }