r53741 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53740‎ | r53741 | r53742 >
Date:03:25, 25 July 2009
Author:dale
Status:deferred
Tags:
Comment:
* updates for strict compliance mode chunk uploading
* fixes for firefogg multiple forms on the special upload page.
Modified paths:
  • /trunk/phase3/includes/api/ApiFormatJson_json.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromChunks.php (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/mv_embed.js (modified) (history)
  • /trunk/phase3/js2/uploadPage.js (modified) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/wikibits.js
@@ -36,7 +36,7 @@
3737 var onloadFuncts = [];
3838 }
3939
40 -//should use mwAddOnloadHook once js2 is enabled
 40+//code that is dependent on js2 functions should use js2AddOnloadHook
4141 function addOnloadHook(hookFunct) {
4242 // Allows add-on scripts to add onload functions
4343 if(!doneOnloadHook) {
@@ -46,6 +46,7 @@
4747 }
4848 }
4949
 50+
5051 function hookEvent(hookName, hookFunct) {
5152 addHandler(window, hookName, hookFunct);
5253 }
Index: trunk/phase3/includes/upload/UploadFromChunks.php
@@ -71,7 +71,7 @@
7272 * Verify whether the upload is sane.
7373 * Returns self::OK or else an array with error information
7474 */
75 - function verifyUpload( $resultDetails ) {
 75+ function verifyUpload() {
7676 // no checks on chunk upload mode:
7777 if( $this->chunk_mode == UploadFromChunks::INIT )
7878 return self::OK;
@@ -79,7 +79,7 @@
8080 // verify on init and last chunk request
8181 if( $this->chunk_mode == UploadFromChunks::CHUNK ||
8282 $this->chunk_mode == UploadFromChunks::DONE )
83 - return parent::verifyUpload( $resultDetails );
 83+ return parent::verifyUpload();
8484 }
8585
8686 // only run verifyFile on completed uploaded chunks
@@ -114,6 +114,7 @@
115115 'mComment' => $comment,
116116 'mSummary' => $summary,
117117 'mWatch' => $watch,
 118+ 'mIgnorewarnings' => true, //ignore warning on chunk uploads (for now)
118119 'mFilteredName' => $this->mFilteredName,
119120 'mTempAppendPath' => null, // the repo append path (not temporary local node mTempPath)
120121 'mDesiredDestName' => $this->mDesiredDestName,
@@ -230,7 +231,7 @@
231232 if( is_file( $this->getRealPath( $this->mTempAppendPath ) ) ){
232233 $status = $this->appendToUploadFile( $this->mTempAppendPath, $this->mTempPath );
233234 } else {
234 - $status->fatal( 'filenotfound', $this->mTempAppendPath );
 235+ $status = Status::newFatal( 'filenotfound', $this->mTempAppendPath );
235236 }
236237 return $status;
237238 }
Index: trunk/phase3/includes/api/ApiFormatJson_json.php
@@ -816,7 +816,8 @@
817817 function isError($data, $code = null)
818818 {
819819 if (class_exists('pear')) {
820 - return PEAR::isError($data, $code);
 820+ //avoid some strict warnings on PEAR isError check (looks like http://pear.php.net/bugs/bug.php?id=9950 has been around for some time)
 821+ return @PEAR::isError($data, $code);
821822 } elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
822823 is_subclass_of($data, 'services_json_error'))) {
823824 return true;
Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js
@@ -92,7 +92,7 @@
9393 attr_name = attr_name.split('|');
9494 }
9595
96 - $j.each(item.getElementsByTagName( tag_name ), function (inx, node){
 96+ $j.each( item.getElementsByTagName( tag_name ), function ( inx, node ){
9797 var tag_val = '';
9898 if( node!=null && attr_name == null ){
9999 if( node.childNodes[0] != null){
@@ -101,11 +101,11 @@
102102 }
103103 }
104104 if( node!=null && attr_name != null){
105 - if(typeof attr_name == 'string'){
 105+ if( typeof attr_name == 'string' ){
106106 tag_val = $j.trim( $j( node ).attr( attr_name ) );
107107 }else{
108108 var attr_vals = {};
109 - for(var j in attr_name){
 109+ for( var j in attr_name ){
110110 if( $j(node).attr( attr_name[j] ).length != 0)
111111 attr_vals[ attr_name[j] ] = $j.trim( $j(node).attr( attr_name[j]) ).replace(/(<([^>]+)>)/ig,"");
112112 }
Index: trunk/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js
@@ -196,19 +196,19 @@
197197 _this.selectFogg();
198198 });
199199 //also setup the text file display on Click to select file:
200 - $j(this.target_input_file_name).unbind().attr('readonly', 'readonly').click(function(){
 200+ $j( this.target_input_file_name ).unbind().attr('readonly', 'readonly').click(function(){
201201 _this.selectFogg();
202202 })
203203
204204 }else{
205205 //first check firefox version:
206 - if(!($j.browser.mozilla && $j.browser.version >= '1.9.1')) {
207 - js_log('show use latest::' + _this.target_use_latest_fox);
208 - if(_this.target_use_latest_fox){
209 - if(_this.form_rewrite)
210 - $j(_this.target_use_latest_fox).prepend( gM('fogg-for_improved_uplods') );
 206+ if(!( $j.browser.mozilla && $j.browser.version >= '1.9.1' )) {
 207+ js_log( 'show use latest::' + _this.target_use_latest_fox );
 208+ if( _this.target_use_latest_fox ){
 209+ if( _this.form_rewrite )
 210+ $j( _this.target_use_latest_fox ).prepend( gM('fogg-for_improved_uplods') );
211211
212 - $j(_this.target_use_latest_fox).show();
 212+ $j( _this.target_use_latest_fox ).show();
213213 }
214214 return ;
215215 }
@@ -224,7 +224,7 @@
225225 }
226226 //if rewriting form use upload msg text
227227 var upMsg = (_this.form_rewrite) ? gM('fogg-for_improved_uplods') : '';
228 - $j(_this.target_please_install).html( upMsg + gM('fogg-please_install',os_link )).css('padding', '10px').show();
 228+ $j( _this.target_please_install ).html( upMsg + gM('fogg-please_install',os_link )).css('padding', '10px').show();
229229 }
230230 //setup the target save local file bindins:
231231 $j( _this.target_btn_save_local_file ).unbind().click(function(){
@@ -243,7 +243,7 @@
244244 //assume input target
245245 setupForm: function(){
246246 js_log('firefogg::setupForm::');
247 - //to parent form setup if we want http updates
 247+ //to parent form setup if we want http updates
248248 if( this.form_rewrite ){
249249 //do parent form setup:
250250 this.pe_setupForm();
@@ -279,7 +279,7 @@
280280 inTag+= '/><span id="' + $j(this.selector).attr('name') + '_fogg-control"></span>';
281281
282282 js_log('set input: ' + inTag);
283 - $j(this.selector).replaceWith(inTag);
 283+ $j( this.selector ).replaceWith( inTag );
284284
285285 this.target_input_file_name = 'input[name=' + $j(this.selector).attr('name') + ']';
286286 //update the selector to the control target:
@@ -292,6 +292,9 @@
293293 this.doControlBindings();
294294 },
295295 getEditForm:function(){
 296+ if( this.target_edit_from ){
 297+ return this.pe_getEditForm();
 298+ }
296299 js_log('get form: action=' + $j(this.selector).parents().find("form").attr('action'));
297300 return $j(this.selector).parents().find("form").get(0);
298301 },
@@ -413,12 +416,12 @@
414417 },
415418 doUploadSwitch:function(){
416419 var _this = this;
417 - js_log("firefogg: doUploadSwitch:: " + this.fogg_enabled);
 420+ js_log( "firefogg: doUploadSwitch:: " + this.fogg_enabled );
418421 //make sure firefogg is enabled otherwise do parent UploadSwich:
419422 if( !this.fogg_enabled || !this.firefogg_form_action )
420423 return _this.pe_doUploadSwitch();
421424
422 - //check what mode to use firefogg in:
 425+ //check what mode to use firefogg in:
423426 if( _this.upload_mode == 'post' ){
424427 _this.doEncode();
425428 }else if( _this.upload_mode == 'api' && _this.chunks_supported){ //if api mode and chunks supported do chunkUpload
@@ -428,7 +431,7 @@
429432 }
430433 },
431434 //doChunkUpload does both uploading and encoding at the same time and uploads one meg chunks as they are ready
432 - doChunkUpload : function(){
 435+ doChunkUpload : function(){
433436 var _this = this;
434437 _this.action_done = false;
435438
@@ -455,17 +458,18 @@
456459 'comment' : _this.formData['wpUploadDescription'],
457460 'enablechunks': true
458461 };
 462+
459463 //check for editToken:
460 - if(!this.etoken)
 464+ if( !this.etoken )
461465 this.etoken = _this.formData['wpEditToken'];
462466
463 - if(this.etoken)
 467+ if( this.etoken )
464468 aReq['token'] = this.etoken;
465469
466470 if( _this.formData['wpWatchthis'] )
467471 aReq['watch'] = _this.formData['wpWatchthis'];
468472
469 - if( _this.formData['wpIgnoreWarning'] )
 473+ if( _this.formData['wpIgnoreWarning'] )
470474 aReq['ignorewarnings'] = _this.formData['wpIgnoreWarning'];
471475
472476 js_log('do fogg upload/encode call: '+ _this.api_url + ' :: ' + JSON.stringify( aReq ) );
@@ -477,6 +481,7 @@
478482 },
479483 //doEncode and monitor progress:
480484 doEncode : function(){
 485+ js_log('firefogg:doEncode');
481486 var _this = this;
482487 _this.action_done = false;
483488 _this.dispProgressOverlay();
@@ -597,7 +602,7 @@
598603 _this.updateProgressWin( gM('successfulupload'), gM( 'mv_upload_done', _this.fogg.resultUrl),buttons);
599604 }else{
600605 //done state with error? ..not really possible given how firefogg works
601 - js_log(" upload done, in chunks mode, but no resultUrl!");
 606+ js_log(" upload done, in chunks mode, but no resultUrl::" + response_text);
602607 }
603608 }
604609 }else{
Index: trunk/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
@@ -45,9 +45,11 @@
4646 'parent_uploader':null,
4747 'edit_from':null,
4848 'done_upload_cb': null,
 49+ 'target_edit_from':null,
4950
5051 //upload_mode can be 'post', 'chunks' or autodetect. (autodetect issues an api call)
5152 'upload_mode':'autodetect'
 53+
5254 }
5355 var mvBaseUploadInterface = function( iObj ){
5456 return this.init( iObj );
@@ -63,7 +65,7 @@
6466 etoken:false,
6567 init: function( iObj ){
6668 if(!iObj)
67 - iObj = {};
 69+ iObj = {};
6870 //inherit iObj properties:
6971 for(var i in default_bui_options){
7072 if(iObj[i]){
@@ -74,22 +76,22 @@
7577 }
7678 },
7779 setupForm:function(){
78 - var _this = this;
 80+ var _this = this;
7981 //set up the local pointer to the edit form:
80 - _this.editForm = _this.getEditForm();
81 -
82 - if(_this.editForm){
 82+ _this.editForm = _this.getEditForm();
 83+
 84+ if( _this.editForm ){
8385 //set up the org_onsubmit if not set:
84 - if( typeof( _this.org_onsubmit ) == 'undefined' )
85 - _this.org_onsubmit = _this.editForm.onsubmit;
 86+ if( typeof( _this.org_onsubmit ) == 'undefined' && _this.editForm.onsubmit )
 87+ _this.org_onsubmit = _this.editForm.onsubmit;
8688
8789 //have to define the onsubmit function inline or its hard to pass the "_this" instance
88 - _this.editForm.onsubmit = function(){
 90+ $j( '#mw-upload-form' ).submit( function(){
8991 //run the original onsubmit (if not run yet set flag to avoid excessive chaining )
90 - if( typeof( _this.org_onsubmit ) == 'function' ){
 92+ if( typeof( _this.org_onsubmit ) == 'function' ){
9193 if( ! _this.org_onsubmit() ){
9294 //error in org submit return false;
93 - return false;
 95+ return false;
9496 }
9597 }
9698 //check for post action override:
@@ -119,7 +121,7 @@
120122
121123 //don't submit the form we will do the post in ajax
122124 return false;
123 - };
 125+ });
124126 }
125127
126128 },
@@ -524,9 +526,9 @@
525527 getProgressTitle:function(){
526528 return gM('upload-in-progress');
527529 },
528 - getEditForm:function(){
529 - if(this.target_edit_from){
530 - return $j(this.target_edit_from).get(0);
 530+ getEditForm:function(){
 531+ if( this.target_edit_from && $j( this.target_edit_from ).length != 0){
 532+ return $j( this.target_edit_from ).get(0);
531533 }
532534 //just return the first form fond on the page.
533535 return $j('form :first').get(0);
Index: trunk/phase3/js2/mwEmbed/mv_embed.js
@@ -20,7 +20,7 @@
2121 MV_DO_INIT=false;
2222 }
2323 //used to grab fresh copies of scripts. (should be changed on commit)
24 -var MV_EMBED_VERSION = '1.0r17';
 24+var MV_EMBED_VERSION = '1.0r18';
2525
2626 /*
2727 * Configuration variables (can be set from some precceding script)
Index: trunk/phase3/js2/uploadPage.js
@@ -5,6 +5,7 @@
66 js2AddOnloadHook( function(){
77 mwUploadHelper.init();
88 });
 9+var mwUploadFormTarget = '#mw-upload-form';
910 //set up the upoload form bindings once all dom manipluation is done
1011 var mwUploadHelper = {
1112 firefogg_installed:false,
@@ -19,13 +20,14 @@
2021 $j('#wpUploadFile').firefogg({
2122 //an api url (we won't submit directly to action of the form)
2223 'api_url' : wgServer + wgScriptPath + '/api.php',
23 - 'form_rewrite': true,
 24+ 'form_rewrite': true,
 25+ 'target_edit_from' : mwUploadFormTarget,
2426 'new_source_cb' : function( orgFilename, oggName ){
2527 if($j('#wpDestFile').val() == "")
2628 $j('#wpDestFile').val( oggName );
2729 mwUploadHelper.doDestCheck();
2830 },
29 - 'detect_cb':function(fogg_installed){
 31+ 'detect_cb':function( fogg_installed ){
3032 if(fogg_installed){
3133 _this.firefogg_installed=true;
3234 }else{
@@ -39,7 +41,7 @@
4042 if($j('#wpUploadFileURL').length != 0){
4143 $j('#wpUploadFileURL').baseUploadInterface({
4244 'api_url' : wgServer + wgScriptPath + '/api.php',
43 - 'target_edit_from' : '#mw-upload-form'
 45+ 'target_edit_from' : mwUploadFormTarget
4446 });
4547 }
4648 }

Status & tagging log