wiki.techinc.nl/includes/htmlform/HTMLUserTextField.php
Florian abd721cb38 Split out UserInputWidgets from mediawiki.widgets
Move it to its own module mediawiki.widgets.UserInputWidget. It's
currently used in HTMLUserTextField only.

Bug: T108733
Change-Id: Id8c6dd5d9616086bdb0918442bfafe9ec708ab31
2015-10-07 08:54:35 -07:00

47 lines
1.2 KiB
PHP

<?php
use MediaWiki\Widget\UserInputWidget;
/**
* Implements a text input field for user names.
* Automatically auto-completes if using the OOUI display format.
*
* FIXME: Does not work for forms that support GET requests.
*
* Optional parameters:
* 'exists' - Whether to validate that the user already exists
*
* @since 1.26
*/
class HTMLUserTextField extends HTMLTextField {
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, false );
if ( !$user ) {
return $this->msg( 'htmlform-user-not-valid', $value )->parse();
} elseif (
( $this->mParams['exists'] && $user->getId() === 0 ) &&
!( $this->mParams['ipallowed'] && User::isIP( $value ) )
) {
return $this->msg( 'htmlform-user-not-exists', $user->getName() )->parse();
}
return parent::validate( $value, $alldata );
}
protected function getInputWidget( $params ) {
$this->mParent->getOutput()->addModules( 'mediawiki.widgets.UserInputWidget' );
return new UserInputWidget( $params );
}
}