| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use ChangesList; |
| 24 |
use ChangesListBooleanFilterGroup; |
| 25 |
use ChangesListStringOptionsFilterGroup; |
| 26 |
use EnhancedChangesList; |
| 27 |
use LogPage; |
| 28 |
use MediaWiki\ChangeTags\ChangeTagsStore; |
| 29 |
use MediaWiki\Context\IContextSource; |
| 30 |
use MediaWiki\Html\FormOptions; |
| 31 |
use MediaWiki\Html\Html; |
| 32 |
use MediaWiki\MainConfigNames; |
| 33 |
use MediaWiki\MediaWikiServices; |
| 34 |
use MediaWiki\Request\DerivativeRequest; |
| 35 |
use MediaWiki\SpecialPage\ChangesListSpecialPage; |
| 36 |
use MediaWiki\SpecialPage\SpecialPage; |
| 37 |
use MediaWiki\Title\TitleValue; |
| 38 |
use MediaWiki\User\Options\UserOptionsLookup; |
| 39 |
use MediaWiki\User\TempUser\TempUserConfig; |
| 40 |
use MediaWiki\User\UserIdentity; |
| 41 |
use MediaWiki\User\UserIdentityUtils; |
| 42 |
use MediaWiki\Watchlist\WatchedItem; |
| 43 |
use MediaWiki\Watchlist\WatchedItemStoreInterface; |
| 44 |
use MediaWiki\Watchlist\WatchlistManager; |
| 45 |
use MediaWiki\Xml\Xml; |
| 46 |
use MediaWiki\Xml\XmlSelect; |
| 47 |
use RecentChange; |
| 48 |
use UserNotLoggedIn; |
| 49 |
use Wikimedia\Rdbms\IReadableDatabase; |
| 50 |
use Wikimedia\Rdbms\IResultWrapper; |
| 51 |
use Wikimedia\Rdbms\RawSQLExpression; |
| 52 |
use Wikimedia\Rdbms\RawSQLValue; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
class SpecialWatchlist extends ChangesListSpecialPage { |
| 66 |
|
| 67 |
public const WATCHLIST_TAB_PATHS = [ |
| 68 |
'Special:Watchlist', |
| 69 |
'Special:EditWatchlist', |
| 70 |
'Special:EditWatchlist/raw', |
| 71 |
'Special:EditWatchlist/clear' |
| 72 |
]; |
| 73 |
|
| 74 |
private WatchedItemStoreInterface $watchedItemStore; |
| 75 |
private WatchlistManager $watchlistManager; |
| 76 |
private UserOptionsLookup $userOptionsLookup; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
private $currentMode; |
| 83 |
private ChangeTagsStore $changeTagsStore; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public function __construct( |
| 91 |
WatchedItemStoreInterface $watchedItemStore, |
| 92 |
WatchlistManager $watchlistManager, |
| 93 |
UserOptionsLookup $userOptionsLookup, |
| 94 |
ChangeTagsStore $changeTagsStore, |
| 95 |
UserIdentityUtils $userIdentityUtils, |
| 96 |
TempUserConfig $tempUserConfig |
| 97 |
) { |
| 98 |
parent::__construct( |
| 99 |
'Watchlist', |
| 100 |
'viewmywatchlist', |
| 101 |
$userIdentityUtils, |
| 102 |
$tempUserConfig |
| 103 |
); |
| 104 |
|
| 105 |
$this->watchedItemStore = $watchedItemStore; |
| 106 |
$this->watchlistManager = $watchlistManager; |
| 107 |
$this->userOptionsLookup = $userOptionsLookup; |
| 108 |
$this->changeTagsStore = $changeTagsStore; |
| 109 |
} |
| 110 |
|
| 111 |
public function doesWrites() { |
| 112 |
return true; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public function execute( $subpage ) { |
| 121 |
$user = $this->getUser(); |
| 122 |
if ( |
| 123 |
|
| 124 |
!$user->isRegistered() |
| 125 |
|
| 126 |
|| ( $user->isTemp() && !$user->isAllowed( 'viewmywatchlist' ) ) |
| 127 |
) { |
| 128 |
throw new UserNotLoggedIn( 'watchlistanontext' ); |
| 129 |
} |
| 130 |
|
| 131 |
$output = $this->getOutput(); |
| 132 |
$request = $this->getRequest(); |
| 133 |
$this->addHelpLink( 'Help:Watching pages' ); |
| 134 |
$output->addModuleStyles( [ 'mediawiki.special' ] ); |
| 135 |
$output->addModules( [ 'mediawiki.special.watchlist' ] ); |
| 136 |
|
| 137 |
$mode = SpecialEditWatchlist::getMode( $request, $subpage ); |
| 138 |
$this->currentMode = $mode; |
| 139 |
|
| 140 |
if ( $mode !== false ) { |
| 141 |
if ( $mode === SpecialEditWatchlist::EDIT_RAW ) { |
| 142 |
$title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' ); |
| 143 |
} elseif ( $mode === SpecialEditWatchlist::EDIT_CLEAR ) { |
| 144 |
$title = SpecialPage::getTitleFor( 'EditWatchlist', 'clear' ); |
| 145 |
} else { |
| 146 |
$title = SpecialPage::getTitleFor( 'EditWatchlist' ); |
| 147 |
} |
| 148 |
|
| 149 |
$output->redirect( $title->getLocalURL() ); |
| 150 |
|
| 151 |
return; |
| 152 |
} |
| 153 |
|
| 154 |
$this->checkPermissions(); |
| 155 |
|
| 156 |
$opts = $this->getOptions(); |
| 157 |
|
| 158 |
$config = $this->getConfig(); |
| 159 |
if ( ( $config->get( MainConfigNames::EnotifWatchlist ) || |
| 160 |
$config->get( MainConfigNames::ShowUpdatedMarker ) ) |
| 161 |
&& $request->getVal( 'reset' ) |
| 162 |
&& $request->wasPosted() |
| 163 |
&& $user->matchEditToken( $request->getVal( 'token' ) ) |
| 164 |
) { |
| 165 |
$this->watchlistManager->clearAllUserNotifications( $user ); |
| 166 |
$output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) ); |
| 167 |
|
| 168 |
return; |
| 169 |
} |
| 170 |
|
| 171 |
parent::execute( $subpage ); |
| 172 |
|
| 173 |
if ( $this->isStructuredFilterUiEnabled() ) { |
| 174 |
$output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] ); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
public static function checkStructuredFilterUiEnabled( UserIdentity $user ) { |
| 182 |
return !MediaWikiServices::getInstance() |
| 183 |
->getUserOptionsLookup() |
| 184 |
->getOption( $user, 'wlenhancedfilters-disable' ); |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
public function getSubpagesForPrefixSearch() { |
| 194 |
return [ |
| 195 |
'edit', |
| 196 |
'raw', |
| 197 |
'clear', |
| 198 |
]; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
protected function transformFilterDefinition( array $filterDefinition ) { |
| 205 |
if ( isset( $filterDefinition['showHideSuffix'] ) ) { |
| 206 |
$filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix']; |
| 207 |
} |
| 208 |
|
| 209 |
return $filterDefinition; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
protected function registerFilters() { |
| 217 |
parent::registerFilters(); |
| 218 |
|
| 219 |
|
| 220 |
$this->registerFilterGroup( new ChangesListBooleanFilterGroup( [ |
| 221 |
'name' => 'extended-group', |
| 222 |
'filters' => [ |
| 223 |
[ |
| 224 |
'name' => 'extended', |
| 225 |
'isReplacedInStructuredUi' => true, |
| 226 |
'activeValue' => false, |
| 227 |
'default' => $this->userOptionsLookup->getBoolOption( $this->getUser(), 'extendwatchlist' ), |
| 228 |
'queryCallable' => function ( string $specialClassName, IContextSource $ctx, |
| 229 |
IReadableDatabase $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds |
| 230 |
) { |
| 231 |
$nonRevisionTypes = [ RC_LOG ]; |
| 232 |
$this->getHookRunner()->onSpecialWatchlistGetNonRevisionTypes( $nonRevisionTypes ); |
| 233 |
if ( $nonRevisionTypes ) { |
| 234 |
$conds[] = $dbr->expr( 'rc_this_oldid', '=', new RawSQLValue( 'page_latest' ) ) |
| 235 |
->or( 'rc_type', '=', $nonRevisionTypes ); |
| 236 |
} |
| 237 |
}, |
| 238 |
] |
| 239 |
], |
| 240 |
|
| 241 |
] ) ); |
| 242 |
|
| 243 |
if ( $this->isStructuredFilterUiEnabled() ) { |
| 244 |
$this->getFilterGroup( 'lastRevision' ) |
| 245 |
->getFilter( 'hidepreviousrevisions' ) |
| 246 |
->setDefault( !$this->userOptionsLookup->getBoolOption( $this->getUser(), 'extendwatchlist' ) ); |
| 247 |
} |
| 248 |
|
| 249 |
$this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [ |
| 250 |
'name' => 'watchlistactivity', |
| 251 |
'title' => 'rcfilters-filtergroup-watchlistactivity', |
| 252 |
'class' => ChangesListStringOptionsFilterGroup::class, |
| 253 |
'priority' => 3, |
| 254 |
'isFullCoverage' => true, |
| 255 |
'filters' => [ |
| 256 |
[ |
| 257 |
'name' => 'unseen', |
| 258 |
'label' => 'rcfilters-filter-watchlistactivity-unseen-label', |
| 259 |
'description' => 'rcfilters-filter-watchlistactivity-unseen-description', |
| 260 |
'cssClassSuffix' => 'watchedunseen', |
| 261 |
'isRowApplicableCallable' => function ( IContextSource $ctx, RecentChange $rc ) { |
| 262 |
return !$this->isChangeEffectivelySeen( $rc ); |
| 263 |
}, |
| 264 |
], |
| 265 |
[ |
| 266 |
'name' => 'seen', |
| 267 |
'label' => 'rcfilters-filter-watchlistactivity-seen-label', |
| 268 |
'description' => 'rcfilters-filter-watchlistactivity-seen-description', |
| 269 |
'cssClassSuffix' => 'watchedseen', |
| 270 |
'isRowApplicableCallable' => function ( IContextSource $ctx, RecentChange $rc ) { |
| 271 |
return $this->isChangeEffectivelySeen( $rc ); |
| 272 |
} |
| 273 |
], |
| 274 |
], |
| 275 |
'default' => ChangesListStringOptionsFilterGroup::NONE, |
| 276 |
'queryCallable' => static function ( |
| 277 |
string $specialPageClassName, |
| 278 |
IContextSource $context, |
| 279 |
IReadableDatabase $dbr, |
| 280 |
&$tables, |
| 281 |
&$fields, |
| 282 |
&$conds, |
| 283 |
&$query_options, |
| 284 |
&$join_conds, |
| 285 |
$selectedValues |
| 286 |
) { |
| 287 |
if ( $selectedValues === [ 'seen' ] ) { |
| 288 |
$conds[] = $dbr->expr( 'wl_notificationtimestamp', '=', null ) |
| 289 |
->orExpr( new RawSQLExpression( 'rc_timestamp < wl_notificationtimestamp' ) ); |
| 290 |
} elseif ( $selectedValues === [ 'unseen' ] ) { |
| 291 |
$conds[] = $dbr->expr( 'wl_notificationtimestamp', '!=', null ) |
| 292 |
->andExpr( new RawSQLExpression( 'rc_timestamp >= wl_notificationtimestamp' ) ); |
| 293 |
} |
| 294 |
} |
| 295 |
] ) ); |
| 296 |
|
| 297 |
$user = $this->getUser(); |
| 298 |
|
| 299 |
$significance = $this->getFilterGroup( 'significance' ); |
| 300 |
$hideMinor = $significance->getFilter( 'hideminor' ); |
| 301 |
$hideMinor->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideminor' ) ); |
| 302 |
|
| 303 |
$automated = $this->getFilterGroup( 'automated' ); |
| 304 |
$hideBots = $automated->getFilter( 'hidebots' ); |
| 305 |
$hideBots->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthidebots' ) ); |
| 306 |
|
| 307 |
$registration = $this->getFilterGroup( 'registration' ); |
| 308 |
$hideAnons = $registration->getFilter( 'hideanons' ); |
| 309 |
$hideAnons->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideanons' ) ); |
| 310 |
$hideLiu = $registration->getFilter( 'hideliu' ); |
| 311 |
$hideLiu->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideliu' ) ); |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideanons' ) && |
| 316 |
!$this->userOptionsLookup->getBoolOption( $user, 'watchlisthideliu' ) |
| 317 |
) { |
| 318 |
$this->getFilterGroup( 'userExpLevel' ) |
| 319 |
->setDefault( 'registered' ); |
| 320 |
} |
| 321 |
|
| 322 |
if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideliu' ) && |
| 323 |
!$this->userOptionsLookup->getBoolOption( $user, 'watchlisthideanons' ) |
| 324 |
) { |
| 325 |
$this->getFilterGroup( 'userExpLevel' ) |
| 326 |
->setDefault( 'unregistered' ); |
| 327 |
} |
| 328 |
|
| 329 |
$reviewStatus = $this->getFilterGroup( 'reviewStatus' ); |
| 330 |
if ( $reviewStatus !== null ) { |
| 331 |
|
| 332 |
if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthidepatrolled' ) ) { |
| 333 |
$reviewStatus->setDefault( 'unpatrolled' ); |
| 334 |
$legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' ); |
| 335 |
$legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' ); |
| 336 |
$legacyHidePatrolled->setDefault( true ); |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
$authorship = $this->getFilterGroup( 'authorship' ); |
| 341 |
$hideMyself = $authorship->getFilter( 'hidemyself' ); |
| 342 |
$hideMyself->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideown' ) ); |
| 343 |
|
| 344 |
$changeType = $this->getFilterGroup( 'changeType' ); |
| 345 |
$hideCategorization = $changeType->getFilter( 'hidecategorization' ); |
| 346 |
if ( $hideCategorization !== null ) { |
| 347 |
|
| 348 |
$hideCategorization->setDefault( |
| 349 |
$this->userOptionsLookup->getBoolOption( $user, 'watchlisthidecategorization' ) |
| 350 |
); |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
protected function fetchOptionsFromRequest( $opts ) { |
| 364 |
static $compatibilityMap = [ |
| 365 |
'hideMinor' => 'hideminor', |
| 366 |
'hideBots' => 'hidebots', |
| 367 |
'hideAnons' => 'hideanons', |
| 368 |
'hideLiu' => 'hideliu', |
| 369 |
'hidePatrolled' => 'hidepatrolled', |
| 370 |
'hideOwn' => 'hidemyself', |
| 371 |
]; |
| 372 |
|
| 373 |
$params = $this->getRequest()->getValues(); |
| 374 |
foreach ( $compatibilityMap as $from => $to ) { |
| 375 |
if ( isset( $params[$from] ) ) { |
| 376 |
$params[$to] = $params[$from]; |
| 377 |
unset( $params[$from] ); |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
if ( $this->getRequest()->getRawVal( 'action' ) == 'submit' ) { |
| 382 |
$allBooleansFalse = []; |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
foreach ( $this->getLegacyShowHideFilters() as $filter ) { |
| 391 |
$allBooleansFalse[ $filter->getName() ] = false; |
| 392 |
} |
| 393 |
|
| 394 |
$params += $allBooleansFalse; |
| 395 |
} |
| 396 |
|
| 397 |
on |
| 398 |
|
| 399 |
$request = new DerivativeRequest( $this->getRequest(), $params ); |
| 400 |
$opts->fetchValuesFromRequest( $request ); |
| 401 |
|
| 402 |
return $opts; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
protected function doMainQuery( $tables, $fields, $conds, $query_options, |
| 409 |
$join_conds, FormOptions $opts |
| 410 |
) { |
| 411 |
$dbr = $this->getDB(); |
| 412 |
$user = $this->getUser(); |
| 413 |
|
| 414 |
$rcQuery = RecentChange::getQueryInfo(); |
| 415 |
$tables = array_merge( $rcQuery['tables'], $tables, [ 'watchlist' ] ); |
| 416 |
$fields = array_merge( $rcQuery['fields'], $fields ); |
| 417 |
|
| 418 |
$join_conds = array_merge( |
| 419 |
[ |
| 420 |
'watchlist' => [ |
| 421 |
'JOIN', |
| 422 |
[ |
| 423 |
'wl_user' => $user->getId(), |
| 424 |
'wl_namespace=rc_namespace', |
| 425 |
'wl_title=rc_title' |
| 426 |
], |
| 427 |
], |
| 428 |
], |
| 429 |
$rcQuery['joins'], |
| 430 |
$join_conds |
| 431 |
); |
| 432 |
|
| 433 |
if ( $this->getConfig()->get( MainConfigNames::WatchlistExpiry ) ) { |
| 434 |
$tables[] = 'watchlist_expiry'; |
| 435 |
$fields[] = 'we_expiry'; |
| 436 |
$join_conds['watchlist_expiry'] = [ 'LEFT JOIN', 'wl_id = we_item' ]; |
| 437 |
$conds[] = $dbr->expr( 'we_expiry', '=', null )->or( 'we_expiry', '>', $dbr->timestamp() ); |
| 438 |
} |
| 439 |
|
| 440 |
$tables[] = 'page'; |
| 441 |
$fields[] = 'page_latest'; |
| 442 |
$join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ]; |
| 443 |
|
| 444 |
$fields[] = 'wl_notificationtimestamp'; |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
$authority = $this->getAuthority(); |
| 449 |
if ( !$authority->isAllowed( 'deletedhistory' ) ) { |
| 450 |
$bitmask = LogPage::DELETED_ACTION; |
| 451 |
} elseif ( !$authority->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) { |
| 452 |
$bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED; |
| 453 |
} else { |
| 454 |
$bitmask = 0; |
| 455 |
} |
| 456 |
if ( $bitmask ) { |
| 457 |
$conds[] = $dbr->expr( 'rc_type', '!=', RC_LOG ) |
| 458 |
->orExpr( new RawSQLExpression( $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" ) ); |
| 459 |
} |
| 460 |
|
| 461 |
$tagFilter = $opts['tagfilter'] !== '' ? explode( '|', $opts['tagfilter'] ) : []; |
| 462 |
$this->changeTagsStore->modifyDisplayQuery( |
| 463 |
$tables, |
| 464 |
$fields, |
| 465 |
$conds, |
| 466 |
$join_conds, |
| 467 |
$query_options, |
| 468 |
$tagFilter, |
| 469 |
$opts['inverttags'] |
| 470 |
); |
| 471 |
|
| 472 |
$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts ); |
| 473 |
|
| 474 |
if ( $this->areFiltersInConflict() ) { |
| 475 |
return false; |
| 476 |
} |
| 477 |
|
| 478 |
$orderByAndLimit = [ |
| 479 |
'ORDER BY' => 'rc_timestamp DESC', |
| 480 |
'LIMIT' => $opts['limit'] |
| 481 |
]; |
| 482 |
if ( in_array( 'DISTINCT', $query_options ) ) { |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
$orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC'; |
| 489 |
$orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id'; |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
$query_options = array_merge( $orderByAndLimit, $query_options ); |
| 494 |
$query_options['MAX_EXECUTION_TIME'] = |
| 495 |
$this->getConfig()->get( MainConfigNames::MaxExecutionTimeForExpensiveQueries ); |
| 496 |
$queryBuilder = $dbr->newSelectQueryBuilder() |
| 497 |
->tables( $tables ) |
| 498 |
->conds( $conds ) |
| 499 |
->fields( $fields ) |
| 500 |
->options( $query_options ) |
| 501 |
->joinConds( $join_conds ) |
| 502 |
->caller( __METHOD__ ); |
| 503 |
|
| 504 |
return $queryBuilder->fetchResultSet(); |
| 505 |
} |
| 506 |
|
| 507 |
public function outputFeedLinks() { |
| 508 |
$user = $this->getUser(); |
| 509 |
$wlToken = $user->getTokenFromOption( 'watchlisttoken' ); |
| 510 |
if ( $wlToken ) { |
| 511 |
$this->addFeedLinks( [ |
| 512 |
'action' => 'feedwatchlist', |
| 513 |
'allrev' => 1, |
| 514 |
'wlowner' => $user->getName(), |
| 515 |
'wltoken' => $wlToken, |
| 516 |
] ); |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
public function outputChangesList( $rows, $opts ) { |
| 527 |
$dbr = $this->getDB(); |
| 528 |
$user = $this->getUser(); |
| 529 |
$output = $this->getOutput(); |
| 530 |
|
| 531 |
|
| 532 |
$lag = $dbr->getSessionLagStatus()['lag']; |
| 533 |
if ( $lag > 0 ) { |
| 534 |
$output->showLagWarning( $lag ); |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
if ( $rows->numRows() == 0 ) { |
| 539 |
$output->wrapWikiMsg( |
| 540 |
"<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult' |
| 541 |
); |
| 542 |
return; |
| 543 |
} |
| 544 |
|
| 545 |
$rows->seek( 0 ); |
| 546 |
|
| 547 |
$list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups ); |
| 548 |
$list->setWatchlistDivs(); |
| 549 |
$list->initChangesListRows( $rows ); |
| 550 |
|
| 551 |
if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlistunwatchlinks' ) ) { |
| 552 |
$list->setChangeLinePrefixer( function ( RecentChange $rc, ChangesList $cl, $grouped ) { |
| 553 |
$unwatch = $this->msg( 'watchlist-unwatch' )->text(); |
| 554 |
|
| 555 |
|
| 556 |
if ( $rc->mAttribs['rc_type'] == RC_LOG && $cl instanceof EnhancedChangesList && |
| 557 |
$grouped ) { |
| 558 |
return "<span style='visibility:hidden'>$unwatch</span>\u{00A0}"; |
| 559 |
} else { |
| 560 |
$unwatchTooltipMessage = 'tooltip-ca-unwatch'; |
| 561 |
$diffInDays = null; |
| 562 |
|
| 563 |
if ( $this->getConfig()->get( MainConfigNames::WatchlistExpiry ) ) { |
| 564 |
$watchedItem = $this->watchedItemStore->getWatchedItem( $this->getUser(), $rc->getTitle() ); |
| 565 |
if ( $watchedItem instanceof WatchedItem && $watchedItem->getExpiry() !== null ) { |
| 566 |
$diffInDays = $watchedItem->getExpiryInDays(); |
| 567 |
|
| 568 |
if ( $diffInDays > 0 ) { |
| 569 |
$unwatchTooltipMessage = 'tooltip-ca-unwatch-expiring'; |
| 570 |
} else { |
| 571 |
$unwatchTooltipMessage = 'tooltip-ca-unwatch-expiring-hours'; |
| 572 |
} |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
return $this->getLinkRenderer() |
| 577 |
->makeKnownLink( $rc->getTitle(), |
| 578 |
$unwatch, [ |
| 579 |
'class' => 'mw-unwatch-link', |
| 580 |
'title' => $this->msg( $unwatchTooltipMessage, [ $diffInDays ] )->text() |
| 581 |
], [ 'action' => 'unwatch' ] ) . "\u{00A0}"; |
| 582 |
} |
| 583 |
} ); |
| 584 |
} |
| 585 |
$rows->seek( 0 ); |
| 586 |
|
| 587 |
$s = $list->beginRecentChangesList(); |
| 588 |
|
| 589 |
if ( $this->isStructuredFilterUiEnabled() ) { |
| 590 |
$s .= $this->makeLegend(); |
| 591 |
} |
| 592 |
|
| 593 |
$userShowHiddenCats = $this->userOptionsLookup->getBoolOption( $user, 'showhiddencats' ); |
| 594 |
$counter = 1; |
| 595 |
foreach ( $rows as $obj ) { |
| 596 |
|
| 597 |
$rc = RecentChange::newFromRow( $obj ); |
| 598 |
|
| 599 |
|
| 600 |
if ( |
| 601 |
$rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE && |
| 602 |
!$userShowHiddenCats && |
| 603 |
$rc->getParam( 'hidden-cat' ) |
| 604 |
) { |
| 605 |
continue; |
| 606 |
} |
| 607 |
|
| 608 |
$rc->counter = $counter++; |
| 609 |
|
| 610 |
if ( $this->getConfig()->get( MainConfigNames::ShowUpdatedMarker ) ) { |
| 611 |
$unseen = !$this->isChangeEffectivelySeen( $rc ); |
| 612 |
} else { |
| 613 |
$unseen = false; |
| 614 |
} |
| 615 |
|
| 616 |
if ( $this->getConfig()->get( MainConfigNames::RCShowWatchingUsers ) |
| 617 |
&& $this->userOptionsLookup->getBoolOption( $user, 'shownumberswatching' ) |
| 618 |
) { |
| 619 |
$rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title ); |
| 620 |
$rc->numberofWatchingusers = $this->watchedItemStore->countWatchers( $rcTitleValue ); |
| 621 |
} else { |
| 622 |
$rc->numberofWatchingusers = 0; |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
$changeLine = $list->recentChangesLine( $rc, $unseen, $counter ); |
| 629 |
if ( $changeLine !== false ) { |
| 630 |
$s .= $changeLine; |
| 631 |
} |
| 632 |
} |
| 633 |
$s .= $list->endRecentChangesList(); |
| 634 |
|
| 635 |
$output->addHTML( $s ); |
| 636 |
} |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
public function getAssociatedNavigationLinks() { |
| 642 |
return self::WATCHLIST_TAB_PATHS; |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
public static function getShortDescriptionHelper( SpecialPage $specialPage, string $path = '' ): string { |
| 651 |
switch ( $path ) { |
| 652 |
case 'Watchlist': |
| 653 |
return $specialPage->msg( 'watchlisttools-view' )->text(); |
| 654 |
case 'EditWatchlist': |
| 655 |
return $specialPage->msg( 'watchlisttools-edit' )->text(); |
| 656 |
case 'EditWatchlist/raw': |
| 657 |
return $specialPage->msg( 'watchlisttools-raw' )->text(); |
| 658 |
case 'EditWatchlist/clear': |
| 659 |
return $specialPage->msg( 'watchlisttools-clear' )->text(); |
| 660 |
default: |
| 661 |
return $path; |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
public function getShortDescription( string $path = '' ): string { |
| 669 |
return self::getShortDescriptionHelper( $this, $path ); |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
public function doHeader( $opts, $numRows ) { |
| 679 |
$user = $this->getUser(); |
| 680 |
$out = $this->getOutput(); |
| 681 |
$skin = $this->getSkin(); |
| 682 |
|
| 683 |
$subpageSubtitle = $skin->supportsMenu( 'associated-pages' ) ? '' : |
| 684 |
' ' . |
| 685 |
SpecialEditWatchlist::buildTools( |
| 686 |
null, |
| 687 |
$this->getLinkRenderer(), |
| 688 |
$this->currentMode |
| 689 |
); |
| 690 |
|
| 691 |
$out->addSubtitle( |
| 692 |
Html::element( |
| 693 |
'span', |
| 694 |
[ |
| 695 |
'class' => 'mw-watchlist-owner' |
| 696 |
], |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
$this->msg( 'watchlistfor2', $this->getUser()->getName(), '' )->text() |
| 702 |
) . $subpageSubtitle |
| 703 |
); |
| 704 |
|
| 705 |
$this->setTopText( $opts ); |
| 706 |
|
| 707 |
$form = ''; |
| 708 |
|
| 709 |
$form .= Xml::openElement( 'form', [ |
| 710 |
'method' => 'get', |
| 711 |
'action' => wfScript(), |
| 712 |
'id' => 'mw-watchlist-form' |
| 713 |
] ); |
| 714 |
$form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ); |
| 715 |
$form .= Xml::openElement( |
| 716 |
'fieldset', |
| 717 |
[ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ] |
| 718 |
); |
| 719 |
$form .= Xml::element( |
| 720 |
'legend', null, $this->msg( 'watchlist-options' )->text() |
| 721 |
); |
| 722 |
|
| 723 |
if ( !$this->isStructuredFilterUiEnabled() ) { |
| 724 |
$form .= $this->makeLegend(); |
| 725 |
} |
| 726 |
|
| 727 |
$lang = $this->getLanguage(); |
| 728 |
$timestamp = wfTimestampNow(); |
| 729 |
$now = $lang->userTimeAndDate( $timestamp, $user ); |
| 730 |
$wlInfo = Html::rawElement( |
| 731 |
'span', |
| 732 |
[ |
| 733 |
'class' => 'wlinfo', |
| 734 |
'data-params' => json_encode( [ 'from' => $timestamp, 'fromFormatted' => $now ] ), |
| 735 |
], |
| 736 |
$this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params( |
| 737 |
$lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user ) |
| 738 |
)->parse() |
| 739 |
) . "<br />\n"; |
| 740 |
|
| 741 |
$nondefaults = $opts->getChangedValues(); |
| 742 |
$cutofflinks = Html::rawElement( |
| 743 |
'span', |
| 744 |
[ 'class' => 'cldays cloption' ], |
| 745 |
$this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts ) |
| 746 |
); |
| 747 |
|
| 748 |
|
| 749 |
$links = []; |
| 750 |
$namesOfDisplayedFilters = []; |
| 751 |
foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) { |
| 752 |
$namesOfDisplayedFilters[] = $filterName; |
| 753 |
$links[] = $this->showHideCheck( |
| 754 |
$nondefaults, |
| 755 |
$filter->getShowHide(), |
| 756 |
$filterName, |
| 757 |
$opts[ $filterName ], |
| 758 |
$filter->isFeatureAvailableOnStructuredUi() |
| 759 |
); |
| 760 |
} |
| 761 |
|
| 762 |
$hiddenFields = $nondefaults; |
| 763 |
$hiddenFields['action'] = 'submit'; |
| 764 |
unset( $hiddenFields['namespace'] ); |
| 765 |
unset( $hiddenFields['invert'] ); |
| 766 |
unset( $hiddenFields['associated'] ); |
| 767 |
unset( $hiddenFields['days'] ); |
| 768 |
foreach ( $namesOfDisplayedFilters as $filterName ) { |
| 769 |
unset( $hiddenFields[$filterName] ); |
| 770 |
} |
| 771 |
|
| 772 |
|
| 773 |
$form .= $wlInfo; |
| 774 |
$form .= $cutofflinks; |
| 775 |
$form .= Html::rawElement( |
| 776 |
'span', |
| 777 |
[ 'class' => 'clshowhide' ], |
| 778 |
$this->msg( 'watchlist-hide' ) . |
| 779 |
$this->msg( 'colon-separator' )->escaped() . |
| 780 |
implode( ' ', $links ) |
| 781 |
); |
| 782 |
$form .= "\n<br />\n"; |
| 783 |
|
| 784 |
$namespaceForm = Html::namespaceSelector( |
| 785 |
[ |
| 786 |
'selected' => $opts['namespace'], |
| 787 |
'all' => '', |
| 788 |
'label' => $this->msg( 'namespace' )->text(), |
| 789 |
'in-user-lang' => true, |
| 790 |
], [ |
| 791 |
'name' => 'namespace', |
| 792 |
'id' => 'namespace', |
| 793 |
'class' => 'namespaceselector', |
| 794 |
] |
| 795 |
) . "\n"; |
| 796 |
$namespaceForm .= Html::rawElement( 'label', [ |
| 797 |
'class' => 'mw-input-with-label', 'title' => $this->msg( 'tooltip-invert' )->text(), |
| 798 |
], Html::element( 'input', [ |
| 799 |
'type' => 'checkbox', 'name' => 'invert', 'value' => '1', 'checked' => $opts['invert'], |
| 800 |
] ) . ' ' . $this->msg( 'invert' )->escaped() ) . "\n"; |
| 801 |
$namespaceForm .= Html::rawElement( 'label', [ |
| 802 |
'class' => 'mw-input-with-label', 'title' => $this->msg( 'tooltip-namespace_association' )->text(), |
| 803 |
], Html::element( 'input', [ |
| 804 |
'type' => 'checkbox', 'name' => 'associated', 'value' => '1', 'checked' => $opts['associated'], |
| 805 |
] ) . ' ' . $this->msg( 'namespace_association' )->escaped() ) . "\n"; |
| 806 |
$form .= Html::rawElement( |
| 807 |
'span', |
| 808 |
[ 'class' => 'namespaceForm cloption' ], |
| 809 |
$namespaceForm |
| 810 |
); |
| 811 |
|
| 812 |
$form .= Xml::submitButton( |
| 813 |
$this->msg( 'watchlist-submit' )->text(), |
| 814 |
[ 'class' => 'cloption-submit' ] |
| 815 |
) . "\n"; |
| 816 |
foreach ( $hiddenFields as $key => $value ) { |
| 817 |
$form .= Html::hidden( $key, $value ) . "\n"; |
| 818 |
} |
| 819 |
$form .= Xml::closeElement( 'fieldset' ) . "\n"; |
| 820 |
$form .= Xml::closeElement( 'form' ) . "\n"; |
| 821 |
|
| 822 |
|
| 823 |
if ( $this->isStructuredFilterUiEnabled() ) { |
| 824 |
$rcfilterContainer = Html::element( |
| 825 |
'div', |
| 826 |
[ 'class' => 'mw-rcfilters-container' ] |
| 827 |
); |
| 828 |
|
| 829 |
$loadingContainer = Html::rawElement( |
| 830 |
'div', |
| 831 |
[ 'class' => 'mw-rcfilters-spinner' ], |
| 832 |
Html::element( |
| 833 |
'div', |
| 834 |
[ 'class' => 'mw-rcfilters-spinner-bounce' ] |
| 835 |
) |
| 836 |
); |
| 837 |
|
| 838 |
|
| 839 |
$this->getOutput()->addHTML( |
| 840 |
Html::rawElement( |
| 841 |
'div', |
| 842 |
[ 'class' => 'mw-rcfilters-head' ], |
| 843 |
$rcfilterContainer . $form |
| 844 |
) |
| 845 |
); |
| 846 |
|
| 847 |
|
| 848 |
$this->getOutput()->addHTML( $loadingContainer ); |
| 849 |
} else { |
| 850 |
$this->getOutput()->addHTML( $form ); |
| 851 |
} |
| 852 |
|
| 853 |
$this->setBottomText( $opts ); |
| 854 |
} |
| 855 |
|
| 856 |
private function cutoffselector( $options ) { |
| 857 |
$selected = (float)$options['days']; |
| 858 |
$maxDays = $this->getConfig()->get( MainConfigNames::RCMaxAge ) / ( 3600 * 24 ); |
| 859 |
if ( $selected <= 0 ) { |
| 860 |
$selected = $maxDays; |
| 861 |
} |
| 862 |
|
| 863 |
$selectedHours = round( $selected * 24 ); |
| 864 |
|
| 865 |
$hours = array_unique( array_filter( [ |
| 866 |
1, |
| 867 |
2, |
| 868 |
6, |
| 869 |
12, |
| 870 |
24, |
| 871 |
72, |
| 872 |
168, |
| 873 |
24 * (float)$this->userOptionsLookup->getOption( $this->getUser(), 'watchlistdays', 0 ), |
| 874 |
24 * $maxDays, |
| 875 |
$selectedHours |
| 876 |
] ) ); |
| 877 |
asort( $hours ); |
| 878 |
|
| 879 |
$select = new XmlSelect( 'days', 'days', $selectedHours / 24 ); |
| 880 |
|
| 881 |
foreach ( $hours as $value ) { |
| 882 |
if ( $value < 24 ) { |
| 883 |
$name = $this->msg( 'hours' )->numParams( $value )->text(); |
| 884 |
} else { |
| 885 |
$name = $this->msg( 'days' )->numParams( $value / 24 )->text(); |
| 886 |
} |
| 887 |
$select->addOption( $name, (float)( $value / 24 ) ); |
| 888 |
} |
| 889 |
|
| 890 |
return $select->getHTML() . "\n<br />\n"; |
| 891 |
} |
| 892 |
|
| 893 |
public function setTopText( FormOptions $opts ) { |
| 894 |
$nondefaults = $opts->getChangedValues(); |
| 895 |
$form = ''; |
| 896 |
$user = $this->getUser(); |
| 897 |
|
| 898 |
$numItems = $this->countItems(); |
| 899 |
$showUpdatedMarker = $this->getConfig()->get( MainConfigNames::ShowUpdatedMarker ); |
| 900 |
|
| 901 |
|
| 902 |
$watchlistHeader = ''; |
| 903 |
if ( $numItems == 0 ) { |
| 904 |
$watchlistHeader = $this->msg( 'nowatchlist' )->parse(); |
| 905 |
} else { |
| 906 |
$watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() |
| 907 |
. $this->msg( 'word-separator' )->escaped(); |
| 908 |
if ( $this->getConfig()->get( MainConfigNames::EnotifWatchlist ) |
| 909 |
&& $this->userOptionsLookup->getBoolOption( $user, 'enotifwatchlistpages' ) |
| 910 |
) { |
| 911 |
$watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() |
| 912 |
. $this->msg( 'word-separator' )->escaped(); |
| 913 |
} |
| 914 |
if ( $showUpdatedMarker ) { |
| 915 |
$watchlistHeader .= $this->msg( |
| 916 |
$this->isStructuredFilterUiEnabled() ? |
| 917 |
'rcfilters-watchlist-showupdated' : |
| 918 |
'wlheader-showupdated' |
| 919 |
)->parse() . $this->msg( 'word-separator' )->escaped(); |
| 920 |
} |
| 921 |
} |
| 922 |
$form .= Html::rawElement( |
| 923 |
'div', |
| 924 |
[ 'class' => 'watchlistDetails' ], |
| 925 |
$watchlistHeader |
| 926 |
); |
| 927 |
|
| 928 |
if ( $numItems > 0 && $showUpdatedMarker ) { |
| 929 |
$form .= Xml::openElement( 'form', [ 'method' => 'post', |
| 930 |
'action' => $this->getPageTitle()->getLocalURL(), |
| 931 |
'id' => 'mw-watchlist-resetbutton' ] ) . "\n" . |
| 932 |
Xml::submitButton( $this->msg( 'enotif_reset' )->text(), |
| 933 |
[ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" . |
| 934 |
Html::hidden( 'token', $user->getEditToken() ) . "\n" . |
| 935 |
Html::hidden( 'reset', 'all' ) . "\n"; |
| 936 |
foreach ( $nondefaults as $key => $value ) { |
| 937 |
$form .= Html::hidden( $key, $value ) . "\n"; |
| 938 |
} |
| 939 |
$form .= Xml::closeElement( 'form' ) . "\n"; |
| 940 |
} |
| 941 |
|
| 942 |
$this->getOutput()->addHTML( $form ); |
| 943 |
} |
| 944 |
|
| 945 |
protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) { |
| 946 |
$options[$name] = 1 - (int)$value; |
| 947 |
|
| 948 |
$attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ]; |
| 949 |
if ( $inStructuredUi ) { |
| 950 |
$attribs[ 'data-feature-in-structured-ui' ] = true; |
| 951 |
} |
| 952 |
|
| 953 |
return Html::rawElement( |
| 954 |
'span', |
| 955 |
$attribs, |
| 956 |
|
| 957 |
Html::check( $name, (bool)$value, [ 'id' => $name ] ) . "\n" . Html::rawElement( |
| 958 |
'label', |
| 959 |
$attribs + [ 'for' => $name ], |
| 960 |
|
| 961 |
$this->msg( $message, '<nowiki/>' )->parse() |
| 962 |
) |
| 963 |
); |
| 964 |
} |
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
protected function countItems() { |
| 974 |
$count = $this->watchedItemStore->countWatchedItems( $this->getUser() ); |
| 975 |
return (int)floor( $count / 2 ); |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
protected function isChangeEffectivelySeen( RecentChange $rc ) { |
| 983 |
$firstUnseen = $this->getLatestNotificationTimestamp( $rc ); |
| 984 |
|
| 985 |
return ( $firstUnseen === null || $firstUnseen > $rc->getAttribute( 'rc_timestamp' ) ); |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
private function getLatestNotificationTimestamp( RecentChange $rc ) { |
| 993 |
return $this->watchedItemStore->getLatestNotificationTimestamp( |
| 994 |
$rc->getAttribute( 'wl_notificationtimestamp' ), |
| 995 |
$this->getUser(), |
| 996 |
$rc->getTitle() |
| 997 |
); |
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
protected function getLimitPreferenceName(): string { |
| 1004 |
return 'wllimit'; |
| 1005 |
} |
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
protected function getSavedQueriesPreferenceName(): string { |
| 1011 |
return 'rcfilters-wl-saved-queries'; |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
protected function getDefaultDaysPreferenceName(): string { |
| 1018 |
return 'watchlistdays'; |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
protected function getCollapsedPreferenceName(): string { |
| 1025 |
return 'rcfilters-wl-collapsed'; |
| 1026 |
} |
| 1027 |
|
| 1028 |
} |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
class_alias( SpecialWatchlist::class, 'SpecialWatchlist' ); |