From 42d4f35696852b2d72089dce86034792fdf4de8e Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 9 Jan 2014 10:38:19 -0800 Subject: [PATCH] Limit searches at 500 per page * 5000 search results in a single page is too many to be useful and just results in a slow page load. If you need that many results use the API. * Adds new parameter to WebRequest::getLimitOffset() to allow making the 5000 limit configurable by callers Change-Id: I7c12e4b0526db6453aaba5d589ee1c01a54b72d4 --- includes/WebRequest.php | 9 +++++---- includes/specials/SpecialSearch.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 2a7c032593..b3dda75b23 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -795,11 +795,12 @@ class WebRequest { * defaults if not given. The limit must be positive and is capped at 5000. * Offset must be positive but is not capped. * - * @param $deflimit Integer: limit to use if no input and the user hasn't set the option. + * @param int $deflimit limit to use if no input and the user hasn't set the option. * @param string $optionname to specify an option other than rclimit to pull from. + * @param int $hardlimit the maximum upper limit to allow, usually 5000 * @return array first element is limit, second is offset */ - public function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) { + public function getLimitOffset( $deflimit = 50, $optionname = 'rclimit', $hardlimit = 5000 ) { global $wgUser; $limit = $this->getInt( 'limit', 0 ); @@ -812,8 +813,8 @@ class WebRequest { if ( $limit <= 0 ) { $limit = $deflimit; } - if ( $limit > 5000 ) { - $limit = 5000; # We have *some* limits... + if ( $limit > $hardlimit ) { + $limit = $hardlimit; # We have *some* limits... } $offset = $this->getInt( 'offset', 0 ); diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index e4ca057057..98ae6f51cd 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -120,7 +120,7 @@ class SpecialSearch extends SpecialPage { */ public function load() { $request = $this->getRequest(); - list( $this->limit, $this->offset ) = $request->getLimitOffset( 20 ); + list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, '', 500 ); $this->mPrefix = $request->getVal( 'prefix', '' ); $user = $this->getUser(); -- 2.20.1