From 49bed9e5a2de22a24b560d0f1470a82049fd1854 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Sat, 25 Jul 2009 03:25:01 +0000 Subject: [PATCH] * updates for strict compliance mode chunk uploading * fixes for firefogg multiple forms on the special upload page. --- includes/api/ApiFormatJson_json.php | 3 +- includes/upload/UploadFromChunks.php | 7 ++-- .../libAddMedia/mvBaseUploadInterface.js | 30 +++++++------- js2/mwEmbed/libAddMedia/mvFirefogg.js | 39 +++++++++++-------- .../searchLibs/baseRemoteSearch.js | 6 +-- js2/mwEmbed/mv_embed.js | 2 +- js2/uploadPage.js | 8 ++-- skins/common/wikibits.js | 3 +- 8 files changed, 55 insertions(+), 43 deletions(-) diff --git a/includes/api/ApiFormatJson_json.php b/includes/api/ApiFormatJson_json.php index f86ec03864..4ec76e6c0d 100644 --- a/includes/api/ApiFormatJson_json.php +++ b/includes/api/ApiFormatJson_json.php @@ -816,7 +816,8 @@ class Services_JSON function isError($data, $code = null) { if (class_exists('pear')) { - return PEAR::isError($data, $code); + //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) + return @PEAR::isError($data, $code); } elseif (is_object($data) && (get_class($data) == 'services_json_error' || is_subclass_of($data, 'services_json_error'))) { return true; diff --git a/includes/upload/UploadFromChunks.php b/includes/upload/UploadFromChunks.php index 5e67fe45ff..5d70716434 100644 --- a/includes/upload/UploadFromChunks.php +++ b/includes/upload/UploadFromChunks.php @@ -71,7 +71,7 @@ class UploadFromChunks extends UploadBase { * Verify whether the upload is sane. * Returns self::OK or else an array with error information */ - function verifyUpload( $resultDetails ) { + function verifyUpload() { // no checks on chunk upload mode: if( $this->chunk_mode == UploadFromChunks::INIT ) return self::OK; @@ -79,7 +79,7 @@ class UploadFromChunks extends UploadBase { // verify on init and last chunk request if( $this->chunk_mode == UploadFromChunks::CHUNK || $this->chunk_mode == UploadFromChunks::DONE ) - return parent::verifyUpload( $resultDetails ); + return parent::verifyUpload(); } // only run verifyFile on completed uploaded chunks @@ -114,6 +114,7 @@ class UploadFromChunks extends UploadBase { 'mComment' => $comment, 'mSummary' => $summary, 'mWatch' => $watch, + 'mIgnorewarnings' => true, //ignore warning on chunk uploads (for now) 'mFilteredName' => $this->mFilteredName, 'mTempAppendPath' => null, // the repo append path (not temporary local node mTempPath) 'mDesiredDestName' => $this->mDesiredDestName, @@ -230,7 +231,7 @@ class UploadFromChunks extends UploadBase { if( is_file( $this->getRealPath( $this->mTempAppendPath ) ) ){ $status = $this->appendToUploadFile( $this->mTempAppendPath, $this->mTempPath ); } else { - $status->fatal( 'filenotfound', $this->mTempAppendPath ); + $status = Status::newFatal( 'filenotfound', $this->mTempAppendPath ); } return $status; } diff --git a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js index 01444ba44f..2b2384f908 100644 --- a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js +++ b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js @@ -45,9 +45,11 @@ var default_bui_options = { 'parent_uploader':null, 'edit_from':null, 'done_upload_cb': null, + 'target_edit_from':null, //upload_mode can be 'post', 'chunks' or autodetect. (autodetect issues an api call) 'upload_mode':'autodetect' + } var mvBaseUploadInterface = function( iObj ){ return this.init( iObj ); @@ -63,7 +65,7 @@ mvBaseUploadInterface.prototype = { etoken:false, init: function( iObj ){ if(!iObj) - iObj = {}; + iObj = {}; //inherit iObj properties: for(var i in default_bui_options){ if(iObj[i]){ @@ -74,22 +76,22 @@ mvBaseUploadInterface.prototype = { } }, setupForm:function(){ - var _this = this; + var _this = this; //set up the local pointer to the edit form: - _this.editForm = _this.getEditForm(); - - if(_this.editForm){ + _this.editForm = _this.getEditForm(); + + if( _this.editForm ){ //set up the org_onsubmit if not set: - if( typeof( _this.org_onsubmit ) == 'undefined' ) - _this.org_onsubmit = _this.editForm.onsubmit; + if( typeof( _this.org_onsubmit ) == 'undefined' && _this.editForm.onsubmit ) + _this.org_onsubmit = _this.editForm.onsubmit; //have to define the onsubmit function inline or its hard to pass the "_this" instance - _this.editForm.onsubmit = function(){ + $j( '#mw-upload-form' ).submit( function(){ //run the original onsubmit (if not run yet set flag to avoid excessive chaining ) - if( typeof( _this.org_onsubmit ) == 'function' ){ + if( typeof( _this.org_onsubmit ) == 'function' ){ if( ! _this.org_onsubmit() ){ //error in org submit return false; - return false; + return false; } } //check for post action override: @@ -119,7 +121,7 @@ mvBaseUploadInterface.prototype = { //don't submit the form we will do the post in ajax return false; - }; + }); } }, @@ -524,9 +526,9 @@ mvBaseUploadInterface.prototype = { getProgressTitle:function(){ return gM('upload-in-progress'); }, - getEditForm:function(){ - if(this.target_edit_from){ - return $j(this.target_edit_from).get(0); + getEditForm:function(){ + if( this.target_edit_from && $j( this.target_edit_from ).length != 0){ + return $j( this.target_edit_from ).get(0); } //just return the first form fond on the page. return $j('form :first').get(0); diff --git a/js2/mwEmbed/libAddMedia/mvFirefogg.js b/js2/mwEmbed/libAddMedia/mvFirefogg.js index 2c56d9be4f..b8b10c373e 100644 --- a/js2/mwEmbed/libAddMedia/mvFirefogg.js +++ b/js2/mwEmbed/libAddMedia/mvFirefogg.js @@ -196,19 +196,19 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface _this.selectFogg(); }); //also setup the text file display on Click to select file: - $j(this.target_input_file_name).unbind().attr('readonly', 'readonly').click(function(){ + $j( this.target_input_file_name ).unbind().attr('readonly', 'readonly').click(function(){ _this.selectFogg(); }) }else{ //first check firefox version: - if(!($j.browser.mozilla && $j.browser.version >= '1.9.1')) { - js_log('show use latest::' + _this.target_use_latest_fox); - if(_this.target_use_latest_fox){ - if(_this.form_rewrite) - $j(_this.target_use_latest_fox).prepend( gM('fogg-for_improved_uplods') ); + if(!( $j.browser.mozilla && $j.browser.version >= '1.9.1' )) { + js_log( 'show use latest::' + _this.target_use_latest_fox ); + if( _this.target_use_latest_fox ){ + if( _this.form_rewrite ) + $j( _this.target_use_latest_fox ).prepend( gM('fogg-for_improved_uplods') ); - $j(_this.target_use_latest_fox).show(); + $j( _this.target_use_latest_fox ).show(); } return ; } @@ -224,7 +224,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface } //if rewriting form use upload msg text var upMsg = (_this.form_rewrite) ? gM('fogg-for_improved_uplods') : ''; - $j(_this.target_please_install).html( upMsg + gM('fogg-please_install',os_link )).css('padding', '10px').show(); + $j( _this.target_please_install ).html( upMsg + gM('fogg-please_install',os_link )).css('padding', '10px').show(); } //setup the target save local file bindins: $j( _this.target_btn_save_local_file ).unbind().click(function(){ @@ -243,7 +243,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface //assume input target setupForm: function(){ js_log('firefogg::setupForm::'); - //to parent form setup if we want http updates + //to parent form setup if we want http updates if( this.form_rewrite ){ //do parent form setup: this.pe_setupForm(); @@ -279,7 +279,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface inTag+= '/>'; js_log('set input: ' + inTag); - $j(this.selector).replaceWith(inTag); + $j( this.selector ).replaceWith( inTag ); this.target_input_file_name = 'input[name=' + $j(this.selector).attr('name') + ']'; //update the selector to the control target: @@ -292,6 +292,9 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface this.doControlBindings(); }, getEditForm:function(){ + if( this.target_edit_from ){ + return this.pe_getEditForm(); + } js_log('get form: action=' + $j(this.selector).parents().find("form").attr('action')); return $j(this.selector).parents().find("form").get(0); }, @@ -413,12 +416,12 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface }, doUploadSwitch:function(){ var _this = this; - js_log("firefogg: doUploadSwitch:: " + this.fogg_enabled); + js_log( "firefogg: doUploadSwitch:: " + this.fogg_enabled ); //make sure firefogg is enabled otherwise do parent UploadSwich: if( !this.fogg_enabled || !this.firefogg_form_action ) return _this.pe_doUploadSwitch(); - //check what mode to use firefogg in: + //check what mode to use firefogg in: if( _this.upload_mode == 'post' ){ _this.doEncode(); }else if( _this.upload_mode == 'api' && _this.chunks_supported){ //if api mode and chunks supported do chunkUpload @@ -428,7 +431,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface } }, //doChunkUpload does both uploading and encoding at the same time and uploads one meg chunks as they are ready - doChunkUpload : function(){ + doChunkUpload : function(){ var _this = this; _this.action_done = false; @@ -455,17 +458,18 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface 'comment' : _this.formData['wpUploadDescription'], 'enablechunks': true }; + //check for editToken: - if(!this.etoken) + if( !this.etoken ) this.etoken = _this.formData['wpEditToken']; - if(this.etoken) + if( this.etoken ) aReq['token'] = this.etoken; if( _this.formData['wpWatchthis'] ) aReq['watch'] = _this.formData['wpWatchthis']; - if( _this.formData['wpIgnoreWarning'] ) + if( _this.formData['wpIgnoreWarning'] ) aReq['ignorewarnings'] = _this.formData['wpIgnoreWarning']; js_log('do fogg upload/encode call: '+ _this.api_url + ' :: ' + JSON.stringify( aReq ) ); @@ -477,6 +481,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface }, //doEncode and monitor progress: doEncode : function(){ + js_log('firefogg:doEncode'); var _this = this; _this.action_done = false; _this.dispProgressOverlay(); @@ -597,7 +602,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface _this.updateProgressWin( gM('successfulupload'), gM( 'mv_upload_done', _this.fogg.resultUrl),buttons); }else{ //done state with error? ..not really possible given how firefogg works - js_log(" upload done, in chunks mode, but no resultUrl!"); + js_log(" upload done, in chunks mode, but no resultUrl::" + response_text); } } }else{ diff --git a/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js b/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js index 610fd41269..6781e023b9 100644 --- a/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js +++ b/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js @@ -92,7 +92,7 @@ baseRemoteSearch.prototype = { attr_name = attr_name.split('|'); } - $j.each(item.getElementsByTagName( tag_name ), function (inx, node){ + $j.each( item.getElementsByTagName( tag_name ), function ( inx, node ){ var tag_val = ''; if( node!=null && attr_name == null ){ if( node.childNodes[0] != null){ @@ -101,11 +101,11 @@ baseRemoteSearch.prototype = { } } if( node!=null && attr_name != null){ - if(typeof attr_name == 'string'){ + if( typeof attr_name == 'string' ){ tag_val = $j.trim( $j( node ).attr( attr_name ) ); }else{ var attr_vals = {}; - for(var j in attr_name){ + for( var j in attr_name ){ if( $j(node).attr( attr_name[j] ).length != 0) attr_vals[ attr_name[j] ] = $j.trim( $j(node).attr( attr_name[j]) ).replace(/(<([^>]+)>)/ig,""); } diff --git a/js2/mwEmbed/mv_embed.js b/js2/mwEmbed/mv_embed.js index 090ec023b1..4cec2440e9 100644 --- a/js2/mwEmbed/mv_embed.js +++ b/js2/mwEmbed/mv_embed.js @@ -20,7 +20,7 @@ if( MV_EMBED_VERSION ){ MV_DO_INIT=false; } //used to grab fresh copies of scripts. (should be changed on commit) -var MV_EMBED_VERSION = '1.0r17'; +var MV_EMBED_VERSION = '1.0r18'; /* * Configuration variables (can be set from some precceding script) diff --git a/js2/uploadPage.js b/js2/uploadPage.js index ea532825dc..101885f1d4 100644 --- a/js2/uploadPage.js +++ b/js2/uploadPage.js @@ -5,6 +5,7 @@ js2AddOnloadHook( function(){ mwUploadHelper.init(); }); +var mwUploadFormTarget = '#mw-upload-form'; //set up the upoload form bindings once all dom manipluation is done var mwUploadHelper = { firefogg_installed:false, @@ -19,13 +20,14 @@ var mwUploadHelper = { $j('#wpUploadFile').firefogg({ //an api url (we won't submit directly to action of the form) 'api_url' : wgServer + wgScriptPath + '/api.php', - 'form_rewrite': true, + 'form_rewrite': true, + 'target_edit_from' : mwUploadFormTarget, 'new_source_cb' : function( orgFilename, oggName ){ if($j('#wpDestFile').val() == "") $j('#wpDestFile').val( oggName ); mwUploadHelper.doDestCheck(); }, - 'detect_cb':function(fogg_installed){ + 'detect_cb':function( fogg_installed ){ if(fogg_installed){ _this.firefogg_installed=true; }else{ @@ -39,7 +41,7 @@ var mwUploadHelper = { if($j('#wpUploadFileURL').length != 0){ $j('#wpUploadFileURL').baseUploadInterface({ 'api_url' : wgServer + wgScriptPath + '/api.php', - 'target_edit_from' : '#mw-upload-form' + 'target_edit_from' : mwUploadFormTarget }); } } diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index 75a281a050..f32b14aca8 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -36,7 +36,7 @@ if (!window.onloadFuncts) { var onloadFuncts = []; } -//should use mwAddOnloadHook once js2 is enabled +//code that is dependent on js2 functions should use js2AddOnloadHook function addOnloadHook(hookFunct) { // Allows add-on scripts to add onload functions if(!doneOnloadHook) { @@ -46,6 +46,7 @@ function addOnloadHook(hookFunct) { } } + function hookEvent(hookName, hookFunct) { addHandler(window, hookName, hookFunct); } -- 2.20.1