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
),
58 'mw-widgets-titlesMultiselectWidget-multilineTextInputWidget'
62 $pending = new PendingTextInputWidget();
64 $this->appendContent( $textarea, $pending );
65 $this->addClasses( [ 'mw-widgets-titlesMultiselectWidget' ] );
68 protected function getJavaScriptClassName() {
69 return 'mw.widgets.TitlesMultiselectWidget';
72 public function getConfig( &$config ) {
73 if ( $this->titlesArray
!== null ) {
74 $config['selected'] = $this->titlesArray
;
76 if ( $this->inputName
!== null ) {
77 $config['name'] = $this->inputName
;
79 if ( $this->inputPlaceholder
!== null ) {
80 $config['placeholder'] = $this->inputPlaceholder
;
82 if ( $this->tagLimit
!== null ) {
83 $config['tagLimit'] = $this->tagLimit
;
85 if ( $this->showMissing
!== null ) {
86 $config['showMissing'] = $this->showMissing
;
88 if ( $this->input
!== null ) {
89 $config['input'] = $this->input
;
92 $config['$overlay'] = true;
93 return parent
::getConfig( $config );