2 * This script is run on [[Special:Upload]].
3 * It controls the invocation of the mvUploader class based on local config.
6 js2AddOnloadHook( function() {
7 js_log("never ran js2hook");
11 var mwUploadFormTarget
= '#mw-upload-form';
12 // Set up the upload form bindings once all DOM manipulation is done
13 var mwUploadHelper
= {
16 // If wgEnableFirefogg is not boolean false, set to true
17 if( typeof wgEnableFirefogg
== 'undefined' )
18 wgEnableFirefogg
= true;
20 if( wgEnableFirefogg
) {
21 // Set up the upload handler to Firefogg. Should work with the HTTP uploads too.
22 $j( '#wpUploadFile' ).firefogg( {
23 // An API URL (we won't submit directly to action of the form)
24 'api_url': wgServer
+ wgScriptPath
+ '/api.php',
26 'target_edit_from': mwUploadFormTarget
,
27 'new_source_cb': function( orgFilename
, oggName
) {
28 $j( '#wpDestFile' ).val( oggName
);
29 $j( '#wpDestFile' ).doDestCheck({
30 'warn_target': '#wpDestFile-warning'
35 // Add basic upload profile support ( http status monitoring, progress box for
36 // browsers that support it, etc.)
37 if( $j( '#wpUploadFileURL' ).length
!= 0 ) {
38 $j( '#wpUploadFileURL' ).baseUploadInterface( {
39 'api_url': wgServer
+ wgScriptPath
+ '/api.php',
40 'target_edit_from': mwUploadFormTarget
45 if( wgAjaxUploadDestCheck
) {
46 // Do destination check
47 $j( '#wpDestFile' ).change( function() {
48 $j( '#wpDestFile' ).doDestCheck({
49 'warn_target':'#wpDestFile-warning'
54 // Check if we have HTTP enabled & setup enable/disable toggle:
55 if( $j( '#wpUploadFileURL' ).length
!= 0 ) {
56 // Set the initial toggleUpType
57 _this
.toggleUpType( true );
59 $j( "input[name='wpSourceType']" ).click( function() {
60 _this
.toggleUpType( this.id
== 'wpSourceTypeFile' );
63 $j( '#wpUploadFile,#wpUploadFileURL' )
65 _this
.toggleUpType( this.id
== 'wpUploadFile' );
67 // Also setup the onChange event binding:
69 if ( wgUploadAutoFill
) {
70 mwUploadHelper
.doDestinationFill( this );
75 * Set the upload radio buttons
79 toggleUpType: function( set ) {
80 $j( '#wpSourceTypeFile' ).attr( 'checked', set );
81 $j( '#wpUploadFile' ).attr( 'disabled', !set );
83 $j( '#wpSourceTypeURL' ).attr( 'checked', !set );
84 $j( '#wpUploadFileURL' ).attr( 'disabled', set );
86 // If Firefogg is enabled, toggle action according to wpSourceTypeFile selection
87 if( wgEnableFirefogg
) {
88 $j( '#wpUploadFile' ).firefogg({
89 'firefogg_form_action': $j( '#wpSourceTypeFile' ).attr( 'checked' )
94 * Fill in a destination file-name based on a source asset name.
96 doDestinationFill: function( targetElm
) {
97 js_log( "doDestinationFill" )
98 // Remove any previously flagged errors
99 $j( '#mw-upload-permitted,#mw-upload-prohibited' ).hide();
101 var path
= $j( targetElm
).val();
102 // Find trailing part
103 var slash
= path
.lastIndexOf( '/' );
104 var backslash
= path
.lastIndexOf( '\\' );
106 if ( slash
== -1 && backslash
== -1 ) {
108 } else if ( slash
> backslash
) {
109 fname
= path
.substring( slash
+1, 10000 );
111 fname
= path
.substring( backslash
+1, 10000 );
113 // URLs are less likely to have a useful extension. Don't include them in the extension check.
114 if( wgFileExtensions
&& $j( targetElm
).attr( 'id' ) != 'wpUploadFileURL' ) {
116 if( fname
.lastIndexOf( '.' ) != -1 ) {
117 var ext
= fname
.substr( fname
.lastIndexOf( '.' ) + 1 );
118 for( var i
= 0; i
< wgFileExtensions
.length
; i
++ ) {
119 if( wgFileExtensions
[i
].toLowerCase() == ext
.toLowerCase() )
124 // Clear the upload. Set mw-upload-permitted to error.
125 $j( targetElm
).val( '' );
126 $j( '#mw-upload-permitted,#mw-upload-prohibited' ).show().addClass( 'error' );
127 $j( '#wpDestFile' ).val( '' );
131 // Capitalise first letter and replace spaces by underscores
132 fname
= fname
.charAt( 0 ).toUpperCase().concat( fname
.substring( 1, 10000 ) ).replace( / /g
, '_' );
134 $j( '#wpDestFile' ).val( fname
);
136 // Do a destination check
137 $j( '#wpDestFile' ).doDestCheck({
138 'warn_target': '#wpDestFile-warning'