MediaWiki REL1_33
SearchFormWidget.php
Go to the documentation of this file.
1<?php
2
4
5use Hooks;
6use Html;
12use Xml;
13
16 protected $specialSearch;
18 protected $searchConfig;
20 protected $profiles;
21
27 public function __construct(
31 ) {
32 $this->specialSearch = $specialSearch;
33 $this->searchConfig = $searchConfig;
34 $this->profiles = $profiles;
35 }
36
46 public function render(
47 $profile,
48 $term,
49 $numResults,
50 $totalResults,
51 $offset,
52 $isPowerSearch
53 ) {
54 return '<div class="mw-search-form-wrapper">' .
55 Xml::openElement(
56 'form',
57 [
58 'id' => $isPowerSearch ? 'powersearch' : 'search',
59 'method' => 'get',
60 'action' => wfScript(),
61 ]
62 ) .
63 '<div id="mw-search-top-table">' .
64 $this->shortDialogHtml( $profile, $term, $numResults, $totalResults, $offset ) .
65 '</div>' .
66 "<div class='mw-search-visualclear'></div>" .
67 "<div class='mw-search-profile-tabs'>" .
68 $this->profileTabsHtml( $profile, $term ) .
69 "<div style='clear:both'></div>" .
70 "</div>" .
71 $this->optionsHtml( $term, $isPowerSearch, $profile ) .
72 '</form>' .
73 '</div>';
74 }
75
84 protected function shortDialogHtml( $profile, $term, $numResults, $totalResults, $offset ) {
85 $html = '';
86
87 $searchWidget = new SearchInputWidget( [
88 'id' => 'searchText',
89 'name' => 'search',
90 'autofocus' => trim( $term ) === '',
91 'value' => $term,
92 'dataLocation' => 'content',
93 'infusable' => true,
94 ] );
95
96 $layout = new \OOUI\ActionFieldLayout( $searchWidget, new \OOUI\ButtonInputWidget( [
97 'type' => 'submit',
98 'label' => $this->specialSearch->msg( 'searchbutton' )->text(),
99 'flags' => [ 'progressive', 'primary' ],
100 ] ), [
101 'align' => 'top',
102 ] );
103
104 $html .= $layout;
105
106 if ( $this->specialSearch->getPrefix() !== '' ) {
107 $html .= Html::hidden( 'prefix', $this->specialSearch->getPrefix() );
108 }
109
110 if ( $totalResults > 0 && $offset < $totalResults ) {
111 $html .= Xml::tags(
112 'div',
113 [
114 'class' => 'results-info',
115 'data-mw-num-results-offset' => $offset,
116 'data-mw-num-results-total' => $totalResults
117 ],
118 $this->specialSearch->msg( 'search-showingresults' )
119 ->numParams( $offset + 1, $offset + $numResults, $totalResults )
120 ->numParams( $numResults )
121 ->parse()
122 );
123 }
124
125 $html .=
126 Html::hidden( 'title', $this->specialSearch->getPageTitle()->getPrefixedText() ) .
127 Html::hidden( 'profile', $profile ) .
128 Html::hidden( 'fulltext', '1' );
129
130 return $html;
131 }
132
140 protected function profileTabsHtml( $profile, $term ) {
141 $bareterm = $this->startsWithImage( $term )
142 ? substr( $term, strpos( $term, ':' ) + 1 )
143 : $term;
144 $lang = $this->specialSearch->getLanguage();
145 $items = [];
146 foreach ( $this->profiles as $id => $profileConfig ) {
147 $profileConfig['parameters']['profile'] = $id;
148 $tooltipParam = isset( $profileConfig['namespace-messages'] )
149 ? $lang->commaList( $profileConfig['namespace-messages'] )
150 : null;
151 $items[] = Xml::tags(
152 'li',
153 [ 'class' => $profile === $id ? 'current' : 'normal' ],
154 $this->makeSearchLink(
155 $bareterm,
156 $this->specialSearch->msg( $profileConfig['message'] )->text(),
157 $this->specialSearch->msg( $profileConfig['tooltip'], $tooltipParam )->text(),
158 $profileConfig['parameters']
159 )
160 );
161 }
162
163 return "<div class='search-types'>" .
164 "<ul>" . implode( '', $items ) . "</ul>" .
165 "</div>";
166 }
167
174 protected function startsWithImage( $term ) {
175 $parts = explode( ':', $term );
176 return count( $parts ) > 1
177 ? MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $parts[0] ) ===
178 NS_FILE
179 : false;
180 }
181
191 protected function makeSearchLink( $term, $label, $tooltip, array $params = [] ) {
192 $params += [
193 'search' => $term,
194 'fulltext' => 1,
195 ];
196
197 return Xml::element(
198 'a',
199 [
200 'href' => $this->specialSearch->getPageTitle()->getLocalURL( $params ),
201 'title' => $tooltip,
202 ],
203 $label
204 );
205 }
206
216 protected function optionsHtml( $term, $isPowerSearch, $profile ) {
217 $html = '';
218
219 if ( $isPowerSearch ) {
220 $html .= $this->powerSearchBox( $term, [] );
221 } else {
222 $form = '';
223 Hooks::run( 'SpecialSearchProfileForm', [
224 $this->specialSearch, &$form, $profile, $term, []
225 ] );
226 $html .= $form;
227 }
228
229 return $html;
230 }
231
238 protected function powerSearchBox( $term, array $opts ) {
239 $rows = [];
240 $activeNamespaces = $this->specialSearch->getNamespaces();
241 $langConverter = $this->specialSearch->getLanguage();
242 foreach ( $this->searchConfig->searchableNamespaces() as $namespace => $name ) {
243 $subject = MWNamespace::getSubject( $namespace );
244 if ( !isset( $rows[$subject] ) ) {
245 $rows[$subject] = "";
246 }
247
248 $name = $langConverter->convertNamespace( $namespace );
249 if ( $name === '' ) {
250 $name = $this->specialSearch->msg( 'blanknamespace' )->text();
251 }
252
253 $rows[$subject] .=
254 '<td>' .
255 Xml::checkLabel(
256 $name,
257 "ns{$namespace}",
258 "mw-search-ns{$namespace}",
259 in_array( $namespace, $activeNamespaces )
260 ) .
261 '</td>';
262 }
263
264 // Lays out namespaces in multiple floating two-column tables so they'll
265 // be arranged nicely while still accomodating diferent screen widths
266 $tableRows = [];
267 foreach ( $rows as $row ) {
268 $tableRows[] = "<tr>{$row}</tr>";
269 }
270 $namespaceTables = [];
271 foreach ( array_chunk( $tableRows, 4 ) as $chunk ) {
272 $namespaceTables[] = implode( '', $chunk );
273 }
274
275 $showSections = [
276 'namespaceTables' => "<table>" . implode( '</table><table>', $namespaceTables ) . '</table>',
277 ];
278 Hooks::run( 'SpecialSearchPowerBox', [ &$showSections, $term, &$opts ] );
279
280 $hidden = '';
281 foreach ( $opts as $key => $value ) {
282 $hidden .= Html::hidden( $key, $value );
283 }
284
285 $divider = "<div class='divider'></div>";
286
287 // Stuff to feed SpecialSearch::saveNamespaces()
288 $user = $this->specialSearch->getUser();
289 $remember = '';
290 if ( $user->isLoggedIn() ) {
291 $remember = $divider . Xml::checkLabel(
292 $this->specialSearch->msg( 'powersearch-remember' )->text(),
293 'nsRemember',
294 'mw-search-powersearch-remember',
295 false,
296 // The token goes here rather than in a hidden field so it
297 // is only sent when necessary (not every form submission)
298 [ 'value' => $user->getEditToken(
299 'searchnamespace',
300 $this->specialSearch->getRequest()
301 ) ]
302 );
303 }
304
305 return "<fieldset id='mw-searchoptions'>" .
306 "<legend>" . $this->specialSearch->msg( 'powersearch-legend' )->escaped() . '</legend>' .
307 "<h4>" . $this->specialSearch->msg( 'powersearch-ns' )->parse() . '</h4>' .
308 // Handled by JavaScript if available
309 '<div id="mw-search-togglebox">' .
310 '<label>' . $this->specialSearch->msg( 'powersearch-togglelabel' )->escaped() . '</label>' .
311 '<input type="button" id="mw-search-toggleall" value="' .
312 $this->specialSearch->msg( 'powersearch-toggleall' )->escaped() . '"/>' .
313 '<input type="button" id="mw-search-togglenone" value="' .
314 $this->specialSearch->msg( 'powersearch-togglenone' )->escaped() . '"/>' .
315 '</div>' .
316 $divider .
317 implode(
318 $divider,
319 $showSections
320 ) .
321 $hidden .
322 $remember .
323 "</fieldset>";
324 }
325}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Hooks class.
Definition Hooks.php:34
This class is a collection of static functions that serve two purposes:
Definition Html.php:49
This is a utility class with only static functions for dealing with namespaces that encodes all the "...
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
profileTabsHtml( $profile, $term)
Generates HTML for the list of available search profiles.
shortDialogHtml( $profile, $term, $numResults, $totalResults, $offset)
startsWithImage( $term)
Check if query starts with image: prefix.
render( $profile, $term, $numResults, $totalResults, $offset, $isPowerSearch)
makeSearchLink( $term, $label, $tooltip, array $params=[])
Make a search link with some target namespaces.
__construct(SpecialSearch $specialSearch, SearchEngineConfig $searchConfig, array $profiles)
optionsHtml( $term, $isPowerSearch, $profile)
Generates HTML for advanced options available with the currently selected search profile.
Configuration handling class for SearchEngine.
implements Special:Search - Run text & title search and display the output
Module of static functions for generating XML.
Definition Xml.php:28
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition hooks.txt:2818
whereas SearchGetNearMatch runs after $term
Definition hooks.txt:2889
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition hooks.txt:2011
const NS_FILE
Definition Defines.php:79
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$params
if(!isset( $args[0])) $lang