From cd307da476d3a8b37de33f20398db32cd38789f5 Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Sun, 13 Mar 2011 14:41:57 +0000 Subject: [PATCH] Fix totally-broken r83810. --- includes/specials/SpecialBlock.php | 31 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 19972a1083..08d8fe05e5 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -203,7 +203,7 @@ class SpecialBlock extends SpecialPage { * already blocked) */ protected function maybeAlterFormDefaults( &$fields ){ - $fields['Target']['default'] = $this->target; + $fields['Target']['default'] = (string)$this->target; $block = self::getBlockFromTargetAndType( $this->target, $this->type ); @@ -454,10 +454,10 @@ class SpecialBlock extends SpecialPage { * @since 1.18 * @return Message */ - public static function validateTargetField( $data, $alldata = null ) { + public static function validateTargetField( $value, $alldata = null ) { global $wgBlockCIDRLimit; - list( $target, $type ) = self::getTargetAndType( $data ); + list( $target, $type ) = self::getTargetAndType( $value ); if( $type == Block::TYPE_USER ){ # TODO: why do we not have a User->exists() method? @@ -470,10 +470,6 @@ class SpecialBlock extends SpecialPage { return wfMessage( 'badaccess', $status ); } - $user = $target; - $target = $user->getName(); - $userId = $user->getId(); - } elseif( $type == Block::TYPE_RANGE ){ list( $ip, $range ) = explode( '/', $target, 2 ); @@ -499,16 +495,14 @@ class SpecialBlock extends SpecialPage { return wfMessage( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] ); } - $userId = 0; - } elseif( $type == Block::TYPE_IP ){ # All is well - $target = $target->getName(); - $userId = 0; } else { return wfMessage( 'badipaddress' ); } + + return true; } /** @@ -522,6 +516,21 @@ class SpecialBlock extends SpecialPage { // Handled by field validator callback // self::validateTargetField( $data['Target'] ); + list( $target, $type ) = self::getTargetAndType( $data['Target'] ); + if( $type == Block::TYPE_USER ){ + $user = $target; + $target = $user->getName(); + $userId = $user->getId(); + } elseif( $type == Block::TYPE_RANGE ){ + $userId = 0; + } elseif( $type == Block::TYPE_IP ){ + $target = $target->getName(); + $userId = 0; + } else { + # This should have been caught in the form field validation + return wfMessage( 'badipaddress' ); + } + if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 ) || !Block::parseExpiryInput( $data['Expiry'] ) ) { -- 2.20.1