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
= {
11 firefogg_installed
:false,
14 //if not boolean false set to true:
15 if(typeof wgEnableFirefogg
== 'undefined')
16 wgEnableFirefogg
= true;
18 if( wgEnableFirefogg
){
19 //setup the upload handler to firefogg (supports our upload proccess) (should work with the http uploads too)
20 $j('#wpUploadFile').firefogg({
21 //an api url (we won't submit directly to action of the form)
22 'api_url' : wgServer
+ wgScriptPath
+ '/api.php',
24 'target_edit_from' : mwUploadFormTarget
,
25 'new_source_cb' : function( orgFilename
, oggName
){
26 if($j('#wpDestFile').val() == "")
27 $j('#wpDestFile').val( oggName
);
28 $j('#wpDestFile').doDestCheck({
29 'warn_target':'#wpDestFile-warning'
32 'detect_cb':function( fogg_installed
){
34 _this
.firefogg_installed
=true;
36 _this
.firefogg_installed
=false;
42 //Add basic upload profile support ( http status monitoring, progress box for browsers that support it etc.)
43 if($j('#wpUploadFileURL').length
!= 0){
44 $j('#wpUploadFileURL').baseUploadInterface({
45 'api_url' : wgServer
+ wgScriptPath
+ '/api.php',
46 'target_edit_from' : mwUploadFormTarget
51 if( wgAjaxUploadDestCheck
){
52 //do destination check:
53 $j('#wpDestFile').change(function(){
54 $j(this).doDestCheck({
55 'warn_target':'#wpDestFile-warning'
60 //check if we have http enabled & setup enable/disable toggle:
61 if($j('#wpUploadFileURL').length
!= 0){
62 //set the initial toggleUpType
63 _this
.toggleUpType(true);
65 $j("input[name='wpSourceType']").click(function(){
66 _this
.toggleUpType( this.id
== 'wpSourceTypeFile' );
69 $j('#wpUploadFile,#wpUploadFileURL').focus(function(){
70 _this
.toggleUpType( this.id
== 'wpUploadFile' );
71 }).change(function(){ //also setup the onChange event binding:
72 if ( wgUploadAutoFill
) {
73 mwUploadHelper
.doDestinationFill( this );
78 * toggleUpType sets the upload radio buttons
82 toggleUpType:function( set ){
83 $j('#wpSourceTypeFile').attr('checked', set);
84 $j('#wpUploadFile').attr('disabled', !set);
86 $j('#wpSourceTypeURL').attr('checked', !set);
87 $j('#wpUploadFileURL').attr('disabled', set);
89 //if firefogg is enbaled: toggle action per form select of http upload vs firefogg upload
90 if( wgEnableFirefogg
){
91 $j('#wpUploadFile').firefogg({
92 'firefogg_form_action': $j('#wpSourceTypeFile').attr('checked')
97 * doDestinationFill fills in a destination file-name based on a source asset name.
99 doDestinationFill : function( targetElm
){
100 js_log("doDestinationFill")
101 //remove any previously flagged errors
102 $j('#mw-upload-permitted,#mw-upload-prohibited').hide();
104 var path
= $j(targetElm
).val();
105 // Find trailing part
106 var slash
= path
.lastIndexOf('/');
107 var backslash
= path
.lastIndexOf('\\');
109 if (slash
== -1 && backslash
== -1) {
111 } else if (slash
> backslash
) {
112 fname
= path
.substring(slash
+1, 10000);
114 fname
= path
.substring(backslash
+1, 10000);
116 //urls are less likely to have a usefull extension don't include them in the extention check
117 if( wgFileExtensions
&& $j(targetElm
).attr('id') != 'wpUploadFileURL' ){
119 if( fname
.lastIndexOf('.')!=-1 ){
120 var ext
= fname
.substr( fname
.lastIndexOf('.')+1 );
121 for(var i
=0; i
< wgFileExtensions
.length
; i
++){
122 if( wgFileExtensions
[i
].toLowerCase() == ext
.toLowerCase() )
127 //clear the upload set mw-upload-permitted to error
128 $j(targetElm
).val('');
129 $j('#mw-upload-permitted,#mw-upload-prohibited').show().addClass('error');
130 //clear the wpDestFile as well:
131 $j('#wpDestFile').val('');
135 // Capitalise first letter and replace spaces by underscores
136 fname
= fname
.charAt(0).toUpperCase().concat(fname
.substring(1,10000)).replace(/ /g
, '_');
138 $j('#wpDestFile').val( fname
);
140 //do a destination check
141 $j('#wpDestFile').doDestCheck({
142 'warn_target':'#wpDestFile-warning'