1
|
|
|
/** |
2
|
|
|
* File containing the SimpleBatchUpload class |
3
|
|
|
* |
4
|
|
|
* @copyright (C) 2016, Stephan Gambke |
5
|
|
|
* @license GNU General Public License, version 2 (or any later version) |
6
|
|
|
* |
7
|
|
|
* This software is free software; you can redistribute it and/or |
8
|
|
|
* modify it under the terms of the GNU General Public License |
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
10
|
|
|
* of the License, or (at your option) any later version. |
11
|
|
|
* This software is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
* |
18
|
|
|
* @file |
19
|
|
|
* @ingroup SimpleBatchUpload |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
/** global: mediaWiki */ |
23
|
|
|
/** global: jQuery */ |
24
|
|
|
|
25
|
|
|
;( function ( $, mw, undefined ) { |
26
|
|
|
|
27
|
|
|
'use strict'; |
28
|
|
|
|
29
|
|
|
$( function () { |
30
|
|
|
$( '#fileupload' ) |
31
|
|
|
|
32
|
|
|
.on( 'change', function ( /* e, data */ ) { $( '#fileupload-results' ).empty(); } ) |
33
|
|
|
.on( 'drop', function ( /* e, data */ ) { $( '#fileupload-results' ).empty(); } ) |
34
|
|
|
|
35
|
|
|
.fileupload( { |
36
|
|
|
dataType: 'json', |
37
|
|
|
dropZone: $( '#fileupload-dropzone' ), |
38
|
|
|
progressInterval: 100, |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
add: function ( e, data ) { |
42
|
|
|
|
43
|
|
|
data.id = Date.now(); |
44
|
|
|
|
45
|
|
|
var status = $('<li>') |
46
|
|
|
.attr( 'id', data.id ) |
47
|
|
|
.text( data.files[0].name ); |
48
|
|
|
|
49
|
|
|
$( '#fileupload-results' ).append( status ); |
50
|
|
|
|
51
|
|
|
var api = new mw.Api(); |
52
|
|
|
api.getEditToken() |
53
|
|
|
.then( |
54
|
|
|
function ( token ) { |
55
|
|
|
|
56
|
|
|
data.formData = { |
57
|
|
|
format: 'json', |
58
|
|
|
action: 'upload', |
59
|
|
|
token: token, |
60
|
|
|
ignorewarnings: 1, |
61
|
|
|
comment: mw.message( 'simplebatchupload-comment' ).text(), |
62
|
|
|
filename: data.files[ 0 ].name |
63
|
|
|
}; |
64
|
|
|
|
65
|
|
|
data.submit() |
66
|
|
|
.success( function ( result /*, textStatus, jqXHR */ ) { |
67
|
|
|
|
68
|
|
|
if ( result.error !== undefined ) { |
69
|
|
|
|
70
|
|
|
status.text( status.text() + " ERROR: " + result.error.info ).addClass( 'ful-error' ); |
71
|
|
|
|
72
|
|
|
} else { |
73
|
|
|
var link = $( '<a>' ); |
74
|
|
|
link |
75
|
|
|
.attr( 'href', mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).file, result.upload.filename ).getUrl() ) |
76
|
|
|
.text( result.upload.filename ); |
77
|
|
|
|
78
|
|
|
status |
79
|
|
|
.addClass( 'ful-success' ) |
80
|
|
|
.text( ' OK' ) |
81
|
|
|
.prepend( link ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} ) |
85
|
|
|
.error( function ( /* jqXHR, textStatus, errorThrown */ ) { |
86
|
|
|
status.text( status.text() + " ERROR" ).addClass( 'ful-error' ); |
87
|
|
|
} ); |
88
|
|
|
}, |
89
|
|
|
function () { |
90
|
|
|
status.text( status.text() + " ERROR" ).addClass( 'ful-error' ); |
91
|
|
|
} |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
}, |
95
|
|
|
|
96
|
|
|
progress: function (e, data) { |
97
|
|
|
if ( data.loaded !== data.total ) { |
98
|
|
|
$( '#' + data.id ) |
99
|
|
|
.text( data.files[0].name + ' ' + parseInt(data.loaded / data.total * 100, 10) + '%' ); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} ); |
103
|
|
|
|
104
|
|
|
$( document ).bind( 'drop dragover', function ( e ) { |
105
|
|
|
e.preventDefault(); |
106
|
|
|
} ); |
107
|
|
|
} ); |
108
|
|
|
|
109
|
|
|
}( jQuery, mediaWiki )); |
110
|
|
|
|