Merge "Revert "Use display name in category page subheadings if provided""
[lhc/web/wiklou.git] / includes / api / ApiSetNotificationTimestamp.php
index ea52e14..3412f38 100644 (file)
@@ -24,6 +24,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * API interface for setting the wl_notificationtimestamp field
@@ -98,13 +99,14 @@ class ApiSetNotificationTimestamp extends ApiBase {
                        }
                }
 
+               $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
                $apiResult = $this->getResult();
                $result = [];
                if ( $params['entirewatchlist'] ) {
                        // Entire watchlist mode: Just update the thing and return a success indicator
-                       $dbw->update( 'watchlist', [ 'wl_notificationtimestamp' => $timestamp ],
-                               [ 'wl_user' => $user->getId() ],
-                               __METHOD__
+                       $watchedItemStore->setNotificationTimestampsForUser(
+                               $user,
+                               $timestamp
                        );
 
                        $result['notificationtimestamp'] = is_null( $timestamp )
@@ -133,23 +135,17 @@ class ApiSetNotificationTimestamp extends ApiBase {
 
                        if ( $pageSet->getTitles() ) {
                                // Now process the valid titles
-                               $lb = new LinkBatch( $pageSet->getTitles() );
-                               $dbw->update( 'watchlist', [ 'wl_notificationtimestamp' => $timestamp ],
-                                       [ 'wl_user' => $user->getId(), $lb->constructSet( 'wl', $dbw ) ],
-                                       __METHOD__
+                               $watchedItemStore->setNotificationTimestampsForUser(
+                                       $user,
+                                       $timestamp,
+                                       $pageSet->getTitles()
                                );
 
                                // Query the results of our update
-                               $timestamps = [];
-                               $res = $dbw->select(
-                                       'watchlist',
-                                       [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
-                                       [ 'wl_user' => $user->getId(), $lb->constructSet( 'wl', $dbw ) ],
-                                       __METHOD__
+                               $timestamps = $watchedItemStore->getNotificationTimestampsBatch(
+                                       $user,
+                                       $pageSet->getTitles()
                                );
-                               foreach ( $res as $row ) {
-                                       $timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp;
-                               }
 
                                // Now, put the valid titles into the result
                                /** @var $title Title */
@@ -162,6 +158,9 @@ class ApiSetNotificationTimestamp extends ApiBase {
                                        ];
                                        if ( !$title->exists() ) {
                                                $r['missing'] = true;
+                                               if ( $title->isKnown() ) {
+                                                       $r['known'] = true;
+                                               }
                                        }
                                        if ( isset( $timestamps[$ns] ) && array_key_exists( $dbkey, $timestamps[$ns] ) ) {
                                                $r['notificationtimestamp'] = '';