Adding/updating Persian translations
[lhc/web/wiklou.git] / includes / User.php
index 5f41c8c..8e3c776 100644 (file)
@@ -527,7 +527,7 @@ class User {
         */
        public static function isValidEmailAddr( $addr ) {
                $result = null;
-               if( !wfRunHooks( 'isValidEmailAddr', array( $addr, &$result, $this ) ) ) {
+               if( !wfRunHooks( 'isValidEmailAddr', array( $addr, &$result ) ) ) {
                        return $result;
                }
 
@@ -1022,7 +1022,7 @@ class User {
                        return $result;
                }
 
-               global $wgRateLimits, $wgRateLimitsExcludedGroups;
+               global $wgRateLimits;
                if( !isset( $wgRateLimits[$action] ) ) {
                        return false;
                }
@@ -1639,8 +1639,8 @@ class User {
 
        /**
         * Get the list of implicit group memberships this user has.
-        * This includes all explicit groups, plus 'user' if logged in
-        * and '*' for all accounts.
+        * This includes all explicit groups, plus 'user' if logged in,
+        * '*' for all accounts and autopromoted groups
         * @param boolean $recache Don't use the cache
         * @return array of strings
         */
@@ -1651,23 +1651,12 @@ class User {
                        $this->mEffectiveGroups[] = '*';
                        if( $this->mId ) {
                                $this->mEffectiveGroups[] = 'user';
-                               
-                               global $wgAutoConfirmAge, $wgAutoConfirmCount;
 
-                               $accountAge = time() - wfTimestampOrNull( TS_UNIX, $this->mRegistration );
-                               if( $accountAge >= $wgAutoConfirmAge && $this->getEditCount() >= $wgAutoConfirmCount ) {
-                                       $this->mEffectiveGroups[] = 'autoconfirmed';
-                               }
-                               # Implicit group for users whose email addresses are confirmed
-                               global $wgEmailAuthentication;
-                               if( self::isValidEmailAddr( $this->mEmail ) ) {
-                                       if( $wgEmailAuthentication ) {
-                                               if( $this->mEmailAuthenticated )
-                                                       $this->mEffectiveGroups[] = 'emailconfirmed';
-                                       } else {
-                                               $this->mEffectiveGroups[] = 'emailconfirmed';
-                                       }
-                               }
+                               $this->mEffectiveGroups = array_unique( array_merge(
+                                       $this->mEffectiveGroups,
+                                       Autopromote::getAutopromoteGroups( $this )
+                               ) );
+
                                # Hook for additional groups
                                wfRunHooks( 'UserEffectiveGroups', array( &$this, &$this->mEffectiveGroups ) );
                        }
@@ -1742,10 +1731,6 @@ class User {
         * @return bool
         */
        function isLoggedIn() {
-               if( $this->mId === null and $this->mName !== null ) {
-                       // Special-case optimization
-                       return !self::isIP( $this->mName );
-               }
                return $this->getID() != 0;
        }
 
@@ -1973,10 +1958,21 @@ class User {
        }
 
        /**
-        * Logout user
-        * Clears the cookies and session, resets the instance cache
+        * Logout user.
         */
        function logout() {
+               global $wgUser;
+               if( wfRunHooks( 'UserLogout', array(&$this) ) ) {
+                       $this->doLogout();
+                       wfRunHooks( 'UserLogoutComplete', array(&$wgUser) );
+               }
+       }
+
+       /**
+        * Really logout user
+        * Clears the cookies and session, resets the instance cache
+        */
+       function doLogout() {
                global $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgCookiePrefix;
                $this->clearInstanceCache( 'defaults' );
 
@@ -2022,11 +2018,11 @@ class User {
 
 
        /**
-        * Checks if a user with the given name exists, returns the ID
+        * Checks if a user with the given name exists, returns the ID.
         */
        function idForName() {
                $s = trim( $this->getName() );
-               if ( 0 == strcmp( '', $s ) ) return 0;
+               if ( $s === '' ) return 0;
 
                $dbr = wfGetDB( DB_SLAVE );
                $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__ );
@@ -2389,10 +2385,10 @@ class User {
         *
         * @param string $subject
         * @param string $body
-        * @param strong $from Optional from address; default $wgPasswordSender will be used otherwise.
+        * @param string $from Optional from address; default $wgPasswordSender will be used otherwise.
         * @return mixed True on success, a WikiError object on failure.
         */
-       function sendMail( $subject, $body, $from = null ) {
+       function sendMail( $subject, $body, $from = null, $replyto = null ) {
                if( is_null( $from ) ) {
                        global $wgPasswordSender;
                        $from = $wgPasswordSender;
@@ -2400,13 +2396,7 @@ class User {
 
                $to = new MailAddress( $this );
                $sender = new MailAddress( $from );
-               $error = UserMailer::send( $to, $sender, $subject, $body );
-
-               if( $error == '' ) {
-                       return true;
-               } else {
-                       return new WikiError( $error );
-               }
+               return UserMailer::send( $to, $sender, $subject, $body, $replyto );
        }
 
        /**
@@ -2463,7 +2453,9 @@ class User {
         * @return bool
         */
        function canSendEmail() {
-               return $this->isEmailConfirmed();
+               $canSend = $this->isEmailConfirmed();
+               wfRunHooks( 'UserCanSendEmail', array( &$this, &$canSend ) );
+               return $canSend;
        }
 
        /**
@@ -2472,7 +2464,7 @@ class User {
         * @return bool
         */
        function canReceiveEmail() {
-               return $this->canSendEmail() && !$this->getOption( 'disablemail' );
+               return $this->isEmailConfirmed() && !$this->getOption( 'disablemail' );
        }
 
        /**
@@ -2595,11 +2587,9 @@ class User {
         * @return array
         */
        public static function getImplicitGroups() {
-               static $groups = null;
-               if( !is_array( $groups ) ) {
-                       $groups = array( '*', 'user', 'autoconfirmed', 'emailconfirmed' );
-                       wfRunHooks( 'UserGetImplicitGroups', array( &$groups ) );
-               }
+               global $wgImplicitGroups;
+               $groups = $wgImplicitGroups;
+               wfRunHooks( 'UserGetImplicitGroups', array( &$groups ) );       #deprecated, use $wgImplictGroups instead
                return $groups;
        }