|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File holding the SearchBar class |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the MediaWiki skin Chameleon. |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2013 - 2014, Stephan Gambke |
|
8
|
|
|
* @license GNU General Public License, version 3 (or any later version) |
|
9
|
|
|
* |
|
10
|
|
|
* The Chameleon skin is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU General Public License as published by the Free |
|
12
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any |
|
13
|
|
|
* later version. |
|
14
|
|
|
* |
|
15
|
|
|
* The Chameleon skin is distributed in the hope that it will be useful, but |
|
16
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
18
|
|
|
* details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU General Public License along |
|
21
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
* |
|
23
|
|
|
* @file |
|
24
|
|
|
* @ingroup Skins |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace Skins\Chameleon\Components; |
|
28
|
|
|
|
|
29
|
|
|
use \Linker; |
|
30
|
|
|
use Skins\Chameleon\IdRegistry; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The SearchBar class. |
|
34
|
|
|
* |
|
35
|
|
|
* The search form wrapped in a div: <div id="p-search" role="search" > |
|
36
|
|
|
* |
|
37
|
|
|
* @author Stephan Gambke |
|
38
|
|
|
* @since 1.0 |
|
39
|
|
|
* @ingroup Skins |
|
40
|
|
|
*/ |
|
41
|
|
|
class SearchBar extends Component { |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Builds the HTML code for this component |
|
45
|
|
|
* |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
7 |
|
public function getHtml() { |
|
49
|
|
|
|
|
50
|
7 |
|
$ret = $this->indent() . '<!-- search form -->' . |
|
51
|
|
|
|
|
52
|
7 |
|
$this->indent() . '<div ' . \Html::expandAttributes( array( |
|
53
|
7 |
|
'id' => IdRegistry::getRegistry()->getId( 'p-search' ), |
|
54
|
7 |
|
'class' => 'p-search ' . $this->getClassString(), |
|
55
|
7 |
|
'role' => 'search', |
|
56
|
|
|
) |
|
57
|
7 |
|
) . Linker::tooltip( 'p-search' ) . '>' . |
|
58
|
|
|
|
|
59
|
7 |
|
$this->indent( 1 ) . '<form ' . \Html::expandAttributes( array( |
|
60
|
7 |
|
'id' => IdRegistry::getRegistry()->getId( 'searchform' ), |
|
61
|
7 |
|
'class' => 'mw-search form-inline', |
|
62
|
|
|
) |
|
63
|
7 |
|
) . ' action="' . $this->getSkinTemplate()->data[ 'wgScript' ] . '">' . |
|
64
|
|
|
|
|
65
|
7 |
|
$this->indent( 1 ) . '<input type="hidden" name="title" value="' . $this->getSkinTemplate()->data[ 'searchtitle' ] . '" />' . |
|
66
|
7 |
|
$this->indent() . '<div class="input-group">' . |
|
67
|
7 |
|
$this->indent( 1 ) . $this->getSkinTemplate()->makeSearchInput( array( 'id' => IdRegistry::getRegistry()->getId( 'searchInput' ), 'type' => 'text', 'class' => 'form-control' ) ) . |
|
68
|
7 |
|
$this->indent() . '<div class="input-group-btn">' . |
|
69
|
7 |
|
$this->indent( 1 ) . $this->getSearchButton( 'go' ) . |
|
70
|
7 |
|
$this->indent( 0 ) . $this->getSearchButton( 'fulltext' ) . |
|
71
|
7 |
|
$this->indent( -1 ) . '</div>' . |
|
72
|
7 |
|
$this->indent( -1 ) . '</div>' . |
|
73
|
7 |
|
$this->indent( -1 ) . '</form>' . |
|
74
|
7 |
|
$this->indent( -1 ) . '</div>' . "\n"; |
|
75
|
|
|
|
|
76
|
7 |
|
return $ret; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* This method basically replicates SkinTemplate::makeSearchButton, but uses buttons instead of inputs to ensure |
|
81
|
|
|
* proper styling by Bootstrap |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $mode 'go' or 'fulltext', optional, default='fulltext' |
|
84
|
|
|
* |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
7 |
|
private function getSearchButton( $mode = 'fulltext' ) { |
|
88
|
|
|
|
|
89
|
7 |
|
if ( $mode === 'go' ) { |
|
90
|
|
|
|
|
91
|
|
|
$buttonAttrs = array( |
|
92
|
7 |
|
'value' => $this->getSkinTemplate()->translator->translate( 'searcharticle' ), |
|
93
|
7 |
|
'id' => IdRegistry::getRegistry()->getId( 'searchGoButton' ), |
|
94
|
7 |
|
'name' => 'go', |
|
95
|
7 |
|
); |
|
96
|
|
|
|
|
97
|
7 |
|
$glyphicon = 'share-alt'; |
|
98
|
|
|
|
|
99
|
7 |
|
} else { |
|
100
|
|
|
|
|
101
|
|
|
$buttonAttrs = array( |
|
102
|
7 |
|
'value' => $this->getSkinTemplate()->translator->translate( 'searchbutton' ), |
|
103
|
7 |
|
'id' => IdRegistry::getRegistry()->getId( 'mw-searchButton' ), |
|
104
|
7 |
|
'name' => 'fulltext', |
|
105
|
7 |
|
); |
|
106
|
|
|
|
|
107
|
7 |
|
$glyphicon = 'search'; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
7 |
|
$buttonAttrs = array_merge( |
|
111
|
7 |
|
$buttonAttrs, |
|
112
|
7 |
|
Linker::tooltipAndAccesskeyAttribs( "search-$mode" ), |
|
113
|
|
|
array( |
|
114
|
7 |
|
'type' => 'submit', |
|
115
|
7 |
|
'class' => $buttonAttrs[ 'id' ] . ' btn btn-default' |
|
116
|
7 |
|
) |
|
117
|
7 |
|
); |
|
118
|
|
|
|
|
119
|
7 |
|
return \Html::rawElement( 'button', $buttonAttrs, '<span class="glyphicon glyphicon-' . $glyphicon . '"></span>' ); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|