Hard deprecate codepaths where tidy is disabled
[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
19 /**
20 * @param array $config Configuration options
21 * - array $config['titles'] Array of titles 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->titlesArray = $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->titlesArray ),
42 'rows' => 10,
43 ] );
44 $this->appendContent( $textarea );
45 $this->addClasses( [ 'mw-widgets-titlesMultiselectWidget' ] );
46 }
47
48 protected function getJavaScriptClassName() {
49 return 'mw.widgets.TitlesMultiselectWidget';
50 }
51
52 public function getConfig( &$config ) {
53 if ( $this->titlesArray !== null ) {
54 $config['selected'] = $this->titlesArray;
55 }
56 if ( $this->inputName !== null ) {
57 $config['name'] = $this->inputName;
58 }
59 if ( $this->inputPlaceholder !== null ) {
60 $config['placeholder'] = $this->inputPlaceholder;
61 }
62
63 $config['$overlay'] = true;
64 return parent::getConfig( $config );
65 }
66
67 }