From 89df167b208ccffed90018934388240b5f2ab63f Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Tue, 17 Apr 2012 09:48:58 +0200 Subject: [PATCH] Use the same object when checking if the user is blocked instead of creating a new one. * 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 | 4 ++-- includes/User.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index dff1a5d336..337be1b728 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -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) diff --git a/includes/User.php b/includes/User.php index af923ffeeb..60b262d968 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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' ) -- 2.20.1