262 $this->loadStatus =
new Status();
265 $this->searchEngineType = $request->getVal(
'srbackend' );
267 list( $this->limit, $this->offset ) = $request->getLimitOffsetForUser(
272 $this->mPrefix = $request->getVal(
'prefix',
'' );
273 if ( $this->mPrefix !==
'' ) {
277 $sort = $request->getVal(
'sort', SearchEngine::DEFAULT_SORT );
279 if ( !in_array(
$sort, $validSorts ) ) {
280 $this->loadStatus->warning(
'search-invalid-sort-order',
$sort,
281 implode(
', ', $validSorts ) );
282 } elseif (
$sort !== $this->sort ) {
289 # Extract manually requested namespaces
291 if ( $nslist === [] ) {
292 # Fallback to user preference
293 $nslist = $this->searchConfig->userNamespaces( $user );
297 if ( $nslist === [] ) {
306 foreach ( $profiles as $key => $data ) {
307 if ( $nslist === $data[
'namespaces'] && $key !==
'advanced' ) {
311 $this->namespaces = $nslist;
312 } elseif (
$profile ===
'advanced' ) {
313 $this->namespaces = $nslist;
314 } elseif ( isset( $profiles[
$profile][
'namespaces'] ) ) {
315 $this->namespaces = $profiles[$profile][
'namespaces'];
318 $this->loadStatus->warning(
'search-unknown-profile', $profile );
319 $profile =
'default';
320 $this->namespaces = $profiles[
'default'][
'namespaces'];
323 $this->fulltext = $request->getVal(
'fulltext' );
324 $this->runSuggestion = (bool)$request->getVal(
'runsuggestion',
true );
325 $this->profile = $profile;
383 if ( $this->searchEngineType !==
null ) {
384 $this->
setExtraParam(
'srbackend', $this->searchEngineType );
388 $widgetOptions = $this->
getConfig()->get(
'SpecialSearchFormOptions' );
393 $this->languageConverterFactory->getLanguageConverter( $this->getLanguage() ),
395 $this->getSearchProfiles()
398 if ( trim( $term ) ===
'' || $filePrefix === trim( $term ) ) {
400 if ( !$this->
getHookRunner()->onSpecialSearchResultsPrepend( $this, $out, $term ) ) {
401 # Hook requested termination
408 $out->addHTML( $formWidget->render(
409 $this->profile, $term, 0, 0, $this->offset, $this->isPowerSearch(), $widgetOptions
415 $engine->setFeatureData(
'rewrite', $this->runSuggestion );
416 $engine->setLimitOffset( $this->limit, $this->offset );
417 $engine->setNamespaces( $this->namespaces );
418 $engine->setSort( $this->sort );
419 $engine->prefix = $this->mPrefix;
421 $this->
getHookRunner()->onSpecialSearchSetupEngine( $this, $this->profile, $engine );
422 if ( !$this->
getHookRunner()->onSpecialSearchResultsPrepend( $this, $out, $term ) ) {
423 # Hook requested termination
427 $title = Title::newFromText( $term );
428 $languageConverter = $this->languageConverterFactory->getLanguageConverter( $this->
getContentLanguage() );
429 if ( $languageConverter->hasVariants() ) {
432 $variantTerm = $term;
433 $languageConverter->findVariantLink( $variantTerm,
$title );
436 $showSuggestion =
$title ===
null || !
$title->isKnown();
437 $engine->setShowSuggestion( $showSuggestion );
439 $rewritten = $engine->replacePrefixes( $term );
440 if ( $rewritten !== $term ) {
441 wfDeprecatedMsg(
'SearchEngine::replacePrefixes() was overridden by ' .
442 get_class( $engine ) .
', this is deprecated since MediaWiki 1.32',
443 '1.32',
false,
false );
447 $titleMatches = $engine->searchTitle( $rewritten );
448 $textMatches = $engine->searchText( $rewritten );
451 if ( $textMatches instanceof
Status ) {
452 $textStatus = $textMatches;
453 $textMatches = $textStatus->getValue();
457 $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
458 if ( $titleMatches ) {
459 $titleMatchesNum = $titleMatches->numRows();
460 $numTitleMatches = $titleMatches->getTotalHits();
462 if ( $textMatches ) {
463 $textMatchesNum = $textMatches->numRows();
464 $numTextMatches = $textMatches->getTotalHits();
465 if ( $textMatchesNum > 0 ) {
466 $engine->augmentSearchResults( $textMatches );
469 $num = $titleMatchesNum + $textMatchesNum;
470 $totalRes = $numTitleMatches + $numTextMatches;
474 $out->addHTML( $formWidget->render(
475 $this->profile, $term, $num, $totalRes, $this->offset, $this->isPowerSearch(), $widgetOptions
479 if ( $textMatches ) {
481 $out->addHTML( $dymWidget->render( $term, $textMatches ) );
484 $hasSearchErrors = $textStatus && $textStatus->getErrors() !== [];
485 $hasOtherResults = $textMatches &&
486 $textMatches->hasInterwikiResults( ISearchResultSet::INLINE_RESULTS );
488 if ( $textMatches && $textMatches->hasInterwikiResults( ISearchResultSet::SECONDARY_RESULTS ) ) {
489 $out->addHTML(
'<div class="searchresults mw-searchresults-has-iw">' );
491 $out->addHTML(
'<div class="searchresults">' );
494 if ( $hasSearchErrors || $this->loadStatus->getErrors() ) {
495 if ( $textStatus ===
null ) {
496 $textStatus = $this->loadStatus;
498 $textStatus->merge( $this->loadStatus );
500 list( $error, $warning ) = $textStatus->splitByErrorType();
501 if ( $error->getErrors() ) {
502 $out->addHTML( Html::errorBox(
503 $error->getHTML(
'search-error' )
506 if ( $warning->getErrors() ) {
507 $out->addHTML( Html::warningBox(
508 $warning->getHTML(
'search-warning' )
516 $this->
getHookRunner()->onSpecialSearchResults( $term, $titleMatches, $textMatches );
519 if ( $num === 0 && !$hasSearchErrors ) {
520 $out->wrapWikiMsg(
"<p class=\"mw-search-nonefound\">\n$1</p>", [
521 $hasOtherResults ?
'search-nonefound-thiswiki' :
'search-nonefound',
534 if ( $engine->getFeatureData(
'enable-new-crossproject-page' ) !==
false ) {
538 $sidebarResultWidget,
540 $this->interwikiLookup,
541 $engine->getFeatureData(
'show-multimedia-search-results' )
547 $sidebarResultWidget,
549 $this->interwikiLookup
555 $out->addHTML( $widget->render(
556 $term, $this->offset, $titleMatches, $textMatches
559 $out->addHTML(
'<div class="mw-search-visualclear"></div>' );
560 $this->
prevNextLinks( $totalRes, $textMatches, $term, $out );
563 $out->addHTML(
"</div>" );
565 $this->
getHookRunner()->onSpecialSearchResultsAppend( $this, $out, $term );