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
28 * - array $config['input'] Config options for the input widget
30 public function __construct( array $config = [] ) {
31 parent
::__construct( $config );
34 if ( isset( $config['default'] ) ) {
35 $this->titlesArray
= $config['default'];
37 if ( isset( $config['name'] ) ) {
38 $this->inputName
= $config['name'];
40 if ( isset( $config['placeholder'] ) ) {
41 $this->inputPlaceholder
= $config['placeholder'];
43 if ( isset( $config['tagLimit'] ) ) {
44 $this->tagLimit
= $config['tagLimit'];
46 if ( isset( $config['showMissing'] ) ) {
47 $this->showMissing
= $config['showMissing'];
49 if ( isset( $config['input'] ) ) {
50 $this->input
= $config['input'];
53 $textarea = new MultilineTextInputWidget( array_merge( [
54 'name' => $this->inputName
,
55 'value' => implode( "\n", $this->titlesArray
),
59 $this->appendContent( $textarea );
60 $this->addClasses( [ 'mw-widgets-titlesMultiselectWidget' ] );
63 protected function getJavaScriptClassName() {
64 return 'mw.widgets.TitlesMultiselectWidget';
67 public function getConfig( &$config ) {
68 if ( $this->titlesArray
!== null ) {
69 $config['selected'] = $this->titlesArray
;
71 if ( $this->inputName
!== null ) {
72 $config['name'] = $this->inputName
;
74 if ( $this->inputPlaceholder
!== null ) {
75 $config['placeholder'] = $this->inputPlaceholder
;
77 if ( $this->tagLimit
!== null ) {
78 $config['tagLimit'] = $this->tagLimit
;
80 if ( $this->showMissing
!== null ) {
81 $config['showMissing'] = $this->showMissing
;
83 if ( $this->input
!== null ) {
84 $config['input'] = $this->input
;
87 $config['$overlay'] = true;
88 return parent
::getConfig( $config );