X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FWatchedItem.php;h=d2fb4683351575c467479efcd801d6ffa46912a3;hb=fe05f85a62275e84d61edf3576cf3f03e262d56a;hp=1e07e7c795cef9a75341523d8673829031f160f9;hpb=5cfec935722d8f4015dc24cda1de8bfc7f330537;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WatchedItem.php b/includes/WatchedItem.php index 1e07e7c795..d2fb468335 100644 --- a/includes/WatchedItem.php +++ b/includes/WatchedItem.php @@ -173,8 +173,9 @@ class WatchedItem { * * @param $force Whether to force the write query to be executed even if the * page is not watched or the notification timestamp is already NULL. + * @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed. */ - public function resetNotificationTimestamp( $force = '' ) { + public function resetNotificationTimestamp( $force = '', $oldid = 0 ) { // Only loggedin user can have a watchlist if ( wfReadOnly() || $this->mUser->isAnon() || !$this->isAllowed( 'editmywatchlist' ) ) { return; @@ -187,10 +188,50 @@ class WatchedItem { } } + $title = $this->getTitle(); + if ( !$oldid ) { + // No oldid given, assuming latest revision; clear the timestamp. + $notificationTimestamp = null; + } elseif ( !$title->getNextRevisionID( $oldid ) ) { + // Oldid given and is the latest revision for this title; clear the timestamp. + $notificationTimestamp = null; + } else { + // See if the version marked as read is more recent than the one we're viewing. + // Call load() if it wasn't called before due to $force. + $this->load(); + + if ( $this->timestamp === null ) { + // This can only happen if $force is enabled. + $notificationTimestamp = null; + } else { + // Oldid given and isn't the latest; update the timestamp. + // This will result in no further notification emails being sent! + $dbr = wfGetDB( DB_SLAVE ); + $notificationTimestamp = $dbr->selectField( + 'revision', 'rev_timestamp', + array( 'rev_page' => $title->getArticleID(), 'rev_id' => $oldid ) + ); + // We need to go one second to the future because of various strict comparisons + // throughout the codebase + $ts = new MWTimestamp( $notificationTimestamp ); + $ts->timestamp->add( new DateInterval( 'PT1S' ) ); + $notificationTimestamp = $ts->getTimestamp( TS_MW ); + + if ( $notificationTimestamp < $this->timestamp ) { + if ( $force != 'force' ) { + return; + } else { + // This is a little silly… + $notificationTimestamp = $this->timestamp; + } + } + } + } + // If the page is watched by the user (or may be watched), update the timestamp on any // any matching rows $dbw = wfGetDB( DB_MASTER ); - $dbw->update( 'watchlist', array( 'wl_notificationtimestamp' => null ), + $dbw->update( 'watchlist', array( 'wl_notificationtimestamp' => $notificationTimestamp ), $this->dbCond(), __METHOD__ ); $this->timestamp = null; }