MediaWiki master
SearchInputWidget.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Widget;
4
5use OOUI\Tag;
6
14
16 protected $performSearchOnClick = true;
18 protected $validateTitle = false;
20 protected $highlightFirst = false;
22 protected $dataLocation = 'header';
24 protected $showDescriptions = false;
25
34 public function __construct( array $config = [] ) {
35 $config = array_merge( [
36 'maxLength' => null,
37 'icon' => 'search',
38 ], $config );
39 '@phan-var array $config';
40
41 parent::__construct( $config );
42
43 // Properties, which are ignored in PHP and just shipped back to JS
44 if ( isset( $config['performSearchOnClick'] ) ) {
45 $this->performSearchOnClick = $config['performSearchOnClick'];
46 }
47
48 if ( isset( $config['dataLocation'] ) ) {
49 // identifies the location of the search bar for tracking purposes
50 $this->dataLocation = $config['dataLocation'];
51 }
52
53 if ( !empty( $config['showDescriptions'] ) ) {
54 $this->showDescriptions = true;
55 }
56
57 // Perhaps should be upstreamed to TextInputWidget?
58 if ( isset( $config['autocapitalize'] ) ) {
59 $this->input->setAttributes( [ 'autocapitalize' => $config['autocapitalize'] ] );
60 }
61
62 // Initialization
63 $this->addClasses( [ 'mw-widget-searchInputWidget' ] );
64 }
65
66 protected function getInputElement( $config ) {
67 return ( new Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
68 }
69
70 protected function getJavaScriptClassName() {
71 return 'mw.widgets.SearchInputWidget';
72 }
73
74 public function getConfig( &$config ) {
75 $config['performSearchOnClick'] = $this->performSearchOnClick;
76 if ( $this->dataLocation ) {
77 $config['dataLocation'] = $this->dataLocation;
78 }
79 if ( $this->showDescriptions ) {
80 $config['showDescriptions'] = true;
81 }
82 $config['$overlay'] = true;
83 return parent::getConfig( $config );
84 }
85}