r48724 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48723‎ | r48724 | r48725 >
Date:23:22, 23 March 2009
Author:dale
Status:deferred
Tags:
Comment:
updates for adding by url
license updates
improved mv_embed oggHanndler support
Modified paths:
  • /trunk/extensions/MetavidWiki/skins/add_media_wizard.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvFirefogg.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvUploader.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/remoteSearchDriver.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/searchLibs/metavidSearch.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/skins/add_media_wizard.js
@@ -9,7 +9,29 @@
1010 //if mv_embed is hosted somewhere other than near by the add_media_wizard you can define it here:
1111 var mv_add_media_wizard_path = 'http://mvbox2.cse.ucsc.edu/w/extensions/MetavidWiki/skins/';
1212
 13+var MV_EMBED_VIDEO_HANDLER = true; // if we should use mv_embed for all ogg_hanlder video embeds.
1314
 15+
 16+if( MV_EMBED_VIDEO_HANDLER ){
 17+ var vidIdList = new Array();
 18+ addOnloadHook( function(){
 19+ var divs = document.getElementsByTagName('div');
 20+ for(var i = 0; i < divs.length; i++){
 21+ if( divs[i].id.substring(0,11) == 'ogg_player_'){
 22+ vidIdList.push( divs[i].id );
 23+ }
 24+ }
 25+ if( vidIdList.length > 0){
 26+ load_mv_embed( function(){
 27+ mvJsLoader.loadBaseLibs(function(){
 28+ //do utilty rewrite of oggHanlder content:
 29+ rewrite_for_oggHanlder( vidIdList );
 30+ });
 31+ });
 32+ }
 33+ });
 34+}
 35+
1436 //*code should not have to modify anything below*/
1537 //check if we are on a edit page:
1638 if( wgAction == 'edit' || wgAction == 'submit' ){
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/searchLibs/metavidSearch.js
@@ -55,12 +55,16 @@
5656
5757 //transform the title into a wiki_safe title:
5858 //rObj['titleKey'] = proe.queryKey['stream_name'] + '_' + rObj['start_time'].replace(/:/g,'.') + '_' + rObj['end_time'].replace(/:/g,'.') + '.ogg';
59 - rObj['titleKey'] = proe.queryKey['stream_name'] + '/' + rObj['start_time'] + '/' + rObj['end_time'] + '__.ogg';
 59+ rObj['titleKey'] = proe.queryKey['stream_name'] + '_start-' + rObj['start_time'].replace(/:/g,'.') + '_end-' + rObj['end_time'].replace(/:/g,'.') + '.ogg';
6060 }
6161 //done loading:
6262 _this.loading=0;
6363 });
6464 },
 65+ //metavid descption tied to public domain license key (government produced content)
 66+ getPermissionWikiTag:function( rObj ){
 67+ return '{{PD-USGov}}';
 68+ },
6569 getEmbedWikiText:function(rObj, options){
6670 //if we are using a local copy do the standard embed:
6771 if( this.cp.local_copy == true)
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvFirefogg.js
@@ -19,7 +19,7 @@
2020 'maxSize': 400,
2121 'videoBitrate': 400
2222 },
23 - formData:{}, //the form to be submited
 23+ formData:{}, //the form to be submitted
