3 namespace MediaWiki\Widget
;
5 use OOUI\MultilineTextInputWidget
;
8 * Widget to select multiple titles.
10 * @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
13 class TitlesMultiselectWidget
extends \OOUI\Widget
{
15 protected $titlesArray = [];
16 protected $inputName = null;
17 protected $inputPlaceholder = null;
18 protected $tagLimit = null;
19 protected $showMissing = null;
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
29 public function __construct( array $config = [] ) {
30 parent
::__construct( $config );
33 if ( isset( $config['default'] ) ) {
34 $this->titlesArray
= $config['default'];
36 if ( isset( $config['name'] ) ) {
37 $this->inputName
= $config['name'];
39 if ( isset( $config['placeholder'] ) ) {
40 $this->inputPlaceholder
= $config['placeholder'];
42 if ( isset( $config['tagLimit'] ) ) {
43 $this->tagLimit
= $config['tagLimit'];
45 if ( isset( $config['showMissing'] ) ) {
46 $this->showMissing
= $config['showMissing'];
49 $textarea = new MultilineTextInputWidget( [
50 'name' => $this->inputName
,
51 'value' => implode( "\n", $this->titlesArray
),
54 $this->appendContent( $textarea );
55 $this->addClasses( [ 'mw-widgets-titlesMultiselectWidget' ] );
58 protected function getJavaScriptClassName() {
59 return 'mw.widgets.TitlesMultiselectWidget';
62 public function getConfig( &$config ) {
63 if ( $this->titlesArray
!== null ) {
64 $config['selected'] = $this->titlesArray
;
66 if ( $this->inputName
!== null ) {
67 $config['name'] = $this->inputName
;
69 if ( $this->inputPlaceholder
!== null ) {
70 $config['placeholder'] = $this->inputPlaceholder
;
72 if ( $this->tagLimit
!== null ) {
73 $config['tagLimit'] = $this->tagLimit
;
75 if ( $this->showMissing
!== null ) {
76 $config['showMissing'] = $this->showMissing
;
79 $config['$overlay'] = true;
80 return parent
::getConfig( $config );