| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
abstract class ChangesListSpecialPage extends SpecialPage { |
| 60 |
|
| 61 |
|
| 62 |
protected $rcSubpage; |
| 63 |
|
| 64 |
|
| 65 |
protected $rcOptions; |
| 66 |
|
| 67 |
protected UserIdentityUtils $userIdentityUtils; |
| 68 |
protected TempUserConfig $tempUserConfig; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
private $filterGroupDefinitions; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
private $legacyReviewStatusFilterGroupDefinition; |
| 93 |
|
| 94 |
|
| 95 |
private $reviewStatusFilterGroupDefinition; |
| 96 |
|
| 97 |
|
| 98 |
private $hideCategorizationFilterDefinition; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
protected $filterGroups = []; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 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 |
|
| 137 |
|
| 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 |
|
| 152 |
|
| 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 |
|
| 249 |
|
| 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 |
|
| 298 |
|
| 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 |
|
| 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 |
|
| 342 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 503 |
|
| 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 |
|
| 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 |
|
| 588 |
|
| 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 |
|
| 606 |
|
| 607 |
|
| 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 |
|
| 644 |
|
| 645 |
public function execute( $subpage ) { |
| 646 |
$this->rcSubpage = $subpage; |
| 647 |
|
| 648 |
if ( $this->considerActionsForDefaultSavedQuery( $subpage ) ) { |
| 649 |
|
| 650 |
return; |
| 651 |
} |
| 652 |
|
| 653 |
|
| 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 |
|
| 667 |
if ( $this->getRequest()->getRawVal( 'action' ) === 'render' ) { |
| 668 |
$this->getOutput()->setArticleBodyOnly( true ); |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 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 |
|
| 709 |
|
| 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 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
public function setTempUserConfig( TempUserConfig $tempUserConfig ) { |
| 741 |
$this->tempUserConfig = $tempUserConfig; |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 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 |
|
| 762 |
|
| 763 |
|
| 764 |
$excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ]; |
| 765 |
$knownParams = array_diff_key( $knownParams, $excludedParams ); |
| 766 |
|
| 767 |
if ( |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
count( $knownParams ) === 0 |
| 772 |
) { |
| 773 |
$prefJson = MediaWikiServices::getInstance() |
| 774 |
->getUserOptionsLookup() |
| 775 |
->getOption( $this->getUser(), $this->getSavedQueriesPreferenceName() ); |
| 776 |
|
| 777 |
|
| 778 |
$savedQueries = $prefJson ? FormatJson::decode( $prefJson, true ) : false; |
| 779 |
|
| 780 |
if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) { |
| 781 |
|
| 782 |
|
| 783 |
if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) { |
| 784 |
$savedQueryDefaultID = $savedQueries[ 'default' ]; |
| 785 |
$defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ]; |
| 786 |
|
| 787 |
|
| 788 |
$query = array_merge( |
| 789 |
$defaultQuery[ 'params' ], |
| 790 |
$defaultQuery[ 'highlights' ], |
| 791 |
[ |
| 792 |
'urlversion' => '2', |
| 793 |
] |
| 794 |
); |
| 795 |
|
| 796 |
|
| 797 |
$query = array_merge( $this->getRequest()->getValues(), $query ); |
| 798 |
unset( $query[ 'title' ] ); |
| 799 |
$this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) ); |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
return true; |
| 804 |
} else { |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
$this->getOutput()->addJsConfigVars( |
| 810 |
'wgStructuredChangeFiltersDefaultSavedQueryExists', |
| 811 |
true |
| 812 |
); |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
$this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' ); |
| 817 |
} |
| 818 |
} |
| 819 |
} |
| 820 |
|
| 821 |
return false; |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 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 |
|
| 834 |
|
| 835 |
|
| 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 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 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 |
|
| 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' => |
| 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 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
public static function getRcFiltersConfigSummary( RL\Context $context ) { |
| 919 |
$lang = MediaWikiServices::getInstance()->getLanguageFactory() |
| 920 |
->getLanguage( $context->getLanguage() ); |
| 921 |
return [ |
| 922 |
|
| 923 |
'RCFiltersChangeTags' => ChangeTags::getChangeTagListSummary( $context, $lang ), |
| 924 |
'StructuredChangeFiltersEditWatchlistUrl' => |
| 925 |
SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL() |
| 926 |
]; |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 972 |
|
| 973 |
|
| 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 |
|
| 990 |
|
| 991 |
|
| 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 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
protected function registerFilters() { |
| 1011 |
$this->registerFiltersFromDefinitions( $this->filterGroupDefinitions ); |
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 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 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
protected function transformFilterDefinition( array $filterDefinition ) { |
| 1091 |
return $filterDefinition; |
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
public function setup( $parameters ) { |
| 1153 |
$this->registerFilters(); |
| 1154 |
|
| 1155 |
$opts = $this->getDefaultOptions(); |
| 1156 |
|
| 1157 |
$opts = $this->fetchOptionsFromRequest( $opts ); |
| 1158 |
|
| 1159 |
|
| 1160 |
if ( $parameters !== null ) { |
| 1161 |
$this->parseParameters( $parameters, $opts ); |
| 1162 |
} |
| 1163 |
|
| 1164 |
$this->validateOptions( $opts ); |
| 1165 |
|
| 1166 |
return $opts; |
| 1167 |
} |
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
public function getDefaultOptions() { |
| 1179 |
$opts = new FormOptions(); |
| 1180 |
$structuredUI = $this->isStructuredFilterUiEnabled(); |
| 1181 |
|
| 1182 |
$useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2; |
| 1183 |
|
| 1184 |
|
| 1185 |
foreach ( $this->filterGroups as $filterGroup ) { |
| 1186 |
$filterGroup->addOptions( $opts, $useDefaults, $structuredUI ); |
| 1187 |
} |
| 1188 |
|
| 1189 |
$opts->add( 'namespace', '', FormOptions::STRING ); |
| 1190 |
|
| 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 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
public function registerFilterGroup( ChangesListFilterGroup $group ) { |
| 1211 |
$groupName = $group->getName(); |
| 1212 |
|
| 1213 |
$this->filterGroups[$groupName] = $group; |
| 1214 |
} |
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
protected function getFilterGroups() { |
| 1222 |
return $this->filterGroups; |
| 1223 |
} |
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
public function getFilterGroup( $groupName ) { |
| 1233 |
return $this->filterGroups[$groupName] ?? null; |
| 1234 |
} |
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 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 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
protected function fetchOptionsFromRequest( $opts ) { |
| 1284 |
$opts->fetchValuesFromRequest( $this->getRequest() ); |
| 1285 |
|
| 1286 |
return $opts; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
public function parseParameters( $par, FormOptions $opts ) { |
| 1296 |
$stringParameterNameSet = []; |
| 1297 |
$hideParameterNameSet = []; |
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 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 |
|
| 1317 |
$opts[$bit] = true; |
| 1318 |
} elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) { |
| 1319 |
|
| 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 |
|
| 1331 |
|
| 1332 |
|
| 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 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 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 |
|
| 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 |
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 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 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 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
public function replaceOldOptions( FormOptions $opts ) { |
| 1417 |
if ( !$this->isStructuredFilterUiEnabled() ) { |
| 1418 |
return false; |
| 1419 |
} |
| 1420 |
|
| 1421 |
$changed = false; |
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 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 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 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 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 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 |
|
| 1493 |
foreach ( $this->filterGroups as $filterGroup ) { |
| 1494 |
$filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds, |
| 1495 |
$query_options, $join_conds, $opts, $isStructuredUI ); |
| 1496 |
} |
| 1497 |
|
| 1498 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 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 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
protected function getDB(): IReadableDatabase { |
| 1599 |
return MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
| 1600 |
} |
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
private function webOutputHeader( $rowCount, $opts ) { |
| 1609 |
if ( !$this->including() ) { |
| 1610 |
$this->outputFeedLinks(); |
| 1611 |
$this->doHeader( $opts, $rowCount ); |
| 1612 |
} |
| 1613 |
} |
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 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 |
|
| 1629 |
} |
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
abstract public function outputChangesList( $rows, $opts ); |
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
public function doHeader( $opts, $numRows ) { |
| 1646 |
$this->setTopText( $opts ); |
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
$this->setBottomText( $opts ); |
| 1651 |
} |
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
public function setTopText( FormOptions $opts ) { |
| 1661 |
|
| 1662 |
} |
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
public function setBottomText( FormOptions $opts ) { |
| 1672 |
|
| 1673 |
} |
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
e? |
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
public function getExtraOptions( $opts ) { |
| 1685 |
return []; |
| 1686 |
} |
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
public function makeLegend() { |
| 1694 |
$context = $this->getContext(); |
| 1695 |
$user = $context->getUser(); |
| 1696 |
|
| 1697 |
$legend = Html::openElement( 'dl' ) . "\n"; |
| 1698 |
|
| 1699 |
$legendItems = $context->getConfig()->get( MainConfigNames::RecentChangesFlags ); |
| 1700 |
if ( !( $user->useRCPatrol() || $user->useNPPatrol() ) ) { |
| 1701 |
unset( $legendItems['unpatrolled'] ); |
| 1702 |
} |
| 1703 |
foreach ( $legendItems as $key => $item ) { |
| 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 |
|
| 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 |
|
| 1727 |
if ( $context->getConfig()->get( MainConfigNames::WatchlistExpiry ) && !$this->including() ) { |
| 1728 |
$widget = new IconWidget( [ |
| 1729 |
'icon' => 'clock', |
| 1730 |
'classes' => [ 'mw-changesList-watchlistExpiry' ], |
| 1731 |
] ); |
| 1732 |
|
| 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 |
|
| 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 |
|
| 1771 |
|
| 1772 |
protected function addModules() { |
| 1773 |
$out = $this->getOutput(); |
| 1774 |
|
| 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 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 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 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 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 |
|
| 1844 |
$dbr->expr( 'user_registration', '=', null ) |
| 1845 |
->or( 'user_registration', '<=', $dbr->timestamp( $timeCutoff ) ) |
| 1846 |
); |
| 1847 |
} |
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 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 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 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 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 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 |
|
| 1905 |
if ( isset( $selected['registered'] ) && isset( $selected['unregistered'] ) ) { |
| 1906 |
unset( $selected['registered'], $selected['unregistered'] ); |
| 1907 |
} |
| 1908 |
|
| 1909 |
|
| 1910 |
if ( !$selected ) { |
| 1911 |
return; |
| 1912 |
} |
| 1913 |
$selectedColumnConds = array_values( array_intersect_key( $columnConds, $selected ) ); |
| 1914 |
$conds[] = $dbr->orExpr( $selectedColumnConds ); |
| 1915 |
|
| 1916 |
|
| 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 |
|
| 1926 |
|
| 1927 |
|
| 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 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
public static function checkStructuredFilterUiEnabled( UserIdentity $user ) { |
| 1945 |
return !MediaWikiServices::getInstance() |
| 1946 |
->getUserOptionsLookup() |
| 1947 |
->getOption( $user, 'rcenhancedfilters-disable' ); |
| 1948 |
} |
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
public function getDefaultLimit() { |
| 1958 |
return MediaWikiServices::getInstance() |
| 1959 |
->getUserOptionsLookup() |
| 1960 |
->getIntOption( $this->getUser(), $this->getLimitPreferenceName() ); |
| 1961 |
} |
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
public function getDefaultDays() { |
| 1972 |
return floatval( MediaWikiServices::getInstance() |
| 1973 |
->getUserOptionsLookup() |
| 1974 |
->getOption( $this->getUser(), $this->getDefaultDaysPreferenceName() ) ); |
| 1975 |
} |
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
abstract protected function getLimitPreferenceName(): string; |
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
abstract protected function getSavedQueriesPreferenceName(): string; |
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
abstract protected function getDefaultDaysPreferenceName(): string; |
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
abstract protected function getCollapsedPreferenceName(): string; |
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 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 |
|
| 2032 |
class_alias( ChangesListSpecialPage::class, 'ChangesListSpecialPage' ); |