2 * This script is run on [[Special:Upload]].
3 * It controls the invocation of the mvUploader class based on local config.
6 var mwUploadFormSelector
= '#mw-upload-form';
7 // Set up the upload form bindings once all DOM manipulation is done
11 // If wgEnableFirefogg is not boolean false, set to true
12 if ( typeof wgEnableFirefogg
== 'undefined' )
13 wgEnableFirefogg
= true;
15 if ( wgEnableFirefogg
) {
16 // Set up the upload handler to Firefogg. Should work with the HTTP uploads too.
17 $j( '#wpUploadFile' ).firefogg( {
18 // An API URL (we won't submit directly to action of the form)
19 'api_url': wgServer
+ wgScriptPath
+ '/api.php',
21 // MediaWiki API supports chunk uploads:
22 'enable_chunks' : true,
23 'edit_form_selector': mwUploadFormSelector
,
24 'new_source_cb': function( orgFilename
, oggName
) {
25 $j( '#wpDestFile' ).val( oggName
);
26 $j( '#wpDestFile' ).doDestCheck( {
27 'warn_target': '#wpDestFile-warning'
32 // Add basic upload profile support ( http status monitoring, progress box for
33 // browsers that support it, etc.)
34 if ( $j( '#wpUploadFileURL' ).length
!= 0 ) {
35 $j( '#wpUploadFileURL' ).baseUploadInterface( {
36 'api_url': wgServer
+ wgScriptPath
+ '/api.php',
37 'edit_form_selector': mwUploadFormSelector
42 if ( wgAjaxUploadDestCheck
) {
43 // Do destination check
44 $j( '#wpDestFile' ).change( function() {
45 $j( '#wpDestFile' ).doDestCheck( {
46 'warn_target':'#wpDestFile-warning'
51 // Check if we have HTTP enabled & setup enable/disable toggle:
52 if ( $j( '#wpUploadFileURL' ).length
!= 0 ) {
53 // Set the initial toggleUpType
54 _this
.toggleUpType( true );
56 $j( "input[name='wpSourceType']" ).click( function() {
57 _this
.toggleUpType( this.id
== 'wpSourceTypeFile' );
60 $j( '#wpUploadFile,#wpUploadFileURL' )
62 _this
.toggleUpType( this.id
== 'wpUploadFile' );
64 // Also setup the onChange event binding:
66 if ( wgUploadAutoFill
) {
67 mwUploadHelper
.doDestinationFill( this );
72 * Set the upload radio buttons
76 toggleUpType: function( set ) {
77 $j( '#wpSourceTypeFile' ).attr( 'checked', set );
78 $j( '#wpUploadFile' ).attr( 'disabled', !set );
80 $j( '#wpSourceTypeURL' ).attr( 'checked', !set );
81 $j( '#wpUploadFileURL' ).attr( 'disabled', set );
83 // If Firefogg is enabled, toggle action according to wpSourceTypeFile selection
84 if ( wgEnableFirefogg
) {
85 $j( '#wpUploadFile' ).firefogg( {
86 'firefogg_form_action': $j( '#wpSourceTypeFile' ).attr( 'checked' )
91 * Fill in a destination file-name based on a source asset name.
93 doDestinationFill: function( targetElm
) {
94 js_log( "doDestinationFill" )
95 // Remove any previously flagged errors
96 $j( '#mw-upload-permitted,#mw-upload-prohibited' ).hide();
98 var path
= $j( targetElm
).val();
100 var slash
= path
.lastIndexOf( '/' );
101 var backslash
= path
.lastIndexOf( '\\' );
103 if ( slash
== -1 && backslash
== -1 ) {
105 } else if ( slash
> backslash
) {
106 fname
= path
.substring( slash
+ 1, 10000 );
108 fname
= path
.substring( backslash
+ 1, 10000 );
110 // URLs are less likely to have a useful extension. Don't include them in the extension check.
111 if ( wgFileExtensions
&& $j( targetElm
).attr( 'id' ) != 'wpUploadFileURL' ) {
113 if ( fname
.lastIndexOf( '.' ) != -1 ) {
114 var ext
= fname
.substr( fname
.lastIndexOf( '.' ) + 1 );
115 for ( var i
= 0; i
< wgFileExtensions
.length
; i
++ ) {
116 if ( wgFileExtensions
[i
].toLowerCase() == ext
.toLowerCase() )
121 // Clear the upload. Set mw-upload-permitted to error.
122 $j( targetElm
).val( '' );
123 $j( '#mw-upload-permitted,#mw-upload-prohibited' ).show().addClass( 'error' );
124 $j( '#wpDestFile' ).val( '' );
128 // Capitalise first letter and replace spaces by underscores
129 fname
= fname
.charAt( 0 ).toUpperCase().concat( fname
.substring( 1, 10000 ) ).replace(/ /g
, '_' );
131 $j( '#wpDestFile' ).val( fname
);
133 // Do a destination check
134 $j( '#wpDestFile' ).doDestCheck( {
135 'warn_target': '#wpDestFile-warning'
141 js2AddOnloadHook( function() {
142 mwUploadHelper
.init();