r44888 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44887‎ | r44888 | r44889 >
Date:04:26, 22 December 2008
Author:dale
Status:deferred
Tags:
Comment:
improved resource import, style fixes
Modified paths:
  • /trunk/extensions/MetavidWiki/skins/external_media_wizard.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libRemoteMediaSearch/mv_remote_media_search.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libSequencer/mv_clipedit.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/skins/mvpcf/styles.css (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/skins/external_media_wizard.js
@@ -11,7 +11,7 @@
1212 'local':true //this will change the output from [[embed:StreamName]] to [[remoteEmbed:roe_url]]
1313 }
1414 }
15 -var wg_local_wiki_api_url = 'http://localhost/wiki/api.php';
 15+var wg_local_wiki_api_url = wgServer + wgScriptPath + '/api.php';
1616
1717
1818 //*code should not have to modify anything below*/
@@ -28,11 +28,12 @@
2929 }
3030 var caret_pos={};
3131 function mv_do_load_wiz(){
32 - caret_pos={};
33 - tb = document.getElementById('wpTextbox1');
34 - caret_pos.s = getTextCusorStartPos( tb );
35 - caret_pos.e = getTextCusorEndPos( tb );
36 -
 32+ caret_pos={};
 33+ var txtarea = document.editform.wpTextbox1;
 34+ caret_pos.s = getTextCusorStartPos( txtarea );
 35+ caret_pos.e = getTextCusorEndPos( txtarea );
 36+ caret_pos.text = txtarea.value;
 37+
3738 //show the loading screen:
3839 var body_elm = document.getElementsByTagName("body")[0];
3940 body_elm.innerHTML = body_elm.innerHTML + ''+
@@ -62,6 +63,10 @@
6364 if( typeof MV_EMBED_VERSION == 'undefined'){
6465 setTimeout('check_for_mv_embed();', 25);
6566 }else{
 67+ //restore text value:
 68+ var txtarea = document.editform.wpTextbox1;
 69+ txtarea.value = caret_pos.text;
 70+ //do the remote search interface:
6671 mv_do_remote_search({
6772 'target_id':'modalbox',
6873 'profile':'mediawiki_edit',
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libSequencer/mv_clipedit.js
@@ -68,7 +68,7 @@
6969 '<textarea id="mv_img_desc" rows="4" cols="30"></textarea><br>'+
7070 '<h3>Actions</h3>'+
7171 '<input type="button" class="mv_insert_image_page" value="' + getMsg('mv_insert_image_page') + '"> '+
72 - '<input type="button" class="mv_preview_insert" value="' + getMsg('mv_preview_insert')+ '"> '+
 72+ '<input type="button" style="font-weight:bold" class="mv_preview_insert" value="' + getMsg('mv_preview_insert')+ '"> '+
7373 '<a href="#" class="mv_cancel_img_edit" title="' + getMsg('mv_cancel_image_insert')+'">' + getMsg('mv_cancel_image_insert') + '</a> '
7474 );
7575 //add bidings:
Index: trunk/extensions/MetavidWiki/skins/mv_embed/skins/mvpcf/styles.css
@@ -494,15 +494,15 @@
495495 display:inline;
496496 list-style-image:none;
497497 list-style-position:outside;
498 - list-style-type:none;
499 - margin:0;
500 - padding:0;
 498+ list-style-type:none;
 499+ z-index:2;
501500 }
502501 ul.rsd_cp_tabs li.rsd_selected {
503502 background:#FFFFFF none repeat scroll 0 0;
504503 border-bottom:0;
505504 padding-bottom:1px;
506505 padding-top:12px;
 506+ top:40px;
507507 }
508508 ul.rsd_cp_tabs li {
509509 display:inline;
@@ -527,16 +527,18 @@
528528 border-top:0;
529529 border:1px solid #777;
530530 position:relative;
531 - background:#FFF;
532 -
533 - position:absolute;
 531+ background:#FFF;
534532 left:2px;
535533 right:2px;
536 - top:66px;
537534 bottom:2px;
538535 z-index:-1;
539536 overflow:auto;
 537+ position:absolute;
 538+ top:75px;
540539 }
 540+#rsd_resource_edit{
 541+ z-index:2;
 542+}
541543 .mv_clip_box_result{
542544 padding:10px;
543545 float:left;
Index: trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js
@@ -132,7 +132,9 @@
133133 return '[' + key + ']';
134134 }
135135 }
136 -function mv_get_loading_img( style, class){
 136+
 137+function mv_get_loading_img( style , class ){
 138+ var style_txt = (style)?style:'';
137139 var class_attr = (class)?'class="'+class+'"':'class="mv_loading_img"';
138140 return '<img '+class_attr+' style="' + style +'" src="'+
139141 mv_embed_path + 'skins/' + mv_skin_name + '/images/loading_ani.gif">';
@@ -2922,26 +2924,26 @@
29232925 api_url = wgServer +((wgServer == null) ? parseUri(document.URL).host + (wgScriptPath + "/api.php") : parseUri(document.URL).host + wgScript);
29242926 //update to api.php (if index.php was in the wgScript path):
29252927 api_url = api_url.replace('index.php', 'api.php');
2926 - }
2927 -
2928 - //build request string: (force the format to json):
2929 - var req_url = api_url + '?format=json';
2930 - for(var i in req_param){
2931 - req_url += '&' + encodeURIComponent( i ) + '=' + encodeURIComponent( req_param[i] );
2932 - }
2933 -
 2928+ }
 2929+ //build request string: (force the format to json):
 2930+ var req_url = api_url + '?format=json';
