Merge "Special:Log: Use OOUI"
[lhc/web/wiklou.git] / includes / widget / TitlesMultiselectWidget.php
1 <?php
2
3 namespace MediaWiki\Widget;
4
5 use OOUI\MultilineTextInputWidget;
6
7 /**
8 * Widget to select multiple titles.
9 *
10 * @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
11 * @license MIT
12 */
13 class TitlesMultiselectWidget extends \OOUI\Widget {
14
15 protected $titlesArray = [];
16 protected $inputName = null;
17 protected $inputPlaceholder = null;
18 protected $tagLimit = null;
19 protected $showMissing = null;
20
21 /**
22 * @param array $config Configuration options
23 * - array $config['titles'] Array of titles to use as preset data
24 * - array $config['placeholder'] Placeholder message for input
25 * - array $config['name'] Name attribute (used in forms)
26 * - number $config['tagLimit'] Maximum number of selected titles
27 * - bool $config['showMissing'] Show missing pages
28 */
29 public function __construct( array $config = [] ) {
30 parent::__construct( $config );
31
32 // Properties
33 if ( isset( $config['default'] ) ) {
34 $this->titlesArray = $config['default'];
35 }
36 if ( isset( $config['name'] ) ) {
37 $this->inputName = $config['name'];
38 }
39 if ( isset( $config['placeholder'] ) ) {
40 $this->inputPlaceholder = $config['placeholder'];
41 }
42 if ( isset( $config['tagLimit'] ) ) {
43 $this->tagLimit = $config['tagLimit'];
44 }
45 if ( isset( $config['showMissing'] ) ) {
46 $this->showMissing = $config['showMissing'];
47 }
48
49 $textarea = new MultilineTextInputWidget( [
50 'name' => $this->inputName,
51 'value' => implode( "\n", $this->titlesArray ),
52 'rows' => 10,
53 ] );
54 $this->appendContent( $textarea );
55 $this->addClasses( [ 'mw-widgets-titlesMultiselectWidget' ] );
56 }
57
58 protected function getJavaScriptClassName() {
59 return 'mw.widgets.TitlesMultiselectWidget';
60 }
61
62 public function getConfig( &$config ) {
63 if ( $this->titlesArray !== null ) {
64 $config['selected'] = $this->titlesArray;
65 }
66 if ( $this->inputName !== null ) {
67 $config['name'] = $this->inputName;
68 }
69 if ( $this->inputPlaceholder !== null ) {
70 $config['placeholder'] = $this->inputPlaceholder;
71 }
72 if ( $this->tagLimit !== null ) {
73 $config['tagLimit'] = $this->tagLimit;
74 }
75 if ( $this->showMissing !== null ) {
76 $config['showMissing'] = $this->showMissing;
77 }
78
79 $config['$overlay'] = true;
80 return parent::getConfig( $config );
81 }
82
83 }