public function __construct( $params ) {
$params += array(
'exists' => false,
+ 'ipallowed' => false,
);
parent::__construct( $params );
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();
- } else if ( $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();
}
}
protected function getInputWidget( $params ) {
- $this->mParent->getOutput()->addModules( 'mediawiki.widgets' );
+ $this->mParent->getOutput()->addModules( 'mediawiki.widgets.UserInputWidget' );
return new UserInputWidget( $params );
}
+
+ public function getInputHtml( $value ) {
+ // add the required module and css class for user suggestions in non-OOUI mode
+ $this->mParent->getOutput()->addModules( 'mediawiki.userSuggest' );
+ $this->mClass .= ' mw-autocomplete-user';
+
+ // return parent html
+ return parent::getInputHtml( $value );
+ }
}