jenkins-bot has submitted this change and it was merged.

Change subject: Pagination of collection itself
......................................................................


Pagination of collection itself

Bug: T94515
Change-Id: I9d1342df0dbef07fa4870c46a4da5fce60969d85
---
M i18n/en.json
M i18n/qqq.json
M includes/models/Collection.php
M includes/models/CollectionBase.php
M includes/specials/SpecialGather.php
M includes/views/Collection.php
6 files changed, 41 insertions(+), 14 deletions(-)

Approvals:
  Jhernandez: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index 8d213ce..2784fae 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -78,5 +78,6 @@
        "apihelp-gather-param-owner": "Owner of the collections to search for. 
If omitted, defaults to current user.",
        "apihelp-gather-example-1": "List the collections for user 
<kbd>john</kbd>.",
        "gather-lists-collection-more-link-label": "View more public 
collections.",
-       "gather-lists-more": "View more collections from this user."
+       "gather-lists-more": "View more collections from this user.",
+       "gather-collection-more": "View more pages in this collection"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index a8f07a4..9ad9b7a 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -81,5 +81,6 @@
        "apihelp-gather-param-owner": "{{doc-apihelp-param|gather|owner}}",
        "apihelp-gather-example-1": "{{doc-apihelp-example|gather}}",
        "gather-lists-collection-more-link-label": "Link label for a more type 
link on the Special:GatherLists page.",
-       "gather-lists-more": "Link label for more link at the bottom of a list 
of users existing collections."
+       "gather-lists-more": "Link label for more link at the bottom of a list 
of users existing collections.",
+       "gather-collection-more": "Label for link at bottom of Gather 
collection when there are more than 50 items."
 }
diff --git a/includes/models/Collection.php b/includes/models/Collection.php
index 7f36a3e..0a38d59 100644
--- a/includes/models/Collection.php
+++ b/includes/models/Collection.php
@@ -13,6 +13,7 @@
 use \FauxRequest;
 use \Title;
 use \Exception;
+use \SpecialPage;
 
 /**
  * A collection with a list of items, which are represented by the 
CollectionItem class.
@@ -118,16 +119,33 @@
        }
 
        /**
+        * Return a URL that allows you to retreive the rest of the items of the
+        * collection
+        * @return string|null
+        */
+       public function getContinueUrl() {
+               return $this->continue ? $this->getUrl( $this->continue ) : 
false;
+       }
+
+       /**
+        * @param array $continue information to obtain further items
+        */
+       public function setContinueQueryString( $continue ) {
+               $this->continue = $continue;
+       }
+
+       /**
         * Generate a Collection from api result
         * @param Integer $id the id of the collection
-        * @param User $user optional collection list owner (if present will be
+        * @param User [$user] optional collection list owner (if present will 
be
         * included in the query and validated)
+        * @param array [$continue] optional parameters to append to the query.
         * @return models\Collections a collection
         */
-       public static function newFromApi( $id, User $user = null ) {
-
+       public static function newFromApi( $id, User $user = null, $continue = 
array() ) {
+               $limit = 50;
                $collection = null;
-               $params = array(
+               $params = array_merge( $continue, array(
                        'action' => 'query',
                        'list' => 'lists',
                        'lstids' => $id,
@@ -138,12 +156,11 @@
                        'explaintext' => true,
                        'exintro' => true,
                        'exchars' => self::EXTRACTS_CHAR_LIMIT,
-                       'glsplimit' => 50,
-                       'exlimit' => 50,
-                       'pilimit' => 50,
-                       // TODO: Pagination
+                       'glsplimit' => $limit,
+                       'exlimit' => $limit,
+                       'pilimit' => $limit,
                        'continue' => '',
-               );
+               ) );
                // If user is present, include it in the request. Api will 
return not found
                // if the specified owner doesn't match the actual collection 
owner.
                if ( $user ) {
@@ -184,6 +201,9 @@
                                        $collection->add( new CollectionItem( 
$title, $pi, $extract ) );
                                }
                        }
+                       if ( isset( $data['continue'] ) ) {
+                               $collection->setContinueQueryString( 
$data['continue'] );
+                       }
                } catch ( Exception $e ) {
                        // just return collection
                }
diff --git a/includes/models/CollectionBase.php 
b/includes/models/CollectionBase.php
index 0632912..ccbf6d2 100644
--- a/includes/models/CollectionBase.php
+++ b/includes/models/CollectionBase.php
@@ -127,14 +127,15 @@
         * Return local url for collection
         * Example: /wiki/Special:Gather/by/user/id
         *
+        * @param array [$args] optional query string parameters
         * @return string localized url for collection
         */
-       public function getUrl() {
+       public function getUrl( $args = array() ) {
                return SpecialPage::getTitleFor( 'Gather' )
                        ->getSubpage( 'by' )
                        ->getSubpage( $this->getOwner() )
                        ->getSubpage( $this->getId() )
-                       ->getLocalURL();
+                       ->getLocalURL( $args );
        }
 
        /** @inheritdoc */
diff --git a/includes/specials/SpecialGather.php 
b/includes/specials/SpecialGather.php
index c84781d..b1a52d4 100644
--- a/includes/specials/SpecialGather.php
+++ b/includes/specials/SpecialGather.php
@@ -113,7 +113,7 @@
                                . gettype( $id ) . ' given.'
                        );
                }
-               $collection = models\Collection::newFromApi( $id, $user );
+               $collection = models\Collection::newFromApi( $id, $user, 
$this->getRequest()->getValues() );
 
                if ( $collection === null ||
                        // If collection is private and current user doesn't 
own it
diff --git a/includes/views/Collection.php b/includes/views/Collection.php
index d48f378..e67fc9a 100644
--- a/includes/views/Collection.php
+++ b/includes/views/Collection.php
@@ -176,6 +176,10 @@
 
                if ( $collection->getCount() > 0 ) {
                        $html .= $this->getCollectionItems( $collection );
+                       $url = $collection->getContinueUrl();
+                       if ( $url ) {
+                               $html .= Pagination::more( $url, wfMessage( 
'gather-collection-more' )->text() );
+                       }
                } else {
                        $html .= $this->getEmptyCollectionMessage();
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/201046
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9d1342df0dbef07fa4870c46a4da5fce60969d85
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Jhernandez <jhernan...@wikimedia.org>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to