r45708 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45707‎ | r45708 | r45709 >
Date:17:16, 13 January 2009
Author:dale
Status:deferred
Tags:
Comment:
rename add media wiz
Modified paths:
  • /trunk/extensions/MetavidWiki/skins/add_media_wizard.js (added) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/skins/add_media_wizard.js
@@ -0,0 +1,146 @@
 2+//add media wizard integration for mediaWiki
 3+
 4+/* config */
 5+//Setup your content providers (see the remoteSearchDriver::content_providers for all options)
 6+var wg_content_proivers_config = {}; //you can overwrite by defining (after)
 7+
 8+var wg_local_wiki_api_url = wgServer + wgScriptPath + '/api.php';
 9+
 10+//if mv_embed is hosted somewhere other than near by the external_media_wizzard you can define it here:
 11+var mv_embed_url = null;
 12+
 13+//*code should not have to modify anything below*/
 14+//check if we are on a edit page:
 15+if(wgAction=='edit'){
 16+ //add onPage ready request:
 17+ addOnloadHook( function(){
 18+ var toolbar = document.getElementById("toolbar");
 19+ var imE = document.createElement('img');
 20+ imE.style.cursor = 'pointer';
 21+ imE.id = 'mv-add_media';
 22+ imE.src = 'http://upload.wikimedia.org/wikipedia/commons/8/86/Button_add_media.png';
 23+ toolbar.appendChild(imE);
 24+ //imE.setAttribute('onClick', 'mv_do_load_wiz()');
 25+ //addHandler only works once cuz of dom manipluations
 26+ addHandler( imE, 'click', function() {
 27+ mv_do_load_wiz();
 28+ });
 29+ });
 30+}
 31+//add firefog support to Special Upload page:
 32+if(wgPageName== "Special:Upload"){
 33+ addOnloadHook( function(){
 34+ load_mv_embed( function(){
 35+ //load jQuery and what not (we need to refactor the loading system for mv_embed)
 36+ mvEmbed.load_libs(function(){
 37+ mvJsLoader.doLoad({'mvUploader' : 'libAddMedia/mv_upload.js'},function(){
 38+ mvUp = new mvUploader();
 39+ });
 40+ });
 41+ });
 42+ });
 43+}
 44+var caret_pos={};
 45+function mv_do_load_wiz(){
 46+ caret_pos={};
 47+ var txtarea = document.editform.wpTextbox1;
 48+ var getTextCusorStartPos = function (o){
 49+ if (o.createTextRange) {
 50+ var r = document.selection.createRange().duplicate()
 51+ r.moveEnd('character', o.value.length)
 52+ if (r.text == '') return o.value.length
 53+ return o.value.lastIndexOf(r.text)
 54+ } else return o.selectionStart
 55+ }
 56+ var getTextCusorEndPos = function (o){
 57+ if (o.createTextRange) {
 58+ var r = document.selection.createRange().duplicate();
 59+ r.moveStart('character', -o.value.length);
 60+ return r.text.length;
 61+ } else{
 62+ return o.selectionEnd
 63+ }
 64+ }
 65+ caret_pos.s = getTextCusorStartPos( txtarea );
 66+ caret_pos.e = getTextCusorEndPos( txtarea );
 67+ caret_pos.text = txtarea.value;
 68+ //show the loading screen:
 69+ var elm = document.getElementById('modalbox')
 70+ if(elm){
 71+ //use jquery to re-display the search
 72+ if( typeof $j != 'undefined'){
 73+ $j('#modalbox,#mv_overlay').show();
 74+ }
 75+ }else{
 76+ var body_elm = document.getElementsByTagName("body")[0];
 77+ body_elm.innerHTML = body_elm.innerHTML + ''+
 78+ '<div id="modalbox" style="background:#DDD;border:3px solid #666666;font-size:115%;'+
 79+ 'top:30px;left:20px;right:20px;bottom:30px;position:fixed;z-index:100;">'+
 80+ 'loading external media wizard<blink>...</blink>'+
 81+ '</div>'+
 82+ '<div id="mv_overlay" style="background:#000;cursor:wait;height:100%;left:0;position:fixed;'+
 83+ 'top:0;width:100%;z-index:5;filter:alpha(opacity=60);-moz-opacity: 0.6;'+
 84+ 'opacity: 0.6;"/>';
 85+ }
 86+ //make sure the click action is still there
 87+ imE = document.getElementById('mv-add_media');
 88+ if(imE){
 89+ addHandler( imE, 'click', function() {
 90+ mv_do_load_wiz();
 91+ });
 92+ }
 93+ //load mv_embed and do text search interface:
 94+ load_mv_embed( function(){
 95+ //restore text value:
 96+ var txtarea = document.editform.wpTextbox1;
 97+ txtarea.value = caret_pos.text;
 98+ //do the remote search interface:
 99+ mv_do_remote_search({
 100+ 'target_id':'modalbox',
 101+ 'profile':'mediawiki_edit',
 102+ 'target_textbox': 'wpTextbox1',
 103+ 'caret_pos': caret_pos,
 104+ //note selections in the textbox will take over the default query
 105+ 'default_query': wgTitle,
 106+ 'target_title':wgPageName,
 107+ 'cpconfig':wg_content_proivers_config,
 108+ 'local_wiki_api_url': wg_local_wiki_api_url
 109+ });
 110+ });
 111+ return false;
 112+}
 113+function load_mv_embed( callback ){
 114+ //get mv_embed path from _this_ file location:
 115+ if(!mv_embed_url)
 116+ mv_embed_url = getMvEmbedUrl();
 117+
 118+ //inject mv_embed
 119+ if( typeof MV_EMBED_VERSION == 'undefined'){
 120+ var e = document.createElement("script");
 121+ e.setAttribute('src', mv_embed_url);
 122+ e.setAttribute('type',"text/javascript");
 123+ document.getElementsByTagName("head")[0].appendChild(e);
 124+ setTimeout('check_for_mv_embed();', 25);
 125+ }else{
 126+ check_for_mv_embed( callback );
 127+ }
 128+}
 129+
 130+function check_for_mv_embed( callback ){
 131+ if( typeof MV_EMBED_VERSION == 'undefined'){
 132+ setTimeout('check_for_mv_embed();', 25);
 133+ }else{
 134+ callback();
 135+ }
 136+}
 137+function getMvEmbedUrl(){
 138+ for(var i=0; i < document.getElementsByTagName('script').length; i++){
 139+ var s = document.getElementsByTagName('script')[i];
 140+ if( s.src.indexOf('add_media_wizard.js') != -1 ){
 141+ //use the external_media_wizard path:
 142+ return s.src= s.src.replace('add_media_wizard.js', '') + 'mv_embed/mv_embed.js';
 143+ }
 144+ }
 145+ alert('Error: could not find mv_embed path');
 146+}
 147+

Status & tagging log