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