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 | /** @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; |
25 | |
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) |
33 | */ |
34 | public function __construct( array $config = [] ) { |
35 | $config = array_merge( [ |
36 | 'maxLength' => null, |
37 | 'icon' => 'search', |
38 | ], $config ); |
39 | '@phan-var array $config'; |
40 | |
41 | parent::__construct( $config ); |
42 | |
43 | // Properties, which are ignored in PHP and just shipped back to JS |
44 | if ( isset( $config['performSearchOnClick'] ) ) { |
45 | $this->performSearchOnClick = $config['performSearchOnClick']; |
46 | } |
47 | |
48 | if ( isset( $config['dataLocation'] ) ) { |
49 | // identifies the location of the search bar for tracking purposes |
50 | $this->dataLocation = $config['dataLocation']; |
51 | } |
52 | |
53 | if ( !empty( $config['showDescriptions'] ) ) { |
54 | $this->showDescriptions = true; |
55 | } |
56 | |
57 | // Perhaps should be upstreamed to TextInputWidget? |
58 | if ( isset( $config['autocapitalize'] ) ) { |
59 | $this->input->setAttributes( [ 'autocapitalize' => $config['autocapitalize'] ] ); |
60 | } |
61 | |
62 | // Initialization |
63 | $this->addClasses( [ 'mw-widget-searchInputWidget' ] ); |
64 | } |
65 | |
66 | protected function getInputElement( $config ) { |
67 | return ( new Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] ); |
68 | } |
69 | |
70 | protected function getJavaScriptClassName() { |
71 | return 'mw.widgets.SearchInputWidget'; |
72 | } |
73 | |
74 | public function getConfig( &$config ) { |
75 | $config['performSearchOnClick'] = $this->performSearchOnClick; |
76 | if ( $this->dataLocation ) { |
77 | $config['dataLocation'] = $this->dataLocation; |
78 | } |
79 | if ( $this->showDescriptions ) { |
80 | $config['showDescriptions'] = true; |
81 | } |
82 | $config['$overlay'] = true; |
83 | return parent::getConfig( $config ); |
84 | } |
85 | } |