Jhernandez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189973
Change subject: Show page image for items on collection page
......................................................................
Show page image for items on collection page
Image loads from the page image extension.
Size hardcoded for now.
Change-Id: Iac09e4e8a3132b8aa685a62e24de9f6043ccc484
---
M Gather.php
M includes/models/CollectionItem.php
A includes/stores/ItemImagesStore.php
M includes/stores/WatchlistCollectionStore.php
M includes/views/CollectionItemCardView.php
A includes/views/ItemImageView.php
M resources/ext.collections.styles/collections.less
7 files changed, 115 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather
refs/changes/73/189973/1
diff --git a/Gather.php b/Gather.php
index 74fc22d..1b3c8ad 100644
--- a/Gather.php
+++ b/Gather.php
@@ -50,11 +50,13 @@
'Gather\CollectionsListStore' => 'stores/CollectionsListStore',
'Gather\DumbWatchlistOnlyCollectionsListStore' =>
'stores/DumbWatchlistOnlyCollectionsListStore',
'Gather\ItemExtractsStore' => 'stores/ItemExtractsStore',
+ 'Gather\ItemImagesStore' => 'stores/ItemImagesStore',
'Gather\View' => 'views/View',
'Gather\UserNotFoundView' => 'views/UserNotFoundView',
'Gather\CollectionView' => 'views/CollectionView',
'Gather\CollectionItemCardView' => 'views/CollectionItemCardView',
+ 'Gather\ItemImageView' => 'views/ItemImageView',
'Gather\CollectionsListView' => 'views/CollectionsListView',
'Gather\CollectionsListItemCardView' =>
'views/CollectionsListItemCardView',
diff --git a/includes/models/CollectionItem.php
b/includes/models/CollectionItem.php
index 131176c..204db1e 100644
--- a/includes/models/CollectionItem.php
+++ b/includes/models/CollectionItem.php
@@ -47,7 +47,7 @@
* @return Boolean
*/
public function hasImage() {
- return $this->image ? true : false;
+ return $this->file ? true : false;
}
/**
@@ -72,4 +72,11 @@
public function getExtract() {
return $this->extract;
}
+
+ /**
+ * @return File|bool Get the file from this item
+ */
+ public function getFile() {
+ return $this->file;
+ }
}
diff --git a/includes/stores/ItemImagesStore.php
b/includes/stores/ItemImagesStore.php
new file mode 100644
index 0000000..27894d1
--- /dev/null
+++ b/includes/stores/ItemImagesStore.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Gather;
+
+use \PageImages;
+
+/**
+ * Loading page images for titles
+ */
+class ItemImagesStore {
+
+ /**
+ * Load images for a collection of titles
+ * @param Title[] $titles
+ *
+ * @return string[]
+ */
+ public static function loadImages( $titles ) {
+ $images = array();
+ foreach ( $titles as $title ) {
+ $images[] = PageImages::getPageImage( $title );
+ }
+ return $images;
+ }
+
+}
+
diff --git a/includes/stores/WatchlistCollectionStore.php
b/includes/stores/WatchlistCollectionStore.php
index ca88feb..e8d7198 100644
--- a/includes/stores/WatchlistCollectionStore.php
+++ b/includes/stores/WatchlistCollectionStore.php
@@ -39,9 +39,10 @@
public function __construct( User $user ) {
$titles = $this->loadTitles( $user );
$extracts = ItemExtractsStore::loadExtracts( $titles );
+ $images = ItemImagesStore::loadImages( $titles );
foreach ( $titles as $key=>$title ) {
- $this->items[] = new CollectionItem( $title, false,
$extracts[$key] );
+ $this->items[] = new CollectionItem( $title,
$images[$key], $extracts[$key] );
}
}
diff --git a/includes/views/CollectionItemCardView.php
b/includes/views/CollectionItemCardView.php
index bf5dd7b..b82aaec 100644
--- a/includes/views/CollectionItemCardView.php
+++ b/includes/views/CollectionItemCardView.php
@@ -15,11 +15,17 @@
protected $item;
/**
+ * @var ItemImageView view for the item image
+ */
+ protected $image;
+
+ /**
* Constructor
* @param CollectionItem $item
*/
public function __construct( CollectionItem $item ) {
$this->item = $item;
+ $this->image = new ItemImageView( $item );
}
/**
@@ -37,6 +43,7 @@
$item = $this->item;
$title = $item->getTitle();
$html = Html::openElement( 'div', array( 'class' =>
'collection-item' ) ) .
+ $this->image->getHtml() .
Html::openElement( 'h2', array( 'class' =>
'collection-item-title' ) ) .
Html::element( 'a', array( 'href' =>
$title->getLocalUrl() ),
$this->getTitle()
diff --git a/includes/views/ItemImageView.php b/includes/views/ItemImageView.php
new file mode 100644
index 0000000..12ce1f9
--- /dev/null
+++ b/includes/views/ItemImageView.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * ItemImageView.php
+ */
+
+namespace Gather;
+
+use Gather\views\helpers\CSS;
+use \Html;
+
+/**
+ * View for the image of an item card.
+ */
+class ItemImageView {
+ protected $item;
+
+ /**
+ * Constructor
+ * @param CollectionItem $item
+ */
+ public function __construct( CollectionItem $item ) {
+ $this->item = $item;
+ }
+
+ /**
+ * Get the view html
+ */
+ public function getHtml() {
+ return $this->getPageImageHtml(750, true);
+ }
+
+ /**
+ * @param integer $size the width of the thumbnail
+ * @param boolean $useBackgroundImage Whether the thumbnail should have
a background image
+ * @return string
+ */
+ private function getPageImageHtml( $size = 750, $useBackgroundImage =
false ) {
+ $imageHtml = '';
+ if ( $this->item->hasImage() ) {
+ $file = $this->item->getFile();
+ $thumb = $file->transform( array( 'width' => $size ) );
+ if ( $thumb && $thumb->getUrl() ) {
+ $className = 'list-thumb ';
+ $className .= $thumb->getWidth() >
$thumb->getHeight()
+ ? 'list-thumb-y'
+ : 'list-thumb-x';
+ $props = array(
+ 'class' => $className,
+ );
+
+ $imgUrl = wfExpandUrl( $thumb->getUrl(),
PROTO_CURRENT );
+ if ( $useBackgroundImage ) {
+ $props['style'] = 'background-image:
url("' . wfExpandUrl( $imgUrl, PROTO_CURRENT ) . '")';
+ $text = '';
+ } else {
+ $props['src'] = $imgUrl;
+ $text = $this->title->getText();
+ }
+ $imageHtml = Html::element( $useBackgroundImage
? 'div' : 'img', $props, $text );
+ }
+ }
+ return $imageHtml;
+ }
+}
diff --git a/resources/ext.collections.styles/collections.less
b/resources/ext.collections.styles/collections.less
index 0eba394..327acf7 100644
--- a/resources/ext.collections.styles/collections.less
+++ b/resources/ext.collections.styles/collections.less
@@ -81,6 +81,11 @@
padding: 0 @collectionItemPadding;
margin-bottom: 2em;
+ .list-thumb {
+ height: 300px;
+ margin: 0 -@collectionItemPadding;
+ }
+
.collection-item-title {
font-size: 2em;
padding-bottom: 0;
--
To view, visit https://gerrit.wikimedia.org/r/189973
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iac09e4e8a3132b8aa685a62e24de9f6043ccc484
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