Merge "Skin: Make skins aware of their registered skin name"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / MediaSearch / mw.widgets.MediaSearchQueue.js
1 /*!
2 * MediaWiki Widgets - MediaSearchQueue 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 ( mw ) {
8
9 /**
10 * MediaWiki media resource queue.
11 *
12 * @class
13 * @extends mw.widgets.MediaResourceQueue
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.MediaSearchQueue = function MwWidgetsMediaSearchQueue( config ) {
21 config = config || {};
22
23 // Parent constructor
24 mw.widgets.MediaSearchQueue.super.call( this, config );
25
26 this.searchQuery = '';
27 };
28
29 /* Inheritance */
30 OO.inheritClass( mw.widgets.MediaSearchQueue, mw.widgets.MediaResourceQueue );
31
32 /**
33 * Override parent method to set up the providers according to
34 * the file repos
35 *
36 * @return {jQuery.Promise} Promise that resolves when the resources are set up
37 */
38 mw.widgets.MediaSearchQueue.prototype.setup = function () {
39 var i, len,
40 queue = this;
41
42 return this.getFileRepos().then( function ( sources ) {
43 if ( queue.providers.length === 0 ) {
44 // Set up the providers
45 for ( i = 0, len = sources.length; i < len; i++ ) {
46 queue.providers.push( new mw.widgets.MediaSearchProvider(
47 sources[ i ].apiurl,
48 {
49 name: sources[ i ].name,
50 local: sources[ i ].local,
51 scriptDirUrl: sources[ i ].scriptDirUrl,
52 userParams: {
53 gsrsearch: queue.getSearchQuery()
54 },
55 staticParams: {
56 iiurlheight: queue.getMaxHeight()
57 }
58 } )
59 );
60 }
61 }
62 } );
63 };
64
65 /**
66 * Set the search query
67 *
68 * @param {string} searchQuery API search query
69 */
70 mw.widgets.MediaSearchQueue.prototype.setSearchQuery = function ( searchQuery ) {
71 this.setParams( { gsrsearch: searchQuery } );
72 };
73
74 /**
75 * Get the search query
76 *
77 * @return {string} API search query
78 */
79 mw.widgets.MediaSearchQueue.prototype.getSearchQuery = function () {
80 return this.getParams().gsrsearch;
81 };
82 }( mediaWiki ) );