diff --git a/MultimediaViewer.php b/MultimediaViewer.php
index c28cefe04..69e99c618 100644
--- a/MultimediaViewer.php
+++ b/MultimediaViewer.php
@@ -719,6 +719,7 @@ call_user_func( function() {
$wgHooks['ResourceLoaderGetConfigVars'][] = 'MultimediaViewerHooks::resourceLoaderGetConfigVars';
$wgHooks['MakeGlobalVariablesScript'][] = 'MultimediaViewerHooks::makeGlobalVariablesScript';
$wgHooks['ResourceLoaderTestModules'][] = 'MultimediaViewerHooks::getTestModules';
+ $wgHooks['ThumbnailBeforeProduceHTML'][] = 'MultimediaViewerHooks::thumbnailBeforeProduceHTML';
$section = 'other';
diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php
index 213e434bf..66fb7c131 100644
--- a/MultimediaViewerHooks.php
+++ b/MultimediaViewerHooks.php
@@ -223,4 +223,30 @@ class MultimediaViewerHooks {
return true;
}
+
+ /**
+ * Modify thumbnail DOM
+ * @param ThumbnailImage $thumbnail
+ * @param array $attribs Attributes of the element
+ * @param array $linkAttribs Attributes of the wrapping element
+ */
+ public static function thumbnailBeforeProduceHTML( ThumbnailImage $thumbnail, array &$attribs, array &$linkAttribs ) {
+ $file = $thumbnail->getFile();
+
+ if ( $file ) {
+ // At the moment all classes that extend File have getWidth() and getHeight()
+ // but since the File class doesn't have these methods defined, this check
+ // is more future-proof
+
+ if ( method_exists( $file, 'getWidth' ) ) {
+ $attribs['data-file-width'] = $file->getWidth();
+ }
+
+ if ( method_exists( $file, 'getHeight' ) ) {
+ $attribs['data-file-height'] = $file->getHeight();
+ }
+ }
+
+ return true;
+ }
}
diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js
index a15105ea1..fce040974 100755
--- a/resources/mmv/mmv.js
+++ b/resources/mmv/mmv.js
@@ -195,11 +195,13 @@
*/
MMVP.loadImage = function ( image, initialImage ) {
var imageWidths,
- viewer = this,
imagePromise,
metadataPromise,
start,
- $initialImage = $( initialImage );
+ viewer = this,
+ $initialImage = $( initialImage ),
+ fileWidth = parseInt( $initialImage.data( 'file-width' ), 10 ),
+ fileHeight = parseInt( $initialImage.data( 'file-height' ), 10 );
this.currentIndex = image.index;
@@ -244,6 +246,20 @@
viewer.ui.panel.percent( 5 );
}
+ if ( fileWidth > 0 && fileHeight > 0 ) {
+ viewer.displayPlaceholderThumbnail( { width : fileWidth , height : fileHeight },
+ $initialImage,
+ imageWidths );
+ } else {
+ this.imageInfoProvider.get( image.filePageTitle ).done( function ( imageInfo ) {
+ if ( viewer.currentIndex !== image.index ) {
+ return;
+ }
+
+ viewer.displayPlaceholderThumbnail( imageInfo, $initialImage, imageWidths );
+ } );
+ }
+
imagePromise.progress( function ( thumbnailInfoResponse, imageResponse ) {
if ( viewer.currentIndex !== image.index ) {
return;
@@ -265,14 +281,6 @@
viewer.ui.canvas.showError( error );
} );
- this.imageInfoProvider.get( image.filePageTitle ).done( function ( imageInfo ) {
- if ( viewer.currentIndex !== image.index ) {
- return;
- }
-
- viewer.displayPlaceholderThumbnail( imageInfo, $initialImage, imageWidths );
- } );
-
metadataPromise = this.fetchSizeIndependentLightboxInfo(
image.filePageTitle
).done( function ( imageInfo, repoInfo, localUsage, globalUsage, userInfo ) {