Merge "mediawiki.Title: Remove dead code and streamline newFromUserInput()"
[lhc/web/wiklou.git] / includes / watcheditem / WatchedItemStore.php
index bd4360e..1a39945 100644 (file)
@@ -553,7 +553,7 @@ class WatchedItemStore implements WatchedItemStoreInterface, StatsdAwareInterfac
         * @since 1.27
         * @param UserIdentity $user
         * @param LinkTarget $target
-        * @return bool
+        * @return WatchedItem|false
         */
        public function getWatchedItem( UserIdentity $user, LinkTarget $target ) {
                if ( !$user->isRegistered() ) {
@@ -573,7 +573,7 @@ class WatchedItemStore implements WatchedItemStoreInterface, StatsdAwareInterfac
         * @since 1.27
         * @param UserIdentity $user
         * @param LinkTarget $target
-        * @return WatchedItem|bool
+        * @return WatchedItem|false
         */
        public function loadWatchedItem( UserIdentity $user, LinkTarget $target ) {
                // Only registered user can have a watchlist
@@ -641,7 +641,7 @@ class WatchedItemStore implements WatchedItemStoreInterface, StatsdAwareInterfac
                        // @todo: Should we add these to the process cache?
                        $watchedItems[] = new WatchedItem(
                                $user,
-                               new TitleValue( (int)$row->wl_namespace, $row->wl_title ),
+                               $target,
                                $this->getLatestNotificationTimestamp(
                                        $row->wl_notificationtimestamp, $user, $target )
                        );
@@ -769,7 +769,7 @@ class WatchedItemStore implements WatchedItemStoreInterface, StatsdAwareInterfac
                foreach ( $rowBatches as $toInsert ) {
                        // Use INSERT IGNORE to avoid overwriting the notification timestamp
                        // if there's already an entry for this page
-                       $dbw->insert( 'watchlist', $toInsert, __METHOD__, 'IGNORE' );
+                       $dbw->insert( 'watchlist', $toInsert, __METHOD__, [ 'IGNORE' ] );
                        $affectedRows += $dbw->affectedRows();
                        if ( $ticket ) {
                                $this->lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
@@ -1103,6 +1103,14 @@ class WatchedItemStore implements WatchedItemStoreInterface, StatsdAwareInterfac
                return "{$target->getNamespace()}:{$target->getDBkey()}";
        }
 
+       /**
+        * @param UserIdentity $user
+        * @param LinkTarget $title
+        * @param WatchedItem $item
+        * @param bool $force
+        * @param int|bool $oldid The ID of the last revision that the user viewed
+        * @return bool|string|null
+        */
        private function getNotificationTimestamp(
                UserIdentity $user, LinkTarget $title, $item, $force, $oldid
        ) {
@@ -1112,7 +1120,8 @@ class WatchedItemStore implements WatchedItemStoreInterface, StatsdAwareInterfac
                }
 
                $oldRev = $this->revisionLookup->getRevisionById( $oldid );
-               if ( !$this->revisionLookup->getNextRevision( $oldRev, $title ) ) {
+               $nextRev = $this->revisionLookup->getNextRevision( $oldRev );
+               if ( !$nextRev ) {
                        // Oldid given and is the latest revision for this title; clear the timestamp.
                        return null;
                }
@@ -1129,6 +1138,8 @@ class WatchedItemStore implements WatchedItemStoreInterface, StatsdAwareInterfac
                // Oldid given and isn't the latest; update the timestamp.
                // This will result in no further notification emails being sent!
                $notificationTimestamp = $this->revisionLookup->getTimestampFromId( $oldid );
+               // @FIXME: this should use getTimestamp() for consistency with updates on new edits
+               // $notificationTimestamp = $nextRev->getTimestamp(); // first unseen revision timestamp
 
                // We need to go one second to the future because of various strict comparisons
                // throughout the codebase