Merge "Improve "selfmove" message's wording"
[lhc/web/wiklou.git] / includes / user / User.php
index 71a4272..1c894a0 100644 (file)
@@ -302,7 +302,7 @@ class User implements IDBAccessObject {
        /** @var Block */
        private $mBlockedFromCreateAccount = false;
 
-       /** @var integer User::READ_* constant bitfield used to load data */
+       /** @var int User::READ_* constant bitfield used to load data */
        protected $queryFlagsUsed = self::READ_NORMAL;
 
        public static $idCacheByName = [];
@@ -357,7 +357,7 @@ class User implements IDBAccessObject {
        /**
         * Load the user table data for this object from the source given by mFrom.
         *
-        * @param integer $flags User::READ_* constant bitfield
+        * @param int $flags User::READ_* constant bitfield
         */
        public function load( $flags = self::READ_NORMAL ) {
                global $wgFullyInitialised;
@@ -419,7 +419,7 @@ class User implements IDBAccessObject {
 
        /**
         * Load user table data, given mId has already been set.
-        * @param integer $flags User::READ_* constant bitfield
+        * @param int $flags User::READ_* constant bitfield
         * @return bool False if the ID does not exist, true otherwise
         */
        public function loadFromId( $flags = self::READ_NORMAL ) {
@@ -450,7 +450,7 @@ class User implements IDBAccessObject {
        /**
         * @since 1.27
         * @param string $wikiId
-        * @param integer $userId
+        * @param int $userId
         */
        public static function purge( $wikiId, $userId ) {
                $cache = ObjectCache::getMainWANInstance();
@@ -759,7 +759,7 @@ class User implements IDBAccessObject {
        /**
         * Get database id given a user name
         * @param string $name Username
-        * @param integer $flags User::READ_* constant bitfield
+        * @param int $flags User::READ_* constant bitfield
         * @return int|null The corresponding user's ID, or null if user is nonexistent
         */
        public static function idFromName( $name, $flags = self::READ_NORMAL ) {
@@ -827,6 +827,16 @@ class User implements IDBAccessObject {
                        || IP::isIPv6( $name );
        }
 
+       /**
+        * Is the user an IP range?
+        *
+        * @since 1.30
+        * @return bool
+        */
+       public function isIPRange() {
+               return IP::isValidRange( $this->mName );
+       }
+
        /**
         * Is the input a valid username?
         *
@@ -1252,7 +1262,7 @@ class User implements IDBAccessObject {
         * Load user and user_group data from the database.
         * $this->mId must be set, this is how the user is identified.
         *
-        * @param integer $flags User::READ_* constant bitfield
+        * @param int $flags User::READ_* constant bitfield
         * @return bool True if the user exists, false if the user is anonymous
         */
        public function loadFromDatabase( $flags = self::READ_LATEST ) {
@@ -1452,15 +1462,17 @@ class User implements IDBAccessObject {
                }
 
                $oldGroups = $this->getGroups(); // previous groups
+               $oldUGMs = $this->getGroupMemberships();
                foreach ( $toPromote as $group ) {
                        $this->addGroup( $group );
                }
+               $newGroups = array_merge( $oldGroups, $toPromote ); // all groups
+               $newUGMs = $this->getGroupMemberships();
+
                // update groups in external authentication database
-               Hooks::run( 'UserGroupsChanged', [ $this, $toPromote, [], false, false ] );
+               Hooks::run( 'UserGroupsChanged', [ $this, $toPromote, [], false, false, $oldUGMs, $newUGMs ] );
                AuthManager::callLegacyAuthPlugin( 'updateExternalDBGroups', [ $this, $toPromote ] );
 
-               $newGroups = array_merge( $oldGroups, $toPromote ); // all groups
-
                $logEntry = new ManualLogEntry( 'rights', 'autopromote' );
                $logEntry->setPerformer( $this );
                $logEntry->setTarget( $this->getUserPage() );
@@ -4109,12 +4121,10 @@ class User implements IDBAccessObject {
                        unset( $params['options'] );
                }
                $dbw = wfGetDB( DB_MASTER );
-               $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
 
                $noPass = PasswordFactory::newInvalidPassword()->toString();
 
                $fields = [
-                       'user_id' => $seqVal,
                        'user_name' => $name,
                        'user_password' => $noPass,
                        'user_newpassword' => $noPass,
@@ -4179,10 +4189,8 @@ class User implements IDBAccessObject {
                $noPass = PasswordFactory::newInvalidPassword()->toString();
 
                $dbw = wfGetDB( DB_MASTER );
-               $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
                $dbw->insert( 'user',
                        [
-                               'user_id' => $seqVal,
                                'user_name' => $this->mName,
                                'user_password' => $noPass,
                                'user_newpassword' => $noPass,
@@ -5311,6 +5319,13 @@ class User implements IDBAccessObject {
                                        $data[$row->up_property] = $row->up_value;
                                }
                        }
+
+                       // Convert the email blacklist from a new line delimited string
+                       // to an array of ids.
+                       if ( isset( $data['email-blacklist'] ) && $data['email-blacklist'] ) {
+                               $data['email-blacklist'] = array_map( 'intval', explode( "\n", $data['email-blacklist'] ) );
+                       }
+
                        foreach ( $data as $property => $value ) {
                                $this->mOptionOverrides[$property] = $value;
                                $this->mOptions[$property] = $value;
@@ -5333,6 +5348,26 @@ class User implements IDBAccessObject {
                // Not using getOptions(), to keep hidden preferences in database
                $saveOptions = $this->mOptions;
 
+               // Convert usernames to ids.
+               if ( isset( $this->mOptions['email-blacklist'] ) ) {
+                       if ( $this->mOptions['email-blacklist'] ) {
+                               $value = $this->mOptions['email-blacklist'];
+                               // Email Blacklist may be an array of ids or a string of new line
+                               // delimnated user names.
+                               if ( is_array( $value ) ) {
+                                       $ids = array_filter( $value, 'is_numeric' );
+                               } else {
+                                       $lookup = CentralIdLookup::factory();
+                                       $ids = $lookup->centralIdsFromNames( explode( "\n", $value ), $this );
+                               }
+                               $this->mOptions['email-blacklist'] = $ids;
+                               $saveOptions['email-blacklist'] = implode( "\n", $this->mOptions['email-blacklist'] );
+                       } else {
+                               // If the blacklist is empty, set it to null rather than an empty string.
+                               $this->mOptions['email-blacklist'] = null;
+                       }
+               }
+
                // Allow hooks to abort, for instance to save to a global profile.
                // Reset options to default state before saving.
                if ( !Hooks::run( 'UserSaveOptions', [ $this, &$saveOptions ] ) ) {