Merge "Add support for PHP7 random_bytes in favor of mcrypt_create_iv"
[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\TextInputWidget;
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 TextInputWidget( [
42 'name' => $this->inputName,
43 'multiline' => true,
44 'value' => implode( "\n", $this->usersArray ),
45 'rows' => 25,
46 ] );
47 $this->prependContent( $textarea );
48 }
49
50 protected function getJavaScriptClassName() {
51 return 'mw.widgets.UsersMultiselectWidget';
52 }
53
54 public function getConfig( &$config ) {
55 if ( $this->usersArray !== null ) {
56 $config['data'] = $this->usersArray;
57 }
58 if ( $this->inputName !== null ) {
59 $config['name'] = $this->inputName;
60 }
61 if ( $this->inputPlaceholder !== null ) {
62 $config['placeholder'] = $this->inputPlaceholder;
63 }
64
65 return parent::getConfig( $config );
66 }
67
68 }