Salt the "nsToken" used for Special:Search namespace remembering
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index ea0a29a..54e9987 100644 (file)
@@ -207,7 +207,8 @@ class SpecialSearch extends SpecialPage {
 
                $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;
@@ -252,9 +253,7 @@ class SpecialSearch extends SpecialPage {
                $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 ) {
@@ -318,13 +317,6 @@ class SpecialSearch extends SpecialPage {
                        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 ) );
@@ -374,7 +366,7 @@ class SpecialSearch extends SpecialPage {
                                        $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 ) );
@@ -411,7 +403,7 @@ class SpecialSearch extends SpecialPage {
                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 ) ) );
@@ -534,7 +526,11 @@ class SpecialSearch extends SpecialPage {
 
                if ( $user->isLoggedIn() &&
                        !is_null( $request->getVal( 'nsRemember' ) ) &&
-                       $user->matchEditToken( $request->getVal( 'nsToken' ) )
+                       $user->matchEditToken(
+                               $request->getVal( 'nsToken' ),
+                               'searchnamespace',
+                               $request
+                       )
                ) {
                        // Reset namespace preferences: namespaces are not searched
                        // when they're not mentioned in the URL parameters.
@@ -569,9 +565,11 @@ class SpecialSearch extends SpecialPage {
 
                $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";
 
@@ -976,7 +974,13 @@ class SpecialSearch extends SpecialPage {
                $remember = '';
                $user = $this->getUser();
                if ( $user->isLoggedIn() ) {
-                       $remember .= Html::hidden( 'nsToken', $user->getEditToken() ) .
+                       $remember .= Html::hidden(
+                               'nsToken',
+                               $user->getEditToken(
+                                       'searchnamespace',
+                                       $this->getRequest()
+                               )
+                       ) .
                        Xml::checkLabel(
                                wfMessage( 'powersearch-remember' )->text(),
                                'nsRemember',