Jhernandez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/204245
Change subject: Hygiene: Extract image to thumbnail to reusable method
......................................................................
Hygiene: Extract image to thumbnail to reusable method
getThumbnail was copy pastad in a couple of places, and I was going to need
to use it in CollectionsList too.
* I've extracted it to a Image model where we can keep image manipulation
related code.
* Cleaned up the getThumbnail method from the interface WithImage and the
implementors (CollectionBase & CollectionItem).
* Use the new method where the old one was called.
* Extracted the sharing thumbnail width to a constant on models\Image because
magic numbers are bad.
Preparation for bug T95239.
Bug: T95239
Change-Id: Iabaff64f49a68f7bbb2dc4ab20ede49cd05ef572
---
M Gather.php
M includes/models/CollectionBase.php
M includes/models/CollectionItem.php
A includes/models/Image.php
M includes/models/WithImage.php
M includes/specials/SpecialGather.php
M includes/views/Image.php
7 files changed, 36 insertions(+), 38 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather
refs/changes/45/204245/1
diff --git a/Gather.php b/Gather.php
index 74cc2ef..af67e2a 100644
--- a/Gather.php
+++ b/Gather.php
@@ -43,6 +43,7 @@
'Gather\models\Collection' => 'models/Collection',
'Gather\models\CollectionsList' => 'models/CollectionsList',
'Gather\models\WithImage' => 'models/WithImage',
+ 'Gather\models\Image' => 'models/Image',
'Gather\models\ArraySerializable' => 'models/ArraySerializable',
'Gather\views\View' => 'views/View',
diff --git a/includes/models/CollectionBase.php
b/includes/models/CollectionBase.php
index e4988ab..8d09866 100644
--- a/includes/models/CollectionBase.php
+++ b/includes/models/CollectionBase.php
@@ -190,21 +190,6 @@
}
/**
- * @param int $size
- * @return bool|\MediaTransformOutput
- */
- public function getThumbnail( $size ) {
- if ( $this->hasImage() ) {
- $file = $this->getFile();
- $thumb = $file->transform( array( 'width' => $size ) );
- if ( $thumb && $thumb->getUrl() ) {
- return $thumb;
- }
- }
- return false;
- }
-
- /**
* Returns if the user is the owner of the collection/list
* @param User $user user to check if it is the owner
* @return boolean
diff --git a/includes/models/CollectionItem.php
b/includes/models/CollectionItem.php
index 6d74203..baeaffe 100644
--- a/includes/models/CollectionItem.php
+++ b/includes/models/CollectionItem.php
@@ -48,21 +48,6 @@
}
/**
- * @param int $size
- * @return bool|\MediaTransformOutput
- */
- public function getThumbnail( $size ) {
- if ( $this->hasImage() ) {
- $file = $this->getFile();
- $thumb = $file->transform( array( 'width' => $size ) );
- if ( $thumb && $thumb->getUrl() ) {
- return $thumb;
- }
- }
- return false;
- }
-
- /**
* Check whether the item has an extract
*
* @return Boolean
diff --git a/includes/models/Image.php b/includes/models/Image.php
new file mode 100644
index 0000000..3061d1b
--- /dev/null
+++ b/includes/models/Image.php
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * Image.php
+ */
+
+namespace Gather\models;
+
+/**
+ * Image class for image manipulation methods.
+ */
+class Image {
+
+ const SHARING_THUMBNAIL_WIDTH = 360;
+
+ /**
+ * @param int $size
+ * @return bool|\MediaTransformOutput
+ */
+ public static function getThumbnail( $image, $size =
self::SHARING_THUMBNAIL_WIDTH ) {
+ if ( $image !== null ) {
+ $thumb = $image->transform( array( 'width' => $size ) );
+ if ( $thumb && $thumb->getUrl() ) {
+ return $thumb;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/includes/models/WithImage.php b/includes/models/WithImage.php
index 722e260..884e3f3 100644
--- a/includes/models/WithImage.php
+++ b/includes/models/WithImage.php
@@ -23,11 +23,5 @@
* @return File Get the file from this item
*/
public function getFile();
-
- /**
- * @param integer $size of thumbnail
- * @return File Get the thumbnail from this item
- */
- public function getThumbnail( $size );
}
diff --git a/includes/specials/SpecialGather.php
b/includes/specials/SpecialGather.php
index 6e8715e..21920a0 100644
--- a/includes/specials/SpecialGather.php
+++ b/includes/specials/SpecialGather.php
@@ -125,7 +125,10 @@
$out->addJsConfigVars( 'wgGatherCollections',
$collection->toArray() );
$this->render( new views\Collection( $this->getUser(),
$collection ) );
$this->updateCollectionImage( $collection );
- $this->addMetaInformation(
$collection->getDescription(), $collection->getThumbnail( 360 ) );
+ $this->addMetaInformation(
+ $collection->getDescription(),
+ models\Image::getThumbnail(
$collection->getFile() )
+ );
}
}
diff --git a/includes/views/Image.php b/includes/views/Image.php
index 79689e2..a234ad7 100644
--- a/includes/views/Image.php
+++ b/includes/views/Image.php
@@ -39,7 +39,7 @@
private function getPageImageHtml( $size = 750, $useBackgroundImage =
false ) {
$imageHtml = '';
if ( $this->item->hasImage() ) {
- $thumb = $this->item->getThumbnail( $size );
+ $thumb = models\Image::getThumbnail(
$this->item->getFile(), $size );
if ( $thumb && $thumb->getUrl() ) {
$className = 'list-thumb ';
$className .= $thumb->getWidth() >
$thumb->getHeight()
--
To view, visit https://gerrit.wikimedia.org/r/204245
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iabaff64f49a68f7bbb2dc4ab20ede49cd05ef572
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