3 use MediaWiki\Widget\UsersMultiselectWidget
;
6 * Implements a capsule multiselect input field for user names.
8 * Besides the parameters recognized by HTMLUserTextField, additional recognized
10 * default - (optional) Array of usernames to use as preset data
11 * placeholder - (optional) Custom placeholder message for input
13 * The result is the array of usernames
15 * @note This widget is not likely to remain functional in non-OOUI forms.
17 class HTMLUsersMultiselectField
extends HTMLUserTextField
{
19 public function loadDataFromRequest( $request ) {
20 if ( !$request->getCheck( $this->mName
) ) {
21 return $this->getDefault();
24 $usersArray = explode( "\n", $request->getText( $this->mName
) );
26 $usersArray = array_values( array_filter( $usersArray, function( $username ) {
27 return trim( $username ) !== '';
32 public function validate( $value, $alldata ) {
33 if ( !$this->mParams
['exists'] ) {
37 if ( is_null( $value ) ) {
41 foreach ( $value as $username ) {
42 $result = parent
::validate( $username, $alldata );
43 if ( $result !== true ) {
51 public function getInputHTML( $values ) {
52 $this->mParent
->getOutput()->enableOOUI();
53 return $this->getInputOOUI( $values );
56 public function getInputOOUI( $values ) {
57 $params = [ 'name' => $this->mName
];
59 if ( isset( $this->mParams
['default'] ) ) {
60 $params['default'] = $this->mParams
['default'];
63 if ( isset( $this->mParams
['placeholder'] ) ) {
64 $params['placeholder'] = $this->mParams
['placeholder'];
66 $params['placeholder'] = $this->msg( 'mw-widgets-usersmultiselect-placeholder' )
71 if ( !is_null( $values ) ) {
72 $params['default'] = $values;
75 return new UsersMultiselectWidget( $params );
78 protected function shouldInfuseOOUI() {
82 protected function getOOUIModules() {
83 return [ 'mediawiki.widgets.UsersMultiselectWidget' ];