Follow-up r84814: revert redundant summary message addition.
[lhc/web/wiklou.git] / includes / User.php
index a0fce2c..996a02c 100644 (file)
@@ -1129,42 +1129,26 @@ class User {
                $this->mHideName = 0;
                $this->mAllowUsertalk = 0;
 
-               # Check if we are looking at an IP or a logged-in user
-               if ( $this->isAllowed( 'ipblock-exempt' ) ) {
-                       # Exempt from all types of IP-block
-                       $ip = '';
-               } elseif ( $this->isIP( $this->getName() ) ) {
-                       $ip = $this->getName();
+               # We only need to worry about passing the IP address to the Block generator if the
+               # user is not immune to autoblocks/hardblocks, and they are the current user so we
+               # know which IP address they're actually coming from
+               if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->getID() == $wgUser->getID() ) {
+                       $ip = wfGetIP();
                } else {
-                       # Check if we are looking at the current user
-                       # If we don't, and the user is logged in, we don't know about
-                       # his IP / autoblock status, so ignore autoblock of current user's IP
-                       if ( $this->getID() != $wgUser->getID() ) {
-                               $ip = '';
-                       } else {
-                               # Get IP of current user
-                               $ip = wfGetIP();
-                       }
+                       $ip = null;
                }
 
                # User/IP blocking
-               $this->mBlock = new Block();
-               $this->mBlock->fromMaster( !$bFromSlave );
-               if ( $this->mBlock->load( $ip , $this->mId ) ) {
+               $this->mBlock = Block::newFromTarget( $this->getName(), $ip, !$bFromSlave );
+               if ( $this->mBlock instanceof Block ) {
                        wfDebug( __METHOD__ . ": Found block.\n" );
-                       $this->mBlockedby = $this->mBlock->mBy;
-                       if( $this->mBlockedby == 0 )
-                               $this->mBlockedby = $this->mBlock->mByName;
+                       $this->mBlockedby = $this->mBlock->getBlocker()->getName();
                        $this->mBlockreason = $this->mBlock->mReason;
                        $this->mHideName = $this->mBlock->mHideName;
-                       $this->mAllowUsertalk = $this->mBlock->mAllowUsertalk;
+                       $this->mAllowUsertalk = !$this->mBlock->prevents( 'editownusertalk' );
                        if ( $this->isLoggedIn() && $wgUser->getID() == $this->getID() ) {
                                $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
-                       // check for edit blocks, $this->mBlockedby is instead.
                }
 
                # Proxy blocking
@@ -1374,7 +1358,7 @@ class User {
         */
        function isBlocked( $bFromSlave = true ) { // hacked from false due to horrible probs on site
                $this->getBlockedStatus( $bFromSlave );
-               return $this->mBlockedby !== 0;
+               return $this->mBlock instanceof Block && $this->mBlock->prevents( 'edit' );
        }
 
        /**
@@ -1427,7 +1411,7 @@ class User {
         */
        function getBlockId() {
                $this->getBlockedStatus();
-               return ( $this->mBlock ? $this->mBlock->mId : false );
+               return ( $this->mBlock ? $this->mBlock->getId() : false );
        }
 
        /**
@@ -1492,8 +1476,8 @@ class User {
         * @return Int The user's ID; 0 if the user is anonymous or nonexistent
         */
        function getId() {
-               if( $this->mId === null and $this->mName !== null
-               and User::isIP( $this->mName ) ) {
+               if( $this->mId === null && $this->mName !== null
+               && User::isIP( $this->mName ) ) {
                        // Special case, we know the user is anonymous
                        return 0;
                } elseif( $this->mId === null ) {
@@ -2251,7 +2235,7 @@ class User {
        public function isAllowedAny( /*...*/ ){
                $permissions = func_get_args();
                foreach( $permissions as $permission ){
-                       if( $this->isAllowedInternal( $permission ) ){
+                       if( $this->isAllowed( $permission ) ){
                                return true;
                        }
                }
@@ -2265,7 +2249,7 @@ class User {
        public function isAllowedAll( /*...*/ ){
                $permissions = func_get_args();
                foreach( $permissions as $permission ){
-                       if( !$this->isAllowedInternal( $permission ) ){
+                       if( !$this->isAllowed( $permission ) ){
                                return false;
                        }
                }
@@ -2735,7 +2719,7 @@ class User {
                        return;
                }
 
-               $userblock = Block::newFromDB( '', $this->mId );
+               $userblock = Block::newFromTarget( $this->getName() );
                if ( !$userblock ) {
                        return;
                }
@@ -2797,11 +2781,24 @@ class User {
 
        /**
         * Get whether the user is explicitly blocked from account creation.
-        * @return Bool
+        * @return Bool|Block
         */
        function isBlockedFromCreateAccount() {
                $this->getBlockedStatus();
-               return $this->mBlock && $this->mBlock->mCreateAccount;
+               if( $this->mBlock && $this->mBlock->prevents( 'createaccount' ) ){
+                       return $this->mBlock;
+               }
+
+               # bug 13611: if the IP address the user is trying to create an account from is
+               # blocked with createaccount disabled, prevent new account creation there even
+               # when the user is logged in
+               static $accBlock = false;
+               if( $accBlock === false ){
+                       $accBlock = Block::newFromTarget( null, wfGetIP() );
+               }
+               return $accBlock instanceof Block && $accBlock->prevents( 'createaccount' )
+                       ? $accBlock
+                       : false;
        }
 
        /**
@@ -2810,7 +2807,7 @@ class User {
         */
        function isBlockedFromEmailuser() {
                $this->getBlockedStatus();
-               return $this->mBlock && $this->mBlock->mBlockEmail;
+               return $this->mBlock && $this->mBlock->prevents( 'sendemail' );
        }
 
        /**