2424
2525 init : function( iObj ){
2626 if(!iObj)
@@ -353,7 +353,7 @@
354354 var error_txt = 'Your upload <i>should be</i> accessible <a href="' +
355355 wgArticlePath.replace(/\$1/, 'File:' + this.formData['wpDestFile'] ) + '">'+
356356 'here</a> \n';
357 - //set the error text in case we dont' get far along in proccessing the response
 357+ //set the error text in case we dont' get far along in processing the response
358358 $j( '#dlbox-centered' ).html( '<h3>Upload Completed:</h3>' + error_txt );
359359
360360 if( result_page && result_page.toLowerCase().indexOf( sstring.toLowerCase() ) != -1){
@@ -372,32 +372,14 @@
373373 if( !result_page ){
374374 //@@todo fix this:
375375 //the mediaWiki upload system does not have an API so we can\'t read errors
376 - }else{
377 - sp = result_page.indexOf('<span class="error">');
378 - if(sp!=-1){
379 - se = result_page.indexOf('</span>', sp);
380 - error_txt = result_page.substr(sp, (sp-se)) + '</span>';
381 - }else{
382 - //look for warning:
383 - sp = result_page.indexOf('<ul class="warning">')
384 - if(sp!=-1){
385 - se = result_page.indexOf('</ul>', sp);
386 - error_txt = result_page.substr(sp, (se-sp)) + '</ul>';
387 - //try and add the ignore form item:
388 - sfp = result_page.indexOf('<form method="post"');
389 - if(sfp!=-1){
390 - sfe = result_page.indexOf('</form>', sfp);
391 - form_txt = result_page.substr(sfp, ( sfe - sfp )) + '</form>';
392 - }
393 - }else{
394 - //one more error type check:
395 - sp = result_page.indexOf('class="mw-warning-with-logexcerpt">')
396 - if(sp!=-1){
397 - se = result_page.indexOf('</div>', sp);
398 - error_txt = result_page.substr(sp, ( se - sp )) + '</div>';
399 - }
400 - }
401 - }
 376+ }else{
 377+ var res = mvUploader.grabWikiFormError( result_page );
 378+
 379+ if(res.error_txt)
 380+ error_txt = opt.error_txt;
 381+
 382+ if(res.form_txt)
 383+ form_txt = res.form_txt;
402384 }
403385 js_log( 'error text is: ' + error_txt );
404386 $j( '#dlbox-centered' ).html( '<h3>Upload Completed:</h3>' + error_txt + '<br>' + form_txt);
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/remoteSearchDriver.js
@@ -45,7 +45,7 @@
4646 'default_query':null, //default search query
4747 //specific to sequence profile
4848 'p_seq':null,
49 - 'cFileNS':'Image', //what is the cannonical namespace for images
 49+ 'cFileNS':'File', //what is the cannonical namespace for images
5050 //@@todo (should get that from the api or inpage vars)
5151
5252 'enable_uploads':false // if we want to enable an uploads tab:
@@ -247,9 +247,10 @@
248248 }
249249 var url = (force_url) ? force_url : cl.base_license_url + cl.licenses[ license_key ];
250250 return {
251 - 'title': title,
252 - 'img_html':imgs,
253 - 'lurl' : url
 251+ 'title' : title,
 252+ 'img_html' : imgs,
 253+ 'key' : license_key,
 254+ 'lurl' : url
254255 };
255256 },
256257 /*
@@ -268,7 +269,7 @@
269270 //could not find it return unknown_license
270271 return {
271272 'title' : gM('unknown_license'),
272 - 'img_html' : '<span>' + gM('unknown_license') + '</span>',
 273+ 'img_html' : '<span>' + gM('unknown_license') + '</span>',
273274 'lurl' : license_url
274275 };
275276 },
@@ -940,7 +941,7 @@
941942
942943 },
943944 checkImportResource:function( rObj, cir_callback){
944 - //@@todo get the localized File/Image namespace name or do a general {NS}:Title aproch
 945+ //@@todo get the localized File/Image namespace name or do a general {NS}:Title
945946 var cp = rObj.pSobj.cp;
946947 var _this = this;
947948 rObj.target_resource_title = rObj.titleKey.replace(/File:|Image:/,'');
@@ -989,20 +990,16 @@
990991
991992 if( rObj.date )
992993 base_resource_desc+='|Date=' + rObj.date +"\n";
993 -
994 - if( rObj.permission )
995 - base_resource_desc+='|Permission='+ rObj.permission +"\n";
 994+
 995+ //add the Permision info:
 996+ base_resource_desc+='|Permission=' + rObj.pSobj.getPermissionWikiTag( rObj ) +"\n";
996997
997998 if( rObj.other_versions )
998 - base_resource_desc+='|Other_versions=' + rObj.other_versions + "\n";
 999+ base_resource_desc+='|other_versions=' + rObj.other_versions + "\n";
9991000
10001001 base_resource_desc+='}}';
10011002
1002 - //add in license template tag:
1003 - if( rObj.license_template_tag )
1004 - base_resource_desc += "\n" +
1005 - '== [[Commons:Copyright tags|Licensing]]: ==' +"\n"+
1006 - '{{' + rObj.license_template_tag + '}}';
 1003+
10071004
10081005 $j('#rsd_resource_import').remove();//remove any old resource imports
10091006 //@@ show user dialog to import the resource
@@ -1039,21 +1036,17 @@
10401037 });
10411038 //add bidings:
10421039 $j('#rsd_import_apreview').click(function(){
1043 - $j('#rsd_import_desc').show().html(
 1040+ /*$j('#rsd_import_desc').show().html(
10441041 mv_get_loading_img()
1045 - );
 1042+ );*/
