From f97609bf868cd2155d2f5094195d4eeb66600571 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Fri, 14 Aug 2009 08:15:41 +0000 Subject: [PATCH] * stubs for upload proxy (upload to commons from other wikis edit page & insert your result). * Only firefogg non-proxied api based uploads supported so far. --- .../Player_Simple_Video_Tag.html | 2 +- .../libAddMedia/mvBaseUploadInterface.js | 7 +- js2/mwEmbed/libAddMedia/mvFirefogg.js | 37 +++-- js2/mwEmbed/libAddMedia/remoteSearchDriver.js | 126 +++++++++++------- js2/mwEmbed/libAddMedia/simpleUploadForm.js | 86 ++++++++++++ js2/mwEmbed/libClipEdit/mvClipEdit.js | 4 +- js2/mwEmbed/libEmbedVideo/embedVideo.js | 8 +- js2/mwEmbed/mv_embed.js | 12 +- js2/mwEmbed/mwHostProxy.html | 14 ++ js2/mwEmbed/php/jsAutoloadLocalClasses.php | 1 + js2/mwRemoteProxy.html | 31 +++++ 11 files changed, 253 insertions(+), 75 deletions(-) create mode 100644 js2/mwEmbed/libAddMedia/simpleUploadForm.js create mode 100644 js2/mwEmbed/mwHostProxy.html create mode 100644 js2/mwRemoteProxy.html diff --git a/js2/mwEmbed/example_usage/Player_Simple_Video_Tag.html b/js2/mwEmbed/example_usage/Player_Simple_Video_Tag.html index 60a791fe74..92c4cf7628 100644 --- a/js2/mwEmbed/example_usage/Player_Simple_Video_Tag.html +++ b/js2/mwEmbed/example_usage/Player_Simple_Video_Tag.html @@ -13,7 +13,7 @@ once you include: mv_embed.js on any remote page you can then use the video tag
- +
Sample Embed
Simple video Embed:
<video poster="http://metavid.org/w/index.php?action=ajax&rs=mv_frame_server&stream_id=71&t=1:23:16&size=400x300" 
diff --git a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
index 26d2541c7c..3e87d2e40e 100644
--- a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
+++ b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
@@ -78,7 +78,7 @@ mvBaseUploadInterface.prototype = {
 	setupForm:function(){	
 		var _this = this;		
 		//set up the local pointer to the edit form:
-		_this.editForm = _this.getEditForm();		
+		_this.editForm = _this.getEditForm();				
 		
 		if( _this.editForm ){
 			//set up the org_onsubmit if not set: 
@@ -86,7 +86,7 @@ mvBaseUploadInterface.prototype = {
 				_this.org_onsubmit = _this.editForm.onsubmit;					
 			
 			//have to define the onsubmit function inline or its hard to pass the "_this" instance
-			$j( '#mw-upload-form' ).submit( function(){		
+			$j( _this.editForm ).submit( function(){		
 				//run the original onsubmit (if not run yet set flag to avoid excessive chaining ) 
 				if( typeof( _this.org_onsubmit ) == 'function' ){								  
 					if( ! _this.org_onsubmit() ){
@@ -95,8 +95,7 @@ mvBaseUploadInterface.prototype = {
 					}
 				}				
 				//check for post action override: 															
-				if( _this.form_post_override ){
-					//alert('will submit here');
+				if( _this.form_post_override ){					
 					return true;
 				}									
 				//get the input form data in flat json: 										
diff --git a/js2/mwEmbed/libAddMedia/mvFirefogg.js b/js2/mwEmbed/libAddMedia/mvFirefogg.js
index ac5a640f5c..01e59ceb80 100644
--- a/js2/mwEmbed/libAddMedia/mvFirefogg.js
+++ b/js2/mwEmbed/libAddMedia/mvFirefogg.js
@@ -150,7 +150,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
 		var out = '';		
 		$j.each(default_firefogg_options, function(target, na){			
 			if(target.substring(0, 6)=='target'){
-				js_log('check for target html: ' + target);
+				//js_log('check for target html: ' + target);
 				//check for the target if missing add to the output: 
 				if( _this[target] === false){					
 					out += _this.getTargetHtml(target) + ' ';
@@ -450,7 +450,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(){
 		js_log('doChunkUpload::');
-		var _this = this;			
+		var _this = this;					
 		_this.action_done = false;					
 		//extension should already be ogg but since its user editable,
 		//check again
@@ -466,7 +466,29 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
 			_this.formData['wpDestFile'] = sf.replace(extreg, '.ogg');
 		}
 		//add chunk response hook to build the resultURL when uploading chunks		
-		
+				
+		//check for editToken:
+		if(!this.etoken){
+			if( _this.formData['wpEditToken']){
+				_this.etoken = _this.formData['wpEditToken'];
+				_this.doChunkWithFormData();
+			}else{
+				get_mw_token(
+					'File:'+ _this.formData['wpDestFile'], 
+					_this.api_url, 
+					function( eToken ){										
+						_this.etoken = eToken;
+						_this.doChunkWithFormData();
+					}
+				);
+			}
+		}else{
+			_this.doChunkWithFormData();
+		}
+	},
+	doChunkWithFormData:function(){
+		var _this = this;
+		js_log("doChunkWithFormData::"  + _this.etoken);
 		//build the api url: 
 		var aReq ={
 			'action'		: 'upload',
@@ -475,11 +497,8 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
 			'comment'		: _this.formData['wpUploadDescription'],
 			'enablechunks'	: 'true'
 		};
-		//check for editToken:
-		if(!this.etoken)
-			this.etoken = _this.formData['wpEditToken'];
-			
-		if( this.etoken )
+		
+		if( _this.etoken )
 			aReq['token'] = this.etoken;
 		
 		if( _this.formData['wpWatchthis'] )
@@ -554,7 +573,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
 	},
 	doUploadStatus:function() {	
 		var _this = this;
-		$j('#up-status-state').html( gM('uploaded-status')  );
+		$j( '#up-status-state' ).html( gM('uploaded-status')  );
 		
 		_this.oldResponseText = '';
 		//setup a local function for timed callback:				 
diff --git a/js2/mwEmbed/libAddMedia/remoteSearchDriver.js b/js2/mwEmbed/libAddMedia/remoteSearchDriver.js
index 7be8ba11dc..5da7e3449a 100644
--- a/js2/mwEmbed/libAddMedia/remoteSearchDriver.js
+++ b/js2/mwEmbed/libAddMedia/remoteSearchDriver.js
@@ -17,7 +17,7 @@ loadGM({
 	"rsd_results_prev" : "previous ",
 	"rsd_no_results"   : "No search results for $1",
 
-	"mv_upload" : "Upload",
+	"upload_tab" : "Upload",
 	"rsd_layout" : "Layout:",
 	"rsd_resource_edit" : "Edit Resource: $1",
 	"resource_description_page": "Resource Description Page",
@@ -34,7 +34,9 @@ loadGM({
 	"no_import_by_url": "This User or Wiki can not import assets from remote URLs. 

Do you need to Login?

If permissions are set you may have to enable $wgAllowCopyUploads, more info

", "results_from": "Results from $2", - "missing_desc_see_soruce": "This Asset is missing a description. Please see the [$1 orginal source] and help describe it" + "missing_desc_see_soruce": "This Asset is missing a description. Please see the [$1 orginal source] and help describe it", + + "rsd_config_error": "Add media Wizard configuation error: $1" }); var default_remote_search_options = { 'profile':'mediawiki_edit', @@ -63,7 +65,8 @@ var default_remote_search_options = { 'cFileNS':'File', //what is the cannonical namespace for images //@@todo (should get that from the api or inpage vars) - 'enable_upload_tab':true // if we want to enable an uploads tab: + 'enable_upload_tab':true, // if we want to enable an uploads tab: + 'upload_api_target' : 'http://127.0.0.1/wiki_trunk/api.php' // can be local or the url of the upload api. } if(typeof wgServer == 'undefined') wgServer = ''; @@ -93,7 +96,7 @@ remoteSearchDriver.prototype = { * sets the default display item: * can be any content_providers key or 'all' */ - disp_item : 'this_wiki', + disp_item : 'upload', /** the default content providers list. * * (should be note that special tabs like "upload" and "combined" don't go into the content proviers list: @@ -330,15 +333,16 @@ remoteSearchDriver.prototype = { } } - //make sure the selected cp has an api to query against: - if(! this.content_providers[ this.disp_item ].api_url ){ + //make sure the selected cp has an api to query against (if its a content_provider + if( this.content_providers[ this.disp_item ] && + !this.content_providers[ this.disp_item ].api_url ){ for(var inx in this.content_providers){ if( this.content_providers[ inx ].api_url ){ this.disp_item = inx; break; } } - } + } //set up the default model config: @@ -554,34 +558,49 @@ remoteSearchDriver.prototype = { }); }, doUploadInteface:function(){ - var _this = this; - mv_set_loading('#tab-upload'); - $j('#tab-upload').html('upload interface goes here ;)'); - - //todo include firefogg support: - /*mvJsLoader.doLoad( [ - 'mvUploader' - ],function(){ - _this.cUpLoader = new mvUploader({ - 'target_div': '#tab-upload', - 'upload_done_action:': function( rTitle){ - //set to loading: - mv_set_loading('#tab-upload'); - //do a direct api query for resource info (to build rObj - _this.getResourceFromTitle( rTitle, function(rObj){ - //call resource Edit: - _this.resourceEdit( rObj ); - }); - } - }); - }); */ + js_log("doUploadInteface::"); + var _this = this; + //set it to loading: + mv_set_loading('#tab-upload'); + + //do config variable reality checks: + if( _this.upload_api_target == 'local' ){ + if( ! _this.local_wiki_api_url ){ + $j('#tab-upload').html( gM( 'rsd_config_error', 'missing_local_api_url' ) ); + return false; + }else{ + _this.upload_api_target = _this.local_wiki_api_url; + } + } + //make sure we have a url for the upload target: + if( parseUri( _this.upload_api_target ).host == _this.upload_api_target ){ + $j('#tab-upload').html( gM('rsd_config_error', 'bad_api_url') ); + return false; + } + //output the form + mvJsLoader.doLoad(['$j.fn.simpleUploadForm'],function(){ + //set the form action based on domain: + if( parseUri( document.URL ).host == parseUri( _this.upload_api_target ).host ){ + //deal with the api form upload form directly: + $j('#tab-upload').simpleUploadForm({ + "api_target" : _this.upload_api_target + }) + }else{ + //setup the proxy + } + }); }, runSearch: function(){ js_log("f:runSearch::" + this.disp_item); //draw_direct_flag var draw_direct_flag = true; - if( !this.content_providers[this.disp_item] ){ - js_log("can't run search for:" + this.disp_item); + if( !this.content_providers[this.disp_item] ){ + //check if its the special upload tab case: + if( this.disp_item == 'upload'){ + this.doUploadInteface(); + }else{ + js_log("can't run search for:" + this.disp_item); + } return false; } cp = this.content_providers[this.disp_item]; @@ -792,8 +811,10 @@ remoteSearchDriver.prototype = { } //do an upload tab if enabled: if( this.enable_upload_tab ){ - o+='
  • ' + gM('upload') + '
  • '; + o+='
  • ' + gM('upload_tab') + '
  • '; tabc+='
    '; + if(this.disp_item == 'upload') + selected_tab = inx++; } o+=''; //output the tab content containers: @@ -1087,31 +1108,36 @@ remoteSearchDriver.prototype = { }, /*set-up the control actions for clipEdit with relevent callbacks */ - getClipEditControlActions:function(){ + getClipEditControlActions:function( cp ){ var _this = this; - return { - 'insert' :function(rObj){ - _this.insertResource(rObj); - }, - 'preview':function(rObj){ + var cConf= {}; + + cConf['insert'] = function(rObj){ + _this.insertResource(rObj); + } + //if not directly inserting the resource is support a preview option: + if( _this.import_url_mode != 'remote_link'){ + cConf['preview'] = function(rObj){ _this.previewResource( rObj ) - }, - 'cancel' :function(){ - _this.cancelClipEditCB() - } - }; + }; + } + cConf['cancel'] = function(){ + _this.cancelClipEditCB() + } + return cConf; }, //loads the media editor: doMediaEdit:function( rObj , mediaType){ - var _this = this; + var _this = this; + var cp = rObj.pSobj.cp; var mvClipInit = { 'rObj':rObj, //the resource object - 'parent_ct':'rsd_modal_target', - 'clip_disp_ct':'clip_edit_disp', - 'control_ct': 'clip_edit_ctrl', - 'media_type': mediaType, - 'p_rsdObj': _this, - 'controlActionsCb':_this.getClipEditControlActions() + 'parent_ct' : 'rsd_modal_target', + 'clip_disp_ct' : 'clip_edit_disp', + 'control_ct' : 'clip_edit_ctrl', + 'media_type' : mediaType, + 'p_rsdObj' : _this, + 'controlActionsCb' : _this.getClipEditControlActions( cp ) }; var clibs = ['mvClipEdit']; @@ -1501,7 +1527,7 @@ remoteSearchDriver.prototype = { updatePreviewText:function( rObj ){ var _this = this; - if(_this.import_url_mode=='remote_link'){ + if( _this.import_url_mode == 'remote_link' ){ _this.cur_embed_code = rObj.pSobj.getEmbedHTML(rObj); }else{ _this.cur_embed_code = rObj.pSobj.getEmbedWikiCode( rObj ); diff --git a/js2/mwEmbed/libAddMedia/simpleUploadForm.js b/js2/mwEmbed/libAddMedia/simpleUploadForm.js new file mode 100644 index 0000000000..f1d493a719 --- /dev/null +++ b/js2/mwEmbed/libAddMedia/simpleUploadForm.js @@ -0,0 +1,86 @@ +/* + * simple form output jquery binding + * enables dynamic form output to a given target + * + */ + +loadGM({ + "select_file" : "Select File", + "more_licence_options" : "For more licence options view the normal upload page", + "select_ownwork" : "I am uploading entirely my own work, and licencing it under:", + "licence_cc-by-sa" : "Creative Commons Share Alike (3.0)", + "upload" : "Upload File", + "destfilename" : "Destination filename:", + "summary" : "Summary" +}); + +var default_form_options = { + 'enable_fogg' : true, + 'licence_options':['cc-by-sa'], + 'api_target' : false +}; + +(function($) { + $.fn.simpleUploadForm = function( opt , callback){ + //set the options: + for(var i in default_form_options){ + if(!opt[i]) + opt[i] = default_form_options[i]; + } + + //first do a reality check on the options: + if(!opt.api_target){ + $(this.selector).html('Error: Missing api target'); + return false; + } + + + //@@todo this is just a proof of concept + //much todo to improved this web form + var o = '
    '+ + '
    ' + + '
    '+ + '
    ' + + '
    '+ + '
    '+ + '
    ' + + '