Merge "Cleanup page creation in RevisionIntegrationTest"
[lhc/web/wiklou.git] / includes / widget / UsersMultiselectWidget.php
1 <?php
2 /**
3 * MediaWiki Widgets – UsersMultiselectWidget class.
4 *
5 * @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
6 * @license The MIT License (MIT); see LICENSE.txt
7 */
8 namespace MediaWiki\Widget;
9
10 use \OOUI\MultilineTextInputWidget;
11
12 /**
13 * Widget to select multiple users.
14 */
15 class UsersMultiselectWidget extends \OOUI\Widget {
16
17 protected $usersArray = [];
18 protected $inputName = null;
19 protected $inputPlaceholder = null;
20
21 /**
22 * @param array $config Configuration options
23 * @param array $config['users'] Array of usernames to use as preset data
24 * @param array $config['placeholder'] Placeholder message for input
25 * @param array $config['name'] Name attribute (used in forms)
26 */
27 public function __construct( array $config = [] ) {
28 parent::__construct( $config );
29
30 // Properties
31 if ( isset( $config['default'] ) ) {
32 $this->usersArray = $config['default'];
33 }
34 if ( isset( $config['name'] ) ) {
35 $this->inputName = $config['name'];
36 }
37 if ( isset( $config['placeholder'] ) ) {
38 $this->inputPlaceholder = $config['placeholder'];
39 }
40
41 $textarea = new MultilineTextInputWidget( [
42 'name' => $this->inputName,
43 'value' => implode( "\n", $this->usersArray ),
44 'rows' => 25,
45 ] );
46 $this->prependContent( $textarea );
47 }
48
49 protected function getJavaScriptClassName() {
50 return 'mw.widgets.UsersMultiselectWidget';
51 }
52
53 public function getConfig( &$config ) {
54 if ( $this->usersArray !== null ) {
55 $config['selected'] = $this->usersArray;
56 }
57 if ( $this->inputName !== null ) {
58 $config['name'] = $this->inputName;
59 }
60 if ( $this->inputPlaceholder !== null ) {
61 $config['placeholder'] = $this->inputPlaceholder;
62 }
63
64 return parent::getConfig( $config );
65 }
66
67 }