Merge "Use ParserCache in CategoryMembershipChangeJob"
[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 * - array $config['input'] Config options for the input widget
29 */
30 public function __construct( array $config = [] ) {
31 parent::__construct( $config );
32
33 // Properties
34 if ( isset( $config['default'] ) ) {
35 $this->titlesArray = $config['default'];
36 }
37 if ( isset( $config['name'] ) ) {
38 $this->inputName = $config['name'];
39 }
40 if ( isset( $config['placeholder'] ) ) {
41 $this->inputPlaceholder = $config['placeholder'];
42 }
43 if ( isset( $config['tagLimit'] ) ) {
44 $this->tagLimit = $config['tagLimit'];
45 }
46 if ( isset( $config['showMissing'] ) ) {
47 $this->showMissing = $config['showMissing'];
48 }
49 if ( isset( $config['input'] ) ) {
50 $this->input = $config['input'];
51 }
52
53 $textarea = new MultilineTextInputWidget( array_merge( [
54 'name' => $this->inputName,
55 'value' => implode( "\n", $this->titlesArray ),
56 'rows' => 10,
57 ], $this->input ) );
58
59 $this->appendContent( $textarea );
60 $this->addClasses( [ 'mw-widgets-titlesMultiselectWidget' ] );
61 }
62
63 protected function getJavaScriptClassName() {
64 return 'mw.widgets.TitlesMultiselectWidget';
65 }
66
67 public function getConfig( &$config ) {
68 if ( $this->titlesArray !== null ) {
69 $config['selected'] = $this->titlesArray;
70 }
71 if ( $this->inputName !== null ) {
72 $config['name'] = $this->inputName;
73 }
74 if ( $this->inputPlaceholder !== null ) {
75 $config['placeholder'] = $this->inputPlaceholder;
76 }
77 if ( $this->tagLimit !== null ) {
78 $config['tagLimit'] = $this->tagLimit;
79 }
80 if ( $this->showMissing !== null ) {
81 $config['showMissing'] = $this->showMissing;
82 }
83 if ( $this->input !== null ) {
84 $config['input'] = $this->input;
85 }
86
87 $config['$overlay'] = true;
88 return parent::getConfig( $config );
89 }
90
91 }