Merge "user: Remove debug entries from User::isValidUserName() rejections"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 10 Mar 2016 16:26:38 +0000 (16:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 10 Mar 2016 16:26:38 +0000 (16:26 +0000)
1  2 
includes/user/User.php

diff --combined includes/user/User.php
@@@ -62,22 -62,17 +62,22 @@@ class User implements IDBAccessObject 
         */
        const VERSION = 10;
  
 -      /**
 -       * Maximum items in $mWatchedItems
 -       */
 -      const MAX_WATCHED_ITEMS_CACHE = 100;
 -
        /**
         * Exclude user options that are set to their default value.
         * @since 1.25
         */
        const GETOPTIONS_EXCLUDE_DEFAULTS = 1;
  
 +      /**
 +       * @since 1.27
 +       */
 +      const CHECK_USER_RIGHTS = true;
 +
 +      /**
 +       * @since 1.27
 +       */
 +      const IGNORE_USER_RIGHTS = false;
 +
        /**
         * Array of Strings List of member variables which are saved to the
         * shared cache (memcached). Any operation which changes the
        /** @var Block */
        private $mBlockedFromCreateAccount = false;
  
 -      /** @var array */
 -      private $mWatchedItems = [];
 -
        /** @var integer User::READ_* constant bitfield used to load data */
        protected $queryFlagsUsed = self::READ_NORMAL;
  
                        || strlen( $name ) > $wgMaxNameChars
                        || $name != $wgContLang->ucfirst( $name )
                ) {
-                       wfDebugLog( 'username', __METHOD__ .
-                               ": '$name' invalid due to empty, IP, slash, length, or lowercase" );
                        return false;
                }
  
                if ( is_null( $parsed )
                        || $parsed->getNamespace()
                        || strcmp( $name, $parsed->getPrefixedText() ) ) {
-                       wfDebugLog( 'username', __METHOD__ .
-                               ": '$name' invalid due to ambiguous prefixes" );
                        return false;
                }
  
                        '\x{e000}-\x{f8ff}' . # private use
                        ']/u';
                if ( preg_match( $unicodeBlacklist, $name ) ) {
-                       wfDebugLog( 'username', __METHOD__ .
-                               ": '$name' invalid due to blacklisted characters" );
                        return false;
                }
  
                }
        }
  
 -      /**
 -       * Get a WatchedItem for this user and $title.
 -       *
 -       * @since 1.22 $checkRights parameter added
 -       * @param Title $title
 -       * @param int $checkRights Whether to check 'viewmywatchlist'/'editmywatchlist' rights.
 -       *     Pass WatchedItem::CHECK_USER_RIGHTS or WatchedItem::IGNORE_USER_RIGHTS.
 -       * @return WatchedItem
 -       */
 -      public function getWatchedItem( $title, $checkRights = WatchedItem::CHECK_USER_RIGHTS ) {
 -              $key = $checkRights . ':' . $title->getNamespace() . ':' . $title->getDBkey();
 -
 -              if ( isset( $this->mWatchedItems[$key] ) ) {
 -                      return $this->mWatchedItems[$key];
 -              }
 -
 -              if ( count( $this->mWatchedItems ) >= self::MAX_WATCHED_ITEMS_CACHE ) {
 -                      $this->mWatchedItems = [];
 -              }
 -
 -              $this->mWatchedItems[$key] = WatchedItem::fromUserTitle( $this, $title, $checkRights );
 -              return $this->mWatchedItems[$key];
 -      }
 -
        /**
         * Check the watched status of an article.
         * @since 1.22 $checkRights parameter added
         * @param Title $title Title of the article to look at
 -       * @param int $checkRights Whether to check 'viewmywatchlist'/'editmywatchlist' rights.
 -       *     Pass WatchedItem::CHECK_USER_RIGHTS or WatchedItem::IGNORE_USER_RIGHTS.
 +       * @param bool $checkRights Whether to check 'viewmywatchlist'/'editmywatchlist' rights.
 +       *     Pass User::CHECK_USER_RIGHTS or User::IGNORE_USER_RIGHTS.
         * @return bool
         */
 -      public function isWatched( $title, $checkRights = WatchedItem::CHECK_USER_RIGHTS ) {
 -              return $this->getWatchedItem( $title, $checkRights )->isWatched();
 +      public function isWatched( $title, $checkRights = self::CHECK_USER_RIGHTS ) {
 +              if ( $title->isWatchable() && ( !$checkRights || $this->isAllowed( 'viewmywatchlist' ) ) ) {
 +                      return WatchedItemStore::getDefaultInstance()->isWatched( $this, $title );
 +              }
 +              return false;
        }
  
        /**
         * Watch an article.
         * @since 1.22 $checkRights parameter added
         * @param Title $title Title of the article to look at
 -       * @param int $checkRights Whether to check 'viewmywatchlist'/'editmywatchlist' rights.
 -       *     Pass WatchedItem::CHECK_USER_RIGHTS or WatchedItem::IGNORE_USER_RIGHTS.
 -       */
 -      public function addWatch( $title, $checkRights = WatchedItem::CHECK_USER_RIGHTS ) {
 -              $this->getWatchedItem( $title, $checkRights )->addWatch();
 +       * @param bool $checkRights Whether to check 'viewmywatchlist'/'editmywatchlist' rights.
 +       *     Pass User::CHECK_USER_RIGHTS or User::IGNORE_USER_RIGHTS.
 +       */
 +      public function addWatch( $title, $checkRights = self::CHECK_USER_RIGHTS ) {
 +              if ( !$checkRights || $this->isAllowed( 'editmywatchlist' ) ) {
 +                      WatchedItemStore::getDefaultInstance()->addWatchBatch( [
 +                              [ $this, $title->getSubjectPage() ],
 +                              [ $this, $title->getTalkPage() ],
 +                      ]
 +                      );
 +              }
                $this->invalidateCache();
        }
  
         * Stop watching an article.
         * @since 1.22 $checkRights parameter added
         * @param Title $title Title of the article to look at
 -       * @param int $checkRights Whether to check 'viewmywatchlist'/'editmywatchlist' rights.
 -       *     Pass WatchedItem::CHECK_USER_RIGHTS or WatchedItem::IGNORE_USER_RIGHTS.
 +       * @param bool $checkRights Whether to check 'viewmywatchlist'/'editmywatchlist' rights.
 +       *     Pass User::CHECK_USER_RIGHTS or User::IGNORE_USER_RIGHTS.
         */
 -      public function removeWatch( $title, $checkRights = WatchedItem::CHECK_USER_RIGHTS ) {
 -              $this->getWatchedItem( $title, $checkRights )->removeWatch();
 +      public function removeWatch( $title, $checkRights = self::CHECK_USER_RIGHTS ) {
 +              if ( !$checkRights || $this->isAllowed( 'editmywatchlist' ) ) {
 +                      WatchedItemStore::getDefaultInstance()->removeWatch( $this, $title->getSubjectPage() );
 +                      WatchedItemStore::getDefaultInstance()->removeWatch( $this, $title->getTalkPage() );
 +              }
                $this->invalidateCache();
        }
  
                        $force = 'force';
                }
  
 -              $this->getWatchedItem( $title )->resetNotificationTimestamp(
 -                      $force, $oldid
 -              );
 +              WatchedItemStore::getDefaultInstance()
 +                      ->resetNotificationTimestamp( $this, $title, $force, $oldid );
        }
  
        /**