Robmoen has submitted this change and it was merged.
Change subject: Collection model is composed of CollectionItems
......................................................................
Collection model is composed of CollectionItems
Break dependency with MobilePage, create CollectionItem to host the item of
a collection which will have title, image, extract.
Change-Id: I450b0312499c4563460fea33f03c7881511cd764
---
M Gather.php
M includes/models/Collection.php
A includes/models/CollectionItem.php
M includes/stores/CollectionStore.php
M includes/stores/WatchlistCollectionStore.php
M includes/views/CollectionItemCardView.php
M includes/views/CollectionView.php
7 files changed, 112 insertions(+), 31 deletions(-)
Approvals:
Robmoen: Verified; Looks good to me, approved
diff --git a/Gather.php b/Gather.php
index c5f6084..a603ba5 100644
--- a/Gather.php
+++ b/Gather.php
@@ -42,6 +42,7 @@
$autoloadClasses = array (
'Gather\Hooks' => 'Gather.hooks',
+ 'Gather\CollectionItem' => 'models/CollectionItem',
'Gather\Collection' => 'models/Collection',
'Gather\CollectionsList' => 'models/CollectionsList',
diff --git a/includes/models/Collection.php b/includes/models/Collection.php
index ff3a69c..71e8ee4 100644
--- a/includes/models/Collection.php
+++ b/includes/models/Collection.php
@@ -10,20 +10,19 @@
use \Title;
use \IteratorAggregate;
use \ArrayIterator;
-use \MobilePage;
use \SpecialPage;
/**
- * A collection of pages, which are represented by the MobilePage class.
+ * A collection of items, which are represented by the CollectionItem class.
*/
class Collection implements IteratorAggregate {
/**
- * The internal collection of pages.
+ * The internal collection of items.
*
- * @var MobilePage[]
+ * @var CollectionItem[]
*/
- protected $pages = array();
+ protected $items = array();
/**
* Owner of collection
@@ -69,12 +68,12 @@
protected $id;
/**
- * Adds a page to the collection.
+ * Adds a item to the collection.
*
- * @param MobilePage $page
+ * @param CollectionItem $item
*/
- public function add( MobilePage $page ) {
- $this->pages[] = $page;
+ public function add( CollectionItem $item ) {
+ $this->items[] = $item;
}
/**
@@ -83,7 +82,7 @@
* @return ArrayIterator
*/
public function getIterator() {
- return new ArrayIterator( $this->pages );
+ return new ArrayIterator( $this->items );
}
/**
@@ -133,12 +132,12 @@
}
/**
- * Returns pages count
+ * Returns items count
*
- * @return int count of pages in collection
+ * @return int count of items in collection
*/
public function getCount() {
- return count( $this->pages );
+ return count( $this->items );
}
/**
@@ -155,10 +154,10 @@
}
/**
- * @return array list of pages
+ * @return array list of items
*/
- public function getPages() {
- return $this->pages;
+ public function getItems() {
+ return $this->items;
}
/**
@@ -168,9 +167,9 @@
*/
public function load( CollectionStore $store ) {
$this->id = $store->getId();
- $titles = $store->getTitles();
- foreach ( $titles as $title ) {
- $this->add( new MobilePage( $title ) );
+ $items = $store->getItems();
+ foreach ( $items as $item ) {
+ $this->add( $item );
}
}
diff --git a/includes/models/CollectionItem.php
b/includes/models/CollectionItem.php
new file mode 100644
index 0000000..069f1e1
--- /dev/null
+++ b/includes/models/CollectionItem.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * CollectionItem.php
+ */
+
+namespace Gather;
+
+use \Title;
+
+/**
+ * An item of a Collection. Similar to a Page and MobilePage, but with some
+ * extra information like the extract and image.
+ */
+class CollectionItem {
+
+ /**
+ * @var Title: Title for page
+ */
+ private $title;
+
+ /**
+ * @var File Associated page image file (see PageImages extension)
+ */
+ private $file;
+
+ /**
+ * @var string Page extract
+ */
+ private $extract;
+
+ /**
+ * Constructor
+ * @param Title $title
+ * @param File|bool $file
+ * @param string|bool $extract
+ */
+ public function __construct( Title $title, $file = false, $extract =
false ) {
+ $this->title = $title;
+ $this->file = $file;
+ $this->extract = $extract;
+ }
+
+ /**
+ * Check whether the item has an image
+ *
+ * @return Boolean
+ */
+ public function hasImage() {
+ return $this->image ? true : false;
+ }
+
+ /**
+ * Check whether the item has an extract
+ *
+ * @return Boolean
+ */
+ public function hasExtract() {
+ return $this->extract ? true : false;
+ }
+
+ /**
+ * @return Title title of the item
+ */
+ public function getTitle() {
+ return $this->title;
+ }
+}
diff --git a/includes/stores/CollectionStore.php
b/includes/stores/CollectionStore.php
index 0f3b0d3..97b0092 100644
--- a/includes/stores/CollectionStore.php
+++ b/includes/stores/CollectionStore.php
@@ -7,11 +7,11 @@
*/
interface CollectionStore {
/**
- * Get titles of all pages in the current collection.
+ * Get CollectionItem of all pages in the current collection.
*
- * @return array titles
+ * @return CollectionItem[] titles
*/
- public function getTitles();
+ public function getItems();
/**
* Get current collection identifier
diff --git a/includes/stores/WatchlistCollectionStore.php
b/includes/stores/WatchlistCollectionStore.php
index 4bfe7c1..505ff65 100644
--- a/includes/stores/WatchlistCollectionStore.php
+++ b/includes/stores/WatchlistCollectionStore.php
@@ -12,15 +12,15 @@
*/
class WatchlistCollectionStore implements CollectionStore {
/**
- * @var title[]
+ * @var CollectionItem[]
*/
- protected $titles = array();
+ protected $items = array();
/**
* @inheritdoc
*/
- public function getTitles() {
- return $this->titles;
+ public function getItems() {
+ return $this->items;
}
/**
@@ -37,6 +37,20 @@
* @param User $user to lookup watchlist members for
*/
public function __construct( User $user ) {
+ $titles = $this->loadTitles( $user );
+ // FIXME: Load here extracts and images from titles.
+
+ foreach ( $titles as $title ) {
+ $this->items[] = new CollectionItem( $title, false,
false );
+ }
+ }
+
+ /**
+ * Load titles of the watchlist
+ *
+ * @return Title[]
+ */
+ private function loadTitles( $user ) {
$list = array();
$dbr = wfGetDB( DB_SLAVE );
@@ -61,7 +75,7 @@
}
GenderCache::singleton()->doTitlesArray( $titles );
- $this->titles = $titles;
+ return $titles;
}
}
diff --git a/includes/views/CollectionItemCardView.php
b/includes/views/CollectionItemCardView.php
index 3b718ca..bb53066 100644
--- a/includes/views/CollectionItemCardView.php
+++ b/includes/views/CollectionItemCardView.php
@@ -5,7 +5,6 @@
namespace Gather;
-use \MobilePage;
use Gather\views\helpers\CSS;
use \Html;
@@ -17,9 +16,9 @@
/**
* Constructor
- * @param MobilePage $item
+ * @param CollectionItem $item
*/
- public function __construct( MobilePage $item ) {
+ public function __construct( CollectionItem $item ) {
$this->item = $item;
}
diff --git a/includes/views/CollectionView.php
b/includes/views/CollectionView.php
index 9db6aef..4675fd1 100644
--- a/includes/views/CollectionView.php
+++ b/includes/views/CollectionView.php
@@ -114,7 +114,7 @@
$html = Html::openElement( 'div', array( 'class' => 'collection
content' ) ) .
$this->getHeaderHtml( $collection );
- if ( count( $collection->getPages() ) > 0 ) {
+ if ( $collection->getCount() > 0 ) {
$html .= $this->getCollectionItems( $collection );
} else {
$html .= $this->getEmptyCollectionMessage();
--
To view, visit https://gerrit.wikimedia.org/r/189933
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I450b0312499c4563460fea33f03c7881511cd764
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
Gerrit-Reviewer: Robmoen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits