Jhernandez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189934
Change subject: Create store for retrieving list of collections
......................................................................
Create store for retrieving list of collections
Abstracted getting the list of collections from a user into a Store
(DumbWatchlistOnlyCollectionsListStore). Right now is a really dumb one. I've
put all the common behavior into a common store (parallel to what we did with
CollectionStore) so that we can substitute easily
DumbWatchlistOnlyCollectionsListStore with the real storage class once we do
it.
As a consequence of cleaning up the CollectionsList model, it turned out we
don't actually store anything extra on that model, so it can actually be
removed and just use an array of Collection for representing a list of
collections, so that's simpler.
Change-Id: Icdac5fc5ab39a696a0c0a142f1f97e094da74029
---
M Gather.php
D includes/models/CollectionsList.php
M includes/specials/SpecialGather.php
A includes/stores/CollectionsListStore.php
A includes/stores/DumbWatchlistOnlyCollectionsListStore.php
M includes/views/CollectionsListView.php
6 files changed, 126 insertions(+), 83 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather
refs/changes/34/189934/1
diff --git a/Gather.php b/Gather.php
index a603ba5..a8d5be0 100644
--- a/Gather.php
+++ b/Gather.php
@@ -44,10 +44,11 @@
'Gather\CollectionItem' => 'models/CollectionItem',
'Gather\Collection' => 'models/Collection',
- 'Gather\CollectionsList' => 'models/CollectionsList',
'Gather\CollectionStore' => 'stores/CollectionStore',
'Gather\WatchlistCollectionStore' => 'stores/WatchlistCollectionStore',
+ 'Gather\CollectionsListStore' => 'stores/CollectionsListStore',
+ 'Gather\DumbWatchlistOnlyCollectionsListStore' =>
'stores/DumbWatchlistOnlyCollectionsListStore',
'Gather\View' => 'views/View',
'Gather\UserNotFoundView' => 'views/UserNotFoundView',
diff --git a/includes/models/CollectionsList.php
b/includes/models/CollectionsList.php
deleted file mode 100644
index c6c31f6..0000000
--- a/includes/models/CollectionsList.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-
-/**
- * CollectionsList.php
- */
-
-namespace Gather;
-
-use \User;
-use \IteratorAggregate;
-use \ArrayIterator;
-
-/**
- * A list of collections, which are represented by the Collection class.
- */
-class CollectionsList implements IteratorAggregate {
- /**
- * @var Collection[] Internal list of collections.
- */
- protected $lists = array();
-
- /**
- * @var bool if the list can show private collections or not
- */
- protected $includePrivate;
-
- /**
- * Creates a list of collection cards
- *
- * @param User $user collection list owner
- * @param boolean $includePrivate if the list can show private
collections or not
- */
- public function __construct( User $user, $includePrivate = false ) {
- $this->includePrivate = $includePrivate;
-
- // Get watchlist collection (private)
- // Directly avoid adding if not owner
- if ( $includePrivate ) {
- $watchlist = new Collection(
- $user,
- wfMessage( 'gather-watchlist-title' ),
- wfMessage( 'gather-watchlist-description' ),
- false
- );
- $watchlist->load( new WatchlistCollectionStore( $user )
);
-
- $this->add( $watchlist );
- }
-
- // FIXME: Add from UserCollectionStore
- }
-
- /**
- * Adds a page to the collection.
- * If the collection to add is private, and this collection list does
not include
- * private items, the collection won't be added
- *
- * @param Collection $collection
- */
- public function add( Collection $collection ) {
- if ( $this->includePrivate ||
- ( !$this->includePrivate && $collection->isPublic() ) )
{
- $this->lists[] = $collection;
- }
- }
-
- /**
- * Gets the iterator for the internal array
- *
- * @return ArrayIterator
- */
- public function getIterator() {
- return new ArrayIterator( $this->lists );
- }
-}
diff --git a/includes/specials/SpecialGather.php
b/includes/specials/SpecialGather.php
index 99ae753..d94756a 100644
--- a/includes/specials/SpecialGather.php
+++ b/includes/specials/SpecialGather.php
@@ -91,8 +91,11 @@
* @param User $user owner of collections
*/
public function renderUserCollectionsList( User $user ) {
- $collectionsList = new CollectionsList( $user, $this->isOwner(
$user ) );
- $this->render( new CollectionsListView( $collectionsList ) );
+ // FIXME: Substitute with proper storage class
+ $collectionsListStore = new
DumbWatchlistOnlyCollectionsListStore(
+ $user, $this->isOwner( $user )
+ );
+ $this->render( new CollectionsListView(
$collectionsListStore->getLists() ) );
}
/**
diff --git a/includes/stores/CollectionsListStore.php
b/includes/stores/CollectionsListStore.php
new file mode 100644
index 0000000..ec18a1f
--- /dev/null
+++ b/includes/stores/CollectionsListStore.php
@@ -0,0 +1,77 @@
+<?php
+
+/**
+ * CollectionsListStore.php
+ */
+
+namespace Gather;
+
+use \User;
+
+/**
+ * Abstract class for a store that loads the collections of a user.
+ * Extend it and implement loadCollections.
+ */
+abstract class CollectionsListStore {
+
+ /**
+ * @var User Owner of the collections
+ */
+ protected $user;
+
+ /**
+ * @var Collection[] Internal list of collections.
+ */
+ protected $lists = array();
+
+ /**
+ * @var bool if the list can show private collections or not
+ */
+ protected $includePrivate;
+
+ /**
+ * Creates a list of collections
+ *
+ * @param User $user collection list owner
+ * @param boolean $includePrivate if the list can show private
collections or not
+ */
+ public function __construct( User $user, $includePrivate = false ) {
+ $this->user = $user;
+ $this->includePrivate = $includePrivate;
+ $collections = $this->loadCollections();
+ foreach ( $collections as $collection ) {
+ $this->add( $collection );
+ }
+ }
+
+ /**
+ * Load collections of the user
+ *
+ * @return CollectionItem[] titles
+ */
+ abstract public function loadCollections();
+
+ /**
+ * Adds a page to the collection.
+ * If the collection to add is private, and this collection list does
not include
+ * private items, the collection won't be added
+ *
+ * @param Collection $collection
+ */
+ public function add( Collection $collection ) {
+ if ( $this->includePrivate ||
+ ( !$this->includePrivate && $collection->isPublic() ) )
{
+ $this->lists[] = $collection;
+ }
+ }
+
+ /**
+ * Returns the list of collections
+ *
+ * @return Collection[]
+ */
+ public function getLists() {
+ return $this->lists;
+ }
+}
+
diff --git a/includes/stores/DumbWatchlistOnlyCollectionsListStore.php
b/includes/stores/DumbWatchlistOnlyCollectionsListStore.php
new file mode 100644
index 0000000..d0d8007
--- /dev/null
+++ b/includes/stores/DumbWatchlistOnlyCollectionsListStore.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * DumbOnlyWatchlistCollectionsListStore.php
+ */
+
+namespace Gather;
+
+/**
+ * Dumb collections list store that only knows to return the watchlist.
+ *
+ * FIXME: This class will be substituted when we actually load collections
list from
+ * somewhere else.
+ */
+class DumbWatchlistOnlyCollectionsListStore extends CollectionsListStore {
+ /**
+ * @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 ) {
+ $watchlist = new Collection(
+ $this->user,
+ wfMessage( 'gather-watchlist-title' ),
+ wfMessage( 'gather-watchlist-description' ),
+ false
+ );
+ $watchlist->load( new WatchlistCollectionStore(
$this->user ) );
+ $collections[] = $watchlist;
+ }
+ return $collections;
+ }
+}
+
diff --git a/includes/views/CollectionsListView.php
b/includes/views/CollectionsListView.php
index 25b99c9..d9ce18b 100644
--- a/includes/views/CollectionsListView.php
+++ b/includes/views/CollectionsListView.php
@@ -12,20 +12,20 @@
*/
class CollectionsListView extends View {
/**
- * @param Collection $collection
+ * @param Collection[] $collectionsList
*/
- public function __construct( CollectionsList $collectionsList ) {
+ public function __construct( $collectionsList ) {
$this->collectionsList = $collectionsList;
}
/**
- * Returns the html for the items of a collection
+ * Returns the html for the collections in a list
*
- * @param CollectionsList
+ * @param Collection[]
*
* @return string Html
*/
- public static function getListItemsHtml( CollectionsList
$collectionsList ) {
+ public static function getListItemsHtml( $collectionsList ) {
$html = Html::openElement( 'div', array( 'class' =>
'collection-cards' ) );
foreach ( $collectionsList as $item ) {
$view = new CollectionsListItemCardView( $item );
--
To view, visit https://gerrit.wikimedia.org/r/189934
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icdac5fc5ab39a696a0c0a142f1f97e094da74029
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