(bug 33037) Special:newfiles treat its subpage parameter as a limit
authorBrian Wolff <bawolff+wn@gmail.com>
Sun, 8 Jul 2012 17:02:35 +0000 (14:02 -0300)
committerCatrope <roan.kattouw@gmail.com>
Tue, 7 Aug 2012 18:54:53 +0000 (11:54 -0700)
This restores the older behaviour of Special:newfiles. This allows
people to easily include variable sized galleries via
{{Special:newfiles/12}} syntax (people could of course previously do
{{special:newfiles|limit=12}} but less people know that.

Also makes IndexPager::setLimit validate the limit in the same way
it validates the limit coming from a url, and makes it so that
calling setLimit takes precedence over its built in determine the limit
code.

p.s. This is my first commit in our great glourious git future, so
let me know if i did anything wrong

Change-Id: I7fc148e56e43b7c453a1a9559ef74b8b3119c6fe

RELEASE-NOTES-1.20
includes/Pager.php
includes/specials/SpecialNewimages.php

index 621bed8..b0a110f 100644 (file)
@@ -192,6 +192,8 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
   when "from" is filled.
 * (bug 35526) jquery.tablesorter now uses a stable sort.
 * (bug 38953) --memory-limit switch not working for runJobs.php.
+* (bug 33037) Make subpage of Special:newfiles control how many files
+  are returned, like in previous versions.
 
 === API changes in 1.20 ===
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
index be43eda..bd6a7f0 100644 (file)
@@ -144,7 +144,10 @@ abstract class IndexPager extends ContextSource implements Pager {
 
                # Use consistent behavior for the limit options
                $this->mDefaultLimit = intval( $this->getUser()->getOption( 'rclimit' ) );
-               list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset();
+               if ( !$this->mLimit ) {
+                       // Don't override if a subclass calls $this->setLimit() in its constructor.
+                       list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset();
+               }
 
                $this->mIsBackwards = ( $this->mRequest->getVal( 'dir' ) == 'prev' );
                $this->mDb = wfGetDB( DB_SLAVE );
@@ -236,10 +239,19 @@ abstract class IndexPager extends ContextSource implements Pager {
        /**
         * Set the limit from an other source than the request
         *
+        * Verifies limit is between 1 and 5000
+        *
         * @param $limit Int|String
         */
        function setLimit( $limit ) {
-               $this->mLimit = $limit;
+               $limit = (int) $limit;
+               // WebRequest::getLimitOffset() puts a cap of 5000, so do same here.
+               if ( $limit > 5000 ) {
+                       $limit = 5000;
+               }
+               if ( $limit > 0 ) {
+                       $this->mLimit = $limit;
+               }
        }
 
        /**
index 35f39ce..350aac6 100644 (file)
@@ -58,6 +58,9 @@ class NewFilesPager extends ReverseChronologicalPager {
        function __construct( IContextSource $context, $par = null ) {
                $this->like = $context->getRequest()->getText( 'like' );
                $this->showbots = $context->getRequest()->getBool( 'showbots' , 0 );
+               if ( is_numeric( $par ) ) {
+                       $this->setLimit( $par );
+               }
 
                parent::__construct( $context );
        }
@@ -148,7 +151,7 @@ class NewFilesPager extends ReverseChronologicalPager {
                        ),
                        'limit' => array(
                                'type' => 'hidden',
-                               'default' => $this->getRequest()->getText( 'limit' ),
+                               'default' => $this->mLimit,
                                'name' => 'limit',
                        ),
                        'offset' => array(