tiddlywiki_cp 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/Manifest.txt +3 -2
- data/README.txt +4 -0
- data/Rakefile +1 -0
- data/lib/tiddlywiki_cp/r4tw.rb +68 -3
- data/lib/tiddlywiki_cp/version.rb +1 -1
- data/lib/tiddlywiki_cp.rb +15 -0
- data/test/content/tiddly_version_2_3.txt +1 -0
- data/test/test_tiddlywiki_cp.rb +68 -2
- data/website/files/ChangeLog.tiddler +86 -1
- data/website/files/DefaultTiddlers.tiddler +2 -2
- data/website/files/Introduction.tiddler +21 -3
- data/website/files/Usage.tiddler +14 -0
- data/website/files/WebDavPlugin.js +310 -0
- data/website/files/WebDavPlugin.js.div +1 -0
- data/website/index.html +1891 -1395
- metadata +6 -4
- data/website/files/WebDAVSavingPlugin.js +0 -234
- data/website/files/WebDAVSavingPlugin.js.div +0 -1
@@ -0,0 +1,310 @@
|
|
1
|
+
/***
|
2
|
+
|''Name:''|WebDavPlugin|
|
3
|
+
|''Description:''|Allows a TiddlyWiki to be saved to a WebDav server|
|
4
|
+
|''Author:''|Saq Imtiaz ( lewcid@gmail.com )|
|
5
|
+
|''Co-author:''|Loic Dachary|
|
6
|
+
|''Source:''|http://tw.lewcid.org/#WebDavPlugin|
|
7
|
+
|''Code Repository:''|http://tw.lewcid.org/svn/plugins|
|
8
|
+
|''Version:''|1.0|
|
9
|
+
|''Date:''|17/11/2007|
|
10
|
+
|''License:''|[[Creative Commons Attribution-ShareAlike 3.0 License|http://creativecommons.org/licenses/by-sa/3.0/]]|
|
11
|
+
|''~CoreVersion:''|2.2.3|
|
12
|
+
|
13
|
+
***/
|
14
|
+
// /%
|
15
|
+
//!BEGIN-PLUGIN-CODE
|
16
|
+
DAV = {
|
17
|
+
run : function(type,u,data,cb,params,headers){
|
18
|
+
var callback = function(status,params,responseText,url,xhr) {
|
19
|
+
url = url.indexOf("nocache=") < 0 ? url : url.substring(0,url.indexOf("nocache=")-1);
|
20
|
+
if(params.length){
|
21
|
+
params.shift().apply(this,[status,params,responseText,url,xhr]);
|
22
|
+
}
|
23
|
+
};
|
24
|
+
params = params||[];
|
25
|
+
params.unshift(cb);
|
26
|
+
var r = doHttp.apply(this,[type,u,data,null,null,null,callback,params,headers]);
|
27
|
+
if (typeof r == "string")
|
28
|
+
alert(r);
|
29
|
+
return r;
|
30
|
+
},
|
31
|
+
|
32
|
+
get : function(url,cb,params){
|
33
|
+
return DAV.run("GET",url,null,cb,params,null);
|
34
|
+
},
|
35
|
+
|
36
|
+
put : function(url,cb,params,data) {
|
37
|
+
return DAV.run("PUT",url,data,cb,params,null);
|
38
|
+
},
|
39
|
+
|
40
|
+
move : function(url,cb,params,destination) {
|
41
|
+
return DAV.run("MOVE",url,null,cb,params,{"Destination":destination,"Overwrite":"T"});
|
42
|
+
},
|
43
|
+
|
44
|
+
copy : function(url,cb,params,destination) {
|
45
|
+
return DAV.run("COPY",url,null,cb,params,{"Destination":destination,"Overwrite":"T","Depth":0});
|
46
|
+
},
|
47
|
+
|
48
|
+
propfind : function(url,cb,params,prop,depth){ // !!!
|
49
|
+
var xml = '<?xml version="1.0" encoding="UTF-8" ?>' +
|
50
|
+
'<D:propfind xmlns:D="DAV:">' +
|
51
|
+
'<D:prop>'+
|
52
|
+
'<D:'+prop+'/>'+
|
53
|
+
'</D:prop>'+
|
54
|
+
'</D:propfind>';
|
55
|
+
return DAV.run("PROPFIND",url,xml,cb,params,{"Content-type":"text/xml","Depth":depth?depth:0});
|
56
|
+
},
|
57
|
+
|
58
|
+
makeDir : function(url,cb,params){
|
59
|
+
return DAV.run("MKCOL",url,null,cb,params,null);
|
60
|
+
},
|
61
|
+
|
62
|
+
options : function(url,cb,params){
|
63
|
+
return DAV.run("OPTIONS",url,null,cb,params,null);
|
64
|
+
},
|
65
|
+
|
66
|
+
safeput : function(url,cb,params,data){
|
67
|
+
firstcb = function(status,p,responseText,u,xhr){
|
68
|
+
if(status)
|
69
|
+
DAV.move(u,cb,p,u.replace("-davsavingtemp",""));
|
70
|
+
else
|
71
|
+
cb.apply(firstcb,arguments);
|
72
|
+
};
|
73
|
+
return DAV.put(url+"-davsavingtemp",firstcb,params,data);
|
74
|
+
}
|
75
|
+
};
|
76
|
+
|
77
|
+
config.DavSaver = {
|
78
|
+
defaultFileName : 'index.html',
|
79
|
+
messages : {
|
80
|
+
startSaveMessage : 'saving to server...',
|
81
|
+
endSaveMessage : 'TiddlyWiki successfuly saved to server',
|
82
|
+
overwriteNewerPrompt : 'The remote file has changed since you last loaded or saved it.\nDo you wish to overwrite it?',
|
83
|
+
getModDateError : "Could not get last modified date",
|
84
|
+
raceError: "Save failed because the remote file is newer than the one you are trying to save"
|
85
|
+
},
|
86
|
+
errors:{
|
87
|
+
raceconflict : 'The save failed because your file is out of date',
|
88
|
+
getlastmodified : 'The save was aborted because the last modified date of the file could not be retrieved',
|
89
|
+
davenabled : 'The server does not support WebDav',
|
90
|
+
saverss : 'There was an error saving the rss file, the save was aborted',
|
91
|
+
saveempty: 'There was an error saving the empty file, the save was aborted',
|
92
|
+
savemain : 'Save failed! There was an error saving the main TW file',
|
93
|
+
savebackup: 'Save failed! There was an error creating a backup file',
|
94
|
+
makebackupdir: 'Save failed! The backup directory could not be created'
|
95
|
+
},
|
96
|
+
timestamp: new Date().toGMTString(),
|
97
|
+
orig_saveChanges: saveChanges,
|
98
|
+
saver : null
|
99
|
+
};
|
100
|
+
|
101
|
+
DavSaver = function(){
|
102
|
+
|
103
|
+
this.Q = [];
|
104
|
+
|
105
|
+
this.reset = function(){
|
106
|
+
config.DavSaver.saver = null;
|
107
|
+
};
|
108
|
+
this.runQ = function(){
|
109
|
+
if(this.Q.length){
|
110
|
+
this.Q.shift().apply(this,arguments);
|
111
|
+
}
|
112
|
+
else
|
113
|
+
this.reset();
|
114
|
+
};
|
115
|
+
this.posDiv = null;
|
116
|
+
this.original = null;
|
117
|
+
|
118
|
+
this.getOriginalPath = function(){
|
119
|
+
var p = document.location.toString();
|
120
|
+
p = convertUriToUTF8(p,config.options.txtFileSystemCharSet);
|
121
|
+
var argPos = p.indexOf("?");
|
122
|
+
if(argPos != -1)
|
123
|
+
p = p.substr(0,argPos);
|
124
|
+
var hashPos = p.indexOf("#");
|
125
|
+
if(hashPos != -1)
|
126
|
+
p = p.substr(0,hashPos);
|
127
|
+
if (p.charAt(p.length-1) == "/")
|
128
|
+
p = p + config.DavSaver.defaultFileName;
|
129
|
+
return p;
|
130
|
+
};
|
131
|
+
|
132
|
+
this.originalPath = this.getOriginalPath();
|
133
|
+
this.backupPath = null;
|
134
|
+
this.emptyPath = null;
|
135
|
+
this.rssPath = null;
|
136
|
+
this.throwError = function(er){
|
137
|
+
clearMessage();
|
138
|
+
this.reset();
|
139
|
+
alert(config.DavSaver.errors[er]); //clear message, reset and delete
|
140
|
+
};
|
141
|
+
};
|
142
|
+
|
143
|
+
DavSaver.prototype.getOriginal = function(){
|
144
|
+
var callback = function(status,params,original,url,xhr) {
|
145
|
+
var that = params[0];
|
146
|
+
if(status){
|
147
|
+
var p = that.posDiv = locateStoreArea(original);
|
148
|
+
if(!p || (p[0] == -1) || (p[1] == -1)) {
|
149
|
+
alert(config.messages.invalidFileError.format([url]));
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
that.original = original;
|
153
|
+
that.runQ();
|
154
|
+
}
|
155
|
+
else
|
156
|
+
that.throwError('getOriginal');
|
157
|
+
};
|
158
|
+
|
159
|
+
DAV.get(this.originalPath,callback,[this]);
|
160
|
+
};
|
161
|
+
|
162
|
+
DavSaver.prototype.checkRace = function(){
|
163
|
+
var callback = function(status,params,responseText,url,xhr){
|
164
|
+
var that = params[0];
|
165
|
+
if(status){
|
166
|
+
var lastmod = responseText.match(/<(\w*?):getlastmodified>(.*?)<\/\1:getlastmodified>/)[2];
|
167
|
+
if(Date.parse(lastmod) > Date.parse(config.DavSaver.timestamp)){
|
168
|
+
if (confirm(config.DavSaver.messages.overwriteNewerPrompt))
|
169
|
+
that.runQ();
|
170
|
+
else
|
171
|
+
that.throwError('raceconflict');
|
172
|
+
}
|
173
|
+
else
|
174
|
+
that.runQ();
|
175
|
+
}
|
176
|
+
else
|
177
|
+
that.throwError('getlastmodified');
|
178
|
+
};
|
179
|
+
|
180
|
+
DAV.propfind(this.originalPath,callback,[this],"getlastmodified",0);
|
181
|
+
};
|
182
|
+
|
183
|
+
DavSaver.prototype.isDavEnabled = function(){
|
184
|
+
var callback = function(status,params,responseText,url,xhr){
|
185
|
+
that = params[0];
|
186
|
+
if(status && !! xhr.getResponseHeader("DAV")){
|
187
|
+
that.runQ();
|
188
|
+
}
|
189
|
+
else
|
190
|
+
that.throwError('davenabled');
|
191
|
+
};
|
192
|
+
DAV.options(this.originalPath,callback,[this]);
|
193
|
+
};
|
194
|
+
|
195
|
+
DavSaver.prototype.saveRss = function(){
|
196
|
+
var callback = function(status,params,responseText,url,xhr){
|
197
|
+
var that = params[0];
|
198
|
+
if(status){
|
199
|
+
displayMessage(config.messages.rssSaved,that.rssPath);
|
200
|
+
that.runQ();
|
201
|
+
}
|
202
|
+
else
|
203
|
+
that.throwError('saverss');
|
204
|
+
};
|
205
|
+
var u = this.originalPath;
|
206
|
+
var rssPath = this.rssPath = u.substr(0,u.lastIndexOf(".")) + ".xml";
|
207
|
+
DAV.safeput(rssPath,callback,[this],convertUnicodeToUTF8(generateRss()));
|
208
|
+
};
|
209
|
+
|
210
|
+
DavSaver.prototype.saveEmpty = function(){
|
211
|
+
var callback = function(status,params,responseText,url,xhr){
|
212
|
+
var that = params[0];
|
213
|
+
if(status){
|
214
|
+
displayMessage(config.messages.emptySaved,that.emptyPath);
|
215
|
+
that.runQ();
|
216
|
+
}
|
217
|
+
else
|
218
|
+
that.throwError('saveempty');
|
219
|
+
};
|
220
|
+
var u = this.originalPath;
|
221
|
+
var emptyPath,p;
|
222
|
+
if((p = u.lastIndexOf("/")) != -1)
|
223
|
+
emptyPath = u.substr(0,p) + "/empty.html";
|
224
|
+
else
|
225
|
+
emptyPath = u + ".empty.html";
|
226
|
+
this.emptyPath = emptyPath;
|
227
|
+
var empty = this.original.substr(0,this.posDiv[0] + startSaveArea.length) + this.original.substr(this.posDiv[1]);
|
228
|
+
DAV.safeput(emptyPath,callback,[this],empty);
|
229
|
+
};
|
230
|
+
|
231
|
+
DavSaver.prototype.saveMain = function(){
|
232
|
+
var callback = function(status,params,responseText,url,xhr){
|
233
|
+
var that = params[0];
|
234
|
+
if(status){
|
235
|
+
config.DavSaver.timestamp = xhr.getResponseHeader('Date');
|
236
|
+
displayMessage(config.messages.mainSaved,that.originalPath);
|
237
|
+
store.setDirty(false);
|
238
|
+
that.runQ();
|
239
|
+
}
|
240
|
+
else
|
241
|
+
that.throwError('savemain');
|
242
|
+
};
|
243
|
+
var revised = updateOriginal(this.original,this.posDiv);
|
244
|
+
DAV.safeput(this.originalPath,callback,[this],revised);
|
245
|
+
};
|
246
|
+
|
247
|
+
DavSaver.prototype.saveBackup = function(){
|
248
|
+
var callback = function(status,params,responseText,url,xhr){
|
249
|
+
var that = params[0];
|
250
|
+
if(status){
|
251
|
+
clearMessage();
|
252
|
+
displayMessage(config.messages.backupSaved,that.backupPath);
|
253
|
+
that.runQ();
|
254
|
+
}
|
255
|
+
else
|
256
|
+
that.throwError('savebackup');
|
257
|
+
};
|
258
|
+
|
259
|
+
var backupPath = this.backupPath = getBackupPath(this.originalPath);
|
260
|
+
DAV.copy(this.originalPath,callback,[this],this.backupPath);
|
261
|
+
};
|
262
|
+
|
263
|
+
DavSaver.prototype.makeBackupDir = function(){
|
264
|
+
var callback = function(status,params,responseText,url,xhr){
|
265
|
+
var that = params[0];
|
266
|
+
if(status)
|
267
|
+
that.runQ();
|
268
|
+
else
|
269
|
+
that.throwError('makebackupdir');
|
270
|
+
};
|
271
|
+
var u = getBackupPath(this.originalPath);
|
272
|
+
var backupDirPath = u.substr(0,u.lastIndexOf("/"));
|
273
|
+
DAV.makeDir(backupDirPath,callback,[this]);
|
274
|
+
};
|
275
|
+
|
276
|
+
DavSaver.prototype.save = function(onlyIfDirty,tiddlers){
|
277
|
+
if(onlyIfDirty && !store.isDirty())
|
278
|
+
return;
|
279
|
+
clearMessage();
|
280
|
+
displayMessage(config.DavSaver.messages.startSaveMessage);
|
281
|
+
var Q = this.Q =[];
|
282
|
+
Q.push(this.isDavEnabled);
|
283
|
+
Q.push(this.getOriginal);
|
284
|
+
Q.push(this.checkRace);
|
285
|
+
if (config.options.chkSaveBackups){
|
286
|
+
if (config.options.txtBackupFolder!='')
|
287
|
+
Q.push(this.makeBackupDir);
|
288
|
+
Q.push(this.saveBackup);
|
289
|
+
}
|
290
|
+
Q.push(this.saveMain);
|
291
|
+
if (config.options.chkGenerateAnRssFeed)
|
292
|
+
Q.push(this.saveRss);
|
293
|
+
if (config.options.chkSaveEmptyTemplate)
|
294
|
+
Q.push(this.saveEmpty);
|
295
|
+
//Q.push(this.reset);
|
296
|
+
this.runQ();
|
297
|
+
};
|
298
|
+
|
299
|
+
window.saveChanges = function(onlyIfDirty,tiddlers)
|
300
|
+
{
|
301
|
+
var c = config.DavSaver;
|
302
|
+
if (document.location.protocol.toString() == "http:"){
|
303
|
+
var saver = c.saver = new DavSaver();
|
304
|
+
saver.save(onlyIfDirty,tiddlers);
|
305
|
+
}
|
306
|
+
else
|
307
|
+
return c.orig_saveChanges(onlyIfDirty,tiddlers);
|
308
|
+
};
|
309
|
+
//!END-PLUGIN-CODE
|
310
|
+
// %/
|
@@ -0,0 +1 @@
|
|
1
|
+
title="WebDavPlugin" modifier="YourName" modified="200711172002" created="200711171415" tags="systemConfig" changecount="3"
|