10461043 //load the preview text:
10471044 _this.getParsedWikiText( $j('#rsd_import_ta').val(), _this.cFileNS +':'+ rObj.target_resource_title, function( o ){
10481045 js_log('got updated preivew: '+ o);
10491046 $j('#rsd_import_desc').html(o);
10501047 });
10511048 });
1052 - $j('#rsd_import_doimport').click(function(){
1053 - //replace the parent with progress bar:
1054 - $j('#rsd_resource_import').html(
1055 - '<h3>Importing asset</h3>'+
1056 - mv_get_loading_img()
1057 - );
 1049+ $j('#rsd_import_doimport').click(function(){
 1050+
10581051 //get an edittoken:
10591052 do_api_req( {
10601053 'data': { 'action':'query',
@@ -1076,16 +1069,16 @@
10771070 });
10781071 }else{
10791072 //not sure if we can do remote url uploads (so just do a local post)
1080 - js_log('got token for new page:' +editToken);
 1073+ js_log('got token for new page:' +editToken);
10811074 var postVars = {
10821075 'wpSourceType' :'web',
1083 - 'wpUploadFileURL' : rObj.url,
 1076+ 'wpUploadFileURL' : rObj.src,
10841077 'wpDestFile' : rObj.target_resource_title,
1085 - 'wpUploadDescription':$j('#rsd_import_ta').val(),
1086 - 'wpWatchthis' : $j('#wpWatchthis').val(),
 1078+ 'wpUploadDescription': $j('#rsd_import_ta').val(),
 1079+ 'wpWatchthis' : $j('#wpWatchthis').val(),
10871080 'wpUpload' : 'Upload file'
10881081 }
1089 - //set to uploading:
 1082+ //set to uploading:
10901083 $j('#rsd_resource_import').append('<div id="rsd_import_progress"'+
10911084 'style="position:absolute;top:0px;'+
10921085 'left:0px;width:100%;height:100%;'+
@@ -1275,9 +1268,9 @@
12761269 var out = gM('rsd_results_desc') + ' ' + (cp.offset+1) + ' to ' + to_num;
12771270 //check if we have more results (next prev link)
12781271 if( cp.offset >= cp.limit )
1279 - out+=' <a href="#" id="rsd_pprev">' + gM('rsd_results_prev') + cp.limit + '</a>';
 1272+ out+=' <a href="#" id="rsd_pprev">' + gM('rsd_results_prev') + ' ' + cp.limit + '</a>';
12801273 if( cp.sObj.more_results )
1281 - out+=' <a href="#" id="rsd_pnext">' + gM('rsd_results_next') + cp.limit + '</a>';
 1274+ out+=' <a href="#" id="rsd_pnext">' + gM('rsd_results_next') + ' ' + cp.limit + '</a>';
12821275 $j(target).html(out);
12831276 //set bindings
12841277 $j('#rsd_pnext').click(function(){
@@ -1427,7 +1420,7 @@
14281421 _this.resultsObj[inx] = rObj;
14291422 _this.num_results++;
14301423 });
1431 - },
 1424+ },
14321425 //by default just return the existing image with callback
14331426 getImageObj:function( rObj, size, callback){
14341427 callback( {'url':rObj.poster} );
@@ -1440,6 +1433,15 @@
14411434 //no desc avaliable:
14421435 return '';
14431436 },
 1437+ //default licence permision wiki text is cc based template mapping (does not confirm the templates actually exist)
 1438+ getPermissionWikiTag: function( rObj ){
 1439+ //check that its a defined creative commons licnese key:
 1440+ if( typeof this.rsd.licenses.cc.licenses[ rObj.license.key ] != 'undefined' ){
 1441+ return '{{Cc-' + rObj.license.key + '}}';
 1442+ }else if( rObj.license.lurl ) {
 1443+ return '{{Template:External_License|' + rObj.license.lurl + '}}';
 1444+ }
 1445+ },
14441446 //by default just return the poster (clients can overide)
14451447 getImageTransform:function(rObj, opt){
14461448 return rObj.poster;
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvUploader.js
@@ -98,6 +98,35 @@
9999 _this.fogg = new mvFirefogg( intFirefoggObj );
100100
101101 },
 102+ grabWikiFormError:function( result_page ){
 103+ var res = {};
 104+ sp = result_page.indexOf('<span class="error">');
 105+ if(sp!=-1){
 106+ se = result_page.indexOf('</span>', sp);
 107+ res.error_txt = result_page.substr(sp, (sp-se)) + '</span>';
 108+ }else{
 109+ //look for warning:
 110+ sp = result_page.indexOf('<ul class="warning">')
 111+ if(sp!=-1){
 112+ se = result_page.indexOf('</ul>', sp);
 113+ error_txt = result_page.substr(sp, (se-sp)) + '</ul>';
 114+ //try and add the ignore form item:
 115+ sfp = result_page.indexOf('<form method="post"');
 116+ if(sfp!=-1){
 117+ sfe = result_page.indexOf('</form>', sfp);
 118+ res.form_txt = result_page.substr(sfp, ( sfe - sfp )) + '</form>';
 119+ }
 120+ }else{
 121+ //one more error type check:
 122+ sp = result_page.indexOf('class="mw-warning-with-logexcerpt">')
 123+ if(sp!=-1){
 124+ se = result_page.indexOf('</div>', sp);
 125+ res.error_txt = result_page.substr(sp, ( se - sp )) + '</div>';
 126+ }
 127+ }
 128+ }
 129+ return res;
 130+ },
102131 //same add code as specialUpload if($wgEnableFirefogg){
103132 addFirefoggHtml:function(){
104133 var itd_html = $j('#mw-upload-table .mw-input:first').html();
Index: trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js
@@ -776,6 +776,28 @@
777777 mv_embed(ready_callback, vid_id );
778778 });
779779 }
 780+function rewrite_for_oggHanlder( vidIdList ){
 781+ for(var i = 0; i < vidIdList.length ; i++){
 782+ var vidId = vidIdList[i];
 783+ js_log('looking at vid: ' + i +' ' + vidId);
 784+ //grab the thumbnail and src video
 785+ var pimg = $j('#'+vidId + ' img');
 786+ var poster = pimg.attr('src');
 787+ var pwidth = pimg.attr('width');
 788+ var pheight = pimg.attr('height');
 789+ //reg videoUrl\":\s*"([^"]*)
 790+
 791+ var re = new RegExp( /videoUrl(&quot;:?\s*)*([^&]*)/ );
 792+ var src = re.exec( $j('#'+vidId).html() )[2];
 793+ //replace the top div with mv_embed based player:
 794+ if( src && poster)
 795+ $j('#'+vidId).replaceWidth( '<video id="vid_' + i +'" '+
 796+ 'src="' + src + ' poster="' + poster + '" style="width:' + pwidth +
 797+ 'px;height:' + pheight + 'px;"></video>';
 798+ //rewrite that video id:
 799+ rewrite_by_id('vid_' + i);
 800+ }
 801+}
780802
781803
782804 /*********** INITIALIZATION CODE *************
@@ -1072,7 +1094,7 @@
10731095
10741096 //does a remote or local api request based on request url
10751097 //@param options: url, data, cbParam, callback
1076 -function do_api_req( options, callback ){
 1098+function do_api_req( options, callback ){
10771099 if(typeof options.data != 'object'){
10781100 js_log('Error: request paramaters must be an object');
10791101 return false;
@@ -1092,12 +1114,13 @@
10931115
10941116 //force format to json (if not already set)
10951117 options.data['format'] = 'json';
1096 -
 1118+
 1119+ js_log('do api req: ' + options.url + options.data);
10971120 //build request string:
10981121 if( parseUri( document.URL ).host == parseUri( options.url ).host ){
10991122 //local request do api request directly
11001123 $j.ajax({
1101 - type: "GET",
 1124+ type: "POST",
11021125 url: options.url,
11031126 data: options.data,
11041127 dataType:'json', //api requests _should_ always return JSON data:
@@ -1105,8 +1128,8 @@
11061129 success:function(data){
11071130 callback( data );
11081131 },
1109 - error:function(){
1110 - js_error( ' error in getting: ' + options.url);
 1132+ error:function(e){
 1133+ js_error( ' error' + e +' in getting: ' + options.url);
11111134 }
11121135 });
11131136 }else{
@@ -1150,6 +1173,7 @@
11511174 loadExternalJs(req_url+'&cb=mv_jsdata_cb&cb_inx='+(global_req_cb.length-1));
11521175 }
11531176 }
 1177+
11541178 function mv_jsdata_cb(response){
11551179 js_log('f:mv_jsdata_cb:'+ response['cb_inx']);
11561180 //run the callback from the global req cb object:

Status & tagging log