Debian Codegraph @

resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaResourceQueue.js

raw symbols SCIP
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 * @classdesc Media resource queue.
11 *
12 * @class
13 * @extends mw.widgets.APIResultsQueue
14 *
15 * @constructor
16 * @description Create an instance of `mw.widgets.MediaResourceQueue`.
17 * @param {Object} [config] Configuration options
18 * @param {number} config.maxHeight The maximum height of the media, used in the
19 * search call to the API.
20 */
21 mw.widgets.MediaResourceQueue = function MwWidgetsMediaResourceQueue( config ) {
22 config = config || {};
23
24 // Parent constructor
25 mw.widgets.MediaResourceQueue.super.call( this, config );
26
27 this.maxHeight = config.maxHeight || 200;
28 };
29
30 /* Inheritance */
31 OO.inheritClass( mw.widgets.MediaResourceQueue, mw.widgets.APIResultsQueue );
32
33 /**
34 * Fetch the file repos.
35 *
36 * @return {jQuery.Promise} Promise that resolves when the resources are set up
37 */
38 mw.widgets.MediaResourceQueue.prototype.getFileRepos = function () {
39 const defaultSource = [ {
40 url: mw.util.wikiScript( 'api' ),
41 local: ''
42 } ];
43
44 if ( !this.fileRepoPromise ) {
45 this.fileRepoPromise = new mw.Api().get( {
46 action: 'query',
47 meta: 'filerepoinfo'
48 } ).then(
49 ( resp ) => resp.query && resp.query.repos || defaultSource,
50 () => $.Deferred().resolve( defaultSource )
51 );
52 }
53
54 return this.fileRepoPromise;
55 };
56
57 /**
58 * Get image maximum height.
59 *
60 * @return {string} Image max height
61 */
62 mw.widgets.MediaResourceQueue.prototype.getMaxHeight = function () {
63 return this.maxHeight;
64 };
65 }() );