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

Change subject: Retrieve collections list from json store
......................................................................


Retrieve collections list from json store

* Introduce UserPageCollectionsList
  * Use it instead of the DumbWatchlistOnlyCollectionsList
* Use CollectionInfo for the collections list everywhere (store and view)

To test create a json file under User:username/GatherCollections.json with the
contents like this: https://gist.github.com/joakin/c62b4d1b751ffd419b25 and
visit Special:Gather and you should see on the ui what you entered on that json
file.

Change-Id: I1cc6334ba895afcdf8371b56ac3c74fd77dca55f
---
M Gather.php
M extension.json
M includes/specials/SpecialGather.php
M includes/stores/CollectionsList.php
M includes/stores/DumbWatchlistOnlyCollectionsList.php
A includes/stores/UserPageCollectionsList.php
M includes/views/CollectionsListItemCard.php
7 files changed, 78 insertions(+), 16 deletions(-)

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



diff --git a/Gather.php b/Gather.php
index f8f02d6..cea45ba 100644
--- a/Gather.php
+++ b/Gather.php
@@ -52,6 +52,7 @@
        'Gather\stores\WatchlistCollection' => 'stores/WatchlistCollection',
        'Gather\stores\CollectionsList' => 'stores/CollectionsList',
        'Gather\stores\DumbWatchlistOnlyCollectionsList' => 
'stores/DumbWatchlistOnlyCollectionsList',
+       'Gather\stores\UserPageCollectionsList' => 
'stores/UserPageCollectionsList',
        'Gather\stores\ItemExtracts' => 'stores/ItemExtracts',
        'Gather\stores\ItemImages' => 'stores/ItemImages',
 
diff --git a/extension.json b/extension.json
index 13648fe..3e99dc5 100644
--- a/extension.json
+++ b/extension.json
@@ -34,6 +34,7 @@
                "Gather\\stores\\WatchlistCollection": 
"includes/stores/WatchlistCollection.php",
                "Gather\\stores\\CollectionsList": 
"includes/stores/CollectionsList.php",
                "Gather\\stores\\DumbWatchlistOnlyCollectionsList": 
"includes/stores/DumbWatchlistOnlyCollectionsList.php",
+               "Gather\\stores\\UserPageCollectionsList": 
"includes/stores/UserPageCollectionsList.php",
                "Gather\\stores\\ItemExtracts": 
"includes/stores/ItemExtracts.php",
                "Gather\\stores\\ItemImages": "includes/stores/ItemImages.php",
                "Gather\\views\\View": "includes/views/View.php",
