Changeset 6443

Show
Ignore:
Timestamp:
08/21/08 10:02:26 (5 months ago)
Author:
MartinBudden
Message:

Updated to TiddlyWiki 2.4.1

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Trunk/contributors/MartinBudden/adaptors/MediaWikiAdaptorPlugin.js

    r6440 r6443  
    55|''Source:''|http://www.martinswiki.com/#MediaWikiAdaptorPlugin | 
    66|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/adaptors/MediaWikiAdaptorPlugin.js | 
    7 |''Version:''|0.6.4| 
     7|''Version:''|0.7.1| 
    88|''Date:''|Jul 27, 2007| 
    99|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev | 
     
    4040function MediaWikiAdaptor() 
    4141{ 
    42         this.host = null; 
    43         this.workspace = null; 
    4442        return this; 
    4543} 
     44 
     45MediaWikiAdaptor.prototype = new AdaptorBase(); 
    4646 
    4747MediaWikiAdaptor.serverType = 'mediawiki'; 
     
    5151MediaWikiAdaptor.doHttpGET = function(uri,callback,params,headers,data,contentType,username,password) 
    5252{ 
    53         return doHttp('GET',uri,data,contentType,username,password,callback,params,headers); 
     53        return httpReq('GET',uri,callback,params,headers,data,contentType,username,password); 
    5454}; 
    5555 
    5656MediaWikiAdaptor.doHttpPOST = function(uri,callback,params,headers,data,contentType,username,password) 
    5757{ 
    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); 
    8559}; 
    8660 
     
    144118//#console.log('login'); 
    145119        //#context = this.setContext(context,userParams,callback); 
    146         var host = MediaWikiAdaptor.fullHostName(context.host); 
     120        var host = this.fullHostName(context.host); 
    147121        var uriTemplate = '%0/api.php?action=login&format=json&lgname=%1&lgpassword=%2'; 
    148122        //var uriTemplate = '%0/api.php?action=query&format=json&prop=info|revisions&intoken=edit&titles=Main%20Page'; 
     
    199173                        context.callback(context,context.userParams); 
    200174        } 
    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; 
    214175}; 
    215176 
     
    367328        context.tiddlers = []; 
    368329        context.uri = null; 
    369         var host = MediaWikiAdaptor.fullHostName(this.host); 
     330        var host = this.fullHostName(context.host); 
    370331        if(!context.tiddlerLimit) 
    371332                context.tiddlerLimit = !config.options.txtMediaAdaptorLimit ? config.maxTiddlerImportCount : config.options.txtMediaAdaptorLimit; 
     
    525486//# http://en.wikipedia.org/wiki/Mars 
    526487        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); 
    528490        if(host.match(/w\/$/)) { 
    529491                host = host.replace(/w\/$/,''); 
     
    552514//# http://www.tiddlywiki.org/api.php?action=query&prop=revisions&titles=Main%20Page&rvprop=content 
    553515//# 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); 
    555517        var uriTemplate = '%0/api.php?format=json&action=query&prop=revisions&titles=%1&rvprop=content|timestamp|user'; 
    556518        if(context.revision) 
     
    702664        if(!limit) 
    703665                limit = 5; 
    704         var host = MediaWikiAdaptor.fullHostName(context.host); 
     666        var host = this.fullHostName(context.host); 
    705667        var uri = uriTemplate.format([host,MediaWikiAdaptor.normalizedTitle(title),limit]); 
    706668//#console.log('uri: '+uri); 
     
    715677//#console.log('getTiddlerRevisionListCallback status:'+status); 
    716678//#console.log(responseText.substr(0,1000)); 
    717 //#displayMessage('xhr:'+xhr); 
    718679        context.status = false; 
    719680        if(status) { 
     
    779740{ 
    780741//#console.log('putTiddlerComplete'); 
    781         var host = MediaWikiAdaptor.fullHostName(context.host); 
     742        var host = this.fullHostName(context.host); 
    782743        var uriTemplate = '%0/api.php?action=edit&title=%1&token=%2&text=%3'; 
    783744        var uri = uriTemplate.format([host,escape(MediaWikiAdaptor.normalizedTitle(context.tiddler.title)),context.sessionToken,escape(context.tiddler.text)]); 
     
    816777{ 
    817778//#fnLog('deleteTiddlerComplete:'+title); 
    818         var host = MediaWikiAdaptor.fullHostName(context.host); 
     779        var host = this.fullHostName(context.host); 
    819780        var uriTemplate = '%0/api.php?action=delete&title=%1&token=%2'; 
    820781        var uri = uriTemplate.format([host,context.workspace,escape(MediaWikiAdaptor.normalizedTitle(context.title)),context.sessionToken]); 
     
    841802}; 
    842803 
    843 // MediaWikiAdaptor.prototype.putTiddler not supported 
    844 MediaWikiAdaptor.prototype.close = function() 
    845 { 
    846         return true; 
    847 }; 
    848  
    849804config.adaptors[MediaWikiAdaptor.serverType] = MediaWikiAdaptor; 
    850805} // end of 'install only once'