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