]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaResourceQueue.js
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / resources / src / mediawiki.widgets / MediaSearch / mw.widgets.MediaResourceQueue.js
diff --git a/resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaResourceQueue.js b/resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaResourceQueue.js
new file mode 100644 (file)
index 0000000..34fa44b
--- /dev/null
@@ -0,0 +1,68 @@
+/*!
+ * MediaWiki Widgets - MediaResourceQueue class.
+ *
+ * @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+( function ( $, mw ) {
+
+       /**
+        * MediaWiki media resource queue.
+        *
+        * @class
+        * @extends mw.widgets.APIResultsQueue
+        *
+        * @constructor
+        * @param {Object} [config] Configuration options
+        * @cfg {number} maxHeight The maximum height of the media, used in the
+        *  search call to the API.
+        */
+       mw.widgets.MediaResourceQueue = function MwWidgetsMediaResourceQueue( config ) {
+               config = config || {};
+
+               // Parent constructor
+               mw.widgets.MediaResourceQueue.super.call( this, config );
+
+               this.maxHeight = config.maxHeight || 200;
+       };
+
+       /* Inheritance */
+       OO.inheritClass( mw.widgets.MediaResourceQueue, mw.widgets.APIResultsQueue );
+
+       /**
+        * Fetch the file repos.
+        *
+        * @return {jQuery.Promise} Promise that resolves when the resources are set up
+        */
+       mw.widgets.MediaResourceQueue.prototype.getFileRepos = function () {
+               var defaultSource = [ {
+                       url: mw.util.wikiScript( 'api' ),
+                       local: ''
+               } ];
+
+               if ( !this.fileRepoPromise ) {
+                       this.fileRepoPromise = new mw.Api().get( {
+                               action: 'query',
+                               meta: 'filerepoinfo'
+                       } ).then(
+                               function ( resp ) {
+                                       return resp.query && resp.query.repos || defaultSource;
+                               },
+                               function () {
+                                       return $.Deferred().resolve( defaultSource );
+                               }
+                       );
+               }
+
+               return this.fileRepoPromise;
+       };
+
+       /**
+        * Get image maximum height
+        *
+        * @return {string} Image max height
+        */
+       mw.widgets.MediaResourceQueue.prototype.getMaxHeight = function () {
+               return this.maxHeight;
+       };
+}( jQuery, mediaWiki ) );