366 if ( $this->searchEngineType !==
null ) {
367 $this->setExtraParam(
'srbackend', $this->searchEngineType );
370 $out = $this->getOutput();
379 $this->getHookContainer(),
380 $this->languageConverterFactory->getLanguageConverter( $this->getLanguage() ),
382 $this->getSearchProfiles()
384 $filePrefix = $this->getContentLanguage()->getFormattedNsText(
NS_FILE ) .
':';
385 if ( trim( $term ) ===
'' || $filePrefix === trim( $term ) ) {
387 if ( !$this->getHookRunner()->onSpecialSearchResultsPrepend( $this, $out, $term ) ) {
388 # Hook requested termination
395 $out->
addHTML( $formWidget->render(
396 $this->profile, $term, 0, 0,
false, $this->offset, $this->isPowerSearch(), $widgetOptions
401 $engine = $this->getSearchEngine();
402 $engine->setFeatureData(
'rewrite', $this->runSuggestion );
403 $engine->setLimitOffset( $this->limit, $this->offset );
404 $engine->setNamespaces( $this->namespaces );
405 $engine->setSort( $this->sort );
406 $engine->prefix = $this->mPrefix;
408 $this->getHookRunner()->onSpecialSearchSetupEngine( $this, $this->profile, $engine );
409 if ( !$this->getHookRunner()->onSpecialSearchResultsPrepend( $this, $out, $term ) ) {
410 # Hook requested termination
414 $title = Title::newFromText( $term );
415 $languageConverter = $this->languageConverterFactory->getLanguageConverter( $this->getContentLanguage() );
416 if ( $languageConverter->hasVariants() ) {
419 $variantTerm = $term;
420 $languageConverter->findVariantLink( $variantTerm, $title );
423 $showSuggestion = $title ===
null || !$title->isKnown();
424 $engine->setShowSuggestion( $showSuggestion );
426 $rewritten = $engine->replacePrefixes( $term );
427 if ( $rewritten !== $term ) {
428 wfDeprecatedMsg(
'SearchEngine::replacePrefixes() was overridden by ' .
429 get_class( $engine ) .
', this is deprecated since MediaWiki 1.32',
430 '1.32',
false,
false );
434 $titleMatches = $engine->searchTitle( $rewritten );
435 $textMatches = $engine->searchText( $rewritten );
438 if ( $textMatches instanceof
Status ) {
439 $textStatus = $textMatches;
440 $textMatches = $textStatus->getValue();
444 $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
445 $approxTotalRes =
false;
446 if ( $titleMatches ) {
447 $titleMatchesNum = $titleMatches->
numRows();
448 $numTitleMatches = $titleMatches->getTotalHits();
449 $approxTotalRes = $titleMatches->isApproximateTotalHits();
451 if ( $textMatches ) {
452 $textMatchesNum = $textMatches->
numRows();
455 if ( $textMatchesNum > 0 ) {
456 $engine->augmentSearchResults( $textMatches );
459 $num = $titleMatchesNum + $textMatchesNum;
460 $totalRes = $numTitleMatches + $numTextMatches;
464 $out->
addHTML( $formWidget->render(
465 $this->profile, $term, $num, $totalRes, $approxTotalRes, $this->offset, $this->isPowerSearch(),
470 if ( $textMatches ) {
472 $out->
addHTML( $dymWidget->render( $term, $textMatches ) );
475 $hasSearchErrors = $textStatus && $textStatus->getMessages() !== [];
476 $hasInlineIwResults = $textMatches &&
478 $hasSecondaryIwResults = $textMatches &&
481 $classNames = [
'searchresults' ];
482 if ( $hasSecondaryIwResults ) {
483 $classNames[] =
'mw-searchresults-has-iw';
485 if ( $this->offset > 0 ) {
486 $classNames[] =
'mw-searchresults-has-offset';
488 $out->
addHTML( Html::openElement(
'div', [
'class' => $classNames ] ) );
490 $out->
addHTML(
'<div class="mw-search-results-info">' );
492 if ( $hasSearchErrors || $this->loadStatus->getMessages() ) {
493 if ( $textStatus ===
null ) {
494 $textStatus = $this->loadStatus;
496 $textStatus->merge( $this->loadStatus );
498 [ $error, $warning ] = $textStatus->splitByErrorType();
499 if ( $error->getMessages() ) {
501 $error->getHTML(
'search-error' )
504 if ( $warning->getMessages() ) {
505 $out->
addHTML( Html::warningBox(
506 $warning->getHTML(
'search-warning' )
512 if ( $num === 0 && !$hasSearchErrors ) {
513 $out->
wrapWikiMsg(
"<p class=\"mw-search-nonefound\">\n$1</p>", [
514 $hasInlineIwResults ?
'search-nonefound-thiswiki' :
'search-nonefound',
521 $this->showCreateLink( $title, $num, $titleMatches, $textMatches );
523 $this->getHookRunner()->onSpecialSearchResults( $term, $titleMatches, $textMatches );
530 $linkRenderer = $this->getLinkRenderer();
534 $this->getHookContainer(),
536 $this->thumbnailProvider,
537 $this->userOptionsManager
543 $sidebarResultWidget,
545 $this->interwikiLookup,
546 $engine->getFeatureData(
'show-multimedia-search-results' )
551 $out->
addHTML(
'<div class="mw-search-visualclear"></div>' );
552 $this->prevNextLinks( $totalRes, $textMatches, $term,
'mw-search-pager-top', $out );
554 $out->
addHTML( $widget->render(
555 $term, $this->offset, $titleMatches, $textMatches
558 $out->
addHTML(
'<div class="mw-search-visualclear"></div>' );
559 $this->prevNextLinks( $totalRes, $textMatches, $term,
'mw-search-pager-bottom', $out );
564 $this->getHookRunner()->onSpecialSearchResultsAppend( $this, $out, $term );