r55379 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55378‎ | r55379 | r55380 >
Date:13:31, 20 August 2009
Author:dale
Status:deferred
Tags:
Comment:
* working inline uploader
Modified paths:
  • /trunk/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js (modified) (history)

Diff [purge]

Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js
@@ -15,7 +15,7 @@
1616 //inherit the cp settings for
1717 },
1818 //returns a rObj by title
19 - getRObjByTitle:function( title , callback){
 19+ addByTitle:function( title , callback){
2020 var _this = this;
2121 var reqObj = {
2222 'action':'query',
@@ -28,15 +28,8 @@
2929 do_api_req( {
3030 'data':reqObj,
3131 'url':this.cp.api_url
32 - }, function(data){
33 - _this.clearResults();
34 - //get results with rObj callback
35 - _this.addResults(data);
36 - //should only be one value:
37 - for(var i in _this.resultsObj){
38 - callback( _this.resultsObj[i] );
39 - break;
40 - }
 32+ }, function(data){
 33+ callback( _this.addSingleResult(data) );
4134 }
4235 );
4336 },
@@ -82,7 +75,7 @@
8376 'rvprop':'content'
8477 },
8578 'url':_this.cp.api_url
86 - },function(data){
 79+ },function(data){
8780 _this.clearResults();
8881 _this.addResults(data);
8982 if(callback)
@@ -130,7 +123,11 @@
131124 _this.loading = false;
132125 });
133126 },
134 - addResults:function( data ){
 127+ //same as below but returns your rObj for convience
 128+ addSingleResult:function( data ){
 129+ return this.addResults(data, true);
 130+ },
 131+ addResults:function( data, returnFirst ){
135132 js_log("f:addResults");
136133 var _this = this
137134 //check if we have
@@ -158,6 +155,7 @@
159156 if( !page.imageinfo )
160157 continue;
161158 var rObj = {
 159+ 'id' : page_id,
162160 'titleKey' : page.title,
163161 'link' : page.imageinfo[0].descriptionurl,
164162 'title' : page.title.replace(/File:|.jpg|.png|.svg|.ogg|.ogv|.oga/ig, ''),
@@ -174,22 +172,25 @@
175173 'meta':{
176174 'categories':page.categories
177175 }
178 - };
179 -
 176+ };
180177 //attempt to parse out some stuff from the teplate:
181178 var desc = rObj.desc.match(/\|Description=(([^\n]*\n)*)\|Source=/)
182179 if( desc && desc[1] ){
183180 rObj.desc = $j.trim( desc[1] );
184 - }
185 -
 181+ }
186182 //likely a audio clip if no poster and type application/ogg
187183 //@@todo we should return audio/ogg for the mime type or some other way to specify its "audio"
188184 if( ! rObj.poster && rObj.mime == 'application/ogg' ){
189185 rObj.mime = 'audio/ogg';
190 - }
 186+ }
 187+ //add to the resultObj
 188+ this.resultsObj[page_id] = rObj;
191189
192 - this.resultsObj[page_id]= rObj;
 190+ //if returnFirst flag:
 191+ if(returnFirst)
 192+ return this.resultsObj[page_id];
193193
 194+
194195 this.num_results++;
195196 //for(var i in this.resultsObj[page_id]){
196197 // js_log('added: '+ i +' '+ this.resultsObj[page_id][i]);
Index: trunk/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js
@@ -33,7 +33,10 @@
3434 "results_from" : "Results from <a href=\"$1\" target=\"_new\" >$2<\/a>",
3535 "missing_desc_see_soruce" : "This asset is missing a description. Please see the [$1 orginal source] and help describe it.",
3636 "rsd_config_error" : "Add media wizard configuration error : $1",
37 - "uploaded_itmes" : "Uploaded Items:"
 37+ "uploaded_itmes" : "Uploaded Items:",
 38+
 39+ "your_recent_uploads" : "Your Recent Uploads",
 40+ "upload_a_file": "Upload a New File"
3841 });
3942 var default_remote_search_options = {
4043 'profile':'mediawiki_edit',
@@ -590,10 +593,20 @@
591594 //load this_wiki search system to grab the rObj
592595 _this.loadSearchLib(cp, function(){
593596 //do basic layout form on left upload "bin" on right
594 - $j('#tab-upload').html('<table>' +
 597+ $j('#tab-upload').html('<table cellspacing="10">' +
595598 '<tr>' +
596 - '<td style="width:350px;padding:10px" id="upload_form">' + mv_get_loading_img() +'</td>' +
597 - '<td valign="top" id="upload_bin"></td>' +
 599+ '<td valign="top" style="width:350px;">' +
 600+ '<h4>' + gM('upload_a_file') + '</h4>' +
 601+ '<div id="upload_form">' +
 602+ mv_get_loading_img() +
 603+ '</div>' +
 604+ '</td>' +
 605+ '<td valign="top" id="upload_bin_cnt">' +
 606+ '<h4>' + gM('your_recent_uploads') + '</h4>' +
 607+ '<div id="upload_bin">' +
 608+ mv_get_loading_img() +
 609+ '</div>'+
 610+ '</td>' +
598611 '</tr>' +
599612 '</table>');
600613
@@ -605,7 +618,7 @@
606619 _this.drawOutputResults();
607620 });
608621 }else{
609 - $j('#upload_bin').empty();
 622+ $j('#upload_bin_cnt').empty();
610623 }
611624
612625 //deal with the api form upload form directly:
@@ -618,9 +631,12 @@
619632 'style="position:absolute;top:0px;left:0px;bottom:5px;right:4px;background-color:#FFF;">' +
620633 mv_get_loading_img('position:absolute;top:30px;left:30px') +
621634 '</div>');
622 - cp.sObj.getRObjByTitle( wTitle, function( rObj ){
 635+ cp.sObj.addByTitle( wTitle, function( rObj ){
623636 $j( _this.target_container ).find('#temp_edit_loader').remove();
624 - //append the image to the upload bin
 637+ //redraw (with added result if new)
 638+ _this.drawOutputResults();
 639+ //pull up recource editor:
 640+ _this.resourceEdit( rObj, $j('#res_upload_' + rObj.id).get(0) );
625641 });
626642 //return false to close progress window:
627643 return false;
@@ -916,20 +932,21 @@
917933 //@@todo we could load the id with the content provider id to find the object faster...
918934 getResourceFromId:function( rid ){
919935 //js_log('getResourceFromId:' + rid );
920 - //strip out /res/ if preset:
 936+ //strip out /res/ if preset:
921937 rid = rid.replace(/res_/, '');
922 - for(var cp_id in this.content_providers){
923 - cp = this.content_providers[ cp_id ];
924 - if(rid.indexOf( cp_id ) != -1){
925 - rid = rid.replace( cp_id + '_','');
926 - if( cp['sObj']){
927 - for(var rInx in cp.sObj.resultsObj){
928 - if( rInx == rid )
929 - return cp.sObj.resultsObj[rInx];
930 - };
931 - }
932 - }
933 - }
 938+ js_log("looking at: " + rid);
 939+ p = rid.split('_');
 940+ var cp_id = p[0];
 941+ var rid = p[1];
 942+ if(cp_id == 'upload')
 943+ cp_id = 'this_wiki';
 944+
 945+ var cp = this.content_providers[cp_id];
 946+
 947+ if(cp['sObj'] && cp.sObj.resultsObj[rid]){
 948+ return cp.sObj.resultsObj[rid];
 949+ }
 950+
934951 js_log("ERROR: could not find " + rid);
935952 return false;
936953 },

Status & tagging log