Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / MediaSearch / mw.widgets.MediaResourceQueue.js
1 /*!
2 * MediaWiki Widgets - MediaResourceQueue class.
3 *
4 * @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7 ( function () {
8
9 /**
10 * MediaWiki media resource queue.
11 *
12 * @class
13 * @extends mw.widgets.APIResultsQueue
14 *
15 * @constructor
16 * @param {Object} [config] Configuration options
17 * @cfg {number} maxHeight The maximum height of the media, used in the
18 * search call to the API.
19 */
20 mw.widgets.MediaResourceQueue = function MwWidgetsMediaResourceQueue( config ) {
21 config = config || {};
22
23 // Parent constructor
24 mw.widgets.MediaResourceQueue.super.call( this, config );
25
26 this.maxHeight = config.maxHeight || 200;
27 };
28
29 /* Inheritance */
30 OO.inheritClass( mw.widgets.MediaResourceQueue, mw.widgets.APIResultsQueue );
31
32 /**
33 * Fetch the file repos.
34 *
35 * @return {jQuery.Promise} Promise that resolves when the resources are set up
36 */
37 mw.widgets.MediaResourceQueue.prototype.getFileRepos = function () {
38 var defaultSource = [ {
39 url: mw.util.wikiScript( 'api' ),
40 local: ''
41 } ];
42
43 if ( !this.fileRepoPromise ) {
44 this.fileRepoPromise = new mw.Api().get( {
45 action: 'query',
46 meta: 'filerepoinfo'
47 } ).then(
48 function ( resp ) {
49 return resp.query && resp.query.repos || defaultSource;
50 },
51 function () {
52 return $.Deferred().resolve( defaultSource );
53 }
54 );
55 }
56
57 return this.fileRepoPromise;
58 };
59
60 /**
61 * Get image maximum height
62 *
63 * @return {string} Image max height
64 */
65 mw.widgets.MediaResourceQueue.prototype.getMaxHeight = function () {
66 return this.maxHeight;
67 };
68 }() );