Merge "SpecialMovepage: Convert form to use OOUI controls"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.ForeignUpload.js
1 ( function ( mw, OO ) {
2 /**
3 * @class mw.ForeignUpload
4 * @extends mw.Upload
5 *
6 * Used to represent an upload in progress on the frontend.
7 *
8 * Subclassed to upload to a foreign API, with no other goodies. Use
9 * this for a generic foreign image repository on your wiki farm.
10 *
11 * Note you can provide the {@link #targetHost targetHost} or not - if the first argument is
12 * an object, we assume you want the default, and treat it as apiconfig
13 * instead.
14 *
15 * @constructor
16 * @param {string} [targetHost="commons.wikimedia.org"] Used to set up the target
17 * wiki. If not remote, this class behaves identically to mw.Upload (unless further subclassed)
18 * @param {Object} [apiconfig] Passed to the constructor of mw.ForeignApi or mw.Api, as needed.
19 */
20 function ForeignUpload( targetHost, apiconfig ) {
21 var api;
22
23 if ( typeof targetHost === 'object' ) {
24 // targetHost probably wasn't passed in, it must
25 // be apiconfig
26 apiconfig = targetHost;
27 } else {
28 // targetHost is a useful string, set it here
29 this.targetHost = targetHost || this.targetHost;
30 }
31
32 if ( location.host !== this.targetHost ) {
33 api = new mw.ForeignApi(
34 location.protocol + '//' + this.targetHost + '/w/api.php',
35 apiconfig
36 );
37 } else {
38 // We'll ignore the CORS and centralauth stuff if we're on Commons already
39 api = new mw.Api( apiconfig );
40 }
41
42 mw.Upload.call( this, api );
43 }
44
45 OO.inheritClass( ForeignUpload, mw.Upload );
46
47 /**
48 * @property targetHost
49 * Used to specify the target repository of the upload.
50 *
51 * You could override this to point at something that isn't Commons,
52 * but be sure it has the correct templates and is CORS and CentralAuth
53 * ready.
54 */
55 ForeignUpload.prototype.targetHost = 'commons.wikimedia.org';
56
57 mw.ForeignUpload = ForeignUpload;
58 }( mediaWiki, OO ) );