213 $this->loadStatus =
new Status();
216 list( $this->limit, $this->offset ) = $request->getLimitOffset( 20,
'' );
217 $this->mPrefix = $request->getVal(
'prefix',
'' );
218 if ( $this->mPrefix !==
'' ) {
222 $sort = $request->getVal(
'sort', SearchEngine::DEFAULT_SORT );
224 if ( !in_array(
$sort, $validSorts ) ) {
225 $this->loadStatus->warning(
'search-invalid-sort-order',
$sort,
226 implode(
', ', $validSorts ) );
227 } elseif (
$sort !== $this->sort ) {
234 # Extract manually requested namespaces
236 if ( $nslist === [] ) {
237 # Fallback to user preference
238 $nslist = $this->searchConfig->userNamespaces( $user );
242 if ( $nslist === [] ) {
251 foreach ( $profiles as $key => $data ) {
252 if ( $nslist === $data[
'namespaces'] && $key !==
'advanced' ) {
256 $this->namespaces = $nslist;
257 } elseif (
$profile ===
'advanced' ) {
258 $this->namespaces = $nslist;
259 } elseif ( isset( $profiles[
$profile][
'namespaces'] ) ) {
260 $this->namespaces = $profiles[$profile][
'namespaces'];
263 $this->loadStatus->warning(
'search-unknown-profile', $profile );
264 $profile =
'default';
265 $this->namespaces = $profiles[
'default'][
'namespaces'];
268 $this->fulltext = $request->getVal(
'fulltext' );
269 $this->runSuggestion = (bool)$request->getVal(
'runsuggestion',
true );
270 $this->profile = $profile;
302 if ( $this->searchEngineType !==
null ) {
303 $this->
setExtraParam(
'srbackend', $this->searchEngineType );
307 $widgetOptions = $this->
getConfig()->get(
'SpecialSearchFormOptions' );
313 $filePrefix = MediaWikiServices::getInstance()->getContentLanguage()->
314 getFormattedNsText(
NS_FILE ) .
':';
315 if ( trim( $term ) ===
'' || $filePrefix === trim( $term ) ) {
317 if ( !Hooks::run(
'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
318 # Hook requested termination
325 $out->addHTML( $formWidget->render(
326 $this->profile, $term, 0, 0, $this->offset, $this->isPowerSearch(), $widgetOptions
332 $engine->setFeatureData(
'rewrite', $this->runSuggestion );
333 $engine->setLimitOffset( $this->limit, $this->offset );
334 $engine->setNamespaces( $this->namespaces );
335 $engine->setSort( $this->sort );
336 $engine->prefix = $this->mPrefix;
338 Hooks::run(
'SpecialSearchSetupEngine', [ $this, $this->profile, $engine ] );
339 if ( !Hooks::run(
'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
340 # Hook requested termination
344 $title = Title::newFromText( $term );
345 $showSuggestion =
$title ===
null || !
$title->isKnown();
346 $engine->setShowSuggestion( $showSuggestion );
348 $rewritten = $engine->replacePrefixes( $term );
349 if ( $rewritten !== $term ) {
350 wfDeprecated(
'SearchEngine::replacePrefixes() (overridden by ' .
351 get_class( $engine ) .
')',
'1.32' );
355 $titleMatches = $engine->searchTitle( $rewritten );
356 $textMatches = $engine->searchText( $rewritten );
359 if ( $textMatches instanceof
Status ) {
360 $textStatus = $textMatches;
361 $textMatches = $textStatus->getValue();
365 $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
366 if ( $titleMatches ) {
367 $titleMatchesNum = $titleMatches->numRows();
368 $numTitleMatches = $titleMatches->getTotalHits();
370 if ( $textMatches ) {
371 $textMatchesNum = $textMatches->numRows();
372 $numTextMatches = $textMatches->getTotalHits();
373 if ( $textMatchesNum > 0 ) {
374 $engine->augmentSearchResults( $textMatches );
377 $num = $titleMatchesNum + $textMatchesNum;
378 $totalRes = $numTitleMatches + $numTextMatches;
382 $out->addHTML( $formWidget->render(
383 $this->profile, $term, $num, $totalRes, $this->offset, $this->isPowerSearch(), $widgetOptions
387 if ( $textMatches ) {
389 $out->addHTML( $dymWidget->render( $term, $textMatches ) );
392 $hasSearchErrors = $textStatus && $textStatus->getErrors() !== [];
393 $hasOtherResults = $textMatches &&
394 $textMatches->hasInterwikiResults( ISearchResultSet::INLINE_RESULTS );
396 if ( $textMatches && $textMatches->hasInterwikiResults( ISearchResultSet::SECONDARY_RESULTS ) ) {
397 $out->addHTML(
'<div class="searchresults mw-searchresults-has-iw">' );
399 $out->addHTML(
'<div class="searchresults">' );
402 if ( $hasSearchErrors || $this->loadStatus->getErrors() ) {
403 if ( $textStatus ===
null ) {
404 $textStatus = $this->loadStatus;
406 $textStatus->merge( $this->loadStatus );
408 list( $error, $warning ) = $textStatus->splitByErrorType();
409 if ( $error->getErrors() ) {
410 $out->addHTML( Html::errorBox(
411 $error->getHTML(
'search-error' )
414 if ( $warning->getErrors() ) {
415 $out->addHTML( Html::warningBox(
416 $warning->getHTML(
'search-warning' )
424 Hooks::run(
'SpecialSearchResults', [ $term, &$titleMatches, &$textMatches ] );
427 if ( $num === 0 && !$hasSearchErrors ) {
428 $out->wrapWikiMsg(
"<p class=\"mw-search-nonefound\">\n$1</p>", [
429 $hasOtherResults ?
'search-nonefound-thiswiki' :
'search-nonefound',
440 if ( $engine->getFeatureData(
'enable-new-crossproject-page' ) !==
false ) {
444 $sidebarResultWidget,
446 MediaWikiServices::getInstance()->getInterwikiLookup(),
447 $engine->getFeatureData(
'show-multimedia-search-results' )
453 $sidebarResultWidget,
455 MediaWikiServices::getInstance()->getInterwikiLookup()
461 $out->addHTML( $widget->render(
462 $term, $this->offset, $titleMatches, $textMatches
465 $out->addHTML(
'<div class="mw-search-visualclear"></div>' );
468 if ( $totalRes > $this->limit || $this->offset ) {
471 if ( $textMatches && $textMatches->getOffset() !==
null ) {
472 $offset = $textMatches->getOffset();
474 $offset = $this->offset;
481 $this->limit + $this->offset >= $totalRes
483 $out->addHTML(
"<p class='mw-search-pager-bottom'>{$prevNext}</p>\n" );
487 $out->addHTML(
"</div>" );
489 Hooks::run(
'SpecialSearchResultsAppend', [ $this, $out, $term ] );