From bf8f69ad5090c61fc42f2ecc1a53ff1d4f7251f2 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Thu, 20 Aug 2009 09:55:40 +0000 Subject: [PATCH] * minor css fixes * fixes to inline uploads * stubs for recent uploaded asset import listing --- .../libAddMedia/mvBaseUploadInterface.js | 72 ++++++++- js2/mwEmbed/libAddMedia/mvFirefogg.js | 2 +- js2/mwEmbed/libAddMedia/remoteSearchDriver.js | 141 ++++++++++++----- .../libAddMedia/searchLibs/mediaWikiSearch.js | 105 +++++++++++-- js2/mwEmbed/libAddMedia/simpleUploadForm.js | 38 ++--- js2/mwEmbed/libEmbedVideo/embedVideo.js | 29 ++-- js2/mwEmbed/mv_embed.js | 8 +- js2/mwEmbed/skins/ctrlBuilder.js | 33 ++-- js2/mwEmbed/skins/kskin/styles.css | 16 +- js2/mwEmbed/skins/mvpcf/styles.css | 142 +++++++++--------- js2/uploadPage.js | 75 ++------- 11 files changed, 421 insertions(+), 240 deletions(-) diff --git a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js index 2e03313f34..2393b23508 100644 --- a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js +++ b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js @@ -658,9 +658,9 @@ mvBaseUploadInterface.prototype = { buttons: _this.cancel_button() }); $j('#upProgressDialog').html( - //set initial content: + //set initial content: '
' + - '
' + + '
' + '
'+ '0% - ' + '' + gM('mwe-uploaded-status') + ' ' + @@ -694,3 +694,71 @@ mvBaseUploadInterface.prototype = { } } }; + +//add some jquery bindings: +(function($) { + /** + * doDestCheck checks the destination + */ + $.fn.doDestCheck = function( opt ){ + var _this = this; + var destFile = this.selector; + //set up option defaults; + if(!opt.warn_target) + opt.warn_target = '#wpDestFile-warning'; + + //empty target warn: + $j(opt.warn_target).empty(); + + //show loading + $j(destFile).after(''); + //try and get a thumb of the current file (check its destination) + do_api_req({ + 'data':{ + 'titles': 'File:' + $j(destFile).val(),//@@todo we may need a more clever way to get a the filename + 'prop': 'imageinfo', + 'iiprop':'url|mime|size', + 'iiurlwidth': 150 + } + },function(data){ + //remove spinner: + $j('#mw-spinner-wpDestFile').remove(); + if(data && data.query && data.query.pages){ + if( data.query.pages[-1] ){ + //all good no file there + }else{ + for(var page_id in data.query.pages){ + var ntitle = ( data.query.normalized)? data.query.normalized[0].to : data.query.pages[ page_id ].title + var img = data.query.pages[ page_id ].imageinfo[0]; + $j('#wpDestFile-warning').html( + '
    ' + + '
  • '+ + gM('mwe-fileexists', ntitle) + + '
  • '+ + '
    ' + + '
    ' + + '' + + '' + ntitle + '' + + '' + + '
    ' + + '
    ' + + '" + + ''+ + '
    '+ + gM('mwe-fileexists-thumb') + + '
    ' + + '
    '+ + '
    ' + + '
' + ); + } + } + } + }); + } +})(jQuery); + diff --git a/js2/mwEmbed/libAddMedia/mvFirefogg.js b/js2/mwEmbed/libAddMedia/mvFirefogg.js index 33b2cf9ace..e57b797e26 100644 --- a/js2/mwEmbed/libAddMedia/mvFirefogg.js +++ b/js2/mwEmbed/libAddMedia/mvFirefogg.js @@ -636,7 +636,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface var go_to_url_txt = gM('mwe-go-to-resource'); if( typeof _this.done_upload_cb == 'function' ){ //if done action return 'true' - if( _this.done_upload_cb() ){ + if( _this.done_upload_cb( _this.formData ) ){ //update status _this.updateProgressWin( gM('mwe-successfulupload'), gM( 'mwe-upload_done', apiResult.resultUrl),buttons); }else{ diff --git a/js2/mwEmbed/libAddMedia/remoteSearchDriver.js b/js2/mwEmbed/libAddMedia/remoteSearchDriver.js index 17c6966f0e..8445babcc6 100644 --- a/js2/mwEmbed/libAddMedia/remoteSearchDriver.js +++ b/js2/mwEmbed/libAddMedia/remoteSearchDriver.js @@ -32,7 +32,8 @@ loadGM({ "no_import_by_url" : "This user or wiki can not<\/b> import assets from remote URLs.<\/p>

Do you need to login?<\/p>

If permissions are set, you may have to enable $wgAllowCopyUploads (more information<\/a>).<\/p>", "results_from" : "Results from $2<\/a>", "missing_desc_see_soruce" : "This asset is missing a description. Please see the [$1 orginal source] and help describe it.", - "rsd_config_error" : "Add media wizard configuration error : $1" + "rsd_config_error" : "Add media wizard configuration error : $1", + "uploaded_itmes" : "Uploaded Items:" }); var default_remote_search_options = { 'profile':'mediawiki_edit', @@ -132,7 +133,7 @@ remoteSearchDriver.prototype = { 'lib' : 'mediaWiki', 'local' : true, 'tab_img': false - }, + }, 'wiki_commons':{ 'enabled': 1, 'checked': 1, @@ -577,15 +578,55 @@ remoteSearchDriver.prototype = { //set the form action based on domain: if( parseUri( document.URL ).host == parseUri( _this.upload_api_target ).host ){ mvJsLoader.doLoad(['$j.fn.simpleUploadForm'],function(){ - //deal with the api form upload form directly: - $j('#tab-upload').simpleUploadForm({ - "api_target" : _this.upload_api_target , - "ondone_cb" : function( resultData ){ - var cat = resultData; - debugger; - return false; - } - }) + + //get extened info about the file + var cp = _this.content_providers['this_wiki']; + //check for "this_wiki" enabled + if(!cp.enabled){ + $j('#tab-upload').html('error this_wiki not enabled (can\'t get uploaded file info)'); + return false; + } + + //load this_wiki search system to grab the rObj + _this.loadSearchLib(cp, function(){ + //do basic layout form on left upload "bin" on right + $j('#tab-upload').html('' + + '' + + '' + + '' + + '' + + '
' + mv_get_loading_img() +'
'); + + + //fill in the user page: + if(typeof wgUserName != 'undefined' && wgUserName){ + //load the upload bin with anything the current user has uploaded + cp.sObj.getUserRecentUploads( wgUserName, function(){ + _this.drawOutputResults(); + }); + }else{ + $j('#upload_bin').empty(); + } + + //deal with the api form upload form directly: + $j('#upload_form').simpleUploadForm({ + "api_target" : _this.upload_api_target , + "ondone_cb" : function( resultData ){ + var wTitle = resultData['wpDestFile']; + //add a loading div + $j( _this.target_container ).append('

'); + cp.sObj.getRObjByTitle( wTitle, function( rObj ){ + $j( _this.target_container ).find('#temp_edit_loader').remove(); + //append the image to the upload bin + }); + //return false to close progress window: + return false; + } + }) + }); }); }else{ //setup the proxy @@ -740,26 +781,33 @@ remoteSearchDriver.prototype = { $j('#tab-' + this.disp_item).html( '
'+ gM('no_import_by_url') +'
'); } return false; - } + } + _this.loadSearchLib(cp, function(){ + //do search + cp.sObj.getSearchResults(); + _this.checkResultsDone(); + }); + }, + loadSearchLib:function(cp, callback){ + var _this = this; //set up the library req: mvJsLoader.doLoad( [ 'baseRemoteSearch', cp.lib +'Search' ], function(){ - js_log("loaded .. disp is: " + _this.disp_item); + js_log("loaded lib:: " + cp.lib ); //else we need to run the search: var iObj = {'cp':cp, 'rsd':_this}; eval('cp.sObj = new '+cp.lib+'Search( iObj );'); - if(!cp.sObj) + if(!cp.sObj){ js_log('Error: could not find search lib for ' + cp_id); + return false; + } //inherit defaults if not set: cp.limit = (cp.limit) ? cp.limit : cp.sObj.limit; cp.offset = (cp.offset) ? cp.offset : cp.sObj.offset; - - //do search - cp.sObj.getSearchResults(); - _this.checkResultsDone(); + callback(); }); }, /* check for all the results to finish */ @@ -889,12 +937,18 @@ remoteSearchDriver.prototype = { js_log('f:drawOutputResults::' + this.disp_item); var _this = this; var o=''; - + var cp_id = this.disp_item; - var cp = this.content_providers[this.disp_item]; - + var tab_target = ''; + if(this.disp_item == 'upload'){ + tab_target = '#upload_bin'; + var cp = this.content_providers['this_wiki']; + }else{ + var cp = this.content_providers[this.disp_item]; + tab_target = '#tab-' + cp_id; + } //empty the existing results: - $j('#tab-' + cp_id).empty(); + $j(tab_target).empty(); //output the results bar / controls _this.setResultBarControl(); @@ -943,7 +997,7 @@ remoteSearchDriver.prototype = { }); js_log('append to: ' + '#tab-' + cp_id); //put in the tab output (plus clear the output) - $j('#tab-' + cp_id).append( o + '
'); + $j(tab_target).append( o + '
'); } js_log( ' drawResultCount :: ' + drawResultCount + ' append: ' + $j('#rsd_q').val() ); @@ -978,6 +1032,27 @@ remoteSearchDriver.prototype = { _this.resourceEdit( rObj, this ); }); }, + addResourceEditLoader:function(maxWidth, overflow_style){ + var _this = this; + if(!maxWidth)maxWidth=400; + if(!overflow_style)overflow_style='overflow:auto;'; + //hide the results container + $j('#rsd_results_container').hide(); + //remove any old instance: + $j( _this.target_container ).find('#rsd_resource_edit').remove(); + //add the edit layout window with loading place holders + $j( _this.target_container ).append('
' + + '
' + + mv_get_loading_img('position:absolute;top:30px;left:30px') + + '
'+ + '
'+ + mv_get_loading_img() + + '
'+ + '
'); + }, resourceEdit:function( rObj, rsdElement){ js_log('f:resourceEdit:' + rObj.title); var _this = this; @@ -999,17 +1074,7 @@ remoteSearchDriver.prototype = { //so that transcripts show ontop var overflow_style = ( mediaType =='video' )?'':'overflow:auto;'; //append to the top level of model window: - $j( _this.target_container ).append('
' + - '
' + - mv_get_loading_img('position:absolute;top:30px;left:30px') + - '
'+ - '
'+ - mv_get_loading_img() + - '
'+ - '
'); + _this.addResourceEditLoader(maxWidth, overflow_style); //update add media wizard title: $j( _this.target_container ).dialog( 'option', 'title', gM('add_media_wizard')+': '+ gM('rsd_resource_edit', rObj.title ) ); js_log('did append to: '+ _this.target_container ); @@ -1098,6 +1163,8 @@ remoteSearchDriver.prototype = { var _this = this; var b_target = _this.target_container + '~ .ui-dialog-buttonpane'; $j('#rsd_resource_edit').remove(); + //restore the resource container: + $j('#rsd_results_container').show(); //restore the title: $j( _this.target_container ).dialog( 'option', 'title', gM('add_media_wizard')); js_log("should update: " + b_target + ' with: cancel'); @@ -1393,8 +1460,12 @@ remoteSearchDriver.prototype = { //@@todo try to load over ajax if( _this.local_wiki_api_url ) is set // (your on the api domain but are inserting from a normal page view) if( _this.local_wiki_api_url){ - + get_mw_token(null, _this.local_wiki_api_url, function(token){ + callback( token ); + }) } + callback(false); + return false; }, /** * doImportSpecialPage diff --git a/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js b/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js index 5a26fe5cf7..6bdb53b86b 100644 --- a/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js +++ b/js2/mwEmbed/libAddMedia/searchLibs/mediaWikiSearch.js @@ -13,7 +13,83 @@ mediaWikiSearch.prototype = { } } //inherit the cp settings for + }, + //returns a rObj by title + getRObjByTitle:function( title , callback){ + var _this = this; + var reqObj = { + 'action':'query', + 'titles':'File:'+title, + 'prop':'imageinfo|revisions|categories', + 'iiprop':'url|mime|size', + 'iiurlwidth': parseInt( this.rsd.thumb_width ), + 'rvprop':'content' + } + do_api_req( { + 'data':reqObj, + 'url':this.cp.api_url + }, function(data){ + _this.clearResults(); + //get results with rObj callback + _this.addResults(data); + //should only be one value: + for(var i in _this.resultsObj){ + callback( _this.resultsObj[i] ); + break; + } + } + ); + }, + clearResults:function(){ + this.resultsObj = {}; + this.last_query =''; }, + //update the resultObj with recently uploaded items by current User: + getUserRecentUploads:function(wgUser, callback){ + var _this = this; + do_api_req({ + 'data':{ + 'action':'query', + 'list':'recentchanges', + 'rcnamespace':6, //only files + 'rcuser': wgUser, + 'rclimit':15, //get last 15 uploaded files + }, + 'url':this.cp.api_url + },function(data){ + var titleSet = {}; + var titleStr='' + var pound=''; + //loop over the data and group by title + if(data.query && data.query.recentchanges){ + for(var i in data.query.recentchanges){ + var rc = data.query.recentchanges[i]; + if( !titleSet[ rc.title ] ){ + titleSet[ rc.title ]=true; + titleStr+= pound + rc.title; + pound ='|'; + } + } + } + //now run the actual query ( too bad we cant use recentchanges as a gennerator + do_api_req({ + 'data' : { + 'action':'query', + 'titles':titleStr, + 'prop':'imageinfo|revisions|categories', + 'iiprop':'url|mime|size', + 'iiurlwidth': parseInt( _this.rsd.thumb_width ), + 'rvprop':'content' + }, + 'url':_this.cp.api_url + },function(data){ + _this.clearResults(); + _this.addResults(data); + if(callback) + callback(); + }); + }); + }, getSearchResults:function(){ //call parent: this.parent_getSearchResults(); @@ -62,8 +138,7 @@ mediaWikiSearch.prototype = { if( typeof data['query-continue'].search != 'undefined') this.more_results = true; } - //make sure we have pages to iderate: - + //make sure we have pages to iderate: if(data.query && data.query.pages){ for(var page_id in data.query.pages){ var page = data.query.pages[ page_id ]; @@ -75,15 +150,14 @@ mediaWikiSearch.prototype = { } //make sure the page is not a redirect - if(page.revisions[0]['*'].indexOf('#REDIRECT')===0){ + if(page.revisions[0]['*'] && page.revisions[0]['*'].indexOf('#REDIRECT')===0){ //skip page is redirect continue; } //skip if its an empty or missing imageinfo: if( !page.imageinfo ) continue; - - this.resultsObj[page_id]={ + var rObj = { 'titleKey' : page.title, 'link' : page.imageinfo[0].descriptionurl, 'title' : page.title.replace(/File:|.jpg|.png|.svg|.ogg|.ogv|.oga/ig, ''), @@ -100,20 +174,21 @@ mediaWikiSearch.prototype = { 'meta':{ 'categories':page.categories } - } + }; + //attempt to parse out some stuff from the teplate: - var desc = this.resultsObj[page_id].desc.match(/\|Description=(([^\n]*\n)*)\|Source=/) + var desc = rObj.desc.match(/\|Description=(([^\n]*\n)*)\|Source=/) if( desc && desc[1] ){ - this.resultsObj[page_id].desc = $j.trim( desc[1] ); - } - - + rObj.desc = $j.trim( desc[1] ); + } //likely a audio clip if no poster and type application/ogg //@@todo we should return audio/ogg for the mime type or some other way to specify its "audio" - if( ! this.resultsObj[page_id].poster && this.resultsObj[page_id].mime == 'application/ogg' ){ - this.resultsObj[page_id].mime = 'audio/ogg'; - } + if( ! rObj.poster && rObj.mime == 'application/ogg' ){ + rObj.mime = 'audio/ogg'; + } + + this.resultsObj[page_id]= rObj; this.num_results++; //for(var i in this.resultsObj[page_id]){ @@ -122,7 +197,7 @@ mediaWikiSearch.prototype = { } }else{ js_log('no results:' + data); - } + } }, //check request done used for when we have multiple requests to check before formating results. checkRequestDone:function(){ diff --git a/js2/mwEmbed/libAddMedia/simpleUploadForm.js b/js2/mwEmbed/libAddMedia/simpleUploadForm.js index eb0714d396..6d74146f63 100644 --- a/js2/mwEmbed/libAddMedia/simpleUploadForm.js +++ b/js2/mwEmbed/libAddMedia/simpleUploadForm.js @@ -45,37 +45,39 @@ var default_form_options = { return false; } - //build the api based upload form: - var o = '
'+ + //build an upload form: + var o = ''+ '
' + //hidden input: ''+ ''+ '' + - //api form name set: - '
'+ - '
' + + //form name set: + '
'+ + '
' + - '
'+ - '
'+ - - '
' + - '
\n' + ' \n' + - '
' + - 'Read This before embeding!
\n' + + '
'+gM('read_before_embed') + '
\n' + '
' // '