Localisation updates from https://translatewiki.net.
[mediawiki.git] / resources / src / mediawiki.widgets / MediaSearch / mw.widgets.MediaUserUploadsQueue.js
blob9588e3f83718d6bdaddb20452eb6c447ca575dbc
1 /*!
2  * MediaWiki Widgets - MediaUserUploadsQueue 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 () {
9         /**
10          * @classdesc Media resource queue.
11          *
12          * @class
13          * @extends mw.widgets.MediaResourceQueue
14          *
15          * @constructor
16          * @description Create an instance of `mw.widgets.MediaUserUploadsQueue`.
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.MediaUserUploadsQueue = function MwWidgetsMediaUserUploadsQueue( config ) {
22                 config = config || {};
24                 // Parent constructor
25                 mw.widgets.MediaUserUploadsQueue.super.call( this, config );
27                 if ( !mw.user.isAnon() ) {
28                         this.setUser( mw.user.getName() );
29                 }
30         };
32         /* Inheritance */
33         OO.inheritClass( mw.widgets.MediaUserUploadsQueue, mw.widgets.MediaResourceQueue );
35         /**
36          * Override parent method to set up the providers according to
37          * the file repos.
38          *
39          * @return {jQuery.Promise} Promise that resolves when the resources are set up
40          */
41         mw.widgets.MediaUserUploadsQueue.prototype.setup = function () {
42                 return this.getFileRepos().then( ( sources ) => {
43                         if ( this.providers.length === 0 ) {
44                                 // Set up the providers
45                                 for ( let i = 0, len = sources.length; i < len; i++ ) {
46                                         this.addProvider( new mw.widgets.MediaUserUploadsProvider(
47                                                 sources[ i ].apiurl,
48                                                 {
49                                                         name: sources[ i ].name,
50                                                         local: sources[ i ].local,
51                                                         scriptDirUrl: sources[ i ].scriptDirUrl,
52                                                         userParams: {
53                                                                 gaiuser: this.getUser()
54                                                         },
55                                                         staticParams: {
56                                                                 iiurlheight: this.getMaxHeight()
57                                                         }
58                                                 } )
59                                         );
60                                 }
61                         }
62                 } );
63         };
65         /**
66          * Set the user name.
67          *
68          * @param {string} user User name
69          */
70         mw.widgets.MediaUserUploadsQueue.prototype.setUser = function ( user ) {
71                 this.setParams( { gaiuser: user } );
72         };
74         /**
75          * Get the user name.
76          *
77          * @return {string} API search query
78          */
79         mw.widgets.MediaUserUploadsQueue.prototype.getUser = function () {
80                 return this.getParams().gaiuser;
81         };
82 }() );