Simplify documentation headers of includes/widgets/…Widget.php files
[lhc/web/wiklou.git] / includes / widget / UsersMultiselectWidget.php
1 <?php
2
3 namespace MediaWiki\Widget;
4
5 use OOUI\MultilineTextInputWidget;
6
7 /**
8 * Widget to select multiple users.
9 *
10 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
11 * @license MIT
12 */
13 class UsersMultiselectWidget extends \OOUI\Widget {
14
15 protected $usersArray = [];
16 protected $inputName = null;
17 protected $inputPlaceholder = null;
18
19 /**
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)
24 */
25 public function __construct( array $config = [] ) {
26 parent::__construct( $config );
27
28 // Properties
29 if ( isset( $config['default'] ) ) {
30 $this->usersArray = $config['default'];
31 }
32 if ( isset( $config['name'] ) ) {
33 $this->inputName = $config['name'];
34 }
35 if ( isset( $config['placeholder'] ) ) {
36 $this->inputPlaceholder = $config['placeholder'];
37 }
38
39 $textarea = new MultilineTextInputWidget( [
40 'name' => $this->inputName,
41 'value' => implode( "\n", $this->usersArray ),
42 'rows' => 25,
43 ] );
44 $this->prependContent( $textarea );
45 }
46
47 protected function getJavaScriptClassName() {
48 return 'mw.widgets.UsersMultiselectWidget';
49 }
50
51 public function getConfig( &$config ) {
52 if ( $this->usersArray !== null ) {
53 $config['selected'] = $this->usersArray;
54 }
55 if ( $this->inputName !== null ) {
56 $config['name'] = $this->inputName;
57 }
58 if ( $this->inputPlaceholder !== null ) {
59 $config['placeholder'] = $this->inputPlaceholder;
60 }
61
62 $config['$overlay'] = true;
63 return parent::getConfig( $config );
64 }
65
66 }