d4ffed2c8c40a11a7389388e905ec434f9b22608
[lhc/web/wiklou.git] / includes / widget / SearchInputWidget.php
1 <?php
2
3 namespace MediaWiki\Widget;
4
5 /**
6 * Search input widget.
7 *
8 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
9 * @license MIT
10 */
11 class SearchInputWidget extends TitleInputWidget {
12
13 protected $performSearchOnClick = true;
14 protected $validateTitle = false;
15 protected $highlightFirst = false;
16 protected $dataLocation = 'header';
17
18 /**
19 * @param array $config Configuration options
20 * - bool|null $config['performSearchOnClick'] If true, the script will start a search
21 * whenever a user hits a suggestion. If false, the text of the suggestion is inserted into
22 * the text field only (default: true)
23 * - string $config['dataLocation'] Where the search input field will be
24 * used (header or content, default: header)
25 */
26 public function __construct( array $config = [] ) {
27 $config = array_merge( [
28 'maxLength' => null,
29 'icon' => 'search',
30 ], $config );
31
32 parent::__construct( $config );
33
34 // Properties, which are ignored in PHP and just shipped back to JS
35 if ( isset( $config['performSearchOnClick'] ) ) {
36 $this->performSearchOnClick = $config['performSearchOnClick'];
37 }
38
39 if ( isset( $config['dataLocation'] ) ) {
40 // identifies the location of the search bar for tracking purposes
41 $this->dataLocation = $config['dataLocation'];
42 }
43
44 // Initialization
45 $this->addClasses( [ 'mw-widget-searchInputWidget' ] );
46 }
47
48 protected function getInputElement( $config ) {
49 return ( new \OOUI\Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
50 }
51
52 protected function getJavaScriptClassName() {
53 return 'mw.widgets.SearchInputWidget';
54 }
55
56 public function getConfig( &$config ) {
57 $config['performSearchOnClick'] = $this->performSearchOnClick;
58 if ( $this->dataLocation ) {
59 $config['dataLocation'] = $this->dataLocation;
60 }
61 $config['$overlay'] = true;
62 return parent::getConfig( $config );
63 }
64 }