summaryrefslogtreecommitdiff
path: root/includes/htmlform/HTMLUserTextField.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-17 09:15:42 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-17 09:44:51 +0100
commita1789ddde42033f1b05cc4929491214ee6e79383 (patch)
tree63615735c4ddffaaabf2428946bb26f90899f7bf /includes/htmlform/HTMLUserTextField.php
parent9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff)
Update to MediaWiki 1.26.0
Diffstat (limited to 'includes/htmlform/HTMLUserTextField.php')
-rw-r--r--includes/htmlform/HTMLUserTextField.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/includes/htmlform/HTMLUserTextField.php b/includes/htmlform/HTMLUserTextField.php
new file mode 100644
index 00000000..9617c0a3
--- /dev/null
+++ b/includes/htmlform/HTMLUserTextField.php
@@ -0,0 +1,47 @@
+<?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 );
+ }
+}