2015-02-04 00:32:46 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWMediaResourceQueue class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki media resource queue.
|
|
|
|
*
|
|
|
|
* @class
|
2015-02-07 01:35:34 +00:00
|
|
|
* @extends ve.dm.APIResultsQueue
|
2015-02-04 00:32:46 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
2015-02-07 01:35:34 +00:00
|
|
|
* @cfg {number} maxHeight The maximum height of the media, used in the
|
|
|
|
* search call to the API.
|
2015-02-04 00:32:46 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWMediaResourceQueue = function VeDmMWMediaResourceQueue( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
2015-02-07 01:35:34 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.dm.MWMediaResourceQueue.super.call( this, config );
|
2015-12-18 16:00:32 +00:00
|
|
|
|
2015-02-07 01:35:34 +00:00
|
|
|
this.maxHeight = config.maxHeight || 200;
|
2015-02-04 00:32:46 +00:00
|
|
|
};
|
|
|
|
|
2015-02-07 01:35:34 +00:00
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.dm.MWMediaResourceQueue, ve.dm.APIResultsQueue );
|
2015-02-04 00:32:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch the file repos.
|
|
|
|
*
|
|
|
|
* @return {jQuery.Promise} Promise that resolves when the resources are set up
|
|
|
|
*/
|
|
|
|
ve.dm.MWMediaResourceQueue.prototype.getFileRepos = function () {
|
|
|
|
var defaultSource = [ {
|
|
|
|
url: mw.util.wikiScript( 'api' ),
|
2015-06-11 00:44:26 +00:00
|
|
|
local: ''
|
2015-02-04 00:32:46 +00:00
|
|
|
} ];
|
|
|
|
|
|
|
|
if ( !this.fileRepoPromise ) {
|
2015-01-24 00:22:17 +00:00
|
|
|
this.fileRepoPromise = new mw.Api().get( {
|
2015-02-04 00:32:46 +00:00
|
|
|
action: 'query',
|
|
|
|
meta: 'filerepoinfo'
|
|
|
|
} ).then(
|
|
|
|
function ( resp ) {
|
|
|
|
return resp.query && resp.query.repos || defaultSource;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
return $.Deferred().resolve( defaultSource );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.fileRepoPromise;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-02-07 01:35:34 +00:00
|
|
|
* Get image maximum height
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2015-02-07 01:35:34 +00:00
|
|
|
* @return {string} Image max height
|
2015-02-04 00:32:46 +00:00
|
|
|
*/
|
2015-02-07 01:35:34 +00:00
|
|
|
ve.dm.MWMediaResourceQueue.prototype.getMaxHeight = function () {
|
|
|
|
return this.maxHeight;
|
2015-02-04 00:32:46 +00:00
|
|
|
};
|