From 35cff434eb9a8bf0c4574004e1793eeeb1030b77 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Thu, 30 Jul 2009 01:29:59 +0000 Subject: [PATCH] refactored get token to mv_embed global function --- js2/mwEmbed/libEmbedVideo/embedVideo.js | 3 +- js2/mwEmbed/libSequencer/mvSequencer.js | 38 +++++++------------------ js2/mwEmbed/mv_embed.js | 35 +++++++++++++++++++++-- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/js2/mwEmbed/libEmbedVideo/embedVideo.js b/js2/mwEmbed/libEmbedVideo/embedVideo.js index f33c1a428a..32c08f38ec 100644 --- a/js2/mwEmbed/libEmbedVideo/embedVideo.js +++ b/js2/mwEmbed/libEmbedVideo/embedVideo.js @@ -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'); diff --git a/js2/mwEmbed/libSequencer/mvSequencer.js b/js2/mwEmbed/libSequencer/mvSequencer.js index c45d6c1c23..815d8a625d 100644 --- a/js2/mwEmbed/libSequencer/mvSequencer.js +++ b/js2/mwEmbed/libSequencer/mvSequencer.js @@ -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 diff --git a/js2/mwEmbed/mv_embed.js b/js2/mwEmbed/mv_embed.js index b321baf9d8..b6b3743b56 100644 --- a/js2/mwEmbed/mv_embed.js +++ b/js2/mwEmbed/mv_embed.js @@ -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');; } -- 2.20.1