29342931 if( parseUri(document.URL).host == parseUri(api_url).host ){
29352932 //local request do api request directly
29362933 $j.ajax({
2937 - type: "GET",
 2934+ type: "POST",
29382935 url:req_url,
 2936+ data: req_param,
29392937 async: false,
29402938 success:function(data){
29412939 eval('var result_data=' + data );
29422940 callback( result_data );
29432941 }
29442942 });
2945 - }else{
 2943+ }else{
 2944+ //put all the values into the GET req:
 2945+ for(var i in req_param){
 2946+ req_url += '&' + encodeURIComponent( i ) + '=' + encodeURIComponent( req_param[i] );
 2947+ }
29462948 var fname = 'mycpfn_' + ( global_cb_count++ );
29472949 _global[ fname ] = callback ;
29482950 req_url += '&callback=' + fname;
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libRemoteMediaSearch/mv_remote_media_search.js
@@ -73,12 +73,12 @@
7474 'title' :'Wikipedia Commons',
7575 'desc' : 'Wikimedia Commons is a media file repository making available public domain '+
7676 'and freely-licensed educational media content (images, sound and video clips) to all.',
77 - 'hompage': 'http://commons.wikimedia.org/wiki/Main_Page',
 77+ 'homepage': 'http://commons.wikimedia.org/wiki/Main_Page',
7878 'api_url':'http://commons.wikimedia.org/w/api.php',
7979 'lib' :'mediaWiki',
8080 'search_title':false, //disable title search
8181 'local' :false,
82 - 'resource_prefix': '' //what prefix to use on imported resources
 82+ 'resource_prefix': 'WC_' //prefix on imported resources (not applicable if the repository is local)
8383 },
8484 'metavid':{
8585 'enabled':1,
@@ -138,10 +138,10 @@
139139 this.add_interface_bindings();
140140 },
141141 //gets the in and out points for insert position or grabs the selected text for search
142 - getTexboxSelection:function(){
 142+ getTexboxSelection:function(){
143143 if(this.caret_pos.s && this.caret_pos.e &&
144144 (this.caret_pos.s != this.caret_pos.e))
145 - this.default_query = $j('#'+this.target_textbox).val().substring(this.caret_pos.s, this.caret_pos.e).replace(/ /g, '\xa0') || '\xa0'
 145+ this.default_query = caret_pos.text.substring(this.caret_pos.s, this.caret_pos.e).replace(/ /g, '\xa0') || '\xa0'
146146 },
147147 //sets up the initial html interface
148148 init_interface_html:function(){
@@ -272,7 +272,7 @@
273273 drawTabs: function(){
274274 var _this = this;
275275 //add the tabs to the rsd_results container:
276 - var o= '<ul class="rsd_cp_tabs" >';
 276+ var o= '<ul class="rsd_cp_tabs" style="margin-bottom:2px;">'; //no idea why margin-bottom does not work in the css file
277277 o+='<li id="rsd_tab_combined" ><img src="' + mv_embed_path + 'skins/'+mv_skin_name+ '/remote_search/combined_tab.png"></li>';
278278 for(var cp_id in this.content_providers){
279279 var cp = this.content_providers[cp_id];
@@ -475,83 +475,168 @@
476476 _this.cEdit = new mvClipEdit( mvClipInit );
477477 });
478478 },
479 - checkImportResource:function( rObj, callback){
 479+ checkImportResource:function( rObj, cir_callback){
480480 //check if the resource is "locally accesible"
481481 if( rObj.pSobj.local ){
482 - callback( rObj );
 482+ js_log("checkImportResource:local");
 483+ cir_callback( rObj );
483484 }else{
484485 var _this = this;
485486 var cp = rObj.pSobj.cp;
486487
487488 //first check if the resource is not already on this wiki:
488 - var target_resource_title = cp.resource_prefix + rObj.titleKey;
489 - reqObj={'action':'query', titles:target_resource_title};
490 - do_api_req( reqObj, this.local_wiki_api_url, function(data){
491 - if( ! data.query.pages['-1'] ){
492 - //resource is already present:
493 - callback( rObj );
 489+ //@@todo get the File Msg
 490+ var cFileNS= 'Image'
 491+ var target_resource_title = cp.resource_prefix + rObj.titleKey.substr( cFileNS.length + 1 );
 492+ reqObj={'action':'query', titles: cFileNS + ':' + target_resource_title + '|' + rObj.titleKey};
 493+ do_api_req( reqObj, this.local_wiki_api_url, function(data){
 494+ var found_title = false;
 495+ for(var i in data.query.pages){
 496+ if(i>0)
 497+ found_title=true;
 498+ }
 499+ if( found_title ){
 500+ //resource is already present (or resource with same name is already present)
 501+ js_log("checkImportResource:resource is already present: {"+
 502+ cp.resource_prefix + '}' + rObj.titleKey);
 503+ cir_callback( rObj );
494504 }else{
495 - var base_resource_desc = '{Information '+
 505+ js_log("resource not present: update:"+ cFileNS + ':' + target_resource_title);
 506+
 507+ //setup the resource description from resource description:
 508+ var base_resource_desc = '{{Information '+"\n"+
496509 '|Description= ' + rObj.title + ' imported from ' + '[' + cp.homepage +
497510 ' ' + cp.title+']' + "\n" +
498 - '|Source=' + '[' + rObj.link +' Original Source]'+ "\n" +
499 - '|Author= US government' +"\n"+
500 - '|Date= October 1st 2008' +"\n"+
501 - '|Permission=' +"\n"+
502 - '|other_versions=' +"\n"+
503 - '}}';
 511+ '|Source=' + '[' + rObj.link +' Original Source]'+ "\n";
 512+
 513+ if( rObj.author )
 514+ base_resource_desc+='|Author= US government' +"\n";
 515+
 516+ if( rObj.date )
 517+ base_resource_desc+='|Date= October 1st 2008' +"\n";
 518+
 519+ if( rObj.permission )
 520+ base_resource_desc+='|Permission=' +"\n";
 521+
 522+ if( rObj.other_versions )
 523+ base_resource_desc+='|other_versions=' +"\n";
 524+
 525+ base_resource_desc+='}}';
 526+ $j('#rsd_resource_import').remove();//remove any old resource imports
504527 //@@ show user dialog to import the resource
505528 $j( '#'+ _this.target_id ).append('<div id="rsd_resource_import" '+
506 - 'style="position:absolute;top:0px;left:0px;width:100%;height:100%;background-color:#FFF;">' +
507 - '<h3>Resource: ' + rObj.title + ' needs to be imported to this wiki</h3>'+
508 - rObj.pSobj.getEmbedHTML( rObj, {'max_height':'300'} )+ //get embedHTML:
509 - '<br>'+
510 - //output the rendered and non-renderd version of description for easy swiching:
511 - '<strong>Resource Description:</strong>'+
512 - '<a id="rsd_import_aedit" href="#">Edit</a>'+
513 - '<a style="display:none;" id="rsd_import_apreview" href="#">Preview</a>'+
514 - '<div id="rsd_impoart_desc" syle="width:60%;border:solid thin black;height:300px;overflow:auto;">'+
515 - mv_get_loading_img('position:absolute;top:5px;left:5px', 'mv_img_loader') +
516 - '</div>'+
517 - '<textarea id="rsd_import_ta" style="display:none" id="mv_img_desc" rows="4" cols="30">'+
518 - base_resource_desc +
519 - '</textarea><br>'+
520 - '<input id="rsd_import_doimport" type="button" value="Do Import Resource">'+
521 - '<a href="#">Cancel Import</a>'+
 529+ 'style="position:absolute;top:50px;left:50px;right:50px;bottom:50px;background-color:#FFF;border:solid thick red;z-index:3">' +
 530+ '<h3 style="color:red">Resource: <span style="color:black">' + rObj.title + '</span> needs to be imported</h3>'+
 531+ '<div id="rsd_preview_import_container" style="position:absolute;width:50%;bottom:0px;left:0px;overflow:auto;top:30px;">' +
 532+ rObj.pSobj.getEmbedHTML( rObj, {'max_height':'200'} )+ //get embedHTML with small thumb:
 533+ '<br style="clear both">'+
 534+ '<strong>Resource Page Description:</strong>'+
 535+ '<div id="rsd_import_desc" syle="display:inline;">'+
 536+ mv_get_loading_img('position:absolute;top:5px;left:5px', 'mv_img_loader') +
 537+ '</div>'+
 538+ '</div>'+
 539+ '<div id="rds_edit_import_container" style="position:absolute;left:50%;' +
 540+ 'bottom:0px;top:30px;right:0px;overflow:auto;">'+
 541+ '<strong>Local Resource Title:</strong><br>'+
 542+ '<input type="text" size="30" value="' + target_resource_title + '" readonly="true"><br>'+
 543+ '<strong>Edit WikiText Resource Description:</strong>(will be replaced by forms soon)'+
 544+ '<textarea id="rsd_import_ta" id="mv_img_desc" rows="8" cols="50">'+
 545+ base_resource_desc +
 546+ '</textarea><br>'+
 547+ '<input type="checkbox" value="true" id="wpWatchthis" name="wpWatchthis" tabindex="7"/>'+
 548+ '<label for="wpWatchthis">Watch this page</label><br>'+
 549+ '<input id="rsd_import_apreview" type="button" value="Update Preview"> ' +
 550+ '<input style="font-weight: bold" id="rsd_import_doimport" type="button" value="Do Import Resource"> '+
 551+ '<a id="rsd_import_acancel" href="#">Cancel Import</a>'+
 552+ '</div>'+
 553+ //output the rendered and non-renderd version of description for easy swiching:
522554 '</div>');
523 - //load the preview text:
524 - _this.getParsedWikiText( base_resource_desc, function( o ){
525 - $j('#rsd_impoart_desc').html(o);
 555+ //load the preview text:
 556+ _this.getParsedWikiText( base_resource_desc, cFileNS +':'+ target_resource_title, function( o ){
 557+ $j('#rsd_import_desc').html(o);
526558 });
527 - //add bidings:
528 - $j('#rsd_import_aedit').click(function(){
529 - $j(this).hide();
530 - $j('#rsd_impoart_desc').hide();
531 - $j('#rsd_import_apreview,#rsd_import_ta').show();
532 - });
 559+ //add bidings:
533560 $j('#rsd_import_apreview').click(function(){
534 - $j(this).hide();
535 - $j('#rsd_impoart_desc').show().html(
536 - mv_get_loading_img('position:absolute;top:5px;left:5px', 'mv_img_loader')
 561+ $j('#rsd_import_desc').show().html(
 562+ mv_get_loading_img()
537563 );
538564 //load the preview text:
539 - _this.getParsedWikiText( $j('#rsd_import_ta').val() , function( o ){
540 - $j('#rsd_impoart_desc').html(o);
 565+ _this.getParsedWikiText( $j('#rsd_import_ta').val(), cFileNS +':'+ target_resource_title, function( o ){
 566+ js_log('got updated preivew: '+ o);
 567+ $j('#rsd_import_desc').html(o);
541568 });
542569 });
543570 $j('#rsd_import_doimport').click(function(){
544571 //replace the parent with progress bar:
545572 $j('rsd_resource_import').html(
546573 '<h3>Importing asset</h3>'+
547 - mv_get_loading_img('position:absolute;top:5px;left:5px', 'mv_img_loader')
 574+ mv_get_loading_img()
548575 );
549576 //get an edittoken:
550577 var reqObj = {'action':'query','prop':'info','intoken':'edit','titles': rObj.titleKey };
551 - do_api_req( reqObj, cp.api_url,function(data){
552 - js_log('edit token: ' + data.page[0]['edittoken']);
 578+ do_api_req( reqObj, _this.local_wiki_api_url, function(data){
 579+ //could recheck if it has been created in the mean time
 580+ if( data.query.pages[-1] ){
 581+ var editToken = data.query.pages[-1]['edittoken'];
 582+ if(!editToken){
 583+ //@@todo give an ajax login or be more friendly in some way:
 584+ js_error("You don't have permision to upload (are you logged in?)");
 585+ //remove top level:
 586+ $j('#modalbox').fadeOut("normal",function(){
 587+ $j(this).remove();
 588+ $j('#mv_overlay').remove();
 589+ });
 590+ }else{
 591+ //not sure if we can do remote url uploads (so just do a local post)
 592+ js_log('got token for new page:' +editToken);
 593+ var postVars = {
 594+ 'wpSourceType' :'web',
 595+ 'wpUploadFileURL' : rObj.url,
 596+ 'wpDestFile' : target_resource_title,
 597+ 'wpUploadDescription':$j('#rsd_import_ta').val(),
 598+ 'wpWatchthis' : $j('#wpWatchthis').val(),
 599+ 'wpUpload' : 'Upload file'
 600+ }
 601+ //set to uploading:
 602+ $j('#rsd_resource_import').append('<div id="rsd_import_progress"'+
 603+ 'style="position:abolute;top:0px;"'+
 604+ 'left:0px;width:100%;height:100%;'+
 605+ 'z-index:4;background:#555;">'+
 606+ '<div style="left:30%;right:30%">Importing Asset' +
 607+ mv_get_loading_img() +
 608+ '</dvi>'+
 609+ '</div>'
 610+ );
 611+
 612+ $j.ajax({
 613+ type:"POST",
 614+ url: wgArticlePath.replace(/\$1/,'Special:Upload'),
 615+ data: postVars,
 616+ sucess:function(data, textStatus){
 617+ js_log('success in uploading: '+target_resource_title +' textStatus:'+ textStatus);
 618+ //cir_callback with pointer to local resource:
 619+ cObj.target_resource_title = target_resource_title;
 620+ cir_callback( rObj )
 621+ },
 622+ error:function(XMLHttpRequest, textStatus, errorThrown){
 623+ js_log('error httpReq:' + ' status:' + XMLHttpRequest.status)
 624+ },
 625+ complete:function(XMLHttpRequest, textStatus){
 626+ js_log('completed request:' + textStatus + ' status:'+ XMLHttpRequest.status);
 627+ rObj.target_resource_title = target_resource_title;
 628+ cir_callback( rObj )
 629+ }
 630+ });
 631+ }
 632+ }
553633 });
554634
555 - });
 635+ });
 636+ $j('#rsd_import_acancel').click(function(){
 637+ $j('#rsd_resource_import').fadeOut("fast",function(){
 638+ $j(this).remove();
 639+ })
 640+ })
556641 }
557642 });
558643 }
@@ -585,8 +670,8 @@
586671 'action':'parse',
587672 'text':wikitext
588673 };
589 - do_api_req( reqObj, this.local_wiki_api_url, function(data){
590 - callback( data.parse['*'] );
 674+ do_api_req( reqObj, this.local_wiki_api_url, function(data){
 675+ callback( data.parse.text['*'] );
591676 });
592677 },
593678 insertResource:function( rObj){
@@ -863,7 +948,7 @@
864949 var page = data.query.pages[ page_id ];
865950 this.resultsObj[page_id]={
866951 'titleKey':page.title,
867 - 'link':'null',
 952+ 'link':page.imageinfo[0].descriptionurl,
868953 'title':page.title.replace(/File:|.jpg|.png|.svg|.ogg|.ogv/ig, ''),
869954 'poster':page.imageinfo[0].thumburl,
870955 'thumbwidth':page.imageinfo[0].thumbwidth,
@@ -897,7 +982,6 @@
898983 //build the query to get the req size image:
899984 var reqObj = {
900985 'action':'query',
901 - 'format':'json',
902986 'titles':rObj.titleKey,
903987 'prop':'imageinfo',
904988 'iiprop':'url|size|mime'

Status & tagging log