Changeset 6443
- Timestamp:
- 08/21/08 10:02:26 (5 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
Trunk/contributors/MartinBudden/adaptors/MediaWikiAdaptorPlugin.js
r6440 r6443 5 5 |''Source:''|http://www.martinswiki.com/#MediaWikiAdaptorPlugin | 6 6 |''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/adaptors/MediaWikiAdaptorPlugin.js | 7 |''Version:''|0. 6.4|7 |''Version:''|0.7.1| 8 8 |''Date:''|Jul 27, 2007| 9 9 |''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev | … … 40 40 function MediaWikiAdaptor() 41 41 { 42 this.host = null;43 this.workspace = null;44 42 return this; 45 43 } 44 45 MediaWikiAdaptor.prototype = new AdaptorBase(); 46 46 47 47 MediaWikiAdaptor.serverType = 'mediawiki'; … … 51 51 MediaWikiAdaptor.doHttpGET = function(uri,callback,params,headers,data,contentType,username,password) 52 52 { 53 return doHttp('GET',uri,data,contentType,username,password,callback,params,headers);53 return httpReq('GET',uri,callback,params,headers,data,contentType,username,password); 54 54 }; 55 55 56 56 MediaWikiAdaptor.doHttpPOST = function(uri,callback,params,headers,data,contentType,username,password) 57 57 { 58 return doHttp('POST',uri,data,contentType,username,password,callback,params,headers); 59 }; 60 61 MediaWikiAdaptor.prototype.setContext = function(context,userParams,callback) 62 { 63 if(!context) context = {}; 64 context.userParams = userParams; 65 if(callback) context.callback = callback; 66 context.adaptor = this; 67 if(!context.host) 68 context.host = this.host; 69 if(!context.workspace && this.workspace) 70 context.workspace = this.workspace; 71 return context; 72 }; 73 74 MediaWikiAdaptor.fullHostName = function(host) 75 { 76 //#displayMessage("fullHostName:"+host); 77 if(!host) 78 return ''; 79 host = host.trim(); 80 if(!host.match(/:\/\//)) 81 host = 'http://' + host; 82 if(host.substr(host.length-1) == '/') 83 host = host.substr(0,host.length-1); 84 return host; 58 return httpReq('POST',uri,callback,params,headers,data,contentType,username,password); 85 59 }; 86 60 … … 144 118 //#console.log('login'); 145 119 //#context = this.setContext(context,userParams,callback); 146 var host = MediaWikiAdaptor.fullHostName(context.host);120 var host = this.fullHostName(context.host); 147 121 var uriTemplate = '%0/api.php?action=login&format=json&lgname=%1&lgpassword=%2'; 148 122 //var uriTemplate = '%0/api.php?action=query&format=json&prop=info|revisions&intoken=edit&titles=Main%20Page'; … … 199 173 context.callback(context,context.userParams); 200 174 } 201 };202 203 204 MediaWikiAdaptor.prototype.openHost = function(host,context,userParams,callback)205 {206 //#console.log("openHost:"+host);207 this.host = MediaWikiAdaptor.fullHostName(host);208 context = this.setContext(context,userParams,callback);209 if(context.callback) {210 context.status = true;211 window.setTimeout(function() {callback(context,userParams);},0);212 }213 return true;214 175 }; 215 176 … … 367 328 context.tiddlers = []; 368 329 context.uri = null; 369 var host = MediaWikiAdaptor.fullHostName(this.host);330 var host = this.fullHostName(context.host); 370 331 if(!context.tiddlerLimit) 371 332 context.tiddlerLimit = !config.options.txtMediaAdaptorLimit ? config.maxTiddlerImportCount : config.options.txtMediaAdaptorLimit; … … 525 486 //# http://en.wikipedia.org/wiki/Mars 526 487 var info = {}; 527 var host = this && this.host ? this.host : MediaWikiAdaptor.fullHostName(tiddler.fields['server.host']); 488 var host = this && this.host ? this.host : tiddler.fields['server.host']; 489 host = this.fullHostName(host); 528 490 if(host.match(/w\/$/)) { 529 491 host = host.replace(/w\/$/,''); … … 552 514 //# http://www.tiddlywiki.org/api.php?action=query&prop=revisions&titles=Main%20Page&rvprop=content 553 515 //# http://wiki.unamesa.org/api.php?format=jsonfm&action=query&prop=revisions&titles=Main%20Page&rvprop=content|timestamp|user 554 var host = MediaWikiAdaptor.fullHostName(context.host);516 var host = this.fullHostName(context.host); 555 517 var uriTemplate = '%0/api.php?format=json&action=query&prop=revisions&titles=%1&rvprop=content|timestamp|user'; 556 518 if(context.revision) … … 702 664 if(!limit) 703 665 limit = 5; 704 var host = MediaWikiAdaptor.fullHostName(context.host);666 var host = this.fullHostName(context.host); 705 667 var uri = uriTemplate.format([host,MediaWikiAdaptor.normalizedTitle(title),limit]); 706 668 //#console.log('uri: '+uri); … … 715 677 //#console.log('getTiddlerRevisionListCallback status:'+status); 716 678 //#console.log(responseText.substr(0,1000)); 717 //#displayMessage('xhr:'+xhr);718 679 context.status = false; 719 680 if(status) { … … 779 740 { 780 741 //#console.log('putTiddlerComplete'); 781 var host = MediaWikiAdaptor.fullHostName(context.host);742 var host = this.fullHostName(context.host); 782 743 var uriTemplate = '%0/api.php?action=edit&title=%1&token=%2&text=%3'; 783 744 var uri = uriTemplate.format([host,escape(MediaWikiAdaptor.normalizedTitle(context.tiddler.title)),context.sessionToken,escape(context.tiddler.text)]); … … 816 777 { 817 778 //#fnLog('deleteTiddlerComplete:'+title); 818 var host = MediaWikiAdaptor.fullHostName(context.host);779 var host = this.fullHostName(context.host); 819 780 var uriTemplate = '%0/api.php?action=delete&title=%1&token=%2'; 820 781 var uri = uriTemplate.format([host,context.workspace,escape(MediaWikiAdaptor.normalizedTitle(context.title)),context.sessionToken]); … … 841 802 }; 842 803 843 // MediaWikiAdaptor.prototype.putTiddler not supported844 MediaWikiAdaptor.prototype.close = function()845 {846 return true;847 };848 849 804 config.adaptors[MediaWikiAdaptor.serverType] = MediaWikiAdaptor; 850 805 } // end of 'install only once'
