Jhernandez has uploaded a new change for review. https://gerrit.wikimedia.org/r/191601
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 A includes/stores/UserPageCollectionsList.php M includes/views/CollectionsListItemCard.php 6 files changed, 79 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather refs/changes/01/191601/1 diff --git a/Gather.php b/Gather.php index 76953ab..a8e250f 100644 --- a/Gather.php +++ b/Gather.php @@ -51,6 +51,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 b8c4183..d2b11d6 100644 --- a/extension.json +++ b/extension.json @@ -33,6 +33,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..a133a09 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(); @@ -48,7 +48,7 @@ /** * Load collections of the user * - * @return CollectionItem[] titles + * @return CollectionInfo[] titles */ abstract public function loadCollections(); @@ -57,9 +57,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/UserPageCollectionsList.php b/includes/stores/UserPageCollectionsList.php new file mode 100644 index 0000000..f205a85 --- /dev/null +++ b/includes/stores/UserPageCollectionsList.php @@ -0,0 +1,70 @@ +<?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(); + $collections = array(); + foreach ( $collectionsData as $collectionData ) { + $this->add( $this->collectionFromJSON( $collectionData ) ); + } + return $collections; + } + + /** + * 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 3215308..e2124eb 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; } -- To view, visit https://gerrit.wikimedia.org/r/191601 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1cc6334ba895afcdf8371b56ac3c74fd77dca55f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Gather Gerrit-Branch: master Gerrit-Owner: Jhernandez <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
