Use the same object when checking if the user is blocked instead of creating a new...
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Tue, 17 Apr 2012 07:48:58 +0000 (09:48 +0200)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Tue, 17 Apr 2012 07:48:58 +0000 (09:48 +0200)
* Block::parseTarget() first called trim() on its parameter which was converting objects into string, thus making the checks for object and null useless; now trim() is called after these checks.
* User::getBlockedStatus() was passing $this->getName() to Block::newFromTargert() which in turn was passed to Block::parseTarget() where a new User object was created.
  Instead of this, the User object is directly passed to Block::newFromTargert(), which avoids creating a new object for the same user.

Change-Id: Iffea21d4f53e8692072749264f7486c22b6be5fd

includes/Block.php
includes/User.php

index dff1a5d..337be1b 100644 (file)
@@ -1075,8 +1075,6 @@ class Block {
         * @return array( User|String, Block::TYPE_ constant )
         */
        public static function parseTarget( $target ) {
-               $target = trim( $target );
-
                # We may have been through this before
                if( $target instanceof User ){
                        if( IP::isValid( $target->getName() ) ){
@@ -1088,6 +1086,8 @@ class Block {
                        return array( null, null );
                }
 
+               $target = trim( $target );
+
                if ( IP::isValid( $target ) ) {
                        # We can still create a User if it's an IP address, but we need to turn
                        # off validation checking (which would exclude IP addresses)
index af923ff..60b262d 100644 (file)
@@ -1283,7 +1283,7 @@ class User {
                }
 
                # User/IP blocking
-               $block = Block::newFromTarget( $this->getName(), $ip, !$bFromSlave );
+               $block = Block::newFromTarget( $this, $ip, !$bFromSlave );
 
                # Proxy blocking
                if ( !$block instanceof Block && $ip !== null && !$this->isAllowed( 'proxyunbannable' )