From: Florian Date: Fri, 24 Jul 2015 16:59:53 +0000 (+0200) Subject: HTMLForm: Allow IP adresses as username in HTMLUserTextField X-Git-Tag: 1.31.0-rc.0~10649^2 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=5c50bb4caf947fd5aa934c1b83816bc460bd7cc5;p=lhc%2Fweb%2Fwiklou.git HTMLForm: Allow IP adresses as username in HTMLUserTextField Can be configured with the 'ipallowed' config parameter, which defaults to false (IP's not allowed). Bug: T106807 Change-Id: Ib2885883bdb3383c60382bf3257afdfc3cc26821 --- diff --git a/includes/htmlform/HTMLUserTextField.php b/includes/htmlform/HTMLUserTextField.php index 949fefd1e6..5869002b95 100644 --- a/includes/htmlform/HTMLUserTextField.php +++ b/includes/htmlform/HTMLUserTextField.php @@ -17,6 +17,7 @@ class HTMLUserTextField extends HTMLTextField { public function __construct( $params ) { $params += array( 'exists' => false, + 'ipallowed' => false, ); parent::__construct( $params ); @@ -24,11 +25,14 @@ class HTMLUserTextField extends HTMLTextField { public function validate( $value, $alldata ) { // check, if a user exists with the given username - $user = User::newFromName( $value ); + $user = User::newFromName( $value, false ); if ( !$user ) { return $this->msg( 'htmlform-user-not-valid', $value )->parse(); - } elseif ( $this->mParams['exists'] && $user->getId() === 0 ) { + } elseif ( + ( $this->mParams['exists'] && $user->getId() === 0 ) && + !( $this->mParams['ipallowed'] && User::isIP( $value ) ) + ) { return $this->msg( 'htmlform-user-not-exists', $user->getName() )->parse(); }