From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/specials/SpecialSearch.php | 198 +++++++++++++++++++++--------------- 1 file changed, 116 insertions(+), 82 deletions(-) (limited to 'includes/specials/SpecialSearch.php') diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 6c401486..8609c740 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -42,6 +42,9 @@ class SpecialSearch extends SpecialPage { /// Search engine protected $searchEngine; + /// Search engine type, if not default + protected $searchEngineType; + /// For links protected $extraParams = array(); @@ -98,6 +101,8 @@ class SpecialSearch extends SpecialPage { $this->load(); + $this->searchEngineType = $request->getVal( 'srbackend' ); + if ( $request->getVal( 'fulltext' ) || !is_null( $request->getVal( 'offset' ) ) || !is_null( $request->getVal( 'searchx' ) ) ) @@ -137,7 +142,7 @@ class SpecialSearch extends SpecialPage { if ( $profile === null ) { // BC with old request format $profile = 'advanced'; - foreach( $profiles as $key => $data ) { + foreach ( $profiles as $key => $data ) { if ( $nslist === $data['namespaces'] && $key !== 'advanced' ) { $profile = $key; } @@ -173,7 +178,7 @@ class SpecialSearch extends SpecialPage { # Try to go to page as entered. $t = Title::newFromText( $term ); # If the string cannot be used to create a title - if( is_null( $t ) ) { + if ( is_null( $t ) ) { $this->showResults( $term ); return; } @@ -185,19 +190,19 @@ class SpecialSearch extends SpecialPage { return; } - if( !is_null( $t ) ) { + if ( !is_null( $t ) ) { $this->getOutput()->redirect( $t->getFullURL() ); return; } # No match, generate an edit URL $t = Title::newFromText( $term ); - if( !is_null( $t ) ) { + if ( !is_null( $t ) ) { global $wgGoToEdit; wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) ); wfDebugLog( 'nogomatch', $t->getText(), false ); # If the feature is enabled, go straight to the edit page - if( $wgGoToEdit ) { + if ( $wgGoToEdit ) { $this->getOutput()->redirect( $t->getFullURL( array( 'action' => 'edit' ) ) ); return; } @@ -253,18 +258,24 @@ class SpecialSearch extends SpecialPage { $rewritten = $search->replacePrefixes( $term ); $titleMatches = $search->searchTitle( $rewritten ); - if( !( $titleMatches instanceof SearchResultTooMany ) ) { + if ( !( $titleMatches instanceof SearchResultTooMany ) ) { $textMatches = $search->searchText( $rewritten ); } + $textStatus = null; + if ( $textMatches instanceof Status ) { + $textStatus = $textMatches; + $textMatches = null; + } + // did you mean... suggestions - if( $textMatches && $textMatches->hasSuggestion() ) { + if ( $textMatches && !$textStatus && $textMatches->hasSuggestion() ) { $st = SpecialPage::getTitleFor( 'Search' ); # mirror Go/Search behavior of original request .. $didYouMeanParams = array( 'search' => $textMatches->getSuggestionQuery() ); - if( $this->fulltext != null ) { + if ( $this->fulltext != null ) { $didYouMeanParams['fulltext'] = $this->fulltext; } @@ -275,7 +286,7 @@ class SpecialSearch extends SpecialPage { $suggestionSnippet = $textMatches->getSuggestionSnippet(); - if( $suggestionSnippet == '' ) { + if ( $suggestionSnippet == '' ) { $suggestionSnippet = null; } @@ -317,14 +328,14 @@ class SpecialSearch extends SpecialPage { ); // Sometimes the search engine knows there are too many hits - if( $titleMatches instanceof SearchResultTooMany ) { + if ( $titleMatches instanceof SearchResultTooMany ) { $out->wrapWikiMsg( "==$1==\n", 'toomanymatches' ); wfProfileOut( __METHOD__ ); return; } $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':'; - if( trim( $term ) === '' || $filePrefix === trim( $term ) ) { + if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) { $out->addHTML( $this->formHeader( $term, 0, 0 ) ); $out->addHtml( $this->getProfileForm( $this->profile, $term ) ); $out->addHTML( '' ); @@ -347,10 +358,12 @@ class SpecialSearch extends SpecialPage { // get total number of results if backend can calculate it $totalRes = 0; - if( $titleMatches && !is_null( $titleMatches->getTotalHits() ) ) + if ( $titleMatches && !is_null( $titleMatches->getTotalHits() ) ) { $totalRes += $titleMatches->getTotalHits(); - if( $textMatches && !is_null( $textMatches->getTotalHits() ) ) + } + if ( $textMatches && !is_null( $textMatches->getTotalHits() ) ) { $totalRes += $textMatches->getTotalHits(); + } // show number of results and current offset $out->addHTML( $this->formHeader( $term, $num, $totalRes ) ); @@ -360,7 +373,7 @@ class SpecialSearch extends SpecialPage { $out->addHtml( "
" ); // prev/next links - if( $num || $this->offset ) { + if ( $num || $this->offset ) { // Show the create link ahead $this->showCreateLink( $t ); $prevnext = $this->getLanguage()->viewPrevNext( $this->getTitle(), $this->offset, $this->limit, @@ -374,40 +387,46 @@ class SpecialSearch extends SpecialPage { } $out->parserOptions()->setEditSection( false ); - if( $titleMatches ) { - if( $numTitleMatches > 0 ) { + if ( $titleMatches ) { + if ( $numTitleMatches > 0 ) { $out->wrapWikiMsg( "==$1==\n", 'titlematches' ); $out->addHTML( $this->showMatches( $titleMatches ) ); } $titleMatches->free(); } - if( $textMatches ) { + if ( $textMatches && !$textStatus ) { // output appropriate heading - if( $numTextMatches > 0 && $numTitleMatches > 0 ) { + if ( $numTextMatches > 0 && $numTitleMatches > 0 ) { // if no title matches the heading is redundant $out->wrapWikiMsg( "==$1==\n", 'textmatches' ); - } elseif( $totalRes == 0 ) { + } elseif ( $totalRes == 0 ) { # Don't show the 'no text matches' if we received title matches # $out->wrapWikiMsg( "==$1==\n", 'notextmatches' ); } // show interwiki results if any - if( $textMatches->hasInterwikiResults() ) { + if ( $textMatches->hasInterwikiResults() ) { $out->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) ); } // show results - if( $numTextMatches > 0 ) { + if ( $numTextMatches > 0 ) { $out->addHTML( $this->showMatches( $textMatches ) ); } $textMatches->free(); } - if( $num === 0 ) { - $out->wrapWikiMsg( "

\n$1

", array( 'search-nonefound', wfEscapeWikiText( $term ) ) ); - $this->showCreateLink( $t ); + if ( $num === 0 ) { + if ( $textStatus ) { + $out->addHTML( '
' . + htmlspecialchars( $textStatus->getWikiText( 'search-error' ) ) . '
' ); + } else { + $out->wrapWikiMsg( "

\n$1

", + array( 'search-nonefound', wfEscapeWikiText( $term ) ) ); + $this->showCreateLink( $t ); + } } $out->addHtml( "
" ); - if( $num || $this->offset ) { + if ( $num || $this->offset ) { $out->addHTML( "

{$prevnext}

\n" ); } wfRunHooks( 'SpecialSearchResultsAppend', array( $this, $out, $term ) ); @@ -421,16 +440,16 @@ class SpecialSearch extends SpecialPage { // show direct page/create link if applicable // Check DBkey !== '' in case of fragment link only. - if( is_null( $t ) || $t->getDBkey() === '' ) { + if ( is_null( $t ) || $t->getDBkey() === '' ) { // invalid title // preserve the paragraph for margins etc... $this->getOutput()->addHtml( '

' ); return; } - if( $t->isKnown() ) { + if ( $t->isKnown() ) { $messageName = 'searchmenu-exists'; - } elseif( $t->userCan( 'create', $this->getUser() ) ) { + } elseif ( $t->userCan( 'create', $this->getUser() ) ) { $messageName = 'searchmenu-new'; } else { $messageName = 'searchmenu-new-nocreate'; @@ -439,7 +458,7 @@ class SpecialSearch extends SpecialPage { wfRunHooks( 'SpecialSearchCreateLink', array( $t, &$params ) ); // Extensions using the hook might still return an empty $messageName - if( $messageName ) { + if ( $messageName ) { $this->getOutput()->wrapWikiMsg( "

\n$1

", $params ); } else { // preserve the paragraph for margins etc... @@ -452,9 +471,9 @@ class SpecialSearch extends SpecialPage { */ protected function setupPage( $term ) { # Should advanced UI be used? - $this->searchAdvanced = ($this->profile === 'advanced'); + $this->searchAdvanced = ( $this->profile === 'advanced' ); $out = $this->getOutput(); - if( strval( $term ) !== '' ) { + if ( strval( $term ) !== '' ) { $out->setPageTitle( $this->msg( 'searchresults' ) ); $out->setHTMLTitle( $this->msg( 'pagetitle' )->rawParams( $this->msg( 'searchresults-title' )->rawParams( $term )->text() @@ -473,8 +492,8 @@ class SpecialSearch extends SpecialPage { */ protected function powerSearch( &$request ) { $arr = array(); - foreach( SearchEngine::searchableNamespaces() as $ns => $name ) { - if( $request->getCheck( 'ns' . $ns ) ) { + foreach ( SearchEngine::searchableNamespaces() as $ns => $name ) { + if ( $request->getCheck( 'ns' . $ns ) ) { $arr[] = $ns; } } @@ -490,10 +509,10 @@ class SpecialSearch extends SpecialPage { protected function powerSearchOptions() { $opt = array(); $opt['redirs'] = $this->searchRedirects ? 1 : 0; - if( $this->profile !== 'advanced' ) { + if ( $this->profile !== 'advanced' ) { $opt['profile'] = $this->profile; } else { - foreach( $this->namespaces as $n ) { + foreach ( $this->namespaces as $n ) { $opt['ns' . $n] = 1; } } @@ -515,12 +534,12 @@ class SpecialSearch extends SpecialPage { $out = ""; $infoLine = $matches->getInfo(); - if( !is_null( $infoLine ) ) { + if ( !is_null( $infoLine ) ) { $out .= "\n\n"; } $out .= "