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