Merge "Split out doBlockLevels() into its own class"
[lhc/web/wiklou.git] / includes / mail / EmailNotification.php
index 30907e6..1d0bdf6 100644 (file)
@@ -23,6 +23,9 @@
  * @author Tim Starling
  * @author Luke Welling lwelling@wikimedia.org
  */
+use MediaWiki\Linker\LinkTarget;
+
+use MediaWiki\MediaWikiServices;
 
 /**
  * This module processes the email notifications when the current page is
@@ -72,10 +75,13 @@ class EmailNotification {
        protected $editor;
 
        /**
+        * @deprecated since 1.27 use WatchedItemStore::updateNotificationTimestamp directly
+        *
         * @param User $editor The editor that triggered the update.  Their notification
         *  timestamp will not be updated(they have already seen it)
         * @param LinkTarget $linkTarget The link target of the title to update timestamps for
         * @param string $timestamp Set the update timestamp to this value
+        *
         * @return int[] Array of user IDs
         */
        public static function updateWatchlistTimestamp(
@@ -83,47 +89,16 @@ class EmailNotification {
                LinkTarget $linkTarget,
                $timestamp
        ) {
-               global $wgEnotifWatchlist, $wgShowUpdatedMarker;
-
-               if ( !$wgEnotifWatchlist && !$wgShowUpdatedMarker ) {
+               // wfDeprecated( __METHOD__, '1.27' );
+               $config = RequestContext::getMain()->getConfig();
+               if ( !$config->get( 'EnotifWatchlist' ) && !$config->get( 'ShowUpdatedMarker' ) ) {
                        return [];
                }
-
-               $dbw = wfGetDB( DB_MASTER );
-               $res = $dbw->select( [ 'watchlist' ],
-                       [ 'wl_user' ],
-                       [
-                               'wl_user != ' . intval( $editor->getID() ),
-                               'wl_namespace' => $linkTarget->getNamespace(),
-                               'wl_title' => $linkTarget->getDBkey(),
-                               'wl_notificationtimestamp IS NULL',
-                       ], __METHOD__
+               return MediaWikiServices::getInstance()->getWatchedItemStore()->updateNotificationTimestamp(
+                       $editor,
+                       $linkTarget,
+                       $timestamp
                );
-
-               $watchers = [];
-               foreach ( $res as $row ) {
-                       $watchers[] = intval( $row->wl_user );
-               }
-
-               if ( $watchers ) {
-                       // Update wl_notificationtimestamp for all watching users except the editor
-                       $fname = __METHOD__;
-                       $dbw->onTransactionIdle(
-                               function () use ( $dbw, $timestamp, $watchers, $linkTarget, $fname ) {
-                                       $dbw->update( 'watchlist',
-                                               [ /* SET */
-                                                       'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
-                                               ], [ /* WHERE */
-                                                       'wl_user' => $watchers,
-                                                       'wl_namespace' => $linkTarget->getNamespace(),
-                                                       'wl_title' => $linkTarget->getDBkey(),
-                                               ], $fname
-                                       );
-                               }
-                       );
-               }
-
-               return $watchers;
        }
 
        /**
@@ -149,7 +124,15 @@ class EmailNotification {
                }
 
                // update wl_notificationtimestamp for watchers
-               $watchers = self::updateWatchlistTimestamp( $editor, $title, $timestamp );
+               $config = RequestContext::getMain()->getConfig();
+               $watchers = [];
+               if ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) ) {
+                       $watchers = MediaWikiServices::getInstance()->getWatchedItemStore()->updateNotificationTimestamp(
+                               $editor,
+                               $title,
+                               $timestamp
+                       );
+               }
 
                $sendEmail = true;
                // $watchers deals with $wgEnotifWatchlist.
@@ -175,7 +158,7 @@ class EmailNotification {
                                $title,
                                [
                                        'editor' => $editor->getName(),
-                                       'editorID' => $editor->getID(),
+                                       'editorID' => $editor->getId(),
                                        'timestamp' => $timestamp,
                                        'summary' => $summary,
                                        'minorEdit' => $minorEdit,
@@ -252,7 +235,7 @@ class EmailNotification {
                                        if ( $watchingUser->getOption( 'enotifwatchlistpages' )
                                                && ( !$minorEdit || $watchingUser->getOption( 'enotifminoredits' ) )
                                                && $watchingUser->isEmailConfirmed()
-                                               && $watchingUser->getID() != $userTalkId
+                                               && $watchingUser->getId() != $userTalkId
                                                && !in_array( $watchingUser->getName(), $wgUsersNotifiedOnAllChanges )
                                                && !( $wgBlockDisablesLogin && $watchingUser->isBlocked() )
                                        ) {