r51351 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51350‎ | r51351 | r51352 >
Date:14:22, 2 June 2009
Author:dale
Status:deferred
Tags:
Comment:
stub commit of multi-type asset import system for addMediaWiz
Modified paths:
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libClipEdit/mvClipEdit.js (modified) (history)

Diff [purge]

Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js
@@ -41,8 +41,10 @@
4242
4343 'caret_pos':null,
4444 'local_wiki_api_url':null,
45 - 'import_url_mode': 'autodetect', //can be 'api', 'form', 'autodetect', 'link', or 'none' (none should be used where no remote repositories are enabled)
4645
 46+ //can be 'api', 'form', 'autodetect', 'link', or 'none' (none should be used where no remote repositories are enabled (only local wiki/uploads)
 47+ 'import_url_mode': 'autodetect',
 48+
4749 'target_title':null,
4850
4951 'target_textbox':null,
@@ -572,7 +574,7 @@
573575 //this check can be avoided by setting the this.import_url_mode = 'api' | 'form' | insted of 'autodetect' or 'none'
574576 checkForCopyURLSupport:function ( callback ){
575577 var _this = this;
576 - //js_log('checkForCopyURLSupport:: ' + wgArticlePath);
 578+ js_log('checkForCopyURLSupport:: ');
577579 if( this.import_url_mode == 'autodetect' ){
578580 do_api_req( {
579581 'data': { 'action':'paraminfo', 'modules':'upload' },
@@ -593,11 +595,14 @@
594596 }else{
595597 _this.import_url_mode = 'none';
596598 }
 599+ js_log('import mode: ' + _this.import_url_mode);
597600 callback();
598601 },
599602 error: function(){
600603 js_log('error in getting Special:Upload page');
601604 _this.import_url_mode = 'none';
 605+
 606+ js_log('import mode: ' + _this.import_url_mode);
602607 callback();
603608 }
604609 });
@@ -610,9 +615,11 @@
611616 _this.checkForCopyURLPermission(function( canCopyUrl ){
612617 if(canCopyUrl){
613618 _this.import_url_mode = 'api';
 619+ js_log('import mode: ' + _this.import_url_mode);
614620 callback();
615621 }else{
616622 _this.import_url_mode = 'none';
 623+ js_log('import mode: ' + _this.import_url_mode);
617624 callback();
618625 }
619626 });
@@ -622,6 +629,7 @@
623630 }
624631 });
625632 }else{
 633+ js_log('import mode: ' + _this.import_url_mode);
626634 callback();
627635 }
628636 },
@@ -1169,7 +1177,7 @@
11701178
11711179 $j.btnHtml('Do Import Resource', 'rsd_import_doimport', 'check' ) + ' ' +
11721180
1173 - $j.btnHtml('Update Preview', 'rsd_import_apreview', 'refresh' ) + ' ' +
 1181+ $j.btnHtml('Update Preview', 'rsd_import_apreview', 'refresh' ) + ' <br><br><br>' +
