r50610 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50609‎ | r50610 | r50611 >
Date:23:26, 14 May 2009
Author:dale
Status:deferred
Tags:
Comment:
* improved upload handling
* uploadPgae.js drives upload handling (refactors upload.js into jQuery land)
* added example add_media_wizard stand-alone page.
Modified paths:
  • /branches/new-upload/phase3/includes/AutoLoader.php (modified) (history)
  • /branches/new-upload/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/example_usage/sample_add_media_wizard.html (added) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvUploader.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/mv_embed.js (modified) (history)
  • /branches/new-upload/phase3/js2/upSetup.js (deleted) (history)
  • /branches/new-upload/phase3/js2/uploadPage.js (added) (history)

Diff [purge]

Index: branches/new-upload/phase3/includes/AutoLoader.php
@@ -579,7 +579,7 @@
580580 'wikibits' => 'skins/common/wikibits.js',
581581
582582 //phase 2 javascript:
583 - 'upSetup' => 'js2/upSetup.js',
 583+ 'uploadPage' => 'js2/uploadPage.js',
584584 );
585585
586586 //add the mwEmbed set of classes that we want to expose: (could be conditional)
Index: branches/new-upload/phase3/includes/specials/SpecialUpload.php
@@ -583,7 +583,7 @@
584584 //$wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
585585
586586 //add javascript phase 2 upload script (will completely replace upload.js shortly)
587 - $wgOut->addScriptClass( 'upSetup' );
 587+ $wgOut->addScriptClass( 'uploadPage' );
588588
589589
590590 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
@@ -712,34 +712,23 @@
713713 $warningChecked = ($this->mIgnoreWarning || $this->mForReUpload) ? 'checked="checked"' : '';
714714
715715 // Prepare form for upload or upload/copy
 716+ //javascript moved from inline calls to setup:
