From f4357b647f5e66a83552a79fbeed74927abd8e2d Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Fri, 30 May 2014 15:28:13 -0700 Subject: [PATCH] Final page of search results sometimes having erroneous "next" link Pre-patch: In the showResults method of the SpecialSearch class, a request is made through the appropriate SearchEngine object for a single page (according to the specified page size) of search results. With this approach, it's impossible for the page formatter to determine whether an additional page is useful when a result set no smaller than the requested size is returned. Post-patch: The solution is to request an extra result, which we do not display, but we do include in our result count. Display of the extra result is avoided by modifying SpecialSearch->showMatches() to explicitly honor the limit property of its calling instance. The criterion for not linking to a next page is then updated from results < limit. which enables the next link whenever the current results page is full, to results <= limit which enables the next link only when there will be results displayed on the next page. Bug: 19938 Change-Id: Ic30586e217fbde4b9d0aeda277a77030c4dce216 --- includes/specials/SpecialSearch.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index ee7ddfdab8..d308681d8f 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -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 ) ); @@ -571,9 +572,11 @@ class SpecialSearch extends SpecialPage { $out = "\n"; -- 2.20.1