Catrope has submitted this change and it was merged.

Change subject: Fix 'original dimensions' async call in MediaEdit dialog
......................................................................


Fix 'original dimensions' async call in MediaEdit dialog

The request for originalDimensions is taken from the API, which can be
rather slow. There is a future (soon) fix that refactors the entire way
we read the originalDimensions asynchronously and load it into the dialog
but until that is available, this fix introduces a couple of basic
fallbacks in case originalDimensions are not yet available in the size
widget.

Bug: 62024
Change-Id: I8d00cea6f1d667359a44a6c185c16340bc6e81c9
---
M modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js
1 file changed, 26 insertions(+), 15 deletions(-)

Approvals:
  Catrope: Verified; Looks good to me, approved



diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js
index 09f6825..123d0ac 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js
@@ -385,9 +385,11 @@
  * @param {OO.ui.ButtonOptionWidget} item Selected item
  */
 ve.ui.MWMediaEditDialog.prototype.onTypeChange = function ( item ) {
-       var originalDimensions = this.sizeWidget.getOriginalDimensions(),
+       var originalDimensions,
                selectedType = item ? item.getData() : '',
                thumbOrFrameless = selectedType === 'thumb' || selectedType === 
'frameless';
+
+       originalDimensions = this.sizeWidget.getOriginalDimensions();
 
        // As per wikitext docs, both 'thumb' and 'frameless' have
        // explicitly limited size, as opposed to the similar case
@@ -395,14 +397,14 @@
        if ( thumbOrFrameless ) {
                // Set the placeholders to be wiki default, but only if the 
image
                // is not smaller. Limit on width only (according to wikitext 
default)
-               if ( originalDimensions.width > this.defaultThumbSize ) {
-                       this.sizeWidget.setPlaceholderDimensions( {
-                               'width': this.defaultThumbSize,
-                       } );
-               } else {
+               if ( originalDimensions && originalDimensions.width < 
this.defaultThumbSize ) {
                        // The image is smaller than wiki default. Make the 
default dimensions
                        // the image max size
                        this.sizeWidget.setPlaceholderDimensions( 
originalDimensions );
+               } else {
+                       this.sizeWidget.setPlaceholderDimensions( {
+                               'width': this.defaultThumbSize,
+                       } );
                }
 
                // Enable the size select widget 'default' option
@@ -414,8 +416,10 @@
                // Set placeholders to be image original dimensions
                // Technically, this is the 'default' of non thumb/frameless
                // images, as that is the size that they render in when
-               // no size is specified.
-               this.sizeWidget.setPlaceholderDimensions( originalDimensions );
+               // no size is specified. Only do that if original dimensions 
exist
+               if ( originalDimensions && originalDimensions.width && 
originalDimensions.height ) {
+                       this.sizeWidget.setPlaceholderDimensions( 
originalDimensions );
+               }
 
                // Don't allow for 'default' choice
                this.sizeSelectWidget.getItemFromData( 'default' ).setDisabled( 
true );
@@ -451,10 +455,10 @@
                        // Sanity check just in case before the comparison
                        this.sizeWidget.getCurrentDimensions() &&
                        // Make sure there are original dimensions set up
-                       this.sizeWidget.getOriginalDimensions() &&
+                       originalDimensions &&
                        OO.compare(
                                this.sizeWidget.getCurrentDimensions(),
-                               this.sizeWidget.getOriginalDimensions()
+                               originalDimensions
                        )
                ) {
                        this.sizeSelectWidget.selectItem(
@@ -518,6 +522,7 @@
        } else if ( currentItem === 'full' ) {
                if (
                        this.typeInput.getSelectedItem() &&
+                       this.sizeWidget.getPlaceholderDimensions() &&
                        (
                                this.typeInput.getSelectedItem().getData() === 
'frame' ||
                                this.typeInput.getSelectedItem().getData() === 
'none'
@@ -529,10 +534,14 @@
                                'height': 0
                        } );
                } else {
-                       // Fill in the values of the original dimensions
-                       this.sizeWidget.setCurrentDimensions(
-                               this.sizeWidget.getOriginalDimensions()
-                       );
+                       // The 'full' button should be disabled if 
originalDimensions
+                       // aren't set, so this is just sanity check
+                       if ( this.sizeWidget.getOriginalDimensions() ) {
+                               // Fill in the values of the original dimensions
+                               this.sizeWidget.setCurrentDimensions(
+                                       this.sizeWidget.getOriginalDimensions()
+                               );
+                       }
                }
        } else {
                if ( this.sizeWidget.isEmpty() ) {
@@ -607,7 +616,7 @@
                                dialog.sizeWidget.setOriginalDimensions( 
mediaNodeView.getOriginalDimensions() );
                                dialog.sizeWidget.setEnforcedMax( false );
                                // Original dimensions available, enable the 
button
-                               this.sizeSelectWidget.getItemFromData( 'full' 
).setDisabled( false );
+                               dialog.sizeSelectWidget.getItemFromData( 'full' 
).setDisabled( false );
                                if ( mediaNodeView.getMaxDimensions() ) {
                                        dialog.sizeWidget.setMaxDimensions( 
mediaNodeView.getMaxDimensions() );
                                        if ( dialog.mediaNode.getAttribute( 
'type' ) === 'thumb' ) {
@@ -633,6 +642,8 @@
                // If there are original dimensions, enable that choice
                if ( this.sizeWidget.getOriginalDimensions() ) {
                        this.sizeSelectWidget.getItemFromData( 'full' 
).setDisabled( false );
+               } else {
+                       this.sizeSelectWidget.getItemFromData( 'full' 
).setDisabled( true );
                }
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/120690
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8d00cea6f1d667359a44a6c185c16340bc6e81c9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: wmf/1.23wmf19
Gerrit-Owner: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Mooeypoo <mor...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to