Limit searches at 500 per page
authorChad Horohoe <chadh@wikimedia.org>
Thu, 9 Jan 2014 18:38:19 +0000 (10:38 -0800)
committerChad Horohoe <chadh@wikimedia.org>
Thu, 9 Jan 2014 18:38:19 +0000 (10:38 -0800)
* 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
includes/specials/SpecialSearch.php

index 2a7c032..b3dda75 100644 (file)
@@ -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 );
index e4ca057..98ae6f5 100644 (file)
@@ -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();