Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
SearchInputWidget | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
30 | |||
getInputElement | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getJavaScriptClassName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getConfig | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Widget; |
4 | |
5 | use OOUI\Tag; |
6 | |
7 | /** |
8 | * Search input widget. |
9 | * |
10 | * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt |
11 | * @license MIT |
12 | */ |
13 | class SearchInputWidget extends TitleInputWidget { |
14 | |
15 | protected $performSearchOnClick = true; |
16 | protected $validateTitle = false; |
17 | protected $highlightFirst = false; |
18 | protected $dataLocation = 'header'; |
19 | protected $showDescriptions = false; |
20 | |
21 | /** |
22 | * @param array $config Configuration options |
23 | * - bool|null $config['performSearchOnClick'] If true, the script will start a search |
24 | * whenever a user hits a suggestion. If false, the text of the suggestion is inserted into |
25 | * the text field only (default: true) |
26 | * - string $config['dataLocation'] Where the search input field will be |
27 | * used (header or content, default: header) |
28 | */ |
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 | } |