Alex Monk has uploaded a new change for review.

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

Change subject: Batch gallery imageinfo requests via ImageInfoCache subclass
......................................................................

Batch gallery imageinfo requests via ImageInfoCache subclass

Bug: T147067
Change-Id: If4444cca300d65e28d6fb9003fcac5e076a5129a
---
M extension.json
A modules/ve-mw/init/ve.init.mw.GalleryImageInfoCache.js
M modules/ve-mw/init/ve.init.mw.Platform.js
M modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js
M modules/ve-mw/ui/styles/dialogs/ve.ui.MWGalleryDialog.css
5 files changed, 69 insertions(+), 23 deletions(-)


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

diff --git a/extension.json b/extension.json
index 3930bf9..d2bb94a 100644
--- a/extension.json
+++ b/extension.json
@@ -460,6 +460,7 @@
                                
"modules/ve-mw/init/ve.init.mw.ApiResponseCache.js",
                                "modules/ve-mw/init/ve.init.mw.LinkCache.js",
                                
"modules/ve-mw/init/ve.init.mw.ImageInfoCache.js",
+                               
"modules/ve-mw/init/ve.init.mw.GalleryImageInfoCache.js",
                                "modules/ve-mw/init/ve.init.mw.Platform.js",
                                
"modules/ve-mw/init/ve.init.mw.Platform.init.js",
                                "modules/ve-mw/init/ve.init.mw.Target.js",
diff --git a/modules/ve-mw/init/ve.init.mw.GalleryImageInfoCache.js 
b/modules/ve-mw/init/ve.init.mw.GalleryImageInfoCache.js
new file mode 100644
index 0000000..d2af18c
--- /dev/null
+++ b/modules/ve-mw/init/ve.init.mw.GalleryImageInfoCache.js
@@ -0,0 +1,42 @@
+/*!
+ * VisualEditor MediaWiki Initialization GalleryImageInfoCache class.
+ *
+ * @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+/**
+ * Get information about images.
+ *
+ * @class
+ * @extends ve.init.mw.ApiResponseCache
+ * @constructor
+ */
+ve.init.mw.GalleryImageInfoCache = function VeInitMwGalleryImageInfoCache() {
+       ve.init.mw.GalleryImageInfoCache.super.call( this );
+};
+
+/* Inheritance */
+
+OO.inheritClass( ve.init.mw.GalleryImageInfoCache, ve.init.mw.ImageInfoCache );
+
+/* Methods */
+
+/**
+ * @inheritdoc
+ */
+ve.init.mw.GalleryImageInfoCache.prototype.getRequestPromise = function ( 
subqueue ) {
+       // If you change what `iiprop`s are being fetched, update
+       // ve.ui.MWMediaDialog to add the same ones to the cache.
+       return new mw.Api().get(
+               {
+                       action: 'query',
+                       prop: 'imageinfo',
+                       iiprop: 'url',
+                       titles: subqueue.join( '|' ),
+                       iiurlwidth: 200,
+                       iiurlheight: 200,
+               },
+               { type: 'POST' }
+       );
+};
diff --git a/modules/ve-mw/init/ve.init.mw.Platform.js 
b/modules/ve-mw/init/ve.init.mw.Platform.js
index c293dd1..789def2 100644
--- a/modules/ve-mw/init/ve.init.mw.Platform.js
+++ b/modules/ve-mw/init/ve.init.mw.Platform.js
@@ -29,6 +29,7 @@
        this.parsedMessages = {};
        this.linkCache = new ve.init.mw.LinkCache();
        this.imageInfoCache = new ve.init.mw.ImageInfoCache();
