Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/211101

Change subject: Whitelist supported media types
......................................................................

Whitelist supported media types

For now this is just BITMAP, DRAWING & VIDEO. Video
support is not perfect, but the rendering is approximately
correct (when TimedMediaHandler is installed).

Change-Id: I3e9a7458f843c5d41300591f432f88fb5da920c1
---
M modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js
M modules/ve-mw/ui/widgets/ve.ui.MWMediaResultWidget.js
M modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
3 files changed, 48 insertions(+), 51 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/01/211101/1

diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js
index f30bdbc..cfbc8f3 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js
@@ -482,7 +482,8 @@
                }
        }
 
-       // Add sizing info for non-audio images
+       // Show different label for dimension-less audio media for
+       // when it is eventually supported.
        if ( imageinfo.mediatype === 'AUDIO' ) {
                // Label this file as an audio
                apiData.fileDetails =  $( '<span>' )
@@ -539,29 +540,20 @@
        this.mediaImageInfoPanel.$element.css( 'overflow-y', 'scroll' );
        windowWidth = this.mediaImageInfoPanel.$element.width();
 
-       // Define thumbnail size
-       if ( imageinfo.mediatype === 'AUDIO' ) {
-               // HACK: We are getting the wrong information from the
-               // API about audio files. Set their thumbnail to square
-               newDimensions = {
-                       width: imageinfo.thumbwidth,
-                       height: imageinfo.thumbwidth
-               };
-       } else {
-               // For regular images, calculate a bigger image dimensions
-               newDimensions = ve.dm.MWImageNode.static.resizeToBoundingBox(
-                       // Original image dimensions
-                       {
-                               width: imageinfo.width,
-                               height: imageinfo.height
-                       },
-                       // Bounding box -- the size of the dialog, minus padding
-                       {
-                               width: windowWidth,
-                               height: this.getBodyHeight() - 120
-                       }
-               );
-       }
+       // For regular images, calculate a bigger image dimensions
+       newDimensions = ve.dm.MWImageNode.static.resizeToBoundingBox(
+               // Original image dimensions
+               {
+                       width: imageinfo.width,
+                       height: imageinfo.height
+               },
+               // Bounding box -- the size of the dialog, minus padding
+               {
+                       width: windowWidth,
+                       height: this.getBodyHeight() - 120
+               }
+       );
+
        // Resize the image
        $image.css( {
                width: newDimensions.width,
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWMediaResultWidget.js 
b/modules/ve-mw/ui/widgets/ve.ui.MWMediaResultWidget.js
index 46d2312..fd0e36a 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWMediaResultWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWMediaResultWidget.js
@@ -34,8 +34,6 @@
 
        this.imageDimensions = {};
 
-       this.isAudio = this.data.mediatype === 'AUDIO';
-
        // Store the thumbnail url
        this.thumbUrl = this.data.thumburl;
        this.src = null;
@@ -95,34 +93,24 @@
  * @param {Object} [boundingBox] Specific bounding box, if supplied
  */
 ve.ui.MWMediaResultWidget.prototype.calculateSizing = function ( 
originalDimensions, boundingBox ) {
-       var wrapperPadding,
-               imageDimensions = {};
+       var wrapperPadding;
 
        boundingBox = boundingBox || {};
 
-       if ( this.isAudio ) {
-               // HACK: We are getting the wrong information from the
-               // API about audio files. Set their thumbnail to square 120px
-               imageDimensions = {
-                       width: 120,
-                       height: 120
-               };
-       } else {
-               // Get the image within the bounding box
-               imageDimensions = ve.dm.MWImageNode.static.resizeToBoundingBox(
-                       // Image original dimensions
-                       {
-                               width: originalDimensions.width,
-                               height: originalDimensions.height
-                       },
-                       // Bounding box
-                       {
-                               width: boundingBox.width || 
this.getImageMaxWidth(),
-                               height: boundingBox.height || 
this.getRowHeight()
-                       }
-               );
-       }
-       this.imageDimensions = imageDimensions;
+       // Get the image within the bounding box
+       this.imageDimensions = ve.dm.MWImageNode.static.resizeToBoundingBox(
+               // Image original dimensions
+               {
+                       width: originalDimensions.width,
+                       height: originalDimensions.height
+               },
+               // Bounding box
+               {
+                       width: boundingBox.width || this.getImageMaxWidth(),
+                       height: boundingBox.height || this.getRowHeight()
+               }
+       );
+
        // Set the thumbnail size
        this.$thumb.css( this.imageDimensions );
 
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js 
b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
index d497a7c..f23fddd 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js
@@ -74,6 +74,19 @@
 
 OO.inheritClass( ve.ui.MWMediaSearchWidget, OO.ui.SearchWidget );
 
+/* Static properties */
+
+/**
+ * Allowed media types to show
+ *
+ * TODO: Only support VIDEO if TimedMediaHandler is installed
+ *
+ * @static
+ * @property {string[]}
+ * @inheritable
+ */
+ve.ui.MWMediaSearchWidget.static.allowedTypes = [ 'BITMAP', 'DRAWING', 'VIDEO' 
];
+
 /* Methods */
 
 /**
@@ -160,6 +173,7 @@
  */
 ve.ui.MWMediaSearchWidget.prototype.processQueueResults = function ( items ) {
        var i, len, title,
+               allowedTypes = this.constructor.static.allowedTypes,
                resultWidgets = [],
                inputSearchQuery = this.query.getValue(),
                queueSearchQuery = this.resourceQueue.getSearchQuery();
@@ -169,6 +183,9 @@
        }
 
        for ( i = 0, len = items.length; i < len; i++ ) {
+               if ( allowedTypes.indexOf( items[i].mediatype ) === -1 ) {
+                       continue;
+               }
                title = new mw.Title( items[i].title ).getMainText();
                // Do not insert duplicates
                if ( !Object.prototype.hasOwnProperty.call( this.itemCache, 
title ) ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e9a7458f843c5d41300591f432f88fb5da920c1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to