/**
* @var string
*/
- protected $sort;
+ protected $sort = SearchEngine::DEFAULT_SORT;
/**
* @var bool
*/
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() {
* @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', '' );
$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 );
}
$this->namespaces = $profiles[$profile]['namespaces'];
} else {
// Unknown profile requested
+ $this->loadStatus->warning( 'search-unknown-profile', $profile );
$profile = 'default';
$this->namespaces = $profiles['default']['namespaces'];
}
$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( '<div class="searchresults mw-searchresults-has-iw">' );
} else {
$out->addHTML( '<div class="searchresults">' );
}
- 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(
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( "<p class=\"mw-search-nonefound\">\n$1</p>", [
$hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound',
wfEscapeWikiText( $term )
$term, $this->offset, $titleMatches, $textMatches
) );
- if ( $titleMatches ) {
- $titleMatches->free();
- }
-
- if ( $textMatches ) {
- $textMatches->free();
- }
-
$out->addHTML( '<div class="mw-search-visualclear"></div>' );
// prev/next links
/**
* @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
$messageName = 'searchmenu-exists';
$linkClass = 'mw-search-exists';
} elseif ( ContentHandler::getForTitle( $title )->supportsDirectEditing()
- && $title->quickUserCan( 'create', $this->getUser() )
+ && MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan( 'create',
+ $this->getUser(), $title )
) {
$messageName = 'searchmenu-new';
}