Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / widget / SearchInputWidget.php
blob5b26f333296796922468ef5425f588d6f7f95a2f
1 <?php
3 namespace MediaWiki\Widget;
5 use OOUI\Tag;
7 /**
8 * Search input widget.
10 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
11 * @license MIT
13 class SearchInputWidget extends TitleInputWidget {
15 /** @var bool */
16 protected $performSearchOnClick = true;
17 /** @var bool */
18 protected $validateTitle = false;
19 /** @var bool */
20 protected $highlightFirst = false;
21 /** @var string */
22 protected $dataLocation = 'header';
23 /** @var bool */
24 protected $showDescriptions = false;
26 /**
27 * @param array $config Configuration options
28 * - bool|null $config['performSearchOnClick'] If true, the script will start a search
29 * whenever a user hits a suggestion. If false, the text of the suggestion is inserted into
30 * the text field only (default: true)
31 * - string $config['dataLocation'] Where the search input field will be
32 * used (header or content, default: header)
34 public function __construct( array $config = [] ) {
35 $config = array_merge( [
36 'maxLength' => null,
37 'icon' => 'search',
38 ], $config );
39 '@phan-var array $config';
41 parent::__construct( $config );
43 // Properties, which are ignored in PHP and just shipped back to JS
44 if ( isset( $config['performSearchOnClick'] ) ) {
45 $this->performSearchOnClick = $config['performSearchOnClick'];
48 if ( isset( $config['dataLocation'] ) ) {
49 // identifies the location of the search bar for tracking purposes
50 $this->dataLocation = $config['dataLocation'];
53 if ( !empty( $config['showDescriptions'] ) ) {
54 $this->showDescriptions = true;
57 // Perhaps should be upstreamed to TextInputWidget?
58 if ( isset( $config['autocapitalize'] ) ) {
59 $this->input->setAttributes( [ 'autocapitalize' => $config['autocapitalize'] ] );
62 // Initialization
63 $this->addClasses( [ 'mw-widget-searchInputWidget' ] );
66 protected function getInputElement( $config ) {
67 return ( new Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
70 protected function getJavaScriptClassName() {
71 return 'mw.widgets.SearchInputWidget';
74 public function getConfig( &$config ) {
75 $config['performSearchOnClick'] = $this->performSearchOnClick;
76 if ( $this->dataLocation ) {
77 $config['dataLocation'] = $this->dataLocation;
79 if ( $this->showDescriptions ) {
80 $config['showDescriptions'] = true;
82 $config['$overlay'] = true;
83 return parent::getConfig( $config );