summaryrefslogtreecommitdiff
path: root/www/wiki/resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaResourceQueue.js
blob: 34fa44b4ec2e96cbb0bddedf7aa3ee5d0c152073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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 ) );