Tholam has uploaded a new change for review.
https://gerrit.wikimedia.org/r/96196
Change subject: Reused processReponsiveImages method from Linker class in File
page and added a call to the method in the createThumb method to generate the
srcset Change-Id: I9fc007399e65b3a6f417766d8411b9bd207301a1
......................................................................
Reused processReponsiveImages method from Linker class in File page and added a
call to the method in the createThumb method to generate the srcset
Change-Id: I9fc007399e65b3a6f417766d8411b9bd207301a1
---
M includes/filerepo/file/File.php
1 file changed, 31 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/96/96196/1
diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php
index 5a5221f..bbd1186 100644
--- a/includes/filerepo/file/File.php
+++ b/includes/filerepo/file/File.php
@@ -835,12 +835,42 @@
$params['height'] = $height;
}
$thumb = $this->transform( $params );
+ self::processResponsiveImages( $this, $thumb, $params );
if ( is_null( $thumb ) || $thumb->isError() ) {
return '';
}
return $thumb->getUrl();
}
-
+ /**
+ * Process responsive images: add 1.5x and 2x subimages to the
thumbnail, where
+ * applicable.
+ *
+ * @param File $file
+ * @param MediaOutput $thumb
+ * @param array $hp image parameters
+ */
+ protected static function processResponsiveImages( $file, $thumb, $hp )
{
+ global $wgResponsiveImages;
+ if ( $wgResponsiveImages ) {
+ $hp15 = $hp;
+ $hp15['width'] = round( $hp['width'] * 1.5 );
+ $hp20 = $hp;
+ $hp20['width'] = $hp['width'] * 2;
+ if ( isset( $hp['height'] ) ) {
+ $hp15['height'] = round( $hp['height'] * 1.5 );
+ $hp20['height'] = $hp['height'] * 2;
+ }
+ $thumb15 = $file->transform( $hp15 );
+ $thumb20 = $file->transform( $hp20 );
+ if ( $thumb15->url !== $thumb->url ) {
+ $thumb->responsiveUrls['1.5'] = $thumb15->url;
+ }
+ if ( $thumb20->url !== $thumb->url ) {
+ $thumb->responsiveUrls['2'] = $thumb20->url;
+ }
+ }
+ }
+
/**
* Return either a MediaTransformError or placeholder thumbnail (if
$wgIgnoreImageErrors)
*
--
To view, visit https://gerrit.wikimedia.org/r/96196
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9fc007399e65b3a6f417766d8411b9bd207301a1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Tholam <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits