2 * uploadPage.js to be run on specialUpload page.
3 * controls the invocation of the mvUploader class based on local config.
5 js2AddOnloadHook( function(){
8 var mwUploadFormTarget = '#mw-upload-form';
9 //set up the upoload form bindings once all dom manipluation is done
10 var mwUploadHelper = {
13 //if not boolean false set to true:
14 if(typeof wgEnableFirefogg == 'undefined')
15 wgEnableFirefogg = true;
17 if( wgEnableFirefogg ){
18 //setup the upload handler to firefogg (supports our upload proccess) (should work with the http uploads too)
19 $j('#wpUploadFile').firefogg({
20 //an api url (we won't submit directly to action of the form)
21 'api_url' : wgServer + wgScriptPath + '/api.php',
23 'target_edit_from' : mwUploadFormTarget,
24 'new_source_cb' : function( orgFilename, oggName ){
25 if($j('#wpDestFile').val() == "")
26 $j('#wpDestFile').val( oggName );
27 $j('#wpDestFile').doDestCheck({
28 'warn_target':'#wpDestFile-warning'
33 //Add basic upload profile support ( http status monitoring, progress box for browsers that support it etc.)
34 if($j('#wpUploadFileURL').length != 0){
35 $j('#wpUploadFileURL').baseUploadInterface({
36 'api_url' : wgServer + wgScriptPath + '/api.php',
37 'target_edit_from' : mwUploadFormTarget
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').focus(function(){
61 _this.toggleUpType( this.id == 'wpUploadFile' );
62 }).change(function(){ //also setup the onChange event binding:
63 if ( wgUploadAutoFill ) {
64 mwUploadHelper.doDestinationFill( this );
69 * toggleUpType sets the upload radio buttons
73 toggleUpType:function( set ){
74 $j('#wpSourceTypeFile').attr('checked', set);
75 $j('#wpUploadFile').attr('disabled', !set);
77 $j('#wpSourceTypeURL').attr('checked', !set);
78 $j('#wpUploadFileURL').attr('disabled', set);
80 //if firefogg is enbaled: toggle action per form select of http upload vs firefogg upload
81 if( wgEnableFirefogg ){
82 $j('#wpUploadFile').firefogg({
83 'firefogg_form_action': $j('#wpSourceTypeFile').attr('checked')
88 * doDestinationFill fills in a destination file-name based on a source asset name.
90 doDestinationFill : function( targetElm ){
91 js_log("doDestinationFill")
92 //remove any previously flagged errors
93 $j('#mw-upload-permitted,#mw-upload-prohibited').hide();
95 var path = $j(targetElm).val();
97 var slash = path.lastIndexOf('/');
98 var backslash = path.lastIndexOf('\\');
100 if (slash == -1 && backslash == -1) {
102 } else if (slash > backslash) {
103 fname = path.substring(slash+1, 10000);
105 fname = path.substring(backslash+1, 10000);
107 //urls are less likely to have a usefull extension don't include them in the extention check
108 if( wgFileExtensions && $j(targetElm).attr('id') != 'wpUploadFileURL' ){
110 if( fname.lastIndexOf('.')!=-1 ){
111 var ext = fname.substr( fname.lastIndexOf('.')+1 );
112 for(var i=0; i < wgFileExtensions.length; i++){
113 if( wgFileExtensions[i].toLowerCase() == ext.toLowerCase() )
118 //clear the upload set mw-upload-permitted to error
119 $j(targetElm).val('');
120 $j('#mw-upload-permitted,#mw-upload-prohibited').show().addClass('error');
121 //clear the wpDestFile as well:
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'