716717 if( UploadFromUrl::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
717718 $filename_form =
718 - "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='upload' " .
719 - "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
720 - "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
721 - "onfocus='" .
722 - "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
723 - "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
724 - "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
 719+ "<input type='radio' id=\"wpSourceTypeFile\" name='wpSourceType' value='upload' checked='checked' />" .
 720+ "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' />" .
725721 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
726 - "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='url' " .
727 - "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" .
728 - "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
729 - "onfocus='" .
730 - "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
731 - "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
732 - "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' />" .
 722+ "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='url' />" .
 723+ "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' size='60' />" .
733724 wfMsgHtml( 'upload_source_url' ) ;
734725 } else {
735726 $filename_form =
736 - "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
737 - ($this->mDesiredDestName?"":"onchange='fillDestFilename(\"wpUploadFile\")' ") .
738 - "size='60' />" .
 727+ "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' />" .
739728 "<input type='hidden' name='wpSourceType' value='upload' />" ;
740729 }
741730 if ( $useAjaxDestCheck ) {
742731 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'>&nbsp;</td></tr>";
743 - $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
 732+ $destOnkeyup = '';
744733 } else {
745734 $warningRow = '';
746735 $destOnkeyup = '';
@@ -788,7 +777,7 @@
789778 else {
790779 $wgOut->addHTML(
791780 "<input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
792 - value=\"{$encDestName}\" onchange='toggleFilenameFiller()' $destOnkeyup />"
 781+ value=\"{$encDestName}\" $destOnkeyup />"
793782 );
794783 }
795784
Index: branches/new-upload/phase3/js2/upSetup.js
@@ -1,11 +0,0 @@
2 -// simple script to invoke the upload with config:
3 -
4 -mwAddOnloadHook( function(){
5 - //make sure we have mvFirefogg & mvUploader loaded:
6 - mvJsLoader.doLoad( {
7 - 'mvFirefogg' : 'libAddMedia/mvFirefogg.js',
8 - 'mvUploader' : 'libAddMedia/mvUploader.js'
9 - },function(){
10 - mvUp = new mvUploader( { 'api_url' : wgServer + wgScriptPath + '/api.php' } );
11 - });
12 -});
\ No newline at end of file
Index: branches/new-upload/phase3/js2/mwEmbed/example_usage/sample_add_media_wizard.html
@@ -0,0 +1,55 @@
 2+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 3+"http://www.w3.org/TR/html4/loose.dtd">
 4+<html>
 5+<head>
 6+ <title>sample mv embed</title>
 7+ <style type="text/css">
 8+ body{
 9+ font-size:80%;
 10+ }
 11+ </style>
 12+ <script type="text/javascript" src="../mv_embed.js"></script>
 13+ <script type="text/javascript">
 14+ mwAddOnloadHook(function(){
 15+ $j('#add_media_link').click(function(){
 16+ //show/empty modalbox
 17+ $j('#modalbox,#mv_overlay').remove();
 18+ $j('body').append(''+
 19+ '<div id="modalbox" style="background:#DDD;border:3px solid #666666;font-size:115%;'+
 20+ 'top:30px;left:20px;right:20px;bottom:30px;position:fixed;z-index:100;">'+
 21+ 'loading external media wizard<blink>...</blink>'+
 22+ '</div>'+
 23+ '<div id="mv_overlay" style="background:#000;cursor:wait;height:100%;left:0;position:fixed;'+
 24+ 'top:0;width:100%;z-index:5;filter:alpha(opacity=60);-moz-opacity: 0.6;'+
 25+ 'opacity: 0.6;"/>');
 26+ //load/configure the mv_embed remote search:
 27+ mv_do_remote_search({
 28+ 'target_id':'modalbox',
 29+ 'profile':'mediawiki_edit',
 30+ 'target_textbox': 'inline_append',
 31+ //note selections in the textbox will take over the default query
 32+ 'default_query': 'fish',
 33+ 'import_url_mode':'link', //don't copy the asset to our local system just link to it
 34+ 'cpconfig':{},
 35+ 'insertCallback':function(link_data){
 36+ $j('#inline_append,#code_append').append( link_data );
 37+ }
 38+ });
 39+ });
 40+ });
 41+
 42+ </script>
 43+</head>
 44+<body>
 45+<h3> Sample Add Media Wizard </h3>
 46+
 47+<a id="add_media_link" href="#">Add Media</a><br>
 48+<table border="1" width="800">
 49+<tr>
 50+<td valign="top" width="50%" id="inline_append">Asset Output</td>
 51+<td valign="top" width="50%" >Html Output:<textarea cols="60" rows="6" id="code_append" name="wpUploadDescription" tabindex="3"/></textarea></td>
 52+</tr>
 53+</table>
 54+</body>
 55+</html>
 56+
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js
@@ -94,7 +94,7 @@
9595 this.fogg_enabled=true;
9696
9797 //make sure file is "checked"
98 - if($j( '#wpSourceTypeFile' ).length != 0)
 98+ if( $j( '#wpSourceTypeFile' ).length != 0 )
9999 $j( '#wpSourceTypeFile' ).get(0).checked = true;
100100
101101 //hide normal file upload stuff
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js
@@ -38,7 +38,7 @@
3939
4040 'caret_pos':null,
4141 'local_wiki_api_url':null,
42 - 'import_url_mode': 'autodetect', //can be 'api', 'form', 'autodetect' or 'none' (none should be used where no remote repositories are enabled)
 42+ 'import_url_mode': 'autodetect', //can be 'api', 'form', 'autodetect', 'link', or 'none' (none should be used where no remote repositories are enabled)
4343
4444 'target_title':null,
4545
@@ -323,9 +323,11 @@
324324 },
325325 //gets the in and out points for insert position or grabs the selected text for search
326326 getTexboxSelection:function(){
327 - if(this.caret_pos.s && this.caret_pos.e &&
328 - (this.caret_pos.s != this.caret_pos.e))
329 - this.default_query = this.caret_pos.text.substring(this.caret_pos.s, this.caret_pos.e).replace(/ /g, '\xa0') || '\xa0'
 327+ if(this.caret_pos){
 328+ if(this.caret_pos.s && this.caret_pos.e &&
 329+ (this.caret_pos.s != this.caret_pos.e))
 330+ this.default_query = this.caret_pos.text.substring(this.caret_pos.s, this.caret_pos.e).replace(/ /g, '\xa0') || '\xa0'
 331+ }
330332 },
331333 //sets up the initial html interface
332334 init_interface_html:function(){
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvUploader.js
@@ -23,8 +23,10 @@
2424 "uploaderror" : "Upload error",
2525 "uploadwarning": "Upload warning",
2626 "unknown-error": "Unknown Error",
27 - "return-to-form": "Return to form"
 27+ "return-to-form": "Return to form",
2828
 29+ "file-exists-duplicate" : "This file is a duplicate of the following file"
 30+
2931 });
3032
3133 var default_upload_options = {
@@ -133,26 +135,26 @@
134136 $j('#mw-upload-table .mw-input').eq(0).html('<div id="wg-base-upload">' + itd_html + '</div>');
135137 //add in firefogg control
136138 $j('#wg-base-upload').after('<p id="fogg-enable-item" >' +
137 - '<input style="display:none" id="fogg-video-file" name="fogg-video-file" type="button" value="' + gM('upload-select-file') + '">' +
138 - "<span id='wgfogg_not_installed'>" +
139 - gM('upload-fogg_not_installed') +
140 - "</span>" +
141 - "<span class='error' id='wgfogg_wrong_version' style='display:none;'><br>" +
142 - gM('wgfogg_wrong_version') +
143 - "<br>" +
144 - "</span>" +
145 - "<span class='error' id='wgfogg_waring_ogg_upload' style='display:none;'><br>"+
146 - gM('wgfogg_waring_ogg_upload') +
147 - "<br>" +
148 - "</span>" +
149 - "<span class='error' id='wgfogg_waring_bad_extension' style='display:none;'><br>"+
150 - gM('wgfogg_waring_bad_extension') +
151 - "<br>" +
152 - "</span>" +
153 - "<span id='wgfogg_installed' style='display:none' >"+
154 - '<input id="wgEnableFirefogg" type="checkbox" name="wgEnableFirefogg" >' +
155 - gM('upload-enable-converter') +
156 - '</span><br></p>');
 139+ '<input style="display:none" id="fogg-video-file" name="fogg-video-file" type="button" value="' + gM('upload-select-file') + '">' +
 140+ "<span id='wgfogg_not_installed'>" +
 141+ gM('upload-fogg_not_installed') +
 142+ "</span>" +
 143+ "<span class='error' id='wgfogg_wrong_version' style='display:none;'><br>" +
 144+ gM('wgfogg_wrong_version') +
 145+ "<br>" +
 146+ "</span>" +
 147+ "<span class='error' id='wgfogg_waring_ogg_upload' style='display:none;'><br>"+
 148+ gM('wgfogg_waring_ogg_upload') +
 149+ "<br>" +
 150+ "</span>" +
 151+ "<span class='error' id='wgfogg_waring_bad_extension' style='display:none;'><br>"+
 152+ gM('wgfogg_waring_bad_extension') +
 153+ "<br>" +
 154+ "</span>" +
 155+ "<span id='wgfogg_installed' style='display:none' >"+
 156+ '<input id="wgEnableFirefogg" type="checkbox" name="wgEnableFirefogg" >' +
 157+ gM('upload-enable-converter') +
 158+ '</span><br></p>');
