$profile = new ProfileSection( __METHOD__ );
$search = $this->getSearchEngine();
- $search->setLimitOffset( $this->limit, $this->offset );
+ // Request an extra result to determine whether a "next page" link is useful
+ $search->setLimitOffset( $this->limit + 1, $this->offset );
$search->setNamespaces( $this->namespaces );
+ $this->saveNamespaces();
$search->prefix = $this->mPrefix;
$term = $search->transformSearchTerm( $term );
$rewritten = $search->replacePrefixes( $term );
$titleMatches = $search->searchTitle( $rewritten );
- if ( !( $titleMatches instanceof SearchResultTooMany ) ) {
- $textMatches = $search->searchText( $rewritten );
- }
+ $textMatches = $search->searchText( $rewritten );
$textStatus = null;
if ( $textMatches instanceof Status ) {
Xml::closeElement( 'div' )
);
- // Sometimes the search engine knows there are too many hits
- if ( $titleMatches instanceof SearchResultTooMany ) {
- $out->wrapWikiMsg( "==$1==\n", 'toomanymatches' );
-
- return;
- }
-
$filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':';
if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
$out->addHTML( $this->formHeader( $term, 0, 0 ) );
$this->offset,
$this->limit,
$this->powerSearchOptions() + array( 'search' => $term ),
- max( $titleMatchesNum, $textMatchesNum ) < $this->limit
+ max( $titleMatchesNum, $textMatchesNum ) <= $this->limit
);
}
wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
if ( $num === 0 ) {
if ( $textStatus ) {
$out->addHTML( '<div class="error">' .
- htmlspecialchars( $textStatus->getWikiText( 'search-error' ) ) . '</div>' );
+ $textStatus->getMessage( 'search-error' ) . '</div>' );
} else {
$out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>",
array( 'search-nonefound', wfEscapeWikiText( $term ) ) );
return $opt + $this->extraParams;
}
+ /**
+ * Save namespace preferences when we're supposed to
+ *
+ * @return bool Whether we wrote something
+ */
+ protected function saveNamespaces() {
+ $user = $this->getUser();
+ $request = $this->getRequest();
+
+ if ( $user->isLoggedIn() &&
+ !is_null( $request->getVal( 'nsRemember' ) ) &&
+ $user->matchEditToken(
+ $request->getVal( 'nsToken' ),
+ 'searchnamespace',
+ $request
+ )
+ ) {
+ // Reset namespace preferences: namespaces are not searched
+ // when they're not mentioned in the URL parameters.
+ foreach ( MWNamespace::getValidNamespaces() as $n ) {
+ $user->setOption( 'searchNs' . $n, false );
+ }
+ // The request parameters include all the namespaces we just searched.
+ // Even if they're the same as an existing profile, they're not eaten.
+ foreach ( $this->namespaces as $n ) {
+ $user->setOption( 'searchNs' . $n, true );
+ }
+
+ $user->saveSettings();
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Show whole set of results
*
$out = "<ul class='mw-search-results'>\n";
$result = $matches->next();
- while ( $result ) {
+ $count = 0;
+ while ( $result && $count < $this->limit ) {
$out .= $this->showHit( $result, $terms );
$result = $matches->next();
+ $count++;
}
$out .= "</ul>\n";
$hidden .= Html::hidden( $key, $value );
}
+ # Stuff to feed saveNamespaces()
+ $remember = '';
+ $user = $this->getUser();
+ if ( $user->isLoggedIn() ) {
+ $remember .= Html::hidden(
+ 'nsToken',
+ $user->getEditToken(
+ 'searchnamespace',
+ $this->getRequest()
+ )
+ ) .
+ Xml::checkLabel(
+ wfMessage( 'powersearch-remember' )->text(),
+ 'nsRemember',
+ 'mw-search-powersearch-remember',
+ false
+ );
+ }
+
// Return final output
return Xml::openElement(
'fieldset',
Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
implode( Xml::element( 'div', array( 'class' => 'divider' ), '', false ), $showSections ) .
$hidden .
+ Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
+ $remember .
Xml::closeElement( 'fieldset' );
}