Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[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 protected $showDescriptions = false;
18
19 /**
20 * @param array $config Configuration options
21 * - bool|null $config['performSearchOnClick'] If true, the script will start a search
22 * whenever a user hits a suggestion. If false, the text of the suggestion is inserted into
23 * the text field only (default: true)
24 * - string $config['dataLocation'] Where the search input field will be
25 * used (header or content, default: header)
26 */
27 public function __construct( array $config = [] ) {
28 $config = array_merge( [
29 'maxLength' => null,
30 'icon' => 'search',
31 ], $config );
32
33 parent::__construct( $config );
34
35 // Properties, which are ignored in PHP and just shipped back to JS
36 if ( isset( $config['performSearchOnClick'] ) ) {
37 $this->performSearchOnClick = $config['performSearchOnClick'];
38 }
39
40 if ( isset( $config['dataLocation'] ) ) {
41 // identifies the location of the search bar for tracking purposes
42 $this->dataLocation = $config['dataLocation'];
43 }
44
45 if ( !empty( $config['showDescriptions'] ) ) {
46 $this->showDescriptions = true;
47 }
48
49 // Initialization
50 $this->addClasses( [ 'mw-widget-searchInputWidget' ] );
51 }
52
53 protected function getInputElement( $config ) {
54 return ( new \OOUI\Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
55 }
56
57 protected function getJavaScriptClassName() {
58 return 'mw.widgets.SearchInputWidget';
59 }
60
61 public function getConfig( &$config ) {
62 $config['performSearchOnClick'] = $this->performSearchOnClick;
63 if ( $this->dataLocation ) {
64 $config['dataLocation'] = $this->dataLocation;
65 }
66 if ( $this->showDescriptions ) {
67 $config['showDescriptions'] = true;
68 }
69 $config['$overlay'] = true;
70 return parent::getConfig( $config );
71 }
72 }