Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[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
24 use MediaWiki\Logger\LoggerFactory;
25 use MediaWiki\MediaWikiServices;
26 use Wikimedia\Rdbms\DBQueryTimeoutError;
27 use Wikimedia\Rdbms\IResultWrapper;
28 use Wikimedia\Rdbms\FakeResultWrapper;
29 use Wikimedia\Rdbms\IDatabase;
30
31 /**
32 * Special page which uses a ChangesList to show query results.
33 * @todo Way too many public functions, most of them should be protected
34 *
35 * @ingroup SpecialPage
36 */
37 abstract class ChangesListSpecialPage extends SpecialPage {
38 /**
39 * Maximum length of a tag description in UTF-8 characters.
40 * Longer descriptions will be truncated.
41 */
42 const TAG_DESC_CHARACTER_LIMIT = 120;
43
44 /**
45 * Preference name for saved queries. Subclasses that use saved queries should override this.
46 * @var string
47 */
48 protected static $savedQueriesPreferenceName;
49
50 /**
51 * Preference name for 'days'. Subclasses should override this.
52 * @var string
53 */
54 protected static $daysPreferenceName;
55
56 /**
57 * Preference name for 'limit'. Subclasses should override this.
58 * @var string
59 */
60 protected static $limitPreferenceName;
61
62 /**
63 * Preference name for collapsing the active filter display. Subclasses should override this.
64 * @var string
65 */
66 protected static $collapsedPreferenceName;
67
68 /** @var string */
69 protected $rcSubpage;
70
71 /** @var FormOptions */
72 protected $rcOptions;
73
74 // Order of both groups and filters is significant; first is top-most priority,
75 // descending from there.
76 // 'showHideSuffix' is a shortcut to and avoid spelling out
77 // details specific to subclasses here.
78 /**
79 * Definition information for the filters and their groups
80 *
81 * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
82 * However, priority is dynamically added for the core groups, to ease maintenance.
83 *
84 * Groups are displayed to the user in the structured UI. However, if necessary,
85 * all of the filters in a group can be configured to only display on the
86 * unstuctured UI, in which case you don't need a group title.
87 *
88 * @var array $filterGroupDefinitions
89 */
90 private $filterGroupDefinitions;
91
92 // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
93 // that is registered conditionally.
94 private $legacyReviewStatusFilterGroupDefinition;
95
96 // Single filter group registered conditionally
97 private $reviewStatusFilterGroupDefinition;
98
99 // Single filter group registered conditionally
100 private $hideCategorizationFilterDefinition;
101
102 /**
103 * Filter groups, and their contained filters
104 * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
105 *
106 * @var array $filterGroups
107 */
108 protected $filterGroups = [];
109
110 public function __construct( $name, $restriction ) {
111 parent::__construct( $name, $restriction );
112
113 $nonRevisionTypes = [ RC_LOG ];
114 Hooks::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
115
116 $this->filterGroupDefinitions = [
117 [
118 'name' => 'registration',
119 'title' => 'rcfilters-filtergroup-registration',
120 'class' => ChangesListBooleanFilterGroup::class,
121 'filters' => [
122 [
123 'name' => 'hideliu',
124 // rcshowhideliu-show, rcshowhideliu-hide,
125 // wlshowhideliu
126 'showHideSuffix' => 'showhideliu',
127 'default' => false,
128 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
129 &$query_options, &$join_conds
130 ) {
131 $actorMigration = ActorMigration::newMigration();
132 $actorQuery = $actorMigration->getJoin( 'rc_user' );
133 $tables += $actorQuery['tables'];
134 $join_conds += $actorQuery['joins'];
135 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
136 },
137 'isReplacedInStructuredUi' => true,
138
139 ],
140 [
141 'name' => 'hideanons',
142 // rcshowhideanons-show, rcshowhideanons-hide,
143 // wlshowhideanons
144 'showHideSuffix' => 'showhideanons',
145 'default' => false,
146 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
147 &$query_options, &$join_conds
148 ) {
149 $actorMigration = ActorMigration::newMigration();
150 $actorQuery = $actorMigration->getJoin( 'rc_user' );
151 $tables += $actorQuery['tables'];
152 $join_conds += $actorQuery['joins'];
153 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
154 },
155 'isReplacedInStructuredUi' => true,
156 ]
157 ],
158 ],
159
160 [
161 'name' => 'userExpLevel',
162 'title' => 'rcfilters-filtergroup-user-experience-level',
163 'class' => ChangesListStringOptionsFilterGroup::class,
164 'isFullCoverage' => true,
165 'filters' => [
166 [
167 'name' => 'unregistered',
168 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
169 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
170 'cssClassSuffix' => 'user-unregistered',
171 'isRowApplicableCallable' => function ( $ctx, $rc ) {
172 return !$rc->getAttribute( 'rc_user' );
173 }
174 ],
175 [
176 'name' => 'registered',
177 'label' => 'rcfilters-filter-user-experience-level-registered-label',
178 'description' => 'rcfilters-filter-user-experience-level-registered-description',
179 'cssClassSuffix' => 'user-registered',
180 'isRowApplicableCallable' => function ( $ctx, $rc ) {
181 return $rc->getAttribute( 'rc_user' );
182 }
183 ],
184 [
185 'name' => 'newcomer',
186 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
187 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
188 'cssClassSuffix' => 'user-newcomer',
189 'isRowApplicableCallable' => function ( $ctx, $rc ) {
190 $performer = $rc->getPerformer();
191 return $performer && $performer->isLoggedIn() &&
192 $performer->getExperienceLevel() === 'newcomer';
193 }
194 ],
195 [
196 'name' => 'learner',
197 'label' => 'rcfilters-filter-user-experience-level-learner-label',
198 'description' => 'rcfilters-filter-user-experience-level-learner-description',
199 'cssClassSuffix' => 'user-learner',
200 'isRowApplicableCallable' => function ( $ctx, $rc ) {
201 $performer = $rc->getPerformer();
202 return $performer && $performer->isLoggedIn() &&
203 $performer->getExperienceLevel() === 'learner';
204 },
205 ],
206 [
207 'name' => 'experienced',
208 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
209 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
210 'cssClassSuffix' => 'user-experienced',
211 'isRowApplicableCallable' => function ( $ctx, $rc ) {
212 $performer = $rc->getPerformer();
213 return $performer && $performer->isLoggedIn() &&
214 $performer->getExperienceLevel() === 'experienced';
215 },
216 ]
217 ],
218 'default' => ChangesListStringOptionsFilterGroup::NONE,
219 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
220 ],
221
222 [
223 'name' => 'authorship',
224 'title' => 'rcfilters-filtergroup-authorship',
225 'class' => ChangesListBooleanFilterGroup::class,
226 'filters' => [
227 [
228 'name' => 'hidemyself',
229 'label' => 'rcfilters-filter-editsbyself-label',
230 'description' => 'rcfilters-filter-editsbyself-description',
231 // rcshowhidemine-show, rcshowhidemine-hide,
232 // wlshowhidemine
233 'showHideSuffix' => 'showhidemine',
234 'default' => false,
235 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
236 &$query_options, &$join_conds
237 ) {
238 $actorQuery = ActorMigration::newMigration()->getWhere( $dbr, 'rc_user', $ctx->getUser() );
239 $tables += $actorQuery['tables'];
240 $join_conds += $actorQuery['joins'];
241 $conds[] = 'NOT(' . $actorQuery['conds'] . ')';
242 },
243 'cssClassSuffix' => 'self',
244 'isRowApplicableCallable' => function ( $ctx, $rc ) {
245 return $ctx->getUser()->equals( $rc->getPerformer() );
246 },
247 ],
248 [
249 'name' => 'hidebyothers',
250 'label' => 'rcfilters-filter-editsbyother-label',
251 'description' => 'rcfilters-filter-editsbyother-description',
252 'default' => false,
253 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
254 &$query_options, &$join_conds
255 ) {
256 $actorQuery = ActorMigration::newMigration()
257 ->getWhere( $dbr, 'rc_user', $ctx->getUser(), false );
258 $tables += $actorQuery['tables'];
259 $join_conds += $actorQuery['joins'];
260 $conds[] = $actorQuery['conds'];
261 },
262 'cssClassSuffix' => 'others',
263 'isRowApplicableCallable' => function ( $ctx, $rc ) {
264 return !$ctx->getUser()->equals( $rc->getPerformer() );
265 },
266 ]
267 ]
268 ],
269
270 [
271 'name' => 'automated',
272 'title' => 'rcfilters-filtergroup-automated',
273 'class' => ChangesListBooleanFilterGroup::class,
274 'filters' => [
275 [
276 'name' => 'hidebots',
277 'label' => 'rcfilters-filter-bots-label',
278 'description' => 'rcfilters-filter-bots-description',
279 // rcshowhidebots-show, rcshowhidebots-hide,
280 // wlshowhidebots
281 'showHideSuffix' => 'showhidebots',
282 'default' => false,
283 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
284 &$query_options, &$join_conds
285 ) {
286 $conds['rc_bot'] = 0;
287 },
288 'cssClassSuffix' => 'bot',
289 'isRowApplicableCallable' => function ( $ctx, $rc ) {
290 return $rc->getAttribute( 'rc_bot' );
291 },
292 ],
293 [
294 'name' => 'hidehumans',
295 'label' => 'rcfilters-filter-humans-label',
296 'description' => 'rcfilters-filter-humans-description',
297 'default' => false,
298 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
299 &$query_options, &$join_conds
300 ) {
301 $conds['rc_bot'] = 1;
302 },
303 'cssClassSuffix' => 'human',
304 'isRowApplicableCallable' => function ( $ctx, $rc ) {
305 return !$rc->getAttribute( 'rc_bot' );
306 },
307 ]
308 ]
309 ],
310
311 // significance (conditional)
312
313 [
314 'name' => 'significance',
315 'title' => 'rcfilters-filtergroup-significance',
316 'class' => ChangesListBooleanFilterGroup::class,
317 'priority' => -6,
318 'filters' => [
319 [
320 'name' => 'hideminor',
321 'label' => 'rcfilters-filter-minor-label',
322 'description' => 'rcfilters-filter-minor-description',
323 // rcshowhideminor-show, rcshowhideminor-hide,
324 // wlshowhideminor
325 'showHideSuffix' => 'showhideminor',
326 'default' => false,
327 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
328 &$query_options, &$join_conds
329 ) {
330 $conds[] = 'rc_minor = 0';
331 },
332 'cssClassSuffix' => 'minor',
333 'isRowApplicableCallable' => function ( $ctx, $rc ) {
334 return $rc->getAttribute( 'rc_minor' );
335 }
336 ],
337 [
338 'name' => 'hidemajor',
339 'label' => 'rcfilters-filter-major-label',
340 'description' => 'rcfilters-filter-major-description',
341 'default' => false,
342 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
343 &$query_options, &$join_conds
344 ) {
345 $conds[] = 'rc_minor = 1';
346 },
347 'cssClassSuffix' => 'major',
348 'isRowApplicableCallable' => function ( $ctx, $rc ) {
349 return !$rc->getAttribute( 'rc_minor' );
350 }
351 ]
352 ]
353 ],
354
355 [
356 'name' => 'lastRevision',
357 'title' => 'rcfilters-filtergroup-lastrevision',
358 'class' => ChangesListBooleanFilterGroup::class,
359 'priority' => -7,
360 'filters' => [
361 [
362 'name' => 'hidelastrevision',
363 'label' => 'rcfilters-filter-lastrevision-label',
364 'description' => 'rcfilters-filter-lastrevision-description',
365 'default' => false,
366 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
367 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
368 $conds[] = $dbr->makeList(
369 [
370 'rc_this_oldid <> page_latest',
371 'rc_type' => $nonRevisionTypes,
372 ],
373 LIST_OR
374 );
375 },
376 'cssClassSuffix' => 'last',
377 'isRowApplicableCallable' => function ( $ctx, $rc ) {
378 return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
379 }
380 ],
381 [
382 'name' => 'hidepreviousrevisions',
383 'label' => 'rcfilters-filter-previousrevision-label',
384 'description' => 'rcfilters-filter-previousrevision-description',
385 'default' => false,
386 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
387 &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
388 $conds[] = $dbr->makeList(
389 [
390 'rc_this_oldid = page_latest',
391 'rc_type' => $nonRevisionTypes,
392 ],
393 LIST_OR
394 );
395 },
396 'cssClassSuffix' => 'previous',
397 'isRowApplicableCallable' => function ( $ctx, $rc ) {
398 return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
399 }
400 ]
401 ]
402 ],
403
404 // With extensions, there can be change types that will not be hidden by any of these.
405 [
406 'name' => 'changeType',
407 'title' => 'rcfilters-filtergroup-changetype',
408 'class' => ChangesListBooleanFilterGroup::class,
409 'priority' => -8,
410 'filters' => [
411 [
412 'name' => 'hidepageedits',
413 'label' => 'rcfilters-filter-pageedits-label',
414 'description' => 'rcfilters-filter-pageedits-description',
415 'default' => false,
416 'priority' => -2,
417 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
418 &$query_options, &$join_conds
419 ) {
420 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT );
421 },
422 'cssClassSuffix' => 'src-mw-edit',
423 'isRowApplicableCallable' => function ( $ctx, $rc ) {
424 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_EDIT;
425 },
426 ],
427 [
428 'name' => 'hidenewpages',
429 'label' => 'rcfilters-filter-newpages-label',
430 'description' => 'rcfilters-filter-newpages-description',
431 'default' => false,
432 'priority' => -3,
433 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
434 &$query_options, &$join_conds
435 ) {
436 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW );
437 },
438 'cssClassSuffix' => 'src-mw-new',
439 'isRowApplicableCallable' => function ( $ctx, $rc ) {
440 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_NEW;
441 },
442 ],
443
444 // hidecategorization
445
446 [
447 'name' => 'hidelog',
448 'label' => 'rcfilters-filter-logactions-label',
449 'description' => 'rcfilters-filter-logactions-description',
450 'default' => false,
451 'priority' => -5,
452 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
453 &$query_options, &$join_conds
454 ) {
455 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG );
456 },
457 'cssClassSuffix' => 'src-mw-log',
458 'isRowApplicableCallable' => function ( $ctx, $rc ) {
459 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_LOG;
460 }
461 ],
462 ],
463 ],
464
465 ];
466
467 $this->legacyReviewStatusFilterGroupDefinition = [
468 [
469 'name' => 'legacyReviewStatus',
470 'title' => 'rcfilters-filtergroup-reviewstatus',
471 'class' => ChangesListBooleanFilterGroup::class,
472 'filters' => [
473 [
474 'name' => 'hidepatrolled',
475 // rcshowhidepatr-show, rcshowhidepatr-hide
476 // wlshowhidepatr
477 'showHideSuffix' => 'showhidepatr',
478 'default' => false,
479 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
480 &$query_options, &$join_conds
481 ) {
482 $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
483 },
484 'isReplacedInStructuredUi' => true,
485 ],
486 [
487 'name' => 'hideunpatrolled',
488 'default' => false,
489 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
490 &$query_options, &$join_conds
491 ) {
492 $conds[] = 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED;
493 },
494 'isReplacedInStructuredUi' => true,
495 ],
496 ],
497 ]
498 ];
499
500 $this->reviewStatusFilterGroupDefinition = [
501 [
502 'name' => 'reviewStatus',
503 'title' => 'rcfilters-filtergroup-reviewstatus',
504 'class' => ChangesListStringOptionsFilterGroup::class,
505 'isFullCoverage' => true,
506 'priority' => -5,
507 'filters' => [
508 [
509 'name' => 'unpatrolled',
510 'label' => 'rcfilters-filter-reviewstatus-unpatrolled-label',
511 'description' => 'rcfilters-filter-reviewstatus-unpatrolled-description',
512 'cssClassSuffix' => 'reviewstatus-unpatrolled',
513 'isRowApplicableCallable' => function ( $ctx, $rc ) {
514 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange::PRC_UNPATROLLED;
515 },
516 ],
517 [
518 'name' => 'manual',
519 'label' => 'rcfilters-filter-reviewstatus-manual-label',
520 'description' => 'rcfilters-filter-reviewstatus-manual-description',
521 'cssClassSuffix' => 'reviewstatus-manual',
522 'isRowApplicableCallable' => function ( $ctx, $rc ) {
523 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange::PRC_PATROLLED;
524 },
525 ],
526 [
527 'name' => 'auto',
528 'label' => 'rcfilters-filter-reviewstatus-auto-label',
529 'description' => 'rcfilters-filter-reviewstatus-auto-description',
530 'cssClassSuffix' => 'reviewstatus-auto',
531 'isRowApplicableCallable' => function ( $ctx, $rc ) {
532 return $rc->getAttribute( 'rc_patrolled' ) == RecentChange::PRC_AUTOPATROLLED;
533 },
534 ],
535 ],
536 'default' => ChangesListStringOptionsFilterGroup::NONE,
537 'queryCallable' => function ( $specialPageClassName, $ctx, $dbr,
538 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selected
539 ) {
540 if ( $selected === [] ) {
541 return;
542 }
543 $rcPatrolledValues = [
544 'unpatrolled' => RecentChange::PRC_UNPATROLLED,
545 'manual' => RecentChange::PRC_PATROLLED,
546 'auto' => RecentChange::PRC_AUTOPATROLLED,
547 ];
548 // e.g. rc_patrolled IN (0, 2)
549 $conds['rc_patrolled'] = array_map( function ( $s ) use ( $rcPatrolledValues ) {
550 return $rcPatrolledValues[ $s ];
551 }, $selected );
552 }
553 ]
554 ];
555
556 $this->hideCategorizationFilterDefinition = [
557 'name' => 'hidecategorization',
558 'label' => 'rcfilters-filter-categorization-label',
559 'description' => 'rcfilters-filter-categorization-description',
560 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
561 // wlshowhidecategorization
562 'showHideSuffix' => 'showhidecategorization',
563 'default' => false,
564 'priority' => -4,
565 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
566 &$query_options, &$join_conds
567 ) {
568 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE );
569 },
570 'cssClassSuffix' => 'src-mw-categorize',
571 'isRowApplicableCallable' => function ( $ctx, $rc ) {
572 return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_CATEGORIZE;
573 },
574 ];
575 }
576
577 /**
578 * Check if filters are in conflict and guaranteed to return no results.
579 *
580 * @return bool
581 */
582 protected function areFiltersInConflict() {
583 $opts = $this->getOptions();
584 /** @var ChangesListFilterGroup $group */
585 foreach ( $this->getFilterGroups() as $group ) {
586 if ( $group->getConflictingGroups() ) {
587 wfLogWarning(
588 $group->getName() .
589 " specifies conflicts with other groups but these are not supported yet."
590 );
591 }
592
593 /** @var ChangesListFilter $conflictingFilter */
594 foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
595 if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
596 return true;
597 }
598 }
599
600 /** @var ChangesListFilter $filter */
601 foreach ( $group->getFilters() as $filter ) {
602 /** @var ChangesListFilter $conflictingFilter */
603 foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
604 if (
605 $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
606 $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
607 ) {
608 return true;
609 }
610 }
611
612 }
613
614 }
615
616 return false;
617 }
618
619 /**
620 * @param string|null $subpage
621 */
622 public function execute( $subpage ) {
623 $this->rcSubpage = $subpage;
624
625 $this->considerActionsForDefaultSavedQuery( $subpage );
626
627 $opts = $this->getOptions();
628 try {
629 $rows = $this->getRows();
630 if ( $rows === false ) {
631 $rows = new FakeResultWrapper( [] );
632 }
633
634 // Used by Structured UI app to get results without MW chrome
635 if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
636 $this->getOutput()->setArticleBodyOnly( true );
637 }
638
639 // Used by "live update" and "view newest" to check
640 // if there's new changes with minimal data transfer
641 if ( $this->getRequest()->getBool( 'peek' ) ) {
642 $code = $rows->numRows() > 0 ? 200 : 204;
643 $this->getOutput()->setStatusCode( $code );
644
645 if ( $this->getUser()->isAnon() !==
646 $this->getRequest()->getFuzzyBool( 'isAnon' )
647 ) {
648 $this->getOutput()->setStatusCode( 205 );
649 }
650
651 return;
652 }
653
654 $batch = new LinkBatch;
655 foreach ( $rows as $row ) {
656 $batch->add( NS_USER, $row->rc_user_text );
657 $batch->add( NS_USER_TALK, $row->rc_user_text );
658 $batch->add( $row->rc_namespace, $row->rc_title );
659 if ( $row->rc_source === RecentChange::SRC_LOG ) {
660 $formatter = LogFormatter::newFromRow( $row );
661 foreach ( $formatter->getPreloadTitles() as $title ) {
662 $batch->addObj( $title );
663 }
664 }
665 }
666 $batch->execute();
667
668 $this->setHeaders();
669 $this->outputHeader();
670 $this->addModules();
671 $this->webOutput( $rows, $opts );
672
673 $rows->free();
674 } catch ( DBQueryTimeoutError $timeoutException ) {
675 MWExceptionHandler::logException( $timeoutException );
676
677 $this->setHeaders();
678 $this->outputHeader();
679 $this->addModules();
680
681 $this->getOutput()->setStatusCode( 500 );
682 $this->webOutputHeader( 0, $opts );
683 $this->outputTimeout();
684 }
685
686 if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
687 // Clean up any bad page entries for titles showing up in RC
688 DeferredUpdates::addUpdate( new WANCacheReapUpdate(
689 $this->getDB(),
690 LoggerFactory::getInstance( 'objectcache' )
691 ) );
692 }
693
694 $this->includeRcFiltersApp();
695 }
696
697 /**
698 * Check whether or not the page should load defaults, and if so, whether
699 * a default saved query is relevant to be redirected to. If it is relevant,
700 * redirect properly with all necessary query parameters.
701 *
702 * @param string $subpage
703 */
704 protected function considerActionsForDefaultSavedQuery( $subpage ) {
705 if ( !$this->isStructuredFilterUiEnabled() || $this->including() ) {
706 return;
707 }
708
709 $knownParams = $this->getRequest()->getValues(
710 ...array_keys( $this->getOptions()->getAllValues() )
711 );
712
713 // HACK: Temporarily until we can properly define "sticky" filters and parameters,
714 // we need to exclude several parameters we know should not be counted towards preventing
715 // the loading of defaults.
716 $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
717 $knownParams = array_diff_key( $knownParams, $excludedParams );
718
719 if (
720 // If there are NO known parameters in the URL request
721 // (that are not excluded) then we need to check into loading
722 // the default saved query
723 count( $knownParams ) === 0
724 ) {
725 // Get the saved queries data and parse it
726 $savedQueries = FormatJson::decode(
727 $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
728 true
729 );
730
731 if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
732 // Only load queries that are 'version' 2, since those
733 // have parameter representation
734 if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
735 $savedQueryDefaultID = $savedQueries[ 'default' ];
736 $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
737
738 // Build the entire parameter list
739 $query = array_merge(
740 $defaultQuery[ 'params' ],
741 $defaultQuery[ 'highlights' ],
742 [
743 'urlversion' => '2',
744 ]
745 );
746 // Add to the query any parameters that we may have ignored before
747 // but are still valid and requested in the URL
748 $query = array_merge( $this->getRequest()->getValues(), $query );
749 unset( $query[ 'title' ] );
750 $this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) );
751 } else {
752 // There's a default, but the version is not 2, and the server can't
753 // actually recognize the query itself. This happens if it is before
754 // the conversion, so we need to tell the UI to reload saved query as
755 // it does the conversion to version 2
756 $this->getOutput()->addJsConfigVars(
757 'wgStructuredChangeFiltersDefaultSavedQueryExists',
758 true
759 );
760
761 // Add the class that tells the frontend it is still loading
762 // another query
763 $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
764 }
765 }
766 }
767 }
768
769 /**
770 * @see $wgRCLinkDays in DefaultSettings.php.
771 * @see $wgRCFilterByAge in DefaultSettings.php.
772 * @return int[]
773 */
774 protected function getLinkDays() {
775 $linkDays = $this->getConfig()->get( 'RCLinkDays' );
776 $filterByAge = $this->getConfig()->get( 'RCFilterByAge' );
777 $maxAge = $this->getConfig()->get( 'RCMaxAge' );
778 if ( $filterByAge ) {
779 // Trim it to only links which are within $wgRCMaxAge.
780 // Note that we allow one link higher than the max for things like
781 // "age 56 days" being accessible through the "60 days" link.
782 sort( $linkDays );
783
784 $maxAgeDays = $maxAge / ( 3600 * 24 );
785 foreach ( $linkDays as $i => $days ) {
786 if ( $days >= $maxAgeDays ) {
787 array_splice( $linkDays, $i + 1 );
788 break;
789 }
790 }
791 }
792
793 return $linkDays;
794 }
795
796 /**
797 * Include the modules and configuration for the RCFilters app.
798 * Conditional on the user having the feature enabled.
799 *
800 * If it is disabled, add a <body> class marking that
801 */
802 protected function includeRcFiltersApp() {
803 $out = $this->getOutput();
804 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
805 $jsData = $this->getStructuredFilterJsData();
806 $messages = [];
807 foreach ( $jsData['messageKeys'] as $key ) {
808 $messages[$key] = $this->msg( $key )->plain();
809 }
810
811 $out->addBodyClasses( 'mw-rcfilters-enabled' );
812 $collapsed = $this->getUser()->getBoolOption( static::$collapsedPreferenceName );
813 if ( $collapsed ) {
814 $out->addBodyClasses( 'mw-rcfilters-collapsed' );
815 }
816
817 // These config and message exports should be moved into a ResourceLoader data module (T201574)
818 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
819 $out->addJsConfigVars( 'wgStructuredChangeFiltersMessages', $messages );
820 $out->addJsConfigVars( 'wgStructuredChangeFiltersCollapsedState', $collapsed );
821
822 $out->addJsConfigVars(
823 'StructuredChangeFiltersDisplayConfig',
824 [
825 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
826 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
827 'limitDefault' => $this->getDefaultLimit(),
828 'daysArray' => $this->getLinkDays(),
829 'daysDefault' => $this->getDefaultDays(),
830 ]
831 );
832
833 $out->addJsConfigVars(
834 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
835 static::$savedQueriesPreferenceName
836 );
837 $out->addJsConfigVars(
838 'wgStructuredChangeFiltersLimitPreferenceName',
839 static::$limitPreferenceName
840 );
841 $out->addJsConfigVars(
842 'wgStructuredChangeFiltersDaysPreferenceName',
843 static::$daysPreferenceName
844 );
845 $out->addJsConfigVars(
846 'wgStructuredChangeFiltersCollapsedPreferenceName',
847 static::$collapsedPreferenceName
848 );
849 } else {
850 $out->addBodyClasses( 'mw-rcfilters-disabled' );
851 }
852 }
853
854 /**
855 * Get essential data about getRcFiltersConfigVars() for change detection.
856 *
857 * @internal For use by Resources.php only.
858 * @see ResourceLoaderModule::getDefinitionSummary() and ResourceLoaderModule::getVersionHash()
859 * @param ResourceLoaderContext $context
860 * @return array
861 */
862 public static function getRcFiltersConfigSummary( ResourceLoaderContext $context ) {
863 return [
864 // Reduce version computation by avoiding Message parsing
865 'RCFiltersChangeTags' => self::getChangeTagListSummary( $context ),
866 'StructuredChangeFiltersEditWatchlistUrl' =>
867 SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL()
868 ];
869 }
870
871 /**
872 * Get config vars to export with the mediawiki.rcfilters.filters.ui module.
873 *
874 * @internal For use by Resources.php only.
875 * @param ResourceLoaderContext $context
876 * @return array
877 */
878 public static function getRcFiltersConfigVars( ResourceLoaderContext $context ) {
879 return [
880 'RCFiltersChangeTags' => self::getChangeTagList( $context ),
881 'StructuredChangeFiltersEditWatchlistUrl' =>
882 SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL()
883 ];
884 }
885
886 /**
887 * Get (cheap to compute) information about change tags.
888 *
889 * Returns an array of associative arrays with information about each tag:
890 * - name: Tag name (string)
891 * - labelMsg: Short description message (Message object)
892 * - descriptionMsg: Long description message (Message object)
893 * - cssClass: CSS class to use for RC entries with this tag
894 * - hits: Number of RC entries that have this tag
895 *
896 * @param ResourceLoaderContext $context
897 * @return array[] Information about each tag
898 */
899 protected static function getChangeTagInfo( ResourceLoaderContext $context ) {
900 $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 );
901 $softwareActivatedTags = array_fill_keys( ChangeTags::listSoftwareActivatedTags(), 0 );
902
903 $tagStats = ChangeTags::tagUsageStatistics();
904 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
905
906 $result = [];
907 foreach ( $tagHitCounts as $tagName => $hits ) {
908 if (
909 (
910 // Only get active tags
911 isset( $explicitlyDefinedTags[ $tagName ] ) ||
912 isset( $softwareActivatedTags[ $tagName ] )
913 ) &&
914 // Only get tags with more than 0 hits
915 $hits > 0
916 ) {
917 $labelMsg = ChangeTags::tagShortDescriptionMessage( $tagName, $context );
918 if ( $labelMsg === false ) {
919 // Tag is hidden, skip it
920 continue;
921 }
922 $result[] = [
923 'name' => $tagName,
924 // 'label' and 'description' filled in by getChangeTagList()
925 'labelMsg' => $labelMsg,
926 'descriptionMsg' => ChangeTags::tagLongDescriptionMessage( $tagName, $context ),
927 'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ),
928 'hits' => $hits,
929 ];
930 }
931 }
932 return $result;
933 }
934
935 /**
936 * Get information about change tags for use in getRcFiltersConfigSummary().
937 *
938 * This expands labelMsg and descriptionMsg to the raw values of each message, which captures
939 * changes in the messages but avoids the expensive step of parsing them.
940 *
941 * @param ResourceLoaderContext $context
942 * @return array[] Result of getChangeTagInfo(), with messages expanded to raw contents
943 */
944 protected static function getChangeTagListSummary( ResourceLoaderContext $context ) {
945 $tags = self::getChangeTagInfo( $context );
946 foreach ( $tags as &$tagInfo ) {
947 $tagInfo['labelMsg'] = $tagInfo['labelMsg']->plain();
948 if ( $tagInfo['descriptionMsg'] ) {
949 $tagInfo['descriptionMsg'] = $tagInfo['descriptionMsg']->plain();
950 }
951 }
952 return $tags;
953 }
954
955 /**
956 * Get information about change tags to export to JS via getRcFiltersConfigVars().
957 *
958 * This removes labelMsg and descriptionMsg, and adds label and description, which are parsed,
959 * stripped and (in the case of description) truncated versions of these messages. Message
960 * parsing is expensive, so to detect whether the tag list has changed, use
961 * getChangeTagListSummary() instead.
962 *
963 * @param ResourceLoaderContext $context
964 * @return array[] Result of getChangeTagInfo(), with messages parsed, stripped and truncated
965 */
966 protected static function getChangeTagList( ResourceLoaderContext $context ) {
967 $tags = self::getChangeTagInfo( $context );
968 $language = Language::factory( $context->getLanguage() );
969 foreach ( $tags as &$tagInfo ) {
970 $tagInfo['label'] = Sanitizer::stripAllTags( $tagInfo['labelMsg']->parse() );
971 $tagInfo['description'] = $tagInfo['descriptionMsg'] ?
972 $language->truncateForVisual(
973 Sanitizer::stripAllTags( $tagInfo['descriptionMsg']->parse() ),
974 self::TAG_DESC_CHARACTER_LIMIT
975 ) :
976 '';
977 unset( $tagInfo['labelMsg'] );
978 unset( $tagInfo['descriptionMsg'] );
979 }
980
981 // Instead of sorting by hit count (disabled for now), sort by display name
982 usort( $tags, function ( $a, $b ) {
983 return strcasecmp( $a['label'], $b['label'] );
984 } );
985 return $tags;
986 }
987
988 /**
989 * Add the "no results" message to the output
990 */
991 protected function outputNoResults() {
992 $this->getOutput()->addHTML(
993 '<div class="mw-changeslist-empty">' .
994 $this->msg( 'recentchanges-noresult' )->parse() .
995 '</div>'
996 );
997 }
998
999 /**
1000 * Add the "timeout" message to the output
1001 */
1002 protected function outputTimeout() {
1003 $this->getOutput()->addHTML(
1004 '<div class="mw-changeslist-empty mw-changeslist-timeout">' .
1005 $this->msg( 'recentchanges-timeout' )->parse() .
1006 '</div>'
1007 );
1008 }
1009
1010 /**
1011 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
1012 *
1013 * @return bool|IResultWrapper Result or false
1014 */
1015 public function getRows() {
1016 $opts = $this->getOptions();
1017
1018 $tables = [];
1019 $fields = [];
1020 $conds = [];
1021 $query_options = [];
1022 $join_conds = [];
1023 $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
1024
1025 return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
1026 }
1027
1028 /**
1029 * Get the current FormOptions for this request
1030 *
1031 * @return FormOptions
1032 */
1033 public function getOptions() {
1034 if ( $this->rcOptions === null ) {
1035 $this->rcOptions = $this->setup( $this->rcSubpage );
1036 }
1037
1038 return $this->rcOptions;
1039 }
1040
1041 /**
1042 * Register all filters and their groups (including those from hooks), plus handle
1043 * conflicts and defaults.
1044 *
1045 * You might want to customize these in the same method, in subclasses. You can
1046 * call getFilterGroup to access a group, and (on the group) getFilter to access a
1047 * filter, then make necessary modfications to the filter or group (e.g. with
1048 * setDefault).
1049 */
1050 protected function registerFilters() {
1051 $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions );
1052
1053 // Make sure this is not being transcluded (we don't want to show this
1054 // information to all users just because the user that saves the edit can
1055 // patrol or is logged in)
1056 if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
1057 $this->registerFiltersFromDefinitions( $this->legacyReviewStatusFilterGroupDefinition );
1058 $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition );
1059 }
1060
1061 $changeTypeGroup = $this->getFilterGroup( 'changeType' );
1062
1063 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
1064 $transformedHideCategorizationDef = $this->transformFilterDefinition(
1065 $this->hideCategorizationFilterDefinition
1066 );
1067
1068 $transformedHideCategorizationDef['group'] = $changeTypeGroup;
1069
1070 $hideCategorization = new ChangesListBooleanFilter(
1071 $transformedHideCategorizationDef
1072 );
1073 }
1074
1075 Hooks::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
1076
1077 $this->registerFiltersFromDefinitions( [] );
1078
1079 $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
1080 $registered = $userExperienceLevel->getFilter( 'registered' );
1081 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
1082 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
1083 $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
1084
1085 $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
1086 $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
1087 $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
1088
1089 $significanceTypeGroup = $this->getFilterGroup( 'significance' );
1090 $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
1091
1092 // categoryFilter is conditional; see registerFilters
1093 if ( $categoryFilter !== null ) {
1094 $hideMinorFilter->conflictsWith(
1095 $categoryFilter,
1096 'rcfilters-hideminor-conflicts-typeofchange-global',
1097 'rcfilters-hideminor-conflicts-typeofchange',
1098 'rcfilters-typeofchange-conflicts-hideminor'
1099 );
1100 }
1101 $hideMinorFilter->conflictsWith(
1102 $logactionsFilter,
1103 'rcfilters-hideminor-conflicts-typeofchange-global',
1104 'rcfilters-hideminor-conflicts-typeofchange',
1105 'rcfilters-typeofchange-conflicts-hideminor'
1106 );
1107 $hideMinorFilter->conflictsWith(
1108 $pagecreationFilter,
1109 'rcfilters-hideminor-conflicts-typeofchange-global',
1110 'rcfilters-hideminor-conflicts-typeofchange',
1111 'rcfilters-typeofchange-conflicts-hideminor'
1112 );
1113 }
1114
1115 /**
1116 * Transforms filter definition to prepare it for constructor.
1117 *
1118 * See overrides of this method as well.
1119 *
1120 * @param array $filterDefinition Original filter definition
1121 *
1122 * @return array Transformed definition
1123 */
1124 protected function transformFilterDefinition( array $filterDefinition ) {
1125 return $filterDefinition;
1126 }
1127
1128 /**
1129 * Register filters from a definition object
1130 *
1131 * Array specifying groups and their filters; see Filter and
1132 * ChangesListFilterGroup constructors.
1133 *
1134 * There is light processing to simplify core maintenance.
1135 * @param array $definition
1136 * @phan-param array<int,array{class:string,filters:array}> $definition
1137 */
1138 protected function registerFiltersFromDefinitions( array $definition ) {
1139 $autoFillPriority = -1;
1140 foreach ( $definition as $groupDefinition ) {
1141 if ( !isset( $groupDefinition['priority'] ) ) {
1142 $groupDefinition['priority'] = $autoFillPriority;
1143 } else {
1144 // If it's explicitly specified, start over the auto-fill
1145 $autoFillPriority = $groupDefinition['priority'];
1146 }
1147
1148 $autoFillPriority--;
1149
1150 $className = $groupDefinition['class'];
1151 unset( $groupDefinition['class'] );
1152
1153 foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
1154 $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
1155 }
1156
1157 $this->registerFilterGroup( new $className( $groupDefinition ) );
1158 }
1159 }
1160
1161 /**
1162 * @return array The legacy show/hide toggle filters
1163 */
1164 protected function getLegacyShowHideFilters() {
1165 $filters = [];
1166 foreach ( $this->filterGroups as $group ) {
1167 if ( $group instanceof ChangesListBooleanFilterGroup ) {
1168 foreach ( $group->getFilters() as $key => $filter ) {
1169 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1170 $filters[ $key ] = $filter;
1171 }
1172 }
1173 }
1174 }
1175 return $filters;
1176 }
1177
1178 /**
1179 * Register all the filters, including legacy hook-driven ones.
1180 * Then create a FormOptions object with options as specified by the user
1181 *
1182 * @param string $parameters
1183 *
1184 * @return FormOptions
1185 */
1186 public function setup( $parameters ) {
1187 $this->registerFilters();
1188
1189 $opts = $this->getDefaultOptions();
1190
1191 $opts = $this->fetchOptionsFromRequest( $opts );
1192
1193 // Give precedence to subpage syntax
1194 if ( $parameters !== null ) {
1195 $this->parseParameters( $parameters, $opts );
1196 }
1197
1198 $this->validateOptions( $opts );
1199
1200 return $opts;
1201 }
1202
1203 /**
1204 * Get a FormOptions object containing the default options. By default, returns
1205 * some basic options. The filters listed explicitly here are overriden in this
1206 * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
1207 * and more) are structured. Structured filters are overriden in registerFilters.
1208 * not here.
1209 *
1210 * @return FormOptions
1211 */
1212 public function getDefaultOptions() {
1213 $opts = new FormOptions();
1214 $structuredUI = $this->isStructuredFilterUiEnabled();
1215 // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
1216 $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
1217
1218 /** @var ChangesListFilterGroup $filterGroup */
1219 foreach ( $this->filterGroups as $filterGroup ) {
1220 $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
1221 }
1222
1223 $opts->add( 'namespace', '', FormOptions::STRING );
1224 $opts->add( 'invert', false );
1225 $opts->add( 'associated', false );
1226 $opts->add( 'urlversion', 1 );
1227 $opts->add( 'tagfilter', '' );
1228
1229 $opts->add( 'days', $this->getDefaultDays(), FormOptions::FLOAT );
1230 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions::INT );
1231
1232 $opts->add( 'from', '' );
1233
1234 return $opts;
1235 }
1236
1237 /**
1238 * Register a structured changes list filter group
1239 *
1240 * @param ChangesListFilterGroup $group
1241 */
1242 public function registerFilterGroup( ChangesListFilterGroup $group ) {
1243 $groupName = $group->getName();
1244
1245 $this->filterGroups[$groupName] = $group;
1246 }
1247
1248 /**
1249 * Gets the currently registered filters groups
1250 *
1251 * @return array Associative array of ChangesListFilterGroup objects, with group name as key
1252 */
1253 protected function getFilterGroups() {
1254 return $this->filterGroups;
1255 }
1256
1257 /**
1258 * Gets a specified ChangesListFilterGroup by name
1259 *
1260 * @param string $groupName Name of group
1261 *
1262 * @return ChangesListFilterGroup|null Group, or null if not registered
1263 */
1264 public function getFilterGroup( $groupName ) {
1265 return $this->filterGroups[$groupName] ?? null;
1266 }
1267
1268 // Currently, this intentionally only includes filters that display
1269 // in the structured UI. This can be changed easily, though, if we want
1270 // to include data on filters that use the unstructured UI. messageKeys is a
1271 // special top-level value, with the value being an array of the message keys to
1272 // send to the client.
1273
1274 /**
1275 * Gets structured filter information needed by JS
1276 *
1277 * @return array Associative array
1278 * * array $return['groups'] Group data
1279 * * array $return['messageKeys'] Array of message keys
1280 */
1281 public function getStructuredFilterJsData() {
1282 $output = [
1283 'groups' => [],
1284 'messageKeys' => [],
1285 ];
1286
1287 usort( $this->filterGroups, function ( $a, $b ) {
1288 return $b->getPriority() <=> $a->getPriority();
1289 } );
1290
1291 foreach ( $this->filterGroups as $groupName => $group ) {
1292 $groupOutput = $group->getJsData( $this );
1293 if ( $groupOutput !== null ) {
1294 $output['messageKeys'] = array_merge(
1295 $output['messageKeys'],
1296 $groupOutput['messageKeys']
1297 );
1298
1299 unset( $groupOutput['messageKeys'] );
1300 $output['groups'][] = $groupOutput;
1301 }
1302 }
1303
1304 return $output;
1305 }
1306
1307 /**
1308 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
1309 *
1310 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
1311 *
1312 * @param FormOptions $opts
1313 * @return FormOptions
1314 */
1315 protected function fetchOptionsFromRequest( $opts ) {
1316 $opts->fetchValuesFromRequest( $this->getRequest() );
1317
1318 return $opts;
1319 }
1320
1321 /**
1322 * Process $par and put options found in $opts. Used when including the page.
1323 *
1324 * @param string $par
1325 * @param FormOptions $opts
1326 */
1327 public function parseParameters( $par, FormOptions $opts ) {
1328 $stringParameterNameSet = [];
1329 $hideParameterNameSet = [];
1330
1331 // URL parameters can be per-group, like 'userExpLevel',
1332 // or per-filter, like 'hideminor'.
1333
1334 foreach ( $this->filterGroups as $filterGroup ) {
1335 if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup ) {
1336 $stringParameterNameSet[$filterGroup->getName()] = true;
1337 } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
1338 foreach ( $filterGroup->getFilters() as $filter ) {
1339 $hideParameterNameSet[$filter->getName()] = true;
1340 }
1341 }
1342 }
1343
1344 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
1345 foreach ( $bits as $bit ) {
1346 $m = [];
1347 if ( isset( $hideParameterNameSet[$bit] ) ) {
1348 // hidefoo => hidefoo=true
1349 $opts[$bit] = true;
1350 } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
1351 // foo => hidefoo=false
1352 $opts["hide$bit"] = false;
1353 } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
1354 if ( isset( $stringParameterNameSet[$m[1]] ) ) {
1355 $opts[$m[1]] = $m[2];
1356 }
1357 }
1358 }
1359 }
1360
1361 /**
1362 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
1363 *
1364 * @param FormOptions $opts
1365 */
1366 public function validateOptions( FormOptions $opts ) {
1367 $isContradictory = $this->fixContradictoryOptions( $opts );
1368 $isReplaced = $this->replaceOldOptions( $opts );
1369
1370 if ( $isContradictory || $isReplaced ) {
1371 $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
1372 $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
1373 }
1374
1375 $opts->validateIntBounds( 'limit', 0, 5000 );
1376 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
1377 }
1378
1379 /**
1380 * Fix invalid options by resetting pairs that should never appear together.
1381 *
1382 * @param FormOptions $opts
1383 * @return bool True if any option was reset
1384 */
1385 private function fixContradictoryOptions( FormOptions $opts ) {
1386 $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
1387
1388 foreach ( $this->filterGroups as $filterGroup ) {
1389 if ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
1390 $filters = $filterGroup->getFilters();
1391
1392 if ( count( $filters ) === 1 ) {
1393 // legacy boolean filters should not be considered
1394 continue;
1395 }
1396
1397 $allInGroupEnabled = array_reduce(
1398 $filters,
1399 function ( $carry, $filter ) use ( $opts ) {
1400 return $carry && $opts[ $filter->getName() ];
1401 },
1402 /* initialValue */ count( $filters ) > 0
1403 );
1404
1405 if ( $allInGroupEnabled ) {
1406 foreach ( $filters as $filter ) {
1407 $opts[ $filter->getName() ] = false;
1408 }
1409
1410 $fixed = true;
1411 }
1412 }
1413 }
1414
1415 return $fixed;
1416 }
1417
1418 /**
1419 * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
1420 * compatibility.
1421 *
1422 * This is deprecated and may be removed.
1423 *
1424 * @param FormOptions $opts
1425 * @return bool True if this change was mode
1426 */
1427 private function fixBackwardsCompatibilityOptions( FormOptions $opts ) {
1428 if ( $opts['hideanons'] && $opts['hideliu'] ) {
1429 $opts->reset( 'hideanons' );
1430 if ( !$opts['hidebots'] ) {
1431 $opts->reset( 'hideliu' );
1432 $opts['hidehumans'] = 1;
1433 }
1434
1435 return true;
1436 }
1437
1438 return false;
1439 }
1440
1441 /**
1442 * Replace old options with their structured UI equivalents
1443 *
1444 * @param FormOptions $opts
1445 * @return bool True if the change was made
1446 */
1447 public function replaceOldOptions( FormOptions $opts ) {
1448 if ( !$this->isStructuredFilterUiEnabled() ) {
1449 return false;
1450 }
1451
1452 $changed = false;
1453
1454 // At this point 'hideanons' and 'hideliu' cannot be both true,
1455 // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
1456 if ( $opts[ 'hideanons' ] ) {
1457 $opts->reset( 'hideanons' );
1458 $opts[ 'userExpLevel' ] = 'registered';
1459 $changed = true;
1460 }
1461
1462 if ( $opts[ 'hideliu' ] ) {
1463 $opts->reset( 'hideliu' );
1464 $opts[ 'userExpLevel' ] = 'unregistered';
1465 $changed = true;
1466 }
1467
1468 if ( $this->getFilterGroup( 'legacyReviewStatus' ) ) {
1469 if ( $opts[ 'hidepatrolled' ] ) {
1470 $opts->reset( 'hidepatrolled' );
1471 $opts[ 'reviewStatus' ] = 'unpatrolled';
1472 $changed = true;
1473 }
1474
1475 if ( $opts[ 'hideunpatrolled' ] ) {
1476 $opts->reset( 'hideunpatrolled' );
1477 $opts[ 'reviewStatus' ] = implode(
1478 ChangesListStringOptionsFilterGroup::SEPARATOR,
1479 [ 'manual', 'auto' ]
1480 );
1481 $changed = true;
1482 }
1483 }
1484
1485 return $changed;
1486 }
1487
1488 /**
1489 * Convert parameters values from true/false to 1/0
1490 * so they are not omitted by wfArrayToCgi()
1491 * T38524
1492 *
1493 * @param array $params
1494 * @return array
1495 */
1496 protected function convertParamsForLink( $params ) {
1497 foreach ( $params as &$value ) {
1498 if ( $value === false ) {
1499 $value = '0';
1500 }
1501 }
1502 unset( $value );
1503 return $params;
1504 }
1505
1506 /**
1507 * Sets appropriate tables, fields, conditions, etc. depending on which filters
1508 * the user requested.
1509 *
1510 * @param array &$tables Array of tables; see IDatabase::select $table
1511 * @param array &$fields Array of fields; see IDatabase::select $vars
1512 * @param array &$conds Array of conditions; see IDatabase::select $conds
1513 * @param array &$query_options Array of query options; see IDatabase::select $options
1514 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1515 * @param FormOptions $opts
1516 */
1517 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
1518 &$join_conds, FormOptions $opts
1519 ) {
1520 $dbr = $this->getDB();
1521 $isStructuredUI = $this->isStructuredFilterUiEnabled();
1522
1523 /** @var ChangesListFilterGroup $filterGroup */
1524 foreach ( $this->filterGroups as $filterGroup ) {
1525 $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
1526 $query_options, $join_conds, $opts, $isStructuredUI );
1527 }
1528
1529 // Namespace filtering
1530 if ( $opts[ 'namespace' ] !== '' ) {
1531 $namespaces = explode( ';', $opts[ 'namespace' ] );
1532
1533 $namespaces = $this->expandSymbolicNamespaceFilters( $namespaces );
1534
1535 if ( $opts[ 'associated' ] ) {
1536 $namespaceInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
1537 $associatedNamespaces = array_map(
1538 function ( $ns ) use ( $namespaceInfo ){
1539 return $namespaceInfo->getAssociated( $ns );
1540 },
1541 array_filter(
1542 $namespaces,
1543 function ( $ns ) use ( $namespaceInfo ) {
1544 return $namespaceInfo->hasTalkNamespace( $ns );
1545 }
1546 )
1547 );
1548 $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
1549 }
1550
1551 if ( count( $namespaces ) === 1 ) {
1552 $operator = $opts[ 'invert' ] ? '!=' : '=';
1553 $value = $dbr->addQuotes( reset( $namespaces ) );
1554 } else {
1555 $operator = $opts[ 'invert' ] ? 'NOT IN' : 'IN';
1556 sort( $namespaces );
1557 $value = '(' . $dbr->makeList( $namespaces ) . ')';
1558 }
1559 $conds[] = "rc_namespace $operator $value";
1560 }
1561
1562 // Calculate cutoff
1563 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
1564 $cutoff = $dbr->timestamp( $cutoff_unixtime );
1565
1566 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
1567 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) {
1568 $cutoff = $dbr->timestamp( $opts['from'] );
1569 } else {
1570 $opts->reset( 'from' );
1571 }
1572
1573 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
1574 }
1575
1576 /**
1577 * Process the query
1578 *
1579 * @param array $tables Array of tables; see IDatabase::select $table
1580 * @param array $fields Array of fields; see IDatabase::select $vars
1581 * @param array $conds Array of conditions; see IDatabase::select $conds
1582 * @param array $query_options Array of query options; see IDatabase::select $options
1583 * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
1584 * @param FormOptions $opts
1585 * @return bool|IResultWrapper Result or false
1586 */
1587 protected function doMainQuery( $tables, $fields, $conds,
1588 $query_options, $join_conds, FormOptions $opts
1589 ) {
1590 $rcQuery = RecentChange::getQueryInfo();
1591 $tables = array_merge( $tables, $rcQuery['tables'] );
1592 $fields = array_merge( $rcQuery['fields'], $fields );
1593 $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
1594
1595 ChangeTags::modifyDisplayQuery(
1596 $tables,
1597 $fields,
1598 $conds,
1599 $join_conds,
1600 $query_options,
1601 ''
1602 );
1603
1604 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
1605 $opts )
1606 ) {
1607 return false;
1608 }
1609
1610 $dbr = $this->getDB();
1611
1612 return $dbr->select(
1613 $tables,
1614 $fields,
1615 $conds,
1616 __METHOD__,
1617 $query_options,
1618 $join_conds
1619 );
1620 }
1621
1622 protected function runMainQueryHook( &$tables, &$fields, &$conds,
1623 &$query_options, &$join_conds, $opts
1624 ) {
1625 return Hooks::run(
1626 'ChangesListSpecialPageQuery',
1627 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
1628 );
1629 }
1630
1631 /**
1632 * Return a IDatabase object for reading
1633 *
1634 * @return IDatabase
1635 */
1636 protected function getDB() {
1637 return wfGetDB( DB_REPLICA );
1638 }
1639
1640 /**
1641 * Send header output to the OutputPage object, only called if not using feeds
1642 *
1643 * @param int $rowCount Number of database rows
1644 * @param FormOptions $opts
1645 */
1646 private function webOutputHeader( $rowCount, $opts ) {
1647 if ( !$this->including() ) {
1648 $this->outputFeedLinks();
1649 $this->doHeader( $opts, $rowCount );
1650 }
1651 }
1652
1653 /**
1654 * Send output to the OutputPage object, only called if not used feeds
1655 *
1656 * @param IResultWrapper $rows Database rows
1657 * @param FormOptions $opts
1658 */
1659 public function webOutput( $rows, $opts ) {
1660 $this->webOutputHeader( $rows->numRows(), $opts );
1661
1662 $this->outputChangesList( $rows, $opts );
1663 }
1664
1665 /**
1666 * Output feed links.
1667 */
1668 public function outputFeedLinks() {
1669 // nothing by default
1670 }
1671
1672 /**
1673 * Build and output the actual changes list.
1674 *
1675 * @param IResultWrapper $rows Database rows
1676 * @param FormOptions $opts
1677 */
1678 abstract public function outputChangesList( $rows, $opts );
1679
1680 /**
1681 * Set the text to be displayed above the changes
1682 *
1683 * @param FormOptions $opts
1684 * @param int $numRows Number of rows in the result to show after this header
1685 */
1686 public function doHeader( $opts, $numRows ) {
1687 $this->setTopText( $opts );
1688
1689 // @todo Lots of stuff should be done here.
1690
1691 $this->setBottomText( $opts );
1692 }
1693
1694 /**
1695 * Send the text to be displayed before the options.
1696 * Should use $this->getOutput()->addWikiTextAsInterface()
1697 * or similar methods to print the text.
1698 *
1699 * @param FormOptions $opts
1700 */
1701 public function setTopText( FormOptions $opts ) {
1702 // nothing by default
1703 }
1704
1705 /**
1706 * Send the text to be displayed after the options.
1707 * Should use $this->getOutput()->addWikiTextAsInterface()
1708 * or similar methods to print the text.
1709 *
1710 * @param FormOptions $opts
1711 */
1712 public function setBottomText( FormOptions $opts ) {
1713 // nothing by default
1714 }
1715
1716 /**
1717 * Get options to be displayed in a form
1718 * @todo This should handle options returned by getDefaultOptions().
1719 * @todo Not called by anything in this class (but is in subclasses), should be
1720 * called by something… doHeader() maybe?
1721 *
1722 * @param FormOptions $opts
1723 * @return array
1724 */
1725 public function getExtraOptions( $opts ) {
1726 return [];
1727 }
1728
1729 /**
1730 * Return the legend displayed within the fieldset
1731 *
1732 * @return string
1733 */
1734 public function makeLegend() {
1735 $context = $this->getContext();
1736 $user = $context->getUser();
1737 # The legend showing what the letters and stuff mean
1738 $legend = Html::openElement( 'dl' ) . "\n";
1739 # Iterates through them and gets the messages for both letter and tooltip
1740 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
1741 if ( !( $user->useRCPatrol() || $user->useNPPatrol() ) ) {
1742 unset( $legendItems['unpatrolled'] );
1743 }
1744 foreach ( $legendItems as $key => $item ) { # generate items of the legend
1745 $label = $item['legend'] ?? $item['title'];
1746 $letter = $item['letter'];
1747 $cssClass = $item['class'] ?? $key;
1748
1749 $legend .= Html::element( 'dt',
1750 [ 'class' => $cssClass ], $context->msg( $letter )->text()
1751 ) . "\n" .
1752 Html::rawElement( 'dd',
1753 [ 'class' => Sanitizer::escapeClass( 'mw-changeslist-legend-' . $key ) ],
1754 $context->msg( $label )->parse()
1755 ) . "\n";
1756 }
1757 # (+-123)
1758 $legend .= Html::rawElement( 'dt',
1759 [ 'class' => 'mw-plusminus-pos' ],
1760 $context->msg( 'recentchanges-legend-plusminus' )->parse()
1761 ) . "\n";
1762 $legend .= Html::element(
1763 'dd',
1764 [ 'class' => 'mw-changeslist-legend-plusminus' ],
1765 $context->msg( 'recentchanges-label-plusminus' )->text()
1766 ) . "\n";
1767 $legend .= Html::closeElement( 'dl' ) . "\n";
1768
1769 $legendHeading = $this->isStructuredFilterUiEnabled() ?
1770 $context->msg( 'rcfilters-legend-heading' )->parse() :
1771 $context->msg( 'recentchanges-legend-heading' )->parse();
1772
1773 # Collapsible
1774 $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
1775 $collapsedClass = $collapsedState === 'collapsed' ? ' mw-collapsed' : '';
1776
1777 $legend =
1778 '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
1779 $legendHeading .
1780 '<div class="mw-collapsible-content">' . $legend . '</div>' .
1781 '</div>';
1782
1783 return $legend;
1784 }
1785
1786 /**
1787 * Add page-specific modules.
1788 */
1789 protected function addModules() {
1790 $out = $this->getOutput();
1791 // Styles and behavior for the legend box (see makeLegend())
1792 $out->addModuleStyles( [
1793 'mediawiki.interface.helpers.styles',
1794 'mediawiki.special.changeslist.legend',
1795 'mediawiki.special.changeslist',
1796 ] );
1797 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
1798
1799 if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
1800 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
1801 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
1802 }
1803 }
1804
1805 protected function getGroupName() {
1806 return 'changes';
1807 }
1808
1809 /**
1810 * Filter on users' experience levels; this will not be called if nothing is
1811 * selected.
1812 *
1813 * @param string $specialPageClassName Class name of current special page
1814 * @param IContextSource $context Context, for e.g. user
1815 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
1816 * @param array &$tables Array of tables; see IDatabase::select $table
1817 * @param array &$fields Array of fields; see IDatabase::select $vars
1818 * @param array &$conds Array of conditions; see IDatabase::select $conds
1819 * @param array &$query_options Array of query options; see IDatabase::select $options
1820 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
1821 * @param array $selectedExpLevels The allowed active values, sorted
1822 * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
1823 * (optional)
1824 */
1825 public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
1826 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
1827 ) {
1828 global $wgLearnerEdits,
1829 $wgExperiencedUserEdits,
1830 $wgLearnerMemberSince,
1831 $wgExperiencedUserMemberSince;
1832
1833 $LEVEL_COUNT = 5;
1834
1835 // If all levels are selected, don't filter
1836 if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
1837 return;
1838 }
1839
1840 // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
1841 if (
1842 in_array( 'registered', $selectedExpLevels ) &&
1843 in_array( 'unregistered', $selectedExpLevels )
1844 ) {
1845 return;
1846 }
1847
1848 $actorMigration = ActorMigration::newMigration();
1849 $actorQuery = $actorMigration->getJoin( 'rc_user' );
1850 $tables += $actorQuery['tables'];
1851 $join_conds += $actorQuery['joins'];
1852
1853 // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
1854 if (
1855 in_array( 'registered', $selectedExpLevels ) &&
1856 !in_array( 'unregistered', $selectedExpLevels )
1857 ) {
1858 $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1859 return;
1860 }
1861
1862 if ( $selectedExpLevels === [ 'unregistered' ] ) {
1863 $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1864 return;
1865 }
1866
1867 $tables[] = 'user';
1868 $join_conds['user'] = [ 'LEFT JOIN', $actorQuery['fields']['rc_user'] . ' = user_id' ];
1869
1870 if ( $now === 0 ) {
1871 $now = time();
1872 }
1873 $secondsPerDay = 86400;
1874 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
1875 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
1876
1877 $aboveNewcomer = $dbr->makeList(
1878 [
1879 'user_editcount >= ' . intval( $wgLearnerEdits ),
1880 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
1881 ],
1882 IDatabase::LIST_AND
1883 );
1884
1885 $aboveLearner = $dbr->makeList(
1886 [
1887 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
1888 'user_registration <= ' .
1889 $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
1890 ],
1891 IDatabase::LIST_AND
1892 );
1893
1894 $conditions = [];
1895
1896 if ( in_array( 'unregistered', $selectedExpLevels ) ) {
1897 $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
1898 $conditions[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
1899 }
1900
1901 if ( $selectedExpLevels === [ 'newcomer' ] ) {
1902 $conditions[] = "NOT ( $aboveNewcomer )";
1903 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
1904 $conditions[] = $dbr->makeList(
1905 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
1906 IDatabase::LIST_AND
1907 );
1908 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
1909 $conditions[] = $aboveLearner;
1910 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
1911 $conditions[] = "NOT ( $aboveLearner )";
1912 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
1913 $conditions[] = $dbr->makeList(
1914 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
1915 IDatabase::LIST_OR
1916 );
1917 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
1918 $conditions[] = $aboveNewcomer;
1919 } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
1920 $conditions[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
1921 }
1922
1923 if ( count( $conditions ) > 1 ) {
1924 $conds[] = $dbr->makeList( $conditions, IDatabase::LIST_OR );
1925 } elseif ( count( $conditions ) === 1 ) {
1926 $conds[] = reset( $conditions );
1927 }
1928 }
1929
1930 /**
1931 * Check whether the structured filter UI is enabled
1932 *
1933 * @return bool
1934 */
1935 public function isStructuredFilterUiEnabled() {
1936 if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
1937 return true;
1938 }
1939
1940 return static::checkStructuredFilterUiEnabled( $this->getUser() );
1941 }
1942
1943 /**
1944 * Static method to check whether StructuredFilter UI is enabled for the given user
1945 *
1946 * @since 1.31
1947 * @param User $user
1948 * @return bool
1949 */
1950 public static function checkStructuredFilterUiEnabled( $user ) {
1951 if ( $user instanceof Config ) {
1952 wfDeprecated( __METHOD__ . ' with Config argument', '1.34' );
1953 $user = func_get_arg( 1 );
1954 }
1955 return !$user->getOption( 'rcenhancedfilters-disable' );
1956 }
1957
1958 /**
1959 * Get the default value of the number of changes to display when loading
1960 * the result set.
1961 *
1962 * @since 1.30
1963 * @return int
1964 */
1965 public function getDefaultLimit() {
1966 return $this->getUser()->getIntOption( static::$limitPreferenceName );
1967 }
1968
1969 /**
1970 * Get the default value of the number of days to display when loading
1971 * the result set.
1972 * Supports fractional values, and should be cast to a float.
1973 *
1974 * @since 1.30
1975 * @return float
1976 */
1977 public function getDefaultDays() {
1978 return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );
1979 }
1980
1981 private function expandSymbolicNamespaceFilters( array $namespaces ) {
1982 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
1983 $symbolicFilters = [
1984 'all-contents' => $nsInfo->getSubjectNamespaces(),
1985 'all-discussions' => $nsInfo->getTalkNamespaces(),
1986 ];
1987 $additionalNamespaces = [];
1988 foreach ( $symbolicFilters as $name => $values ) {
1989 if ( in_array( $name, $namespaces ) ) {
1990 $additionalNamespaces = array_merge( $additionalNamespaces, $values );
1991 }
1992 }
1993 $namespaces = array_diff( $namespaces, array_keys( $symbolicFilters ) );
1994 $namespaces = array_merge( $namespaces, $additionalNamespaces );
1995 return array_unique( $namespaces );
1996 }
1997 }