11741182
11751183 $j.btnHtml('Cancel Import', 'rsd_import_acancel', 'close' ) + ' ' +
11761184
@@ -1192,89 +1200,12 @@
11931201 });
11941202 });
11951203 $j(_this.target_container + ' .rsd_import_doimport').click(function(){
1196 -
1197 - //get an edittoken:
1198 - do_api_req( {
1199 - 'data': { 'action':'query',
1200 - 'prop':'info',
1201 - 'intoken':'edit',
1202 - 'titles': rObj.titleKey
1203 - },
1204 - 'url':_this.local_wiki_api_url
1205 - }, function(data){
1206 - //could recheck if it has been created in the mean time
1207 - if( data.query.pages[-1] ){
1208 - var editToken = data.query.pages[-1]['edittoken'];
1209 - if(!editToken){
1210 - //@@todo give an ajax login or be more friendly in some way:
1211 - js_error("You don't have permission to upload (are you logged in?)");
1212 - //remove top level:
1213 - $j('#modalbox').fadeOut("normal",function(){
1214 - $j(this).remove();
1215 - $j('#mv_overlay').remove();
1216 - });
1217 - }else{
1218 - //not sure if we can do remote url uploads (so just do a local post)
1219 - js_log('got token for new page:' +editToken);
1220 - var postVars = {
1221 - 'wpSourceType' :'web',
1222 - 'wpUploadFileURL' : rObj.src,
1223 - 'wpDestFile' : rObj.target_resource_title,
1224 - 'wpUploadDescription': $j('#rsd_import_ta').val(),
1225 - 'wpWatchthis' : $j('#wpWatchthis').val(),
1226 - 'wpUpload' : 'Upload file'
1227 - }
1228 - //set to uploading:
1229 - $j('#rsd_resource_import').append('<div id="rsd_import_progress"'+
1230 - 'style="position:absolute;top:0px;'+
1231 - 'left:0px;width:100%;height:100%;'+
1232 - 'z-index:5;background:#FFF;overflow:auto;">'+
1233 - '<div style="position:absolute;left:30%;right:30%"><h3>Importing Asset</h3><br>' +
1234 - mv_get_loading_img('','mv_loading_bar_img') +
1235 - '</div>'+
1236 - '</div>'
1237 - );
1238 - $j.post(wgArticlePath.replace(/\$1/,'Special:Upload'),
1239 - postVars,
1240 - function(data){
1241 - //@@todo this will be replaced once we add upload image support to the api.
1242 -
1243 - //very basic test to see if we got passed to the image page:
1244 - //@@todo more normalization stuff
1245 - var sstring ='var wgPageName = "' + _this.cFileNS + ':' + rObj.target_resource_title.replace(/ /g,'_') +'"';
1246 - if(data.indexOf( sstring ) !=-1){
1247 - js_log('found: ' + sstring);
1248 - $j('#rsd_resource_import').remove();
1249 - cir_callback( rObj );
1250 - }else{
1251 - js_log("Error or warning: (did not find: \"" + sstring + ' in output' );
1252 - pos_etitle = '<h1 class="firstHeading">';
1253 - var error_txt = form_txt = '';
1254 - var res = grabWikiFormError( data );
1255 -
1256 - if( res.error_txt )
1257 - error_txt = res.error_txt;
1258 -
1259 - if( res.form_txt )
1260 - form_txt = res.form_txt;
1261 -
1262 - js_log( 'error text is: ' + error_txt );
1263 - $j( '#rsd_resource_import' ).html( '<h3>Error</h3>' + error_txt + '<br>' + form_txt +
1264 - '<br>'+
1265 - '<a href="#" id="rsd_import_error" >Cancel import</a>'
1266 - );
1267 - //set up cancel action:
1268 - $j('#rsd_import_error').click(function(){
1269 - $j('#rsd_resource_import').remove();
1270 - });
1271 - }
1272 -
1273 - }
1274 - );
1275 - }
1276 - }
1277 - }
1278 - );
 1204+ //check import mode:
 1205+ if(_this.import_url_mode=='form'){
 1206+ _this.doImportSpecialPage();
 1207+ }else{
 1208+ _this.doImportAPI();
 1209+ }
12791210 });
12801211 $j( _this.target_container + ' .rsd_import_acancel').click(function(){
12811212 $j('#rsd_resource_import').fadeOut("fast",function(){
@@ -1286,6 +1217,93 @@
12871218 );
12881219 }
12891220 },
 1221+ doImportAPI:function(){
 1222+
 1223+ },
 1224+ doImportSpecialPage:function(){
 1225+ //get an edittoken:
 1226+ do_api_req( {
 1227+ 'data': { 'action':'query',
 1228+ 'prop':'info',
 1229+ 'intoken':'edit',
 1230+ 'titles': rObj.titleKey
 1231+ },
 1232+ 'url':_this.local_wiki_api_url
 1233+ }, function(data){
 1234+ //could recheck if it has been created in the mean time
 1235+ if( data.query.pages[-1] ){
 1236+ var editToken = data.query.pages[-1]['edittoken'];
 1237+ if(!editToken){
 1238+ //@@todo give an ajax login or be more friendly in some way:
 1239+ js_error("You don't have permission to upload (are you logged in?)");
 1240+ //remove top level:
 1241+ $j('#modalbox').fadeOut("normal",function(){
 1242+ $j(this).remove();
 1243+ $j('#mv_overlay').remove();
 1244+ });
 1245+ }else{
 1246+ //not sure if we can do remote url uploads (so just do a local post)
 1247+ js_log('got token for new page:' +editToken);
 1248+ var postVars = {
 1249+ 'wpSourceType' :'web',
 1250+ 'wpUploadFileURL' : rObj.src,
 1251+ 'wpDestFile' : rObj.target_resource_title,
 1252+ 'wpUploadDescription': $j('#rsd_import_ta').val(),
 1253+ 'wpWatchthis' : $j('#wpWatchthis').val(),
 1254+ 'wpUpload' : 'Upload file'
 1255+ }
 1256+ //set to uploading:
 1257+ $j('#rsd_resource_import').append('<div id="rsd_import_progress"'+
 1258+ 'style="position:absolute;top:0px;'+
 1259+ 'left:0px;width:100%;height:100%;'+
 1260+ 'z-index:5;background:#FFF;overflow:auto;">'+
 1261+ '<div style="position:absolute;left:30%;right:30%"><h3>Importing Asset</h3><br>' +
 1262+ mv_get_loading_img('','mv_loading_bar_img') +
 1263+ '</div>'+
 1264+ '</div>'
 1265+ );
 1266+ $j.post(wgArticlePath.replace(/\$1/,'Special:Upload'),
 1267+ postVars,
 1268+ function(data){
 1269+ //@@todo this will be replaced once we add upload image support to the api.
 1270+
 1271+ //very basic test to see if we got passed to the image page:
 1272+ //@@todo more normalization stuff
 1273+ var sstring ='var wgPageName = "' + _this.cFileNS + ':' + rObj.target_resource_title.replace(/ /g,'_') +'"';
 1274+ if(data.indexOf( sstring ) !=-1){
 1275+ js_log('found: ' + sstring);
 1276+ $j('#rsd_resource_import').remove();
 1277+ cir_callback( rObj );
 1278+ }else{
 1279+ js_log("Error or warning: (did not find: \"" + sstring + ' in output' );
 1280+ pos_etitle = '<h1 class="firstHeading">';
 1281+ var error_txt = form_txt = '';
 1282+ var res = grabWikiFormError( data );
 1283+
 1284+ if( res.error_txt )
 1285+ error_txt = res.error_txt;
 1286+
 1287+ if( res.form_txt )
 1288+ form_txt = res.form_txt;
 1289+
 1290+ js_log( 'error text is: ' + error_txt );
 1291+ $j( '#rsd_resource_import' ).html( '<h3>Error</h3>' + error_txt + '<br>' + form_txt +
 1292+ '<br>'+
 1293+ '<a href="#" id="rsd_import_error" >Cancel import</a>'
 1294+ );
 1295+ //set up cancel action:
 1296+ $j('#rsd_import_error').click(function(){
 1297+ $j('#rsd_resource_import').remove();
 1298+ });
 1299+ }
 1300+
 1301+ }
 1302+ );
 1303+ }
 1304+ }
 1305+ }
 1306+ );
 1307+ },
12901308 previewResource:function( rObj ){
12911309 var _this = this;
12921310 this.checkImportResource( rObj, function(){
Index: branches/new-upload/phase3/js2/mwEmbed/libClipEdit/mvClipEdit.js
@@ -545,7 +545,7 @@
546546 '<div id="mv_crop_img" style="position:absolute;'+
547547 'top:-' + _this.rObj.crop.y +'px;'+
548548 'left:-' + _this.rObj.crop.x + 'px;">'+
549 - '<img src="' + _this.rObj.url + '">'+
 549+ '<img src="' + _this.rObj.src + '">'+
550550 '</div>'+
551551 '</div>'
552552 );

Status & tagging log