Debian Codegraph @

includes/specialpage/ChangesListSpecialPage.php

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