X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialSearch.php;h=ad045e43f3c6764dcf4b2755dd9eb5176b49ead5;hb=592c19692e8bd1218e9e58c89116566dccce0315;hp=e1fbe6a4882ef8cefd71f7901d2ffdf81b717c1e;hpb=dfe30d511823a06589aeb554c47d5d38abf49c73;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index e1fbe6a488..ad045e43f3 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -79,7 +79,7 @@ class SpecialSearch extends SpecialPage { /** * @var string */ - protected $sort; + protected $sort = SearchEngine::DEFAULT_SORT; /** * @var bool @@ -92,6 +92,12 @@ class SpecialSearch extends SpecialPage { */ protected $searchConfig; + /** + * @var Status Holds any parameter validation errors that should + * be displayed back to the user. + */ + private $loadStatus; + const NAMESPACES_CURRENT = 'sense'; public function __construct() { @@ -204,6 +210,8 @@ class SpecialSearch extends SpecialPage { * @see tests/phpunit/includes/specials/SpecialSearchTest.php */ public function load() { + $this->loadStatus = new Status(); + $request = $this->getRequest(); list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, '' ); $this->mPrefix = $request->getVal( 'prefix', '' ); @@ -211,8 +219,13 @@ class SpecialSearch extends SpecialPage { $this->setExtraParam( 'prefix', $this->mPrefix ); } - $this->sort = $request->getVal( 'sort', SearchEngine::DEFAULT_SORT ); - if ( $this->sort !== SearchEngine::DEFAULT_SORT ) { + $sort = $request->getVal( 'sort', SearchEngine::DEFAULT_SORT ); + $validSorts = $this->getSearchEngine()->getValidSorts(); + if ( !in_array( $sort, $validSorts ) ) { + $this->loadStatus->warning( 'search-invalid-sort-order', $sort, + implode( ', ', $validSorts ) ); + } elseif ( $sort !== $this->sort ) { + $this->sort = $sort; $this->setExtraParam( 'sort', $this->sort ); } @@ -247,6 +260,7 @@ class SpecialSearch extends SpecialPage { $this->namespaces = $profiles[$profile]['namespaces']; } else { // Unknown profile requested + $this->loadStatus->warning( 'search-unknown-profile', $profile ); $profile = 'default'; $this->namespaces = $profiles['default']['namespaces']; } @@ -375,17 +389,22 @@ class SpecialSearch extends SpecialPage { $out->addHTML( $dymWidget->render( $term, $textMatches ) ); } - $hasErrors = $textStatus && $textStatus->getErrors() !== []; + $hasSearchErrors = $textStatus && $textStatus->getErrors() !== []; $hasOtherResults = $textMatches && - $textMatches->hasInterwikiResults( SearchResultSet::INLINE_RESULTS ); + $textMatches->hasInterwikiResults( ISearchResultSet::INLINE_RESULTS ); - if ( $textMatches && $textMatches->hasInterwikiResults( SearchResultSet::SECONDARY_RESULTS ) ) { + if ( $textMatches && $textMatches->hasInterwikiResults( ISearchResultSet::SECONDARY_RESULTS ) ) { $out->addHTML( '
' ); } else { $out->addHTML( '
' ); } - if ( $hasErrors ) { + if ( $hasSearchErrors || $this->loadStatus->getErrors() ) { + if ( $textStatus === null ) { + $textStatus = $this->loadStatus; + } else { + $textStatus->merge( $this->loadStatus ); + } list( $error, $warning ) = $textStatus->splitByErrorType(); if ( $error->getErrors() ) { $out->addHTML( Html::errorBox( @@ -405,7 +424,7 @@ class SpecialSearch extends SpecialPage { Hooks::run( 'SpecialSearchResults', [ $term, &$titleMatches, &$textMatches ] ); // If we have no results and have not already displayed an error message - if ( $num === 0 && !$hasErrors ) { + if ( $num === 0 && !$hasSearchErrors ) { $out->wrapWikiMsg( "

\n$1

", [ $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound', wfEscapeWikiText( $term ) @@ -443,14 +462,6 @@ class SpecialSearch extends SpecialPage { $term, $this->offset, $titleMatches, $textMatches ) ); - if ( $titleMatches ) { - $titleMatches->free(); - } - - if ( $textMatches ) { - $textMatches->free(); - } - $out->addHTML( '
' ); // prev/next links @@ -481,8 +492,8 @@ class SpecialSearch extends SpecialPage { /** * @param Title $title * @param int $num The number of search results found - * @param null|SearchResultSet $titleMatches Results from title search - * @param null|SearchResultSet $textMatches Results from text search + * @param null|ISearchResultSet $titleMatches Results from title search + * @param null|ISearchResultSet $textMatches Results from text search */ protected function showCreateLink( $title, $num, $titleMatches, $textMatches ) { // show direct page/create link if applicable