2 * This script is run on [[Special:Upload]].
3 * It controls the invocation of the mvUploader class based on local config.
6 var mwUploadFormTarget
= '#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 'target_edit_from': mwUploadFormTarget
,
22 'new_source_cb': function( orgFilename
, oggName
) {
23 $j( '#wpDestFile' ).val( oggName
);
24 $j( '#wpDestFile' ).doDestCheck( {
25 'warn_target': '#wpDestFile-warning'
30 // Add basic upload profile support ( http status monitoring, progress box for
31 // browsers that support it, etc.)
32 if ( $j( '#wpUploadFileURL' ).length
!= 0 ) {
33 $j( '#wpUploadFileURL' ).baseUploadInterface( {
34 'api_url': wgServer
+ wgScriptPath
+ '/api.php',
35 'target_edit_from': mwUploadFormTarget
40 if ( wgAjaxUploadDestCheck
) {
41 // Do destination check
42 $j( '#wpDestFile' ).change( function() {
43 $j( '#wpDestFile' ).doDestCheck( {
44 'warn_target':'#wpDestFile-warning'
49 // Check if we have HTTP enabled & setup enable/disable toggle:
50 if ( $j( '#wpUploadFileURL' ).length
!= 0 ) {
51 // Set the initial toggleUpType
52 _this
.toggleUpType( true );
54 $j( "input[name='wpSourceType']" ).click( function() {
55 _this
.toggleUpType( this.id
== 'wpSourceTypeFile' );
58 $j( '#wpUploadFile,#wpUploadFileURL' )
60 _this
.toggleUpType( this.id
== 'wpUploadFile' );
62 // Also setup the onChange event binding:
64 if ( wgUploadAutoFill
) {
65 mwUploadHelper
.doDestinationFill( this );
70 * Set the upload radio buttons
74 toggleUpType: function( set ) {
75 $j( '#wpSourceTypeFile' ).attr( 'checked', set );
76 $j( '#wpUploadFile' ).attr( 'disabled', !set );
78 $j( '#wpSourceTypeURL' ).attr( 'checked', !set );
79 $j( '#wpUploadFileURL' ).attr( 'disabled', set );
81 // If Firefogg is enabled, toggle action according to wpSourceTypeFile selection
82 if ( wgEnableFirefogg
) {
83 $j( '#wpUploadFile' ).firefogg( {
84 'firefogg_form_action': $j( '#wpSourceTypeFile' ).attr( 'checked' )
89 * Fill in a destination file-name based on a source asset name.
91 doDestinationFill: function( targetElm
) {
92 js_log( "doDestinationFill" )
93 // Remove any previously flagged errors
94 $j( '#mw-upload-permitted,#mw-upload-prohibited' ).hide();
96 var path
= $j( targetElm
).val();
98 var slash
= path
.lastIndexOf( '/' );
99 var backslash
= path
.lastIndexOf( '\\' );
101 if ( slash
== - 1 && backslash
== - 1 ) {
103 } else if ( slash
> backslash
) {
104 fname
= path
.substring( slash
+ 1, 10000 );
106 fname
= path
.substring( backslash
+ 1, 10000 );
108 // URLs are less likely to have a useful extension. Don't include them in the extension check.
109 if ( wgFileExtensions
&& $j( targetElm
).attr( 'id' ) != 'wpUploadFileURL' ) {
111 if ( fname
.lastIndexOf( '.' ) != - 1 ) {
112 var ext
= fname
.substr( fname
.lastIndexOf( '.' ) + 1 );
113 for ( var i
= 0; i
< wgFileExtensions
.length
; i
++ ) {
114 if ( wgFileExtensions
[i
].toLowerCase() == ext
.toLowerCase() )
119 // Clear the upload. Set mw-upload-permitted to error.
120 $j( targetElm
).val( '' );
121 $j( '#mw-upload-permitted,#mw-upload-prohibited' ).show().addClass( 'error' );
122 $j( '#wpDestFile' ).val( '' );
126 // Capitalise first letter and replace spaces by underscores
127 fname
= fname
.charAt( 0 ).toUpperCase().concat( fname
.substring( 1, 10000 ) ).replace(/ /g
, '_' );
129 $j( '#wpDestFile' ).val( fname
);
131 // Do a destination check
132 $j( '#wpDestFile' ).doDestCheck( {
133 'warn_target': '#wpDestFile-warning'
139 js2AddOnloadHook( function() {
140 mwUploadHelper
.init();