Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js |
— | — | @@ -41,8 +41,10 @@ |
42 | 42 | |
43 | 43 | 'caret_pos':null, |
44 | 44 | '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) |
46 | 45 | |
| 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 | + |
47 | 49 | 'target_title':null, |
48 | 50 | |
49 | 51 | 'target_textbox':null, |
— | — | @@ -572,7 +574,7 @@ |
573 | 575 | //this check can be avoided by setting the this.import_url_mode = 'api' | 'form' | insted of 'autodetect' or 'none' |
574 | 576 | checkForCopyURLSupport:function ( callback ){ |
575 | 577 | var _this = this; |
576 | | - //js_log('checkForCopyURLSupport:: ' + wgArticlePath); |
| 578 | + js_log('checkForCopyURLSupport:: '); |
577 | 579 | if( this.import_url_mode == 'autodetect' ){ |
578 | 580 | do_api_req( { |
579 | 581 | 'data': { 'action':'paraminfo', 'modules':'upload' }, |
— | — | @@ -593,11 +595,14 @@ |
594 | 596 | }else{ |
595 | 597 | _this.import_url_mode = 'none'; |
596 | 598 | } |
| 599 | + js_log('import mode: ' + _this.import_url_mode); |
597 | 600 | callback(); |
598 | 601 | }, |
599 | 602 | error: function(){ |
600 | 603 | js_log('error in getting Special:Upload page'); |
601 | 604 | _this.import_url_mode = 'none'; |
| 605 | + |
| 606 | + js_log('import mode: ' + _this.import_url_mode); |
602 | 607 | callback(); |
603 | 608 | } |
604 | 609 | }); |
— | — | @@ -610,9 +615,11 @@ |
611 | 616 | _this.checkForCopyURLPermission(function( canCopyUrl ){ |
612 | 617 | if(canCopyUrl){ |
613 | 618 | _this.import_url_mode = 'api'; |
| 619 | + js_log('import mode: ' + _this.import_url_mode); |
614 | 620 | callback(); |
615 | 621 | }else{ |
616 | 622 | _this.import_url_mode = 'none'; |
| 623 | + js_log('import mode: ' + _this.import_url_mode); |
617 | 624 | callback(); |
618 | 625 | } |
619 | 626 | }); |
— | — | @@ -622,6 +629,7 @@ |
623 | 630 | } |
624 | 631 | }); |
625 | 632 | }else{ |
| 633 | + js_log('import mode: ' + _this.import_url_mode); |
626 | 634 | callback(); |
627 | 635 | } |
628 | 636 | }, |
— | — | @@ -1169,7 +1177,7 @@ |
1170 | 1178 | |
1171 | 1179 | $j.btnHtml('Do Import Resource', 'rsd_import_doimport', 'check' ) + ' ' + |
1172 | 1180 | |
1173 | | - $j.btnHtml('Update Preview', 'rsd_import_apreview', 'refresh' ) + ' ' + |
| 1181 | + $j.btnHtml('Update Preview', 'rsd_import_apreview', 'refresh' ) + ' <br><br><br>' + |
1174 | 1182 | |
1175 | 1183 | $j.btnHtml('Cancel Import', 'rsd_import_acancel', 'close' ) + ' ' + |
1176 | 1184 | |
— | — | @@ -1192,89 +1200,12 @@ |
1193 | 1201 | }); |
1194 | 1202 | }); |
1195 | 1203 | $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 | + } |
1279 | 1210 | }); |
1280 | 1211 | $j( _this.target_container + ' .rsd_import_acancel').click(function(){ |
1281 | 1212 | $j('#rsd_resource_import').fadeOut("fast",function(){ |
— | — | @@ -1286,6 +1217,93 @@ |
1287 | 1218 | ); |
1288 | 1219 | } |
1289 | 1220 | }, |
| 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 | + }, |
1290 | 1308 | previewResource:function( rObj ){ |
1291 | 1309 | var _this = this; |
1292 | 1310 | this.checkImportResource( rObj, function(){ |
Index: branches/new-upload/phase3/js2/mwEmbed/libClipEdit/mvClipEdit.js |
— | — | @@ -545,7 +545,7 @@ |
546 | 546 | '<div id="mv_crop_img" style="position:absolute;'+ |
547 | 547 | 'top:-' + _this.rObj.crop.y +'px;'+ |
548 | 548 | 'left:-' + _this.rObj.crop.x + 'px;">'+ |
549 | | - '<img src="' + _this.rObj.url + '">'+ |
| 549 | + '<img src="' + _this.rObj.src + '">'+ |
550 | 550 | '</div>'+ |
551 | 551 | '</div>' |
552 | 552 | ); |