Add ISearchResultSet
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
1 <?php
2 /**
3 * Implements Special:Search
4 *
5 * Copyright © 2004 Brion Vibber <brion@pobox.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @file
23 * @ingroup SpecialPage
24 */
25
26 use MediaWiki\MediaWikiServices;
27 use MediaWiki\Widget\Search\BasicSearchResultSetWidget;
28 use MediaWiki\Widget\Search\FullSearchResultWidget;
29 use MediaWiki\Widget\Search\InterwikiSearchResultWidget;
30 use MediaWiki\Widget\Search\InterwikiSearchResultSetWidget;
31 use MediaWiki\Widget\Search\SimpleSearchResultWidget;
32 use MediaWiki\Widget\Search\SimpleSearchResultSetWidget;
33
34 /**
35 * implements Special:Search - Run text & title search and display the output
36 * @ingroup SpecialPage
37 */
38 class SpecialSearch extends SpecialPage {
39 /**
40 * Current search profile. Search profile is just a name that identifies
41 * the active search tab on the search page (content, discussions...)
42 * For users tt replaces the set of enabled namespaces from the query
43 * string when applicable. Extensions can add new profiles with hooks
44 * with custom search options just for that profile.
45 * @var null|string
46 */
47 protected $profile;
48
49 /** @var SearchEngine Search engine */
50 protected $searchEngine;
51
52 /** @var string Search engine type, if not default */
53 protected $searchEngineType;
54
55 /** @var array For links */
56 protected $extraParams = [];
57
58 /**
59 * @var string The prefix url parameter. Set on the searcher and the
60 * is expected to treat it as prefix filter on titles.
61 */
62 protected $mPrefix;
63
64 /**
65 * @var int
66 */
67 protected $limit, $offset;
68
69 /**
70 * @var array
71 */
72 protected $namespaces;
73
74 /**
75 * @var string
76 */
77 protected $fulltext;
78
79 /**
80 * @var string
81 */
82 protected $sort;
83
84 /**
85 * @var bool
86 */
87 protected $runSuggestion = true;
88
89 /**
90 * Search engine configurations.
91 * @var SearchEngineConfig
92 */
93 protected $searchConfig;
94
95 const NAMESPACES_CURRENT = 'sense';
96
97 public function __construct() {
98 parent::__construct( 'Search' );
99 $this->searchConfig = MediaWikiServices::getInstance()->getSearchEngineConfig();
100 }
101
102 /**
103 * Entry point
104 *
105 * @param string|null $par
106 */
107 public function execute( $par ) {
108 $request = $this->getRequest();
109 $out = $this->getOutput();
110
111 // Fetch the search term
112 $term = str_replace( "\n", " ", $request->getText( 'search' ) );
113
114 // Historically search terms have been accepted not only in the search query
115 // parameter, but also as part of the primary url. This can have PII implications
116 // in releasing page view data. As such issue a 301 redirect to the correct
117 // URL.
118 if ( $par !== null && $par !== '' && $term === '' ) {
119 $query = $request->getValues();
120 unset( $query['title'] );
121 // Strip underscores from title parameter; most of the time we'll want
122 // text form here. But don't strip underscores from actual text params!
123 $query['search'] = str_replace( '_', ' ', $par );
124 $out->redirect( $this->getPageTitle()->getFullURL( $query ), 301 );
125 return;
126 }
127
128 // Need to load selected namespaces before handling nsRemember
129 $this->load();
130 // TODO: This performs database actions on GET request, which is going to
131 // be a problem for our multi-datacenter work.
132 if ( $request->getCheck( 'nsRemember' ) ) {
133 $this->saveNamespaces();
134 // Remove the token from the URL to prevent the user from inadvertently
135 // exposing it (e.g. by pasting it into a public wiki page) or undoing
136 // later settings changes (e.g. by reloading the page).
137 $query = $request->getValues();
138 unset( $query['title'], $query['nsRemember'] );
139 $out->redirect( $this->getPageTitle()->getFullURL( $query ) );
140 return;
141 }
142
143 $this->searchEngineType = $request->getVal( 'srbackend' );
144 if ( !$request->getVal( 'fulltext' ) && !$request->getCheck( 'offset' ) ) {
145 $url = $this->goResult( $term );
146 if ( $url !== null ) {
147 // successful 'go'
148 $out->redirect( $url );
149 return;
150 }
151 // No match. If it could plausibly be a title
152 // run the No go match hook.
153 $title = Title::newFromText( $term );
154 if ( !is_null( $title ) ) {
155 Hooks::run( 'SpecialSearchNogomatch', [ &$title ] );
156 }
157 }
158
159 $this->setupPage( $term );
160
161 if ( $this->getConfig()->get( 'DisableTextSearch' ) ) {
162 $searchForwardUrl = $this->getConfig()->get( 'SearchForwardUrl' );
163 if ( $searchForwardUrl ) {
164 $url = str_replace( '$1', urlencode( $term ), $searchForwardUrl );
165 $out->redirect( $url );
166 } else {
167 $this->showGoogleSearch( $term );
168 }
169
170 return;
171 }
172
173 $this->showResults( $term );
174 }
175
176 /**
177 * Output a google search form if search is disabled
178 *
179 * @param string $term Search term
180 * @todo FIXME Maybe we should get rid of this raw html message at some future time
181 * @suppress SecurityCheck-XSS
182 */
183 private function showGoogleSearch( $term ) {
184 $this->getOutput()->addHTML(
185 "<fieldset>" .
186 "<legend>" .
187 $this->msg( 'search-external' )->escaped() .
188 "</legend>" .
189 "<p class='mw-searchdisabled'>" .
190 $this->msg( 'searchdisabled' )->escaped() .
191 "</p>" .
192 $this->msg( 'googlesearch' )->rawParams(
193 htmlspecialchars( $term ),
194 'UTF-8',
195 $this->msg( 'searchbutton' )->escaped()
196 )->text() .
197 "</fieldset>"
198 );
199 }
200
201 /**
202 * Set up basic search parameters from the request and user settings.
203 *
204 * @see tests/phpunit/includes/specials/SpecialSearchTest.php
205 */
206 public function load() {
207 $request = $this->getRequest();
208 list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, '' );
209 $this->mPrefix = $request->getVal( 'prefix', '' );
210 if ( $this->mPrefix !== '' ) {
211 $this->setExtraParam( 'prefix', $this->mPrefix );
212 }
213
214 $this->sort = $request->getVal( 'sort', SearchEngine::DEFAULT_SORT );
215 if ( $this->sort !== SearchEngine::DEFAULT_SORT ) {
216 $this->setExtraParam( 'sort', $this->sort );
217 }
218
219 $user = $this->getUser();
220
221 # Extract manually requested namespaces
222 $nslist = $this->powerSearch( $request );
223 if ( $nslist === [] ) {
224 # Fallback to user preference
225 $nslist = $this->searchConfig->userNamespaces( $user );
226 }
227
228 $profile = null;
229 if ( $nslist === [] ) {
230 $profile = 'default';
231 }
232
233 $profile = $request->getVal( 'profile', $profile );
234 $profiles = $this->getSearchProfiles();
235 if ( $profile === null ) {
236 // BC with old request format
237 $profile = 'advanced';
238 foreach ( $profiles as $key => $data ) {
239 if ( $nslist === $data['namespaces'] && $key !== 'advanced' ) {
240 $profile = $key;
241 }
242 }
243 $this->namespaces = $nslist;
244 } elseif ( $profile === 'advanced' ) {
245 $this->namespaces = $nslist;
246 } elseif ( isset( $profiles[$profile]['namespaces'] ) ) {
247 $this->namespaces = $profiles[$profile]['namespaces'];
248 } else {
249 // Unknown profile requested
250 $profile = 'default';
251 $this->namespaces = $profiles['default']['namespaces'];
252 }
253
254 $this->fulltext = $request->getVal( 'fulltext' );
255 $this->runSuggestion = (bool)$request->getVal( 'runsuggestion', true );
256 $this->profile = $profile;
257 }
258
259 /**
260 * If an exact title match can be found, jump straight ahead to it.
261 *
262 * @param string $term
263 * @return string|null The url to redirect to, or null if no redirect.
264 */
265 public function goResult( $term ) {
266 # If the string cannot be used to create a title
267 if ( is_null( Title::newFromText( $term ) ) ) {
268 return null;
269 }
270 # If there's an exact or very near match, jump right there.
271 $title = $this->getSearchEngine()
272 ->getNearMatcher( $this->getConfig() )->getNearMatch( $term );
273 if ( is_null( $title ) ) {
274 return null;
275 }
276 $url = null;
277 if ( !Hooks::run( 'SpecialSearchGoResult', [ $term, $title, &$url ] ) ) {
278 return null;
279 }
280
281 return $url ?? $title->getFullUrlForRedirect();
282 }
283
284 /**
285 * @param string $term
286 */
287 public function showResults( $term ) {
288 if ( $this->searchEngineType !== null ) {
289 $this->setExtraParam( 'srbackend', $this->searchEngineType );
290 }
291
292 $out = $this->getOutput();
293 $widgetOptions = $this->getConfig()->get( 'SpecialSearchFormOptions' );
294 $formWidget = new MediaWiki\Widget\Search\SearchFormWidget(
295 $this,
296 $this->searchConfig,
297 $this->getSearchProfiles()
298 );
299 $filePrefix = MediaWikiServices::getInstance()->getContentLanguage()->
300 getFormattedNsText( NS_FILE ) . ':';
301 if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
302 // Empty query -- straight view of search form
303 if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
304 # Hook requested termination
305 return;
306 }
307 $out->enableOOUI();
308 // The form also contains the 'Showing results 0 - 20 of 1234' so we can
309 // only do the form render here for the empty $term case. Rendering
310 // the form when a search is provided is repeated below.
311 $out->addHTML( $formWidget->render(
312 $this->profile, $term, 0, 0, $this->offset, $this->isPowerSearch(), $widgetOptions
313 ) );
314 return;
315 }
316
317 $engine = $this->getSearchEngine();
318 $engine->setFeatureData( 'rewrite', $this->runSuggestion );
319 $engine->setLimitOffset( $this->limit, $this->offset );
320 $engine->setNamespaces( $this->namespaces );
321 $engine->setSort( $this->sort );
322 $engine->prefix = $this->mPrefix;
323
324 Hooks::run( 'SpecialSearchSetupEngine', [ $this, $this->profile, $engine ] );
325 if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
326 # Hook requested termination
327 return;
328 }
329
330 $title = Title::newFromText( $term );
331 $showSuggestion = $title === null || !$title->isKnown();
332 $engine->setShowSuggestion( $showSuggestion );
333
334 $rewritten = $engine->replacePrefixes( $term );
335 if ( $rewritten !== $term ) {
336 wfDeprecated( 'SearchEngine::replacePrefixes() (overridden by ' .
337 get_class( $engine ) . ')', '1.32' );
338 }
339
340 // fetch search results
341 $titleMatches = $engine->searchTitle( $rewritten );
342 $textMatches = $engine->searchText( $rewritten );
343
344 $textStatus = null;
345 if ( $textMatches instanceof Status ) {
346 $textStatus = $textMatches;
347 $textMatches = $textStatus->getValue();
348 }
349
350 // Get number of results
351 $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
352 if ( $titleMatches ) {
353 $titleMatchesNum = $titleMatches->numRows();
354 $numTitleMatches = $titleMatches->getTotalHits();
355 }
356 if ( $textMatches ) {
357 $textMatchesNum = $textMatches->numRows();
358 $numTextMatches = $textMatches->getTotalHits();
359 if ( $textMatchesNum > 0 ) {
360 $engine->augmentSearchResults( $textMatches );
361 }
362 }
363 $num = $titleMatchesNum + $textMatchesNum;
364 $totalRes = $numTitleMatches + $numTextMatches;
365
366 // start rendering the page
367 $out->enableOOUI();
368 $out->addHTML( $formWidget->render(
369 $this->profile, $term, $num, $totalRes, $this->offset, $this->isPowerSearch(), $widgetOptions
370 ) );
371
372 // did you mean... suggestions
373 if ( $textMatches ) {
374 $dymWidget = new MediaWiki\Widget\Search\DidYouMeanWidget( $this );
375 $out->addHTML( $dymWidget->render( $term, $textMatches ) );
376 }
377
378 $hasErrors = $textStatus && $textStatus->getErrors() !== [];
379 $hasOtherResults = $textMatches &&
380 $textMatches->hasInterwikiResults( ISearchResultSet::INLINE_RESULTS );
381
382 if ( $textMatches && $textMatches->hasInterwikiResults( ISearchResultSet::SECONDARY_RESULTS ) ) {
383 $out->addHTML( '<div class="searchresults mw-searchresults-has-iw">' );
384 } else {
385 $out->addHTML( '<div class="searchresults">' );
386 }
387
388 if ( $hasErrors ) {
389 list( $error, $warning ) = $textStatus->splitByErrorType();
390 if ( $error->getErrors() ) {
391 $out->addHTML( Html::errorBox(
392 $error->getHTML( 'search-error' )
393 ) );
394 }
395 if ( $warning->getErrors() ) {
396 $out->addHTML( Html::warningBox(
397 $warning->getHTML( 'search-warning' )
398 ) );
399 }
400 }
401
402 // Show the create link ahead
403 $this->showCreateLink( $title, $num, $titleMatches, $textMatches );
404
405 Hooks::run( 'SpecialSearchResults', [ $term, &$titleMatches, &$textMatches ] );
406
407 // If we have no results and have not already displayed an error message
408 if ( $num === 0 && !$hasErrors ) {
409 $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>", [
410 $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound',
411 wfEscapeWikiText( $term )
412 ] );
413 }
414
415 // Although $num might be 0 there can still be secondary or inline
416 // results to display.
417 $linkRenderer = $this->getLinkRenderer();
418 $mainResultWidget = new FullSearchResultWidget( $this, $linkRenderer );
419
420 // Default (null) on. Can be explicitly disabled.
421 if ( $engine->getFeatureData( 'enable-new-crossproject-page' ) !== false ) {
422 $sidebarResultWidget = new InterwikiSearchResultWidget( $this, $linkRenderer );
423 $sidebarResultsWidget = new InterwikiSearchResultSetWidget(
424 $this,
425 $sidebarResultWidget,
426 $linkRenderer,
427 MediaWikiServices::getInstance()->getInterwikiLookup(),
428 $engine->getFeatureData( 'show-multimedia-search-results' )
429 );
430 } else {
431 $sidebarResultWidget = new SimpleSearchResultWidget( $this, $linkRenderer );
432 $sidebarResultsWidget = new SimpleSearchResultSetWidget(
433 $this,
434 $sidebarResultWidget,
435 $linkRenderer,
436 MediaWikiServices::getInstance()->getInterwikiLookup()
437 );
438 }
439
440 $widget = new BasicSearchResultSetWidget( $this, $mainResultWidget, $sidebarResultsWidget );
441
442 $out->addHTML( $widget->render(
443 $term, $this->offset, $titleMatches, $textMatches
444 ) );
445
446 $out->addHTML( '<div class="mw-search-visualclear"></div>' );
447
448 // prev/next links
449 if ( $totalRes > $this->limit || $this->offset ) {
450 // Allow matches to define the correct offset, as interleaved
451 // AB testing may require a different next page offset.
452 if ( $textMatches && $textMatches->getOffset() !== null ) {
453 $offset = $textMatches->getOffset();
454 } else {
455 $offset = $this->offset;
456 }
457
458 $prevNext = $this->buildPrevNextNavigation(
459 $offset,
460 $this->limit,
461 $this->powerSearchOptions() + [ 'search' => $term ],
462 $this->limit + $this->offset >= $totalRes
463 );
464 $out->addHTML( "<p class='mw-search-pager-bottom'>{$prevNext}</p>\n" );
465 }
466
467 // Close <div class='searchresults'>
468 $out->addHTML( "</div>" );
469
470 Hooks::run( 'SpecialSearchResultsAppend', [ $this, $out, $term ] );
471 }
472
473 /**
474 * @param Title $title
475 * @param int $num The number of search results found
476 * @param null|ISearchResultSet $titleMatches Results from title search
477 * @param null|ISearchResultSet $textMatches Results from text search
478 */
479 protected function showCreateLink( $title, $num, $titleMatches, $textMatches ) {
480 // show direct page/create link if applicable
481
482 // Check DBkey !== '' in case of fragment link only.
483 if ( is_null( $title ) || $title->getDBkey() === ''
484 || ( $titleMatches !== null && $titleMatches->searchContainedSyntax() )
485 || ( $textMatches !== null && $textMatches->searchContainedSyntax() )
486 ) {
487 // invalid title
488 // preserve the paragraph for margins etc...
489 $this->getOutput()->addHTML( '<p></p>' );
490
491 return;
492 }
493
494 $messageName = 'searchmenu-new-nocreate';
495 $linkClass = 'mw-search-createlink';
496
497 if ( !$title->isExternal() ) {
498 if ( $title->isKnown() ) {
499 $messageName = 'searchmenu-exists';
500 $linkClass = 'mw-search-exists';
501 } elseif ( ContentHandler::getForTitle( $title )->supportsDirectEditing()
502 && $title->quickUserCan( 'create', $this->getUser() )
503 ) {
504 $messageName = 'searchmenu-new';
505 }
506 }
507
508 $params = [
509 $messageName,
510 wfEscapeWikiText( $title->getPrefixedText() ),
511 Message::numParam( $num )
512 ];
513 Hooks::run( 'SpecialSearchCreateLink', [ $title, &$params ] );
514
515 // Extensions using the hook might still return an empty $messageName
516 if ( $messageName ) {
517 $this->getOutput()->wrapWikiMsg( "<p class=\"$linkClass\">\n$1</p>", $params );
518 } else {
519 // preserve the paragraph for margins etc...
520 $this->getOutput()->addHTML( '<p></p>' );
521 }
522 }
523
524 /**
525 * Sets up everything for the HTML output page including styles, javascript,
526 * page title, etc.
527 *
528 * @param string $term
529 */
530 protected function setupPage( $term ) {
531 $out = $this->getOutput();
532
533 $this->setHeaders();
534 $this->outputHeader();
535 // TODO: Is this true? The namespace remember uses a user token
536 // on save.
537 $out->allowClickjacking();
538 $this->addHelpLink( 'Help:Searching' );
539
540 if ( strval( $term ) !== '' ) {
541 $out->setPageTitle( $this->msg( 'searchresults' ) );
542 $out->setHTMLTitle( $this->msg( 'pagetitle' )
543 ->plaintextParams( $this->msg( 'searchresults-title' )->plaintextParams( $term )->text() )
544 ->inContentLanguage()->text()
545 );
546 }
547
548 if ( $this->mPrefix !== '' ) {
549 $subtitle = $this->msg( 'search-filter-title-prefix' )->plaintextParams( $this->mPrefix );
550 $params = $this->powerSearchOptions();
551 unset( $params['prefix'] );
552 $params += [
553 'search' => $term,
554 'fulltext' => 1,
555 ];
556
557 $subtitle .= ' (';
558 $subtitle .= Xml::element(
559 'a',
560 [
561 'href' => $this->getPageTitle()->getLocalURL( $params ),
562 'title' => $this->msg( 'search-filter-title-prefix-reset' )->text(),
563 ],
564 $this->msg( 'search-filter-title-prefix-reset' )->text()
565 );
566 $subtitle .= ')';
567 $out->setSubtitle( $subtitle );
568 }
569
570 $out->addJsConfigVars( [ 'searchTerm' => $term ] );
571 $out->addModules( 'mediawiki.special.search' );
572 $out->addModuleStyles( [
573 'mediawiki.special', 'mediawiki.special.search.styles', 'mediawiki.ui', 'mediawiki.ui.button',
574 'mediawiki.ui.input', 'mediawiki.widgets.SearchInputWidget.styles',
575 ] );
576 }
577
578 /**
579 * Return true if current search is a power (advanced) search
580 *
581 * @return bool
582 */
583 protected function isPowerSearch() {
584 return $this->profile === 'advanced';
585 }
586
587 /**
588 * Extract "power search" namespace settings from the request object,
589 * returning a list of index numbers to search.
590 *
591 * @param WebRequest &$request
592 * @return array
593 */
594 protected function powerSearch( &$request ) {
595 $arr = [];
596 foreach ( $this->searchConfig->searchableNamespaces() as $ns => $name ) {
597 if ( $request->getCheck( 'ns' . $ns ) ) {
598 $arr[] = $ns;
599 }
600 }
601
602 return $arr;
603 }
604
605 /**
606 * Reconstruct the 'power search' options for links
607 * TODO: Instead of exposing this publicly, could we instead expose
608 * a function for creating search links?
609 *
610 * @return array
611 */
612 public function powerSearchOptions() {
613 $opt = [];
614 if ( $this->isPowerSearch() ) {
615 foreach ( $this->namespaces as $n ) {
616 $opt['ns' . $n] = 1;
617 }
618 } else {
619 $opt['profile'] = $this->profile;
620 }
621
622 return $opt + $this->extraParams;
623 }
624
625 /**
626 * Save namespace preferences when we're supposed to
627 *
628 * @return bool Whether we wrote something
629 */
630 protected function saveNamespaces() {
631 $user = $this->getUser();
632 $request = $this->getRequest();
633
634 if ( $user->isLoggedIn() &&
635 $user->matchEditToken(
636 $request->getVal( 'nsRemember' ),
637 'searchnamespace',
638 $request
639 ) && !wfReadOnly()
640 ) {
641 // Reset namespace preferences: namespaces are not searched
642 // when they're not mentioned in the URL parameters.
643 foreach ( MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces()
644 as $n
645 ) {
646 $user->setOption( 'searchNs' . $n, false );
647 }
648 // The request parameters include all the namespaces to be searched.
649 // Even if they're the same as an existing profile, they're not eaten.
650 foreach ( $this->namespaces as $n ) {
651 $user->setOption( 'searchNs' . $n, true );
652 }
653
654 DeferredUpdates::addCallableUpdate( function () use ( $user ) {
655 $user->saveSettings();
656 } );
657
658 return true;
659 }
660
661 return false;
662 }
663
664 /**
665 * @return array
666 */
667 protected function getSearchProfiles() {
668 // Builds list of Search Types (profiles)
669 $nsAllSet = array_keys( $this->searchConfig->searchableNamespaces() );
670 $defaultNs = $this->searchConfig->defaultNamespaces();
671 $profiles = [
672 'default' => [
673 'message' => 'searchprofile-articles',
674 'tooltip' => 'searchprofile-articles-tooltip',
675 'namespaces' => $defaultNs,
676 'namespace-messages' => $this->searchConfig->namespacesAsText(
677 $defaultNs
678 ),
679 ],
680 'images' => [
681 'message' => 'searchprofile-images',
682 'tooltip' => 'searchprofile-images-tooltip',
683 'namespaces' => [ NS_FILE ],
684 ],
685 'all' => [
686 'message' => 'searchprofile-everything',
687 'tooltip' => 'searchprofile-everything-tooltip',
688 'namespaces' => $nsAllSet,
689 ],
690 'advanced' => [
691 'message' => 'searchprofile-advanced',
692 'tooltip' => 'searchprofile-advanced-tooltip',
693 'namespaces' => self::NAMESPACES_CURRENT,
694 ]
695 ];
696
697 Hooks::run( 'SpecialSearchProfiles', [ &$profiles ] );
698
699 foreach ( $profiles as &$data ) {
700 if ( !is_array( $data['namespaces'] ) ) {
701 continue;
702 }
703 sort( $data['namespaces'] );
704 }
705
706 return $profiles;
707 }
708
709 /**
710 * @since 1.18
711 *
712 * @return SearchEngine
713 */
714 public function getSearchEngine() {
715 if ( $this->searchEngine === null ) {
716 $services = MediaWikiServices::getInstance();
717 $this->searchEngine = $this->searchEngineType ?
718 $services->getSearchEngineFactory()->create( $this->searchEngineType ) :
719 $services->newSearchEngine();
720 }
721
722 return $this->searchEngine;
723 }
724
725 /**
726 * Current search profile.
727 * @return null|string
728 */
729 function getProfile() {
730 return $this->profile;
731 }
732
733 /**
734 * Current namespaces.
735 * @return array
736 */
737 function getNamespaces() {
738 return $this->namespaces;
739 }
740
741 /**
742 * Users of hook SpecialSearchSetupEngine can use this to
743 * add more params to links to not lose selection when
744 * user navigates search results.
745 * @since 1.18
746 *
747 * @param string $key
748 * @param mixed $value
749 */
750 public function setExtraParam( $key, $value ) {
751 $this->extraParams[$key] = $value;
752 }
753
754 /**
755 * The prefix value send to Special:Search using the 'prefix' URI param
756 * It means that the user is willing to search for pages whose titles start with
757 * this prefix value.
758 * (Used by the InputBox extension)
759 *
760 * @return string
761 */
762 public function getPrefix() {
763 return $this->mPrefix;
764 }
765
766 protected function getGroupName() {
767 return 'pages';
768 }
769 }