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
|
|
|
|
34
|
|
|
.fileupload( { |
35
|
|
|
dataType: 'json', |
36
|
|
|
dropZone: $( '#fileupload-dropzone' ), |
37
|
|
|
progressInterval: 100, |
38
|
|
|
|
39
|
|
|
drop: function ( e, data ) { |
|
|
|
|
40
|
|
|
$( '#fileupload-results' ).empty(); |
41
|
|
|
}, |
42
|
|
|
|
43
|
|
|
add: function ( e, data ) { |
44
|
|
|
|
45
|
|
|
data.id = Date.now(); |
46
|
|
|
|
47
|
|
|
var status = $('<li>') |
48
|
|
|
.attr( 'id', data.id ) |
49
|
|
|
.text( data.files[0].name ); |
50
|
|
|
$( '#fileupload-results' ).append( status ); |
51
|
|
|
|
52
|
|
|
data.formData = { |
53
|
|
|
format: 'json', |
54
|
|
|
action: 'upload', |
55
|
|
|
token: $( this ).fileupload( 'option', 'token' ), |
56
|
|
|
ignorewarnings: 1, |
57
|
|
|
filename: data.files[ 0 ].name |
58
|
|
|
}; |
59
|
|
|
|
60
|
|
|
data.submit() |
61
|
|
|
.success( function ( result /*, textStatus, jqXHR */ ) { |
62
|
|
|
|
63
|
|
|
if ( result.error != undefined ) { |
64
|
|
|
|
65
|
|
|
status.text( status.text() + " ERROR: " + result.error.info ).addClass( 'ful-error' ); |
66
|
|
|
|
67
|
|
|
} else { |
68
|
|
|
var link = $( '<a>' ); |
69
|
|
|
link |
70
|
|
|
.attr( 'href', mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).file, result.upload.filename ).getUrl() ) |
71
|
|
|
.text( result.upload.filename ); |
72
|
|
|
|
73
|
|
|
status |
74
|
|
|
.addClass( 'ful-success' ) |
75
|
|
|
.text( ' OK' ) |
76
|
|
|
.prepend( link ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} ) |
80
|
|
|
.error( function ( /* jqXHR, textStatus, errorThrown */ ) { |
81
|
|
|
status.text( status.text() + " ERROR" ).addClass( 'ful-error' ); |
82
|
|
|
} ); |
83
|
|
|
|
84
|
|
|
}, |
85
|
|
|
|
86
|
|
|
progress: function (e, data) { |
87
|
|
|
if ( data.loaded != data.total ) { |
88
|
|
|
$( '#' + data.id ) |
89
|
|
|
.text( data.files[0].name + ' ' + parseInt(data.loaded / data.total * 100, 10) + '%' ); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} ); |
93
|
|
|
|
94
|
|
|
$( document ).bind( 'drop dragover', function ( e ) { |
95
|
|
|
e.preventDefault(); |
96
|
|
|
} ); |
97
|
|
|
} ); |
98
|
|
|
|
99
|
|
|
}( jQuery, mediaWiki )); |
|
|
|
|
100
|
|
|
|
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.