3 namespace MediaWiki\Widget
;
8 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
11 class SearchInputWidget
extends TitleInputWidget
{
13 protected $performSearchOnClick = true;
14 protected $validateTitle = false;
15 protected $highlightFirst = false;
16 protected $dataLocation = 'header';
17 protected $showDescriptions = false;
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)
27 public function __construct( array $config = [] ) {
28 $config = array_merge( [
33 parent
::__construct( $config );
35 // Properties, which are ignored in PHP and just shipped back to JS
36 if ( isset( $config['performSearchOnClick'] ) ) {
37 $this->performSearchOnClick
= $config['performSearchOnClick'];
40 if ( isset( $config['dataLocation'] ) ) {
41 // identifies the location of the search bar for tracking purposes
42 $this->dataLocation
= $config['dataLocation'];
45 if ( !empty( $config['showDescriptions'] ) ) {
46 $this->showDescriptions
= true;
50 $this->addClasses( [ 'mw-widget-searchInputWidget' ] );
53 protected function getInputElement( $config ) {
54 return ( new \OOUI\
Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
57 protected function getJavaScriptClassName() {
58 return 'mw.widgets.SearchInputWidget';
61 public function getConfig( &$config ) {
62 $config['performSearchOnClick'] = $this->performSearchOnClick
;
63 if ( $this->dataLocation
) {
64 $config['dataLocation'] = $this->dataLocation
;
66 if ( $this->showDescriptions
) {
67 $config['showDescriptions'] = true;
69 $config['$overlay'] = true;
70 return parent
::getConfig( $config );