}
//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');
//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
//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 ){
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');;
}