+       this.galleryImageInfoCache = new ve.init.mw.GalleryImageInfoCache();
 };
 
 /* Inheritance */
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js
index 71fdf3d..01aa55f 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js
@@ -257,7 +257,7 @@
 ve.ui.MWGalleryDialog.prototype.getSetupProcess = function ( data ) {
        return ve.ui.MWGalleryDialog.super.prototype.getSetupProcess.call( 
this, data )
                .next( function () {
-                       var titlesString, title, titleText, imageTitles, mode,
+                       var title, titleText, imageTitles, mode,
                                caption, widths, heights, perrow,
                                showFilename, classes, styles,
                                dialog = this,
@@ -298,9 +298,8 @@
                                );
 
                                // Populate menu and edit panels
-                               titlesString = imageTitles.join( '|' );
                                this.imagesPromise = this.requestImages( {
-                                       titlesString: titlesString
+                                       titles: imageTitles
                                } ).done( function () {
                                        dialog.onHighlightItem();
                                } );
@@ -392,34 +391,37 @@
  * @param {Object} options Options for the request
  */
 ve.ui.MWGalleryDialog.prototype.requestImages = function ( options ) {
-       return new mw.Api().get( {
-               action: 'query',
-               prop: 'imageinfo',
-               iiprop: 'url',
-               iiurlwidth: options.width || 200,
-               // Matches height of this.$highlightedImage
-               iiurlheight: options.height || 200,
-               titles: options.titlesString
-       } ).done( this.onRequestImagesSuccess.bind( this ) );
+       var i, len,
+               dialog = this,
+               promises = [];
+       for ( i = 0, len = options.titles.length; i < len; i++ ) {
+               promises.push( ve.init.platform.galleryImageInfoCache.get( 
options.titles[ i ] ) );
+       }
+       console.log( options.titles, promises );
+       return $.when.apply( $, promises )
+               .done( function () {
+                       var resp = {};
+                       console.log( arguments );
+                       for ( i = 0; i < len; i++ ) {
+                               resp[ options.titles[ i ] ] = arguments[ i ];
+                       }
+                       console.log( resp );
+                       dialog.onRequestImagesSuccess( resp );
+               } );
 };
 
 /**
  * Create items for the returned images and add them to the gallery group
  *
- * @param {Object} deferred jQuery deferred object
  * @param {Object} response jQuery response object
  */
-ve.ui.MWGalleryDialog.prototype.onRequestImagesSuccess = function ( deferred, 
response ) {
+ve.ui.MWGalleryDialog.prototype.onRequestImagesSuccess = function ( response ) 
{
        var index,
                thumbUrls = {},
-               items = [],
-               pages = response.responseJSON.query.pages;
+               items = [];
 
-       // Store object of titles to thumbUrls
-       for ( index in pages ) {
-               if ( pages[ index ].imageinfo ) {
-                       thumbUrls[ pages[ index ].title ] = pages[ index 
].imageinfo[ 0 ].thumburl;
-               }
+       for ( title in response ) {
+               thumbUrls[ title ] = response[ title ].thumburl;
        }
 
        // Make items for every image in imageData
@@ -451,7 +453,7 @@
 
        // Request image
        this.requestImages( {
-               titlesString: title
+               titles: [ title ]
        } ).done( function () {
 
                // populate edit panel with the new image
diff --git a/modules/ve-mw/ui/styles/dialogs/ve.ui.MWGalleryDialog.css 
b/modules/ve-mw/ui/styles/dialogs/ve.ui.MWGalleryDialog.css
index 2b48a72..b92b9e6 100644
--- a/modules/ve-mw/ui/styles/dialogs/ve.ui.MWGalleryDialog.css
+++ b/modules/ve-mw/ui/styles/dialogs/ve.ui.MWGalleryDialog.css
@@ -29,7 +29,7 @@
 .ve-ui-mwGalleryDialog-highlighted-image {
        background-color: #f9f9f9;
        width: 100%;
-       /* Matches default height in requestImages */
+       /* Matches default height in GalleryImageInfoCache */
        height: 200px;
        background-repeat: no-repeat;
        background-position: 50% 50%;

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

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

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

Reply via email to