46bf061c3ffd8727f84f1091ad7858acd9eeb361
2 * uploadPage.js to be run on specialUpload page.
3 * controls the invocation of the mvUploader class based on local config.
5 mwAddOnloadHook( function(){
8 //set up the upoload form bindings once all dom manipluation is done
10 firefogg_installed
:false,
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 'new_source_cb' : function( orgFilename
, oggName
){
24 $j('#wpDestFile').val( oggName
);
25 mwUploadHelper
.doDestCheck();
27 'detect_cb':function(fogg_installed
){
29 _this
.firefogg_installed
=true;
31 _this
.firefogg_installed
=false;
37 //Add basic upload profile support ( http status monitoring, progress box for browsers that support it etc.)
38 if($j('#wpUploadFileURL').length
!= 0){
39 $j('#wpUploadFileURL').baseUploadInterface({
40 'api_url' : wgServer
+ wgScriptPath
+ '/api.php',
41 'target_edit_from' : '#mw-upload-form'
46 if( wgAjaxUploadDestCheck
){
47 //do destination check:
48 $j('#wpDestFile').change( mwUploadHelper
.doDestCheck
);
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 * doDestCheck checks the destination
89 * @@todo we should be able to configure its "targets" via parent config
91 doDestCheck:function(){
93 $j('#wpDestFile-warning').empty();
95 $j('#wpDestFile').after('<img id = "mw-spinner-wpDestFile" src ="'+ stylepath
+ '/common/images/spinner.gif" />');
96 //try and get a thumb of the current file (check its destination)
99 'titles': 'File:' + $j('#wpDestFile').val(),//@@todo we may need a more clever way to get a the filename
101 'iiprop':'url|mime|size',
106 $j('#mw-spinner-wpDestFile').remove();
107 if(data
&& data
.query
&& data
.query
.pages
){
108 if( data
.query
.pages
[-1] ){
109 //all good no file there
111 for(var page_id
in data
.query
.pages
){
112 if( data
.query
.normalized
){
113 var ntitle
= data
.query
.normalized
[0].to
;
115 var ntitle
= data
.query
.pages
[ page_id
].title
;
117 var img
= data
.query
.pages
[ page_id
].imageinfo
[0];
118 $j('#wpDestFile-warning').html(
121 gM('fileexists', ntitle
) +
123 '<div class="thumb tright">' +
124 '<div style="width: ' + ( parseInt(img
.thumbwidth
)+2 ) + 'px;" class="thumbinner">' +
125 '<a title="' + ntitle
+ '" class="image" href="' + img
.descriptionurl
+ '">' +
126 '<img width="' + img
.thumbwidth
+ '" height="' + img
.thumbheight
+ '" border="0" class="thumbimage" ' +
127 'src="' + img
.thumburl
+ '"' +
128 ' alt="' + ntitle
+ '"/>' +
130 '<div class="thumbcaption">' +
131 '<div class="magnify">' +
132 '<a title="' + gM('thumbnail-more') + '" class="internal" ' +
133 'href="' + img
.descriptionurl
+'"><img width="15" height="11" alt="" ' +
134 'src="' + stylepath
+"/>" +
137 gM('fileexists-thumb') +
149 * doDestinationFill fills in a destination file-name based on a source asset name.
150 * @@todo we should be able to configure its "targets" via parent config
152 doDestinationFill:function( targetElm
){
153 js_log("doDestinationFill")
154 //remove any previously flagged errors
155 $j('#mw-upload-permitted,#mw-upload-prohibited').hide();
157 var path
= $j(targetElm
).val();
158 // Find trailing part
159 var slash
= path
.lastIndexOf('/');
160 var backslash
= path
.lastIndexOf('\\');
162 if (slash
== -1 && backslash
== -1) {
164 } else if (slash
> backslash
) {
165 fname
= path
.substring(slash
+1, 10000);
167 fname
= path
.substring(backslash
+1, 10000);
169 //urls are less likely to have a usefull extension don't include them in the extention check
170 if( wgFileExtensions
&& $j(targetElm
).attr('id') != 'wpUploadFileURL' ){
172 if( fname
.lastIndexOf('.')!=-1 ){
173 var ext
= fname
.substr( fname
.lastIndexOf('.')+1 );
174 for(var i
=0; i
< wgFileExtensions
.length
; i
++){
175 if( wgFileExtensions
[i
].toLowerCase() == ext
.toLowerCase() )
180 //clear the upload set mw-upload-permitted to error
181 $j(targetElm
).val('');
182 $j('#mw-upload-permitted,#mw-upload-prohibited').show().addClass('error');
183 //clear the wpDestFile as well:
184 $j('#wpDestFile').val('');
188 // Capitalise first letter and replace spaces by underscores
189 fname
= fname
.charAt(0).toUpperCase().concat(fname
.substring(1,10000)).replace(/ /g
, '_');
191 $j('#wpDestFile').val( fname
);
193 //do a destination check