Fix log type and name in revdeleted messages: suppressions are stored in the suppress...
[lhc/web/wiklou.git] / includes / User.php
index 02111b7..5849ec0 100644 (file)
@@ -43,7 +43,7 @@ class PasswordError extends MWException {
 class User {
 
        /**
-        * \type{\arrayof{\string}} A list of default user toggles, i.e., boolean user 
+        * \type{\arrayof{\string}} A list of default user toggles, i.e., boolean user
          * preferences that are displayed by Special:Preferences as checkboxes.
         * This list can be extended via the UserToggles hook or by
         * $wgContLang::getExtraUserToggles().
@@ -95,8 +95,8 @@ class User {
        );
 
        /**
-        * \type{\arrayof{\string}} List of member variables which are saved to the 
-        * shared cache (memcached). Any operation which changes the 
+        * \type{\arrayof{\string}} List of member variables which are saved to the
+        * shared cache (memcached). Any operation which changes the
         * corresponding database fields must call a cache-clearing function.
         * @showinitializer
         */
@@ -124,7 +124,7 @@ class User {
 
        /**
         * \type{\arrayof{\string}} Core rights.
-        * Each of these should have a corresponding message of the form 
+        * Each of these should have a corresponding message of the form
         * "right-$right".
         * @showinitializer
         */
@@ -211,14 +211,14 @@ class User {
        /** @name Lazy-initialized variables, invalidated with clearInstanceCache */
        //@{
        var $mNewtalk, $mDatePreference, $mBlockedby, $mHash, $mSkin, $mRights,
-               $mBlockreason, $mBlock, $mEffectiveGroups, $mBlockedGlobally, 
+               $mBlockreason, $mBlock, $mEffectiveGroups, $mBlockedGlobally,
                $mLocked, $mHideName, $mOptions;
        //@}
 
        /**
         * Lightweight constructor for an anonymous user.
         * Use the User::newFrom* factory functions for other kinds of users.
-        * 
+        *
         * @see newFromName()
         * @see newFromId()
         * @see newFromConfirmationCode()
@@ -282,7 +282,7 @@ class User {
                # Try cache
                $key = wfMemcKey( 'user', 'id', $this->mId );
                $data = $wgMemc->get( $key );
-               if ( !is_array( $data ) || $data['mVersion'] < 'MW_USER_VERSION' ) {
+               if ( !is_array( $data ) || $data['mVersion'] < MW_USER_VERSION ) {
                        # Object is expired, load from DB
                        $data = false;
                }
@@ -325,8 +325,8 @@ class User {
                global $wgMemc;
                $wgMemc->set( $key, $data );
        }
-       
-       
+
+
        /** @name newFrom*() static factory methods */
        //@{
 
@@ -341,8 +341,8 @@ class User {
         *    User::getCanonicalName(), except that true is accepted as an alias
         *    for 'valid', for BC.
         *
-        * @return \type{User} The User object, or null if the username is invalid. If the 
-        *    username is not present in the database, the result will be a user object 
+        * @return \type{User} The User object, or null if the username is invalid. If the
+        *    username is not present in the database, the result will be a user object
         *    with a name, zero user ID and default settings.
         */
        static function newFromName( $name, $validate = 'valid' ) {
@@ -420,9 +420,9 @@ class User {
                $user->loadFromRow( $row );
                return $user;
        }
-       
+
        //@}
-       
+
 
        /**
         * Get the username corresponding to a given user ID
@@ -661,7 +661,7 @@ class User {
                        return false;
 
                # Clean up name according to title rules
-               $t = ($validate === 'valid') ? 
+               $t = ($validate === 'valid') ?
                        Title::newFromText( $name ) : Title::makeTitle( NS_USER, $name );
                # Check for invalid titles
                if( is_null( $t ) ) {
@@ -755,9 +755,9 @@ class User {
        }
 
        /**
-        * Set cached properties to default. 
+        * Set cached properties to default.
         *
-        * @note This no longer clears uncached lazy-initialised properties; 
+        * @note This no longer clears uncached lazy-initialised properties;
         *       the constructor does that instead.
         * @private
         */
@@ -819,7 +819,7 @@ class User {
                        $sId = intval( $_COOKIE["{$wgCookiePrefix}UserID"] );
                        if( isset( $_SESSION['wsUserID'] ) && $sId != $_SESSION['wsUserID'] ) {
                                $this->loadDefaults(); // Possible collision!
-                               wfDebugLog( 'loginSessions', "Session user ID ({$_SESSION['wsUserID']}) and 
+                               wfDebugLog( 'loginSessions', "Session user ID ({$_SESSION['wsUserID']}) and
                                        cookie user ID ($sId) don't match!" );
                                return false;
                        }
@@ -937,7 +937,7 @@ class User {
                $this->mEmailToken = $row->user_email_token;
                $this->mEmailTokenExpires = wfTimestampOrNull( TS_MW, $row->user_email_token_expires );
                $this->mRegistration = wfTimestampOrNull( TS_MW, $row->user_registration );
-               $this->mEditCount = $row->user_editcount; 
+               $this->mEditCount = $row->user_editcount;
        }
 
        /**
@@ -972,7 +972,7 @@ class User {
                $this->mSkin = null;
                $this->mRights = null;
                $this->mEffectiveGroups = null;
-               $this->mOptions = array();
+               $this->mOptions = null;
 
                if ( $reloadFrom ) {
                        $this->mDataLoaded = false;
@@ -1065,7 +1065,7 @@ class User {
                // due to -1 !== 0. Probably session-related... Nothing should be
                // overwriting mBlockedby, surely?
                $this->load();
-               
+
                $this->mBlockedby = 0;
                $this->mHideName = 0;
                $this->mAllowUsertalk = 0;
@@ -1089,8 +1089,8 @@ class User {
                                $this->spreadBlock();
                        }
                } else {
-                       // Bug 13611: don't remove mBlock here, to allow account creation blocks to 
-                       // apply to users. Note that the existence of $this->mBlock is not used to 
+                       // Bug 13611: don't remove mBlock here, to allow account creation blocks to
+                       // apply to users. Note that the existence of $this->mBlock is not used to
                        // check for edit blocks, $this->mBlockedby is instead.
                }
 
@@ -1169,17 +1169,10 @@ class User {
         */
        public function isPingLimitable() {
                global $wgRateLimitsExcludedGroups;
-               global $wgRateLimitsExcludedIPs;
                if( array_intersect( $this->getEffectiveGroups(), $wgRateLimitsExcludedGroups ) ) {
                        // Deprecated, but kept for backwards-compatibility config
                        return false;
                }
-               if( in_array( wfGetIP(), $wgRateLimitsExcludedIPs ) ) {
-                       // No other good way currently to disable rate limits
-                       // for specific IPs. :P
-                       // But this is a crappy hack and should die.
-                       return false;
-               }
                return !$this->isAllowed('noratelimit');
        }
 
@@ -1282,7 +1275,7 @@ class User {
 
        /**
         * Check if user is blocked
-        * 
+        *
         * @param $bFromSlave \bool Whether to check the slave database instead of the master
         * @return \bool True if blocked, false otherwise
         */
@@ -1294,7 +1287,7 @@ class User {
 
        /**
         * Check if user is blocked from editing a particular article
-        * 
+        *
         * @param $title      \string Title to check
         * @param $bFromSlave \bool   Whether to check the slave database instead of the master
         * @return \bool True if blocked, false otherwise
@@ -1334,7 +1327,7 @@ class User {
                $this->getBlockedStatus();
                return $this->mBlockreason;
        }
-       
+
        /**
         * If user is blocked, return the ID for the block
         * @return \int Block ID
@@ -1343,12 +1336,12 @@ class User {
                $this->getBlockedStatus();
                return ($this->mBlock ? $this->mBlock->mId : false);
        }
-       
+
        /**
         * Check if user is blocked on all wikis.
         * Do not use for actual edit permission checks!
         * This is intented for quick UI checks.
-        * 
+        *
         * @param $ip \type{\string} IP address, uses current client if none given
         * @return \type{\bool} True if blocked, false otherwise
         */
@@ -1367,10 +1360,10 @@ class User {
                $this->mBlockedGlobally = (bool)$blocked;
                return $this->mBlockedGlobally;
        }
-       
+
        /**
         * Check if user account is locked
-        * 
+        *
         * @return \type{\bool} True if locked, false otherwise
         */
        function isLocked() {
@@ -1382,10 +1375,10 @@ class User {
                $this->mLocked = (bool)$authUser->isLocked();
                return $this->mLocked;
        }
-       
+
        /**
         * Check if user account is hidden
-        * 
+        *
         * @return \type{\bool} True if hidden, false otherwise
         */
        function isHidden() {
@@ -1740,7 +1733,7 @@ class User {
                $this->mNewpassword = '';
                $this->mNewpassTime = null;
        }
-       
+
        /**
         * Get the user's current token.
         * @return \string Token
@@ -1749,7 +1742,7 @@ class User {
                $this->load();
                return $this->mToken;
        }
-       
+
        /**
         * Set the random token (used for persistent authentication)
         * Called from loadDefaults() among other places.
@@ -1773,7 +1766,7 @@ class User {
                        $this->mToken = $token;
                }
        }
-       
+
        /**
         * Set the cookie password
         *
@@ -1800,7 +1793,7 @@ class User {
        }
 
        /**
-        * Has password reminder email been sent within the last 
+        * Has password reminder email been sent within the last
         * $wgPasswordReminderResendTime hours?
         * @return \bool True or false
         */
@@ -1887,7 +1880,7 @@ class User {
                        return $defaultOverride;
                }
        }
-       
+
        /**
         * Get the user's current setting for a given option, as a boolean value.
         *
@@ -1899,7 +1892,7 @@ class User {
                return (bool)$this->getOption( $oname );
        }
 
-       
+
        /**
         * Get the user's current setting for a given option, as a boolean value.
         *
@@ -1939,10 +1932,10 @@ class User {
                
                $this->mOptions[$oname] = $val;
        }
-       
+
        /**
         * Reset all options to the site defaults
-        */     
+        */
        function resetOptions() {
                $this->mOptions = User::getDefaultOptions();
        }
@@ -2119,7 +2112,7 @@ class User {
                        if( !$wgUseRCPatrol && !$wgUseNPPatrol )
                                return false;
                }
-               # Use strict parameter to avoid matching numeric 0 accidentally inserted 
+               # Use strict parameter to avoid matching numeric 0 accidentally inserted
                # by misconfiguration: 0 == 'foo'
                return in_array( $action, $this->getRights(), true );
        }
@@ -2149,19 +2142,21 @@ class User {
         * @todo FIXME : need to check the old failback system [AV]
         */
        function &getSkin( $t = null ) {
-               global $wgRequest, $wgAllowUserSkin, $wgDefaultSkin;
                if ( ! isset( $this->mSkin ) ) {
                        wfProfileIn( __METHOD__ );
 
-                       if( $wgAllowUserSkin ) {
+                       global $wgHiddenPrefs;
+                       if( !in_array( 'skin', $wgHiddenPrefs ) ) {
                                # get the user skin
+                               global $wgRequest;
                                $userSkin = $this->getOption( 'skin' );
                                $userSkin = $wgRequest->getVal('useskin', $userSkin);
                        } else {
                                # if we're not allowing users to override, then use the default
+                               global $wgDefaultSkin;
                                $userSkin = $wgDefaultSkin;
                        }
-                       
+
                        $this->mSkin =& Skin::newFromKey( $userSkin );
                        wfProfileOut( __METHOD__ );
                }
@@ -2314,20 +2309,20 @@ class User {
                        }
                }
        }
-       
+
        /**
-        * Set a cookie on the user's client. Wrapper for 
+        * Set a cookie on the user's client. Wrapper for
         * WebResponse::setCookie
         * @param $name \string Name of the cookie to set
         * @param $value \string Value to set
-        * @param $exp \int Expiration time, as a UNIX time value; 
+        * @param $exp \int Expiration time, as a UNIX time value;
         *                   if 0 or not specified, use the default $wgCookieExpiration
         */
        protected function setCookie( $name, $value, $exp=0 ) {
                global $wgRequest;
                $wgRequest->response()->setcookie( $name, $value, $exp );
        }
-       
+
        /**
         * Clear a cookie on the user's client
         * @param $name \string Name of the cookie to clear
@@ -2342,7 +2337,7 @@ class User {
        function setCookies() {
                $this->load();
                if ( 0 == $this->mId ) return;
-               $session = array( 
+               $session = array(
                        'wsUserID' => $this->mId,
                        'wsToken' => $this->mToken,
                        'wsUserName' => $this->getName()
@@ -2356,9 +2351,9 @@ class User {
                } else {
                        $cookies['Token'] = false;
                }
-               
+
                wfRunHooks( 'UserSetCookies', array( $this, &$session, &$cookies ) );
-               #check for null, since the hook could cause a null value 
+               #check for null, since the hook could cause a null value
                if ( !is_null( $session ) && isset( $_SESSION ) ){
                        $_SESSION = $session + $_SESSION;
                }
@@ -2375,7 +2370,6 @@ class User {
         * Log this user out.
         */
        function logout() {
-               global $wgUser;
                if( wfRunHooks( 'UserLogout', array(&$this) ) ) {
                        $this->doLogout();
                }
@@ -2485,7 +2479,7 @@ class User {
                        'user_email' => $user->mEmail,
                        'user_email_authenticated' => $dbw->timestampOrNull( $user->mEmailAuthenticated ),
                        'user_real_name' => $user->mRealName,
-                       'user_options' => $user->encodeOptions(),
+                       'user_options' => '',
                        'user_token' => $user->mToken,
                        'user_registration' => $dbw->timestamp( $user->mRegistration ),
                        'user_editcount' => 0,
@@ -2675,27 +2669,27 @@ class User {
        function isNewbie() {
                return !$this->isAllowed( 'autoconfirmed' );
        }
-       
+
        /**
         * Is the user active? We check to see if they've made at least
         * X number of edits in the last Y days.
-        * 
+        *
         * @return \bool True if the user is active, false if not.
         */
        public function isActiveEditor() {
                global $wgActiveUserEditCount, $wgActiveUserDays;
                $dbr = wfGetDB( DB_SLAVE );
-               
+
                // Stolen without shame from RC
                $cutoff_unixtime = time() - ( $wgActiveUserDays * 86400 );
                $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime % 86400 );
                $oldTime = $dbr->addQuotes( $dbr->timestamp( $cutoff_unixtime ) );
-               
+
                $res = $dbr->select( 'revision', '1',
                                array( 'rev_user_text' => $this->getName(), "rev_timestamp > $oldTime"),
                                __METHOD__,
                                array('LIMIT' => $wgActiveUserEditCount ) );
-               
+
                $count = $dbr->numRows($res);
                $dbr->freeResult($res);
 
@@ -2839,14 +2833,16 @@ class User {
                $url = $this->confirmationTokenUrl( $token );
                $invalidateURL = $this->invalidationTokenUrl( $token );
                $this->saveSettings();
-               
+
                return $this->sendMail( wfMsg( 'confirmemail_subject' ),
                        wfMsg( 'confirmemail_body',
                                wfGetIP(),
                                $this->getName(),
                                $url,
                                $wgLang->timeanddate( $expiration, false ),
-                               $invalidateURL ) );
+                               $invalidateURL,
+                               $wgLang->date( $expiration, false ),
+                               $wgLang->time( $expiration, false ) ) );
        }
 
        /**
@@ -2911,7 +2907,7 @@ class User {
        function invalidationTokenUrl( $token ) {
                return $this->getTokenUrl( 'Invalidateemail', $token );
        }
-       
+
        /**
         * Internal function to format the e-mail validation/invalidation URLs.
         * This uses $wgArticlePath directly as a quickie hack to use the
@@ -3043,7 +3039,7 @@ class User {
                        ? $this->mRegistration
                        : false;
        }
-       
+
        /**
         * Get the timestamp of the first edit
         *
@@ -3060,7 +3056,7 @@ class User {
                );
                if( !$time ) return false; // no edits
                return wfTimestamp( TS_MW, $time );
-       }       
+       }
 
        /**
         * Get the permissions associated with a given list of groups
@@ -3069,8 +3065,9 @@ class User {
         * @return \type{\arrayof{\string}} List of permission key names for given groups combined
         */
        static function getGroupPermissions( $groups ) {
-               global $wgGroupPermissions;
+               global $wgGroupPermissions, $wgRevokePermissions;
                $rights = array();
+               // grant every granted permission first
                foreach( $groups as $group ) {
                        if( isset( $wgGroupPermissions[$group] ) ) {
                                $rights = array_merge( $rights,
@@ -3078,12 +3075,19 @@ class User {
                                        array_keys( array_filter( $wgGroupPermissions[$group] ) ) );
                        }
                }
+               // now revoke the revoked permissions
+               foreach( $groups as $group ) {
+                       if( isset( $wgRevokePermissions[$group] ) ) {
+                               $rights = array_diff( $rights,
+                                       array_keys( array_filter( $wgRevokePermissions[$group] ) ) );
+                       }
+               }
                return array_unique($rights);
        }
-       
+
        /**
         * Get all the groups who have a given permission
-        * 
+        *
         * @param $role \string Role to check
         * @return \type{\arrayof{\string}} List of internal group names with the given permission
         */
@@ -3137,9 +3141,9 @@ class User {
         * @return \type{\arrayof{\string}} Array of internal group names
         */
        static function getAllGroups() {
-               global $wgGroupPermissions;
+               global $wgGroupPermissions, $wgRevokePermissions;
                return array_diff(
-                       array_keys( $wgGroupPermissions ),
+                       array_merge( array_keys( $wgGroupPermissions ), array_keys( $wgRevokePermissions ) ),
                        self::getImplicitGroups()
                );
        }
@@ -3191,7 +3195,7 @@ class User {
        }
 
        /**
-        * Create a link to the group in HTML, if available; 
+        * Create a link to the group in HTML, if available;
         * else return the group name.
         *
         * @param $group \string Internal name of the group
@@ -3206,14 +3210,14 @@ class User {
                if( $title ) {
                        global $wgUser;
                        $sk = $wgUser->getSkin();
-                       return $sk->makeLinkObj( $title, htmlspecialchars( $text ) );
+                       return $sk->link( $title, htmlspecialchars( $text ) );
                } else {
                        return $text;
                }
        }
 
        /**
-        * Create a link to the group in Wikitext, if available; 
+        * Create a link to the group in Wikitext, if available;
         * else return the group name.
         *
         * @param $group \string Internal name of the group
@@ -3232,7 +3236,7 @@ class User {
                        return $text;
                }
        }
-       
+
        /**
         * Returns an array of the groups that a particular group can add/remove.
         *
@@ -3262,7 +3266,7 @@ class User {
                } elseif( is_array($wgRemoveGroups[$group]) ) {
                        $groups['remove'] = $wgRemoveGroups[$group];
                }
-               
+
                // Re-map numeric keys of AddToSelf/RemoveFromSelf to the 'user' key for backwards compatibility
                if( empty($wgGroupsAddToSelf['user']) || $wgGroupsAddToSelf['user'] !== true ) {
                        foreach($wgGroupsAddToSelf as $key => $value) {
@@ -3271,7 +3275,7 @@ class User {
                                }
                        }
                }
-               
+
                if( empty($wgGroupsRemoveFromSelf['user']) || $wgGroupsRemoveFromSelf['user'] !== true ) {
                        foreach($wgGroupsRemoveFromSelf as $key => $value) {
                                if( is_int($key) ) {
@@ -3279,7 +3283,7 @@ class User {
                                }
                        }
                }
-               
+
                // Now figure out what groups the user can add to him/herself
                if( empty($wgGroupsAddToSelf[$group]) ) {
                } elseif( $wgGroupsAddToSelf[$group] === true ) {
@@ -3288,17 +3292,17 @@ class User {
                } elseif( is_array($wgGroupsAddToSelf[$group]) ) {
                        $groups['add-self'] = $wgGroupsAddToSelf[$group];
                }
-               
+
                if( empty($wgGroupsRemoveFromSelf[$group]) ) {
                } elseif( $wgGroupsRemoveFromSelf[$group] === true ) {
                        $groups['remove-self'] = User::getAllGroups();
                } elseif( is_array($wgGroupsRemoveFromSelf[$group]) ) {
                        $groups['remove-self'] = $wgGroupsRemoveFromSelf[$group];
                }
-               
+
                return $groups;
        }
-       
+
        /**
         * Returns an array of groups that this user can add and remove
         * @return Array array( 'add' => array( addablegroups ),
@@ -3384,7 +3388,7 @@ class User {
                // edit count in user cache too
                $this->invalidateCache();
        }
-       
+
        /**
         * Get the description of a given right
         *
@@ -3421,7 +3425,7 @@ class User {
         * Make a new-style password hash
         *
         * @param $password \string Plain-text password
-        * @param $salt \string Optional salt, may be random or the user ID. 
+        * @param $salt \string Optional salt, may be random or the user ID.
         *                     If unspecified or false, will generate one automatically
         * @return \string Password hash
         */
@@ -3432,7 +3436,7 @@ class User {
                if( !wfRunHooks( 'UserCryptPassword', array( &$password, &$salt, &$wgPasswordSalt, &$hash ) ) ) {
                        return $hash;
                }
-               
+
                if( $wgPasswordSalt ) {
                        if ( $salt === false ) {
                                $salt = substr( wfGenerateToken(), 0, 8 );
@@ -3455,12 +3459,12 @@ class User {
        static function comparePasswords( $hash, $password, $userId = false ) {
                $m = false;
                $type = substr( $hash, 0, 3 );
-               
+
                $result = false;
                if( !wfRunHooks( 'UserComparePasswords', array( &$hash, &$password, &$userId, &$result ) ) ) {
                        return $result;
                }
-               
+
                if ( $type == ':A:' ) {
                        # Unsalted
                        return md5( $password ) === substr( $hash, 3 );
@@ -3473,7 +3477,7 @@ class User {
                        return self::oldCrypt( $password, $userId ) === $hash;
                }
        }
-       
+
        /**
         * Add a newuser log entry for this user
         * @param $byEmail Boolean: account made by email?