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  // Perhaps should be upstreamed to TextInputWidget?
50  if ( isset( $config['autocapitalize'] ) ) {
51  $this->input->setAttributes( [ 'autocapitalize' => $config['autocapitalize'] ] );
52  }
53 
54  // Initialization
55  $this->addClasses( [ 'mw-widget-searchInputWidget' ] );
56  }
57 
58  protected function getInputElement( $config ) {
59  return ( new \OOUI\Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
60  }
61 
62  protected function getJavaScriptClassName() {
63  return 'mw.widgets.SearchInputWidget';
64  }
65 
66  public function getConfig( &$config ) {
67  $config['performSearchOnClick'] = $this->performSearchOnClick;
68  if ( $this->dataLocation ) {
69  $config['dataLocation'] = $this->dataLocation;
70  }
71  if ( $this->showDescriptions ) {
72  $config['showDescriptions'] = true;
73  }
74  $config['$overlay'] = true;
75  return parent::getConfig( $config );
76  }
77 }