Move most User::clearAllNotifications() logic to WatchedItemStore
[lhc/web/wiklou.git] / includes / user / User.php
index 3102cfc..9777148 100644 (file)
@@ -885,7 +885,7 @@ class User implements IDBAccessObject, UserIdentity {
                        return null;
                }
 
-               if ( !( $flags & self::READ_LATEST ) && isset( self::$idCacheByName[$name] ) ) {
+               if ( !( $flags & self::READ_LATEST ) && array_key_exists( $name, self::$idCacheByName ) ) {
                        return self::$idCacheByName[$name];
                }
 
@@ -1871,7 +1871,9 @@ class User implements IDBAccessObject, UserIdentity {
                        $this->mHideName = $block->mHideName;
                        $this->mAllowUsertalk = !$block->prevents( 'editownusertalk' );
                } else {
+                       $this->mBlock = null;
                        $this->mBlockedby = '';
+                       $this->mBlockreason = '';
                        $this->mHideName = 0;
                        $this->mAllowUsertalk = false;
                }
@@ -3082,7 +3084,7 @@ class User implements IDBAccessObject, UserIdentity {
         * @param string $oname The option to check
         * @param string $defaultOverride A default value returned if the option does not exist
         * @param bool $ignoreHidden Whether to ignore the effects of $wgHiddenPrefs
-        * @return string|null User's current value for the option
+        * @return string|array|int|null User's current value for the option
         * @see getBoolOption()
         * @see getIntOption()
         */
@@ -3967,51 +3969,9 @@ class User implements IDBAccessObject, UserIdentity {
                        return;
                }
 
-               $dbw = wfGetDB( DB_MASTER );
-               $asOfTimes = array_unique( $dbw->selectFieldValues(
-                       'watchlist',
-                       'wl_notificationtimestamp',
-                       [ 'wl_user' => $id, 'wl_notificationtimestamp IS NOT NULL' ],
-                       __METHOD__,
-                       [ 'ORDER BY' => 'wl_notificationtimestamp DESC', 'LIMIT' => 500 ]
-               ) );
-               if ( !$asOfTimes ) {
-                       return;
-               }
-               // Immediately update the most recent touched rows, which hopefully covers what
-               // the user sees on the watchlist page before pressing "mark all pages visited"....
-               $dbw->update(
-                       'watchlist',
-                       [ 'wl_notificationtimestamp' => null ],
-                       [ 'wl_user' => $id, 'wl_notificationtimestamp' => $asOfTimes ],
-                       __METHOD__
-               );
-               // ...and finish the older ones in a post-send update with lag checks...
-               DeferredUpdates::addUpdate( new AutoCommitUpdate(
-                       $dbw,
-                       __METHOD__,
-                       function () use ( $dbw, $id ) {
-                               global $wgUpdateRowsPerQuery;
-
-                               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
-                               $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
-                               $asOfTimes = array_unique( $dbw->selectFieldValues(
-                                       'watchlist',
-                                       'wl_notificationtimestamp',
-                                       [ 'wl_user' => $id, 'wl_notificationtimestamp IS NOT NULL' ],
-                                       __METHOD__
-                               ) );
-                               foreach ( array_chunk( $asOfTimes, $wgUpdateRowsPerQuery ) as $asOfTimeBatch ) {
-                                       $dbw->update(
-                                               'watchlist',
-                                               [ 'wl_notificationtimestamp' => null ],
-                                               [ 'wl_user' => $id, 'wl_notificationtimestamp' => $asOfTimeBatch ],
-                                               __METHOD__
-                                       );
-                                       $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
-                               }
-                       }
-               ) );
+               $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
+               $watchedItemStore->resetAllNotificationTimestampsForUser( $this );
+
                // We also need to clear here the "you have new message" notification for the own
                // user_talk page; it's cleared one page view later in WikiPage::doViewUpdates().
        }
@@ -4052,76 +4012,6 @@ class User implements IDBAccessObject, UserIdentity {
                }
        }
 
-       /**
-        * Set a cookie on the user's client. Wrapper for
-        * WebResponse::setCookie
-        * @deprecated since 1.27
-        * @param string $name Name of the cookie to set
-        * @param string $value Value to set
-        * @param int $exp Expiration time, as a UNIX time value;
-        *                   if 0 or not specified, use the default $wgCookieExpiration
-        * @param bool $secure
-        *  true: Force setting the secure attribute when setting the cookie
-        *  false: Force NOT setting the secure attribute when setting the cookie
-        *  null (default): Use the default ($wgCookieSecure) to set the secure attribute
-        * @param array $params Array of options sent passed to WebResponse::setcookie()
-        * @param WebRequest|null $request WebRequest object to use; $wgRequest will be used if null
-        *        is passed.
-        */
-       protected function setCookie(
-               $name, $value, $exp = 0, $secure = null, $params = [], $request = null
-       ) {
-               wfDeprecated( __METHOD__, '1.27' );
-               if ( $request === null ) {
-                       $request = $this->getRequest();
-               }
-               $params['secure'] = $secure;
-               $request->response()->setCookie( $name, $value, $exp, $params );
-       }
-
-       /**
-        * Clear a cookie on the user's client
-        * @deprecated since 1.27
-        * @param string $name Name of the cookie to clear
-        * @param bool $secure
-        *  true: Force setting the secure attribute when setting the cookie
-        *  false: Force NOT setting the secure attribute when setting the cookie
-        *  null (default): Use the default ($wgCookieSecure) to set the secure attribute
-        * @param array $params Array of options sent passed to WebResponse::setcookie()
-        */
-       protected function clearCookie( $name, $secure = null, $params = [] ) {
-               wfDeprecated( __METHOD__, '1.27' );
-               $this->setCookie( $name, '', time() - 86400, $secure, $params );
-       }
-
-       /**
-        * Set an extended login cookie on the user's client. The expiry of the cookie
-        * is controlled by the $wgExtendedLoginCookieExpiration configuration
-        * variable.
-        *
-        * @see User::setCookie
-        *
-        * @deprecated since 1.27
-        * @param string $name Name of the cookie to set
-        * @param string $value Value to set
-        * @param bool $secure
-        *  true: Force setting the secure attribute when setting the cookie
-        *  false: Force NOT setting the secure attribute when setting the cookie
-        *  null (default): Use the default ($wgCookieSecure) to set the secure attribute
-        */
-       protected function setExtendedLoginCookie( $name, $value, $secure ) {
-               global $wgExtendedLoginCookieExpiration, $wgCookieExpiration;
-
-               wfDeprecated( __METHOD__, '1.27' );
-
-               $exp = time();
-               $exp += $wgExtendedLoginCookieExpiration !== null
-                       ? $wgExtendedLoginCookieExpiration
-                       : $wgCookieExpiration;
-
-               $this->setCookie( $name, $value, $exp, $secure );
-       }
-
        /**
         * Persist this user's session (e.g. set cookies)
         *