refactored get token to mv_embed global function
authorMichael Dale <dale@users.mediawiki.org>
Thu, 30 Jul 2009 01:29:59 +0000 (01:29 +0000)
committerMichael Dale <dale@users.mediawiki.org>
Thu, 30 Jul 2009 01:29:59 +0000 (01:29 +0000)
js2/mwEmbed/libEmbedVideo/embedVideo.js
js2/mwEmbed/libSequencer/mvSequencer.js
js2/mwEmbed/mv_embed.js

index f33c1a4..32c08f3 100644 (file)
@@ -647,7 +647,8 @@ mediaSource.prototype =
                }                               
                //update duration from hit if present: 
                if(this.durationHint)
-                       this.duration = this.durationHint;
+                       this.duration = this.durationHint;              
+                                       
                        
                if ( $j(element).attr('type'))
                        this.mime_type = $j(element).attr('type');
index c45d6c1..815d8a6 100644 (file)
@@ -502,34 +502,18 @@ mvSequencer.prototype = {
                //if on an edit page just grab from the form:           
                this.sequenceEditToken = $j('input[wpEditToken]').val();
                
-               if(typeof this.sequenceEditToken == 'undefined' && this.getLocalApiUrl()!=null){                                        
-                       var reqObj = {
-                               'action':'query',
-                               'prop':'info',
-                               'intoken':'edit',
-                               'titles': _this.plObj.mTitle
-                       };                      
-                       do_api_req( {
-                               'data': reqObj,
-                               'url' : _this.getLocalApiUrl()
-                               },function(data){
-                                       var cat = data;                                                 
-                                       for(var i in data.query.pages){ 
-                                               if(data.query.pages[i]['edittoken'])
-                                                       _this.sequenceEditToken = data.query.pages[i]['edittoken'];                                                             
-                                       }
-                                       _this.updateSeqSaveButtons();
+               if(typeof this.sequenceEditToken == 'undefined' && this.getLocalApiUrl()!=null){
+                       get_mw_token(_this.plObj.mTitle, _this.getLocalApiUrl(), 
+                               function(token){
+                                       if(token){
+                                               _this.sequenceEditToken = token;
+                                               _this.updateSeqSaveButtons();
+                                       }       
                                }
-                       );
-                       reqObj['titles']=_this.plObj.mTalk;
-                       do_api_req( {
-                               'data': reqObj,
-                               'url' : _this.getLocalApiUrl()
-                               }, function( data ){
-                                       for(var j in data.query.pages){
-                                               if(data.query.pages[j]['edittoken'])
-                                                       _this.clipboardEditToken = data.query.pages[j]['edittoken'];
-                                       }
+                       );                      
+                       get_mw_token(_this.plObj.mTalk, _this.getLocalApiUrl(), 
+                               function(token){
+                                       _this.clipboardEditToken = token;
                                }
                        );
                        //also grab permissions for sending clipboard commands to the server
index b321baf..b6b3743 100644 (file)
@@ -1034,7 +1034,38 @@ function npt2seconds( npt_str ){
        //return seconds float (ie take seconds float value if present):
        return parseInt(times[0]*3600)+parseInt(times[1]*60)+parseFloat(times[2]);
 }
-
+/*
+ * simple helper to grab a edit token
+ * 
+ * @param title the wiki page title you want to edit )
+ * @param api_url 'optional' the target api url
+ * @param callback the callback function to pass the token or "false" to  
+ */
+function get_mw_token( title, api_url, callback){
+       if(!title && wgUserName){
+               title = 'User:' + wgUserName; 
+       }
+       var reqObj = {
+                       'action':'query',
+                       'prop':'info',
+                       'intoken':'edit',
+                       'titles':title
+               };                      
+               do_api_req( {
+                       'data': reqObj,
+                       'url' : api_url
+                       },function(data){                                                                                       
+                               for(var i in data.query.pages){ 
+                                       if(data.query.pages[i]['edittoken']){
+                                               if(typeof callback == 'function')
+                                                       callback ( data.query.pages[i]['edittoken'] );
+                                       }                                                               
+                               }
+                               //no token found:
+                               return false;
+                       }
+               );
+}
 //does a remote or local api request based on request url 
 //@param options: url, data, cbParam, callback
 function do_api_req( options, callback ){              
@@ -1042,7 +1073,7 @@ function do_api_req( options, callback ){
                return js_error('Error: request paramaters must be an object');;
        }
        //gennerate the url if its missing:
-       if( typeof options.url == 'undefined' ){
+       if( typeof options.url == 'undefined' ||  options.url === false){
                if(!wgServer || ! wgScriptPath){                        
                        return js_error('Error: no api url for api request');;
                }