Use quickUserCan instead of userCan for searches
[lhc/web/wiklou.git] / includes / specials / SpecialSearch.php
index ee7ddfd..f44703c 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;
@@ -374,7 +375,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 +412,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 ) ) );
@@ -448,7 +449,7 @@ class SpecialSearch extends SpecialPage {
 
                if ( $title->isKnown() ) {
                        $messageName = 'searchmenu-exists';
-               } elseif ( $title->userCan( 'create', $this->getUser() ) ) {
+               } elseif ( $title->quickUserCan( 'create', $this->getUser() ) ) {
                        $messageName = 'searchmenu-new';
                } else {
                        $messageName = 'searchmenu-new-nocreate';
@@ -539,9 +540,7 @@ class SpecialSearch extends SpecialPage {
                        // Reset namespace preferences: namespaces are not searched
                        // when they're not mentioned in the URL parameters.
                        foreach ( MWNamespace::getValidNamespaces() as $n ) {
-                               if ( $n >= 0 ) {
-                                       $user->setOption( 'searchNs' . $n, false );
-                               }
+                               $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.
@@ -571,9 +570,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";