157159 }
158160 }
159161 /**
@@ -184,7 +186,7 @@
185187 }
186188 },
187189 setupForm:function(){
188 - var _this = this;
 190+ var _this = this;
189191 //set up the local pointer to the edit form:
190192 _this.getEditForm();
191193
@@ -214,8 +216,13 @@
215217 _this.formData[ tmpAryData[i]['name'] ] = tmpAryData[i]['value'];
216218 }
217219
218 - //display the loader:
219 - _this.dispProgressOverlay();
 220+ //get a clean loader:
 221+ _this.dispProgressOverlay();
 222+
 223+ //update the status to loading (we don't know if we will get status updates or not)
 224+ $j('#dlbox-centered').html( '<h5>' + _this.getProgressTitle() + '</h5>' +
 225+ mv_get_loading_img( 'left:40%;top:20%')
 226+ );
220227
221228 //for some unknown reason we have to drop down the #p-search z-index:
222229 $j('#p-search').css('z-index', 1);
@@ -276,10 +283,15 @@
277284
278285 //do normal post upload no status indicators (also since its a file I think we have to submit the form)
279286 _this.form_post_override = true;
 287+
280288 //trick the browser into thinking the wpUpload button was pressed (there might be a cleaner way to do this)
281289 $j(_this.editForm).append('<input type="hidden" name="wpUpload" value="' + $j('#wpUpload').val() + '"/>');
 290+
 291+ //@@todo support firefox 3.0 ajax file upload progress
 292+ //http://igstan.blogspot.com/2009/01/pure-javascript-file-upload.html
 293+
282294 //do the submit :
283 - _this.editForm.submit();
 295+ _this.editForm.submit();
284296 }else if( _this.upload_mode == 'api' && $j('#wpSourceTypeURL').get(0).checked){
285297 //if the api is supported.. && source type is http do upload with http status updates
286298 _this.doHttpUpload();
@@ -304,7 +316,16 @@
305317 if( data.error){
306318 _this.updateUploadError( data.error.code );
307319 return ;
308 - }
 320+ }
 321+ //check for warning:
 322+ if( data.upload.warnings ){
 323+ if( data.upload.warnings.duplicate ){
 324+ _this.updateUploadError( gM('file-exists-duplicate', data.upload.warnings.duplicate[0].title.mTextform ) );
 325+
 326+ //@@todo should use warning and let the user "ignore"
 327+ //_this.updateUploadWarning( gM('file-exists-duplicate') );
 328+ }
 329+ }
309330 //check for session key:
310331 if( data.upload && data.upload.upload_session_key ){
311332 //set the session key
@@ -319,6 +340,10 @@
320341 },
321342 doAjaxUploadStatus:function() {
322343 var _this = this;
 344+
 345+ //set up the progress display for status updates:
 346+ _this.dispProgressOverlay();
 347+
323348 var uploadStatus = function(){
324349 //do the api request:
325350 do_api_req({
@@ -328,8 +353,7 @@
329354 'sessionkey' : _this.upload_session_key
330355 },
331356 'url' : _this.api_url
332 - }, function( data ){
333 -
 357+ }, function( data ){
334358 //@@check if we are done
335359 if( data.upload['apiUploadResult'] ){
336360 //update status to 100%
@@ -419,6 +443,9 @@
420444 return false;
421445 });
422446 },
 447+ updateUploadWarning:function( msg ){
 448+
 449+ },
423450 updateUploadDone:function( url ){
424451 $j( '#dlbox-centered' ).html( '<h3>' + gM('successfulupload') + '</h3>' +
425452 gM( 'mv_upload_done', url) );
@@ -451,8 +478,7 @@
452479 '</div>' +
453480 '<div id="dlbox-overlay" class="dlbox-overlay" style="background:#000;cursor:wait;height:100%;'+
454481 'left:0;top:0;position:fixed;width:100%;z-index:99;filter:alpha(opacity=60);'+
455 - '-moz-opacity: 0.6; opacity: 0.6;" ></div>');
456 - $j('#dlbox-centered,#dlbox-overlay').show();
 482+ '-moz-opacity: 0.6; opacity: 0.6;" ></div>');
457483 }
458484
459485 }
Index: branches/new-upload/phase3/js2/mwEmbed/mv_embed.js
@@ -240,6 +240,7 @@
241241 //base lib flags:
242242 onReadyEvents:new Array(),
243243 doneReadyEvents:false,
 244+ jQueryCheckFlag:false,
244245 //to keep consistency across threads:
245246 ptime:0,
246247 ctime:0,
@@ -392,12 +393,25 @@
393394 addLoadEvent:function(fn){
394395 this.onReadyEvents.push(fn);
395396 },
396 - runQuededFunctions:function(){
397 - this.doneReadyEvents=true;
398 - while( this.onReadyEvents.length ){
 397+ //checks the jQuery flag (this way when remote embeding we don't load jQuery
 398+ // unless mwAddOnloadHook was used or there is video on the page
 399+ runQuededFunctions:function(){
 400+ var _this = this;
 401+ this.doneReadyEvents=true;
 402+ if(this.jQueryCheckFlag){
 403+ this.jQueryCheck(function(){
 404+ _this.runReadyEvents();
 405+ });
 406+ }else{
 407+ this.runReadyEvents();
 408+ }
 409+ },
 410+ runReadyEvents:function(){
 411+ while( this.onReadyEvents.length ){
399412 this.onReadyEvents.shift()();
400 - }
401 - }
 413+ }
 414+ }
 415+
402416 }
403417 //load an external JS (similar to jquery .require plugin)
404418 //but checks for object availability rather than load state
@@ -430,15 +444,24 @@
431445 });
432446 });
433447 }else{
434 - //if we already have jQuery make sure its loaded into its proper context $j
435 - //otherwise it will load if needed.
436 - js_log("run jCheck:");
437 - mvJsLoader.jQueryCheck(function(){
438 - //run any queded global events:
439 - mvJsLoader.runQuededFunctions();
440 - });
 448+ //if we already have jQuery make sure its loaded into its proper context $j
 449+ //run any queded global events:
 450+ mvJsLoader.runQuededFunctions();
441451 }
442452 }
 453+//mwAddOnloadHook: ensure jQuery and the DOM are ready:
 454+function mwAddOnloadHook( func ) {
 455+ //if we have already run the dom ready just run the function directly:
 456+ if( mvJsLoader.doneReadyEvents ){
 457+ //make sure jQuery is there:
 458+ mvJsLoader.jQueryCheck(function(){
 459+ func();
 460+ });
 461+ }else{
 462+ mvJsLoader.jQueryCheckFlag = true;
 463+ mvJsLoader.addLoadEvent( func );
 464+ };
 465+}
443466 /*
444467 * this function allows for targeted rewriting
445468 */
@@ -635,17 +658,6 @@
636659 return parseInt(times[0]*3600)+parseInt(times[1]*60)+parseFloat(times[2]);
637660 }
638661
639 -//addLoadEvent for adding functions to be run when the page DOM is done loading
640 -//@@todo depricate in favor of:
641 -function mwAddOnloadHook( func ) {
642 - //if we have already run the dom ready just run the function directly:
643 - if( mvJsLoader.doneReadyEvents ){
644 - func();
645 - }else{
646 - mvJsLoader.addLoadEvent(func);
647 - };
648 -}
649 -
650662 //does a remote or local api request based on request url
651663 //@param options: url, data, cbParam, callback
652664 function do_api_req( options, callback ){
Index: branches/new-upload/phase3/js2/uploadPage.js
@@ -0,0 +1,141 @@
 2+
 3+loadGM({
 4+ "fileexists" : "A file with this name exists already, please check <i><tt>$1</tt></i> if you are not sure if you want to change it.",
 5+ "fileexists-thumb": "<center><b>Existing file<b></center>"
 6+});
 7+
 8+// simple script to invoke the upload with config:
 9+mwAddOnloadHook( function(){
 10+ //setup the upload handler for firefogg and normal uploads:
 11+ mvJsLoader.doLoad( {
 12+ 'mvFirefogg' : 'libAddMedia/mvFirefogg.js',
 13+ 'mvUploader' : 'libAddMedia/mvUploader.js'
 14+ },function(){
 15+ mvUp = new mvUploader( { 'api_url' : wgServer + wgScriptPath + '/api.php' } );
 16+ setupUploadFormBindings();
 17+ });
 18+ //set up the upoload form bindings once all dom manipluation is done
 19+ var setupUploadFormBindings = function(){
 20+ if( wgAjaxUploadDestCheck ){
 21+ //do destination check:
 22+ var doDestCheck = function(){
 23+ $j('#wpDestFile-warning').empty();
 24+ //show loading
 25+ $j('#wpDestFile').after('<img id = "mw-spinner-wpDestFile" src ="'+ stylepath + '/common/images/spinner.gif" />');
 26+ //try and get a thumb of the current file (check its destination)
 27+ do_api_req({
 28+ 'data':{
 29+ 'titles': 'File:' + $j('#wpDestFile').val(),//@@todo we may need a more clever way to get a the filename
 30+ 'prop': 'imageinfo',
 31+ 'iiprop':'url|mime|size',
 32+ 'iiurlwidth': 150
 33+ }
 34+ },function(data){
 35+ $j('#mw-spinner-wpDestFile').remove();
 36+ if(data && data.query && data.query.pages){
 37+ if( data.query.pages[-1] ){
 38+ //all good no file there
 39+ }else{
 40+ for(var page_id in data.query.pages){
 41+ if( data.query.normalized){
 42+ var ntitle = data.query.normalized[0].to;
 43+ }else{
 44+ var ntitle = data.query.pages[ page_id ].title;
 45+ }
 46+ var img = data.query.pages[ page_id ].imageinfo[0];
 47+ $j('#wpDestFile-warning').html(
 48+ '<ul>' +
 49+ '<li>'+
 50+ gM('fileexists', ntitle) +
 51+ '</li>'+
 52+ '<div class="thumb tright">' +
 53+ '<div style="width: ' + ( parseInt(img.thumbwidth)+2 ) + 'px;" class="thumbinner">' +
 54+ '<a title="' + ntitle + '" class="image" href="' + img.descriptionurl + '">' +
 55+ '<img width="' + img.thumbwidth + '" height="' + img.thumbheight + '" border="0" class="thumbimage" ' +
 56+ 'src="' + img.thumburl + '"' +
 57+ ' alt="' + ntitle + '"/>' +
 58+ '</a>' +
 59+ '<div class="thumbcaption">' +
 60+ '<div class="magnify">' +
 61+ '<a title="' + gM('thumbnail-more') + '" class="internal" ' +
 62+ 'href="' + img.descriptionurl +'"><img width="15" height="11" alt="" ' +
 63+ 'src="' + stylepath +"/>" +
 64+ '</a>'+
 65+ '</div>'+
 66+ gM('fileexists-thumb') +
 67+ '</div>' +
 68+ '</div>'+
 69+ '</div>' +
 70+ '</ul>'
 71+ );
 72+ }
 73+ }
 74+ }
 75+ });
 76+ };
 77+ $j('#wpDestFile').change(doDestCheck);
 78+ }
 79+ var toggleUpType = function( set ){
 80+ $j('#wpSourceTypeFile').get(0).checked = set;
 81+ $j('#wpUploadFile').get(0).disabled = !set;
 82+
 83+ $j('#wpSourceTypeURL').get(0).checked = !set;
 84+ $j('#wpUploadFileURL').get(0).disabled = set;
 85+ }
 86+ //set the initial toggleUpType
 87+ toggleUpType(true);
 88+
 89+ $j("input[name='wpSourceType']").click(function(){
 90+ toggleUpType( this.id == 'wpSourceTypeFile' );
 91+ });
 92+
 93+
 94+ $j('#wpUploadFile,#wpUploadFileURL').focus(function(){
 95+ toggleUpType( this.id == 'wpUploadFile' );
 96+ }).change(function(){ //also setup the onChange event binding:
 97+ if (!wgUploadAutoFill) {
 98+ return;
 99+ }
 100+ //remove any previously flagged errors
 101+ $j('#mw-upload-permitted,#mw-upload-prohibited').hide();
 102+
 103+ var path = $j(this).val();
 104+ // Find trailing part
 105+ var slash = path.lastIndexOf('/');
 106+ var backslash = path.lastIndexOf('\\');
 107+ var fname;
 108+ if (slash == -1 && backslash == -1) {
 109+ fname = path;
 110+ } else if (slash > backslash) {
 111+ fname = path.substring(slash+1, 10000);
 112+ } else {
 113+ fname = path.substring(backslash+1, 10000);
 114+ }
 115+ //urls are less likely to have a usefull extension don't include them in the extention check
 116+ if( wgFileExtensions && $j(this).attr('id') != 'wpUploadFileURL' ){
 117+ var found = false;
 118+ if( fname.lastIndexOf('.')!=-1 ){
 119+ var ext = fname.substr( fname.lastIndexOf('.')+1 );
 120+ for(var i=0; i < wgFileExtensions.length; i++){
 121+ if( wgFileExtensions[i].toLowerCase() == ext.toLowerCase() )
 122+ found = true;
 123+ }
 124+ }
 125+ if(!found){
 126+ //clear the upload set mw-upload-permitted to error
 127+ $j(this).val('');
 128+ $j('#mw-upload-permitted,#mw-upload-prohibited').show().addClass('error');
 129+ //clear the wpDestFile as well:
 130+ $j('#wpDestFile').val('');
 131+ return false;
 132+ }
 133+ }
 134+ // Capitalise first letter and replace spaces by underscores
 135+ fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
 136+ // Output result
 137+ $j('#wpDestFile').val( fname );
 138+ //do a destination check
 139+ doDestCheck();
 140+ });
 141+ }
 142+});
\ No newline at end of file
Property changes on: branches/new-upload/phase3/js2/uploadPage.js
___________________________________________________________________
Name: svn:mergeinfo
1143 + /trunk/phase3/js2/upSetup.js:46619-47809

Status & tagging log