MediaWiki  master
SearchInputWidget.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Widget;
4 
12 
13  protected $performSearchOnClick = true;
14  protected $validateTitle = false;
15  protected $highlightFirst = false;
16  protected $dataLocation = 'header';
17  protected $showDescriptions = false;
18 
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 }
Config $config
Definition: MediaWiki.php:39