Merge "Log thumbnail access"
[lhc/web/wiklou.git] / includes / htmlform / HTMLUserTextField.php
1 <?php
2
3 use MediaWiki\Widget\UserInputWidget;
4
5 /**
6 * Implements a text input field for user names.
7 * Automatically auto-completes if using the OOUI display format.
8 *
9 * FIXME: Does not work for forms that support GET requests.
10 *
11 * Optional parameters:
12 * 'exists' - Whether to validate that the user already exists
13 *
14 * @since 1.26
15 */
16 class HTMLUserTextField extends HTMLTextField {
17 public function __construct( $params ) {
18 $params += array(
19 'exists' => false,
20 );
21
22 parent::__construct( $params );
23 }
24
25 public function validate( $value, $alldata ) {
26 // check, if a user exists with the given username
27 $user = User::newFromName( $value );
28
29 if ( !$user ) {
30 return $this->msg( 'htmlform-user-not-valid', $value )->parse();
31 } else if ( $this->mParams['exists'] && $user->getId() === 0 ) {
32 return $this->msg( 'htmlform-user-not-exists', $user->getName() )->parse();
33 }
34
35 return parent::validate( $value, $alldata );
36 }
37
38 protected function getInputWidget( $params ) {
39 $this->mParent->getOutput()->addModules( 'mediawiki.widgets' );
40
41 return new UserInputWidget( $params );
42 }
43 }