3 namespace MediaWiki\Widget
;
5 use OOUI\MultilineTextInputWidget
;
8 * Widget to select multiple users.
10 * @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
13 class UsersMultiselectWidget
extends \OOUI\Widget
{
15 protected $usersArray = [];
16 protected $inputName = null;
17 protected $inputPlaceholder = null;
20 * @param array $config Configuration options
21 * - array $config['users'] Array of usernames to use as preset data
22 * - array $config['placeholder'] Placeholder message for input
23 * - array $config['name'] Name attribute (used in forms)
25 public function __construct( array $config = [] ) {
26 parent
::__construct( $config );
29 if ( isset( $config['default'] ) ) {
30 $this->usersArray
= $config['default'];
32 if ( isset( $config['name'] ) ) {
33 $this->inputName
= $config['name'];
35 if ( isset( $config['placeholder'] ) ) {
36 $this->inputPlaceholder
= $config['placeholder'];
39 $textarea = new MultilineTextInputWidget( [
40 'name' => $this->inputName
,
41 'value' => implode( "\n", $this->usersArray
),
44 $this->prependContent( $textarea );
47 protected function getJavaScriptClassName() {
48 return 'mw.widgets.UsersMultiselectWidget';
51 public function getConfig( &$config ) {
52 if ( $this->usersArray
!== null ) {
53 $config['selected'] = $this->usersArray
;
55 if ( $this->inputName
!== null ) {
56 $config['name'] = $this->inputName
;
58 if ( $this->inputPlaceholder
!== null ) {
59 $config['placeholder'] = $this->inputPlaceholder
;
62 $config['$overlay'] = true;
63 return parent
::getConfig( $config );