58 private $isEnotifEnabled;
64 private $readOnlyMode;
67 private $revisionLookup;
70 private $talkPageNotificationManager;
73 private $watchedItemStore;
82 private $wikiPageFactory;
100 private $notificationTimestampCache = [];
125 $this->hookRunner =
new HookRunner( $hookContainer );
126 $this->readOnlyMode = $readOnlyMode;
127 $this->revisionLookup = $revisionLookup;
128 $this->talkPageNotificationManager = $talkPageNotificationManager;
129 $this->watchedItemStore = $watchedItemStore;
130 $this->userFactory = $userFactory;
131 $this->nsInfo = $nsInfo;
132 $this->wikiPageFactory = $wikiPageFactory;
145 if ( $this->readOnlyMode->isReadOnly() ) {
150 if ( !$performer instanceof
Authority ) {
151 $performer = $this->userFactory->newFromUserIdentity( $performer );
154 $user = $performer->getUser();
158 if ( !$this->isEnotifEnabled ) {
159 $this->talkPageNotificationManager->removeUserHasNewMessages( $user );
163 if ( !$performer->isAllowed(
'editmywatchlist' ) ) {
168 if ( !$user->isRegistered() ) {
172 $this->watchedItemStore->resetAllNotificationTimestampsForUser( $user );
197 if ( $this->readOnlyMode->isReadOnly() ) {
202 if ( !$performer instanceof
Authority ) {
203 $performer = $this->userFactory->newFromUserIdentity( $performer );
206 $userIdentity = $performer->getUser();
209 $title->getDBkey() === strtr( $userIdentity->getName(),
' ',
'_' )
212 if ( $userTalkPage ) {
215 } elseif ( !$oldRev ) {
216 $oldRev = $this->revisionLookup->getRevisionById( $oldid );
221 $this->talkPageNotificationManager->clearForPageView( $userIdentity, $oldRev );
224 if ( !$this->isEnotifEnabled ) {
228 if ( !$userIdentity->isRegistered() ) {
236 if ( !$performer->isAllowed(
'editmywatchlist' ) ) {
245 $force = $userTalkPage ?
'force' :
'';
246 $this->watchedItemStore->resetNotificationTimestamp( $userIdentity, $title, $force, $oldid );
261 $cacheKey =
'u' . $user->
getId() .
'-' .
262 $title->getNamespace() .
':' . $title->getDBkey();
265 if ( array_key_exists( $cacheKey, $this->notificationTimestampCache ) ) {
266 return $this->notificationTimestampCache[ $cacheKey ];
269 $watchedItem = $this->watchedItemStore->getWatchedItem( $user, $title );
270 if ( $watchedItem ) {
271 $timestamp = $watchedItem->getNotificationTimestamp();
276 $this->notificationTimestampCache[ $cacheKey ] = $timestamp;
286 if ( !$this->nsInfo->
isWatchable( $target->getNamespace() ) ) {
306 if ( $this->isWatchable( $target ) ) {
307 return $this->watchedItemStore->isWatched( $userIdentity, $target );
321 if ( $performer->isAllowed(
'viewmywatchlist' ) ) {
322 return $this->isWatchedIgnoringRights( $performer->
getUser(), $target );
335 if ( $this->isWatchable( $target ) ) {
336 return $this->watchedItemStore->isTempWatched( $userIdentity, $target );
350 if ( $performer->isAllowed(
'viewmywatchlist' ) ) {
351 return $this->isTempWatchedIgnoringRights( $performer->
getUser(), $target );
368 ?
string $expiry =
null
370 if ( !$this->isWatchable( $target ) ) {
374 $wikiPage = $this->wikiPageFactory->newFromTitle( $target );
375 $title = $wikiPage->getTitle();
378 $status = Status::newFatal(
'hookaborted' );
379 $user = $this->userFactory->newFromUserIdentity( $userIdentity );
380 if ( $this->hookRunner->onWatchArticle( $user, $wikiPage, $status, $expiry ) ) {
382 $this->watchedItemStore->addWatch( $userIdentity, $this->nsInfo->getSubjectPage( $title ), $expiry );
383 if ( $this->nsInfo->canHaveTalkPage( $title ) ) {
384 $this->watchedItemStore->addWatch( $userIdentity, $this->nsInfo->getTalkPage( $title ), $expiry );
386 $this->hookRunner->onWatchArticleComplete( $user, $wikiPage );
390 $user->invalidateCache();
408 ?
string $expiry =
null
410 if ( !$performer->isAllowed(
'editmywatchlist' ) ) {
412 return User::newFatalPermissionDeniedStatus(
'editmywatchlist' );
415 return $this->addWatchIgnoringRights( $performer->getUser(), $target, $expiry );
429 if ( !$this->isWatchable( $target ) ) {
433 $wikiPage = $this->wikiPageFactory->newFromTitle( $target );
434 $title = $wikiPage->getTitle();
437 $status = Status::newFatal(
'hookaborted' );
438 $user = $this->userFactory->newFromUserIdentity( $userIdentity );
439 if ( $this->hookRunner->onUnwatchArticle( $user, $wikiPage, $status ) ) {
441 $this->watchedItemStore->removeWatch( $userIdentity, $this->nsInfo->getSubjectPage( $title ) );
442 if ( $this->nsInfo->canHaveTalkPage( $title ) ) {
443 $this->watchedItemStore->removeWatch( $userIdentity, $this->nsInfo->getTalkPage( $title ) );
445 $this->hookRunner->onUnwatchArticleComplete( $user, $wikiPage );
449 $user->invalidateCache();
466 if ( !$performer->isAllowed(
'editmywatchlist' ) ) {
468 return User::newFatalPermissionDeniedStatus(
'editmywatchlist' );
471 return $this->removeWatchIgnoringRights( $performer->getUser(), $target );
491 string $expiry =
null
494 if ( !$performer->
getUser()->isRegistered() ) {
499 $oldWatchedItem = $this->watchedItemStore->getWatchedItem( $performer->getUser(), $target );
500 $changingWatchStatus = (bool)$oldWatchedItem !== $watch;
501 if ( $oldWatchedItem && $expiry !==
null ) {
503 $oldWatchPeriod = $oldWatchedItem->getExpiry() ??
'infinity';
504 $changingWatchStatus = $changingWatchStatus ||
505 $oldWatchPeriod !== ExpiryDef::normalizeExpiry( $expiry, TS_MW );
508 if ( $changingWatchStatus ) {
512 return $this->addWatchIgnoringRights( $performer->getUser(), $target, $expiry );
514 return $this->removeWatch( $performer, $target );
if(!defined('MW_SETUP_CALLBACK'))
Service for creating WikiPage objects.
Manages user talk page notifications.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.
Interface for objects (potentially) representing an editable wiki page.
canExist()
Checks whether this PageIdentity represents a "proper" page, meaning that it could exist as an editab...