diff --git a/includes/specials/SpecialGather.php 
b/includes/specials/SpecialGather.php
index 3d92e84..eecee4c 100644
--- a/includes/specials/SpecialGather.php
+++ b/includes/specials/SpecialGather.php
@@ -91,8 +91,7 @@
         * @param User $user owner of collections
         */
        public function renderUserCollectionsList( User $user ) {
-               // FIXME: Substitute with proper storage class
-               $collectionsListStore = new 
stores\DumbWatchlistOnlyCollectionsList(
+               $collectionsListStore = new stores\UserPageCollectionsList(
                        $user, $this->isOwner( $user )
                );
                $this->render( new views\CollectionsList( 
$collectionsListStore->getLists() ) );
diff --git a/includes/stores/CollectionsList.php 
b/includes/stores/CollectionsList.php
index 8d5bee4..79642e5 100644
--- a/includes/stores/CollectionsList.php
+++ b/includes/stores/CollectionsList.php
@@ -21,7 +21,7 @@
        protected $user;
 
        /**
-        * @var models\Collection[] Internal list of collections.
+        * @var models\CollectionInfo[] Internal list of collections.
         */
        protected $lists = array();
 
@@ -39,16 +39,11 @@
        public function __construct( User $user, $includePrivate = false ) {
                $this->user = $user;
                $this->includePrivate = $includePrivate;
-               $collections = $this->loadCollections();
-               foreach ( $collections as $collection ) {
-                       $this->add( $collection );
-               }
+               $this->loadCollections();
        }
 
        /**
         * Load collections of the user
-        *
-        * @return CollectionItem[] titles
         */
        abstract public function loadCollections();
 
@@ -57,9 +52,9 @@
         * If the collection to add is private, and this collection list does 
not include
         * private items, the collection won't be added
         *
-        * @param models\Collection $collection
+        * @param models\CollectionInfo $collection
         */
-       public function add( models\Collection $collection ) {
+       public function add( models\CollectionInfo $collection ) {
                if ( $this->includePrivate ||
                        ( !$this->includePrivate && $collection->isPublic() ) ) 
{
                        $this->lists[] = $collection;
diff --git a/includes/stores/DumbWatchlistOnlyCollectionsList.php 
b/includes/stores/DumbWatchlistOnlyCollectionsList.php
index e540253..3dd8ce5 100644
--- a/includes/stores/DumbWatchlistOnlyCollectionsList.php
+++ b/includes/stores/DumbWatchlistOnlyCollectionsList.php
@@ -19,15 +19,13 @@
         * @inherit
         */
        public function loadCollections() {
-               $collections = array();
                // Dumb collections list getter, only returns the watchlist.
                // Get watchlist collection (private)
                // Directly avoid adding if no privates
                if ( $this->includePrivate ) {
                        $watchlistStore = new WatchlistCollection( $this->user 
);
-                       $collections[] = $watchlistStore->getCollection();
+                       $this->add( $watchlistStore->getCollection() );
                }
-               return $collections;
        }
 }
 
diff --git a/includes/stores/UserPageCollectionsList.php 
b/includes/stores/UserPageCollectionsList.php
new file mode 100644
index 0000000..ec2f86d
--- /dev/null
+++ b/includes/stores/UserPageCollectionsList.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * UserPageCollectionsList.php
+ */
+
+namespace Gather\stores;
+
+use Gather\models;
+use \User;
+use \Title;
+use \WikiPage;
+use \FormatJson;
+
+/**
+ * Stores and retrieves collection lists from user pages
+ */
+class UserPageCollectionsList extends CollectionsList {
+       const MANIFEST_FILE = 'GatherCollections.json';
+
+       /**
+        * @inherit
+        */
+       public function loadCollections() {
+               $collectionsData = $this->getManifest();
+               foreach ( $collectionsData as $collectionData ) {
+                       $this->add( $this->collectionFromJSON( $collectionData 
) );
+               }
+       }
+
+       /**
+        * Gets manifest json file
+        */
+       private function getManifest() {
+               $page = WikiPage::factory( self::getStorageTitle() );
+               if ( $page->exists() ) {
+                       $content = $page->getContent();
+                       $data = FormatJson::decode( $content->getNativeData(), 
true );
+               } else {
+                       $data = array();
+               }
+               return $data;
+       }
+
+       /**
+        * Get formatted title of the page that contains the manifest
+        */
+       private function getStorageTitle() {
+               $title = $this->user->getName() . '/' 
.UserPageCollectionsList::MANIFEST_FILE;
+               return Title::makeTitleSafe( NS_USER, $title );
+       }
+
+       /**
+        * Get a models\CollectionInfo from json data in the manifest
+        */
+       private function collectionFromJSON( $json ) {
+               $collection = new models\CollectionInfo(
+                       $json['id'],
+                       User::newFromName( $json['owner'] ),
+                       $json['title'],
+                       $json['description'],
+                       $json['public']
+               );
+               $collection->setCount( $json['count'] );
+               return $collection;
+       }
+
+}
diff --git a/includes/views/CollectionsListItemCard.php 
b/includes/views/CollectionsListItemCard.php
index fd63f73..dcdeddb 100644
--- a/includes/views/CollectionsListItemCard.php
+++ b/includes/views/CollectionsListItemCard.php
@@ -14,9 +14,9 @@
 class CollectionsListItemCard extends View {
 
        /**
-        * @param models\Collection $collection
+        * @param models\CollectionInfo $collection
         */
-       public function __construct( models\Collection $collection ) {
+       public function __construct( models\CollectionInfo $collection ) {
                $this->collection = $collection;
                $this->image = new ItemImage( $collection );
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1cc6334ba895afcdf8371b56ac3c74fd77dca55f
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Robmoen <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to