Welcome to TiddlyWiki created by Jeremy Ruston, Copyright © 2007 UnaMesa Association
/***
|''Name:''|CryptoFunctionsPlugin|
|''Description:''|Support for cryptographic functions|
***/
//{{{
if(!version.extensions.CryptoFunctionsPlugin) {
version.extensions.CryptoFunctionsPlugin = {installed:true};
//--
//-- Crypto functions and associated conversion routines
//--
// Crypto "namespace"
function Crypto() {}
// Convert a string to an array of big-endian 32-bit words
Crypto.strToBe32s = function(str)
{
var be = Array();
var len = Math.floor(str.length/4);
var i, j;
for(i=0, j=0; i<len; i++, j+=4) {
be[i] = ((str.charCodeAt(j)&0xff) << 24)|((str.charCodeAt(j+1)&0xff) << 16)|((str.charCodeAt(j+2)&0xff) << 8)|(str.charCodeAt(j+3)&0xff);
}
while (j<str.length) {
be[j>>2] |= (str.charCodeAt(j)&0xff)<<(24-(j*8)%32);
j++;
}
return be;
};
// Convert an array of big-endian 32-bit words to a string
Crypto.be32sToStr = function(be)
{
var str = "";
for(var i=0;i<be.length*32;i+=8)
str += String.fromCharCode((be[i>>5]>>>(24-i%32)) & 0xff);
return str;
};
// Convert an array of big-endian 32-bit words to a hex string
Crypto.be32sToHex = function(be)
{
var hex = "0123456789ABCDEF";
var str = "";
for(var i=0;i<be.length*4;i++)
str += hex.charAt((be[i>>2]>>((3-i%4)*8+4))&0xF) + hex.charAt((be[i>>2]>>((3-i%4)*8))&0xF);
return str;
};
// Return, in hex, the SHA-1 hash of a string
Crypto.hexSha1Str = function(str)
{
return Crypto.be32sToHex(Crypto.sha1Str(str));
};
// Return the SHA-1 hash of a string
Crypto.sha1Str = function(str)
{
return Crypto.sha1(Crypto.strToBe32s(str),str.length);
};
// Calculate the SHA-1 hash of an array of blen bytes of big-endian 32-bit words
Crypto.sha1 = function(x,blen)
{
// Add 32-bit integers, wrapping at 32 bits
add32 = function(a,b)
{
var lsw = (a&0xFFFF)+(b&0xFFFF);
var msw = (a>>16)+(b>>16)+(lsw>>16);
return (msw<<16)|(lsw&0xFFFF);
};
// Add five 32-bit integers, wrapping at 32 bits
add32x5 = function(a,b,c,d,e)
{
var lsw = (a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF);
var msw = (a>>16)+(b>>16)+(c>>16)+(d>>16)+(e>>16)+(lsw>>16);
return (msw<<16)|(lsw&0xFFFF);
};
// Bitwise rotate left a 32-bit integer by 1 bit
rol32 = function(n)
{
return (n>>>31)|(n<<1);
};
var len = blen*8;
// Append padding so length in bits is 448 mod 512
x[len>>5] |= 0x80 << (24-len%32);
// Append length
x[((len+64>>9)<<4)+15] = len;
var w = Array(80);
var k1 = 0x5A827999;
var k2 = 0x6ED9EBA1;
var k3 = 0x8F1BBCDC;
var k4 = 0xCA62C1D6;
var h0 = 0x67452301;
var h1 = 0xEFCDAB89;
var h2 = 0x98BADCFE;
var h3 = 0x10325476;
var h4 = 0xC3D2E1F0;
for(var i=0;i<x.length;i+=16) {
var j,t;
var a = h0;
var b = h1;
var c = h2;
var d = h3;
var e = h4;
for(j = 0;j<16;j++) {
w[j] = x[i+j];
t = add32x5(e,(a>>>27)|(a<<5),d^(b&(c^d)),w[j],k1);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a = t;
}
for(j=16;j<20;j++) {
w[j] = rol32(w[j-3]^w[j-8]^w[j-14]^w[j-16]);
t = add32x5(e,(a>>>27)|(a<<5),d^(b&(c^d)),w[j],k1);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a = t;
}
for(j=20;j<40;j++) {
w[j] = rol32(w[j-3]^w[j-8]^w[j-14]^w[j-16]);
t = add32x5(e,(a>>>27)|(a<<5),b^c^d,w[j],k2);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a = t;
}
for(j=40;j<60;j++) {
w[j] = rol32(w[j-3]^w[j-8]^w[j-14]^w[j-16]);
t = add32x5(e,(a>>>27)|(a<<5),(b&c)|(d&(b|c)),w[j],k3);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a = t;
}
for(j=60;j<80;j++) {
w[j] = rol32(w[j-3]^w[j-8]^w[j-14]^w[j-16]);
t = add32x5(e,(a>>>27)|(a<<5),b^c^d,w[j],k4);
e=d; d=c; c=(b>>>2)|(b<<30); b=a; a = t;
}
h0 = add32(h0,a);
h1 = add32(h1,b);
h2 = add32(h2,c);
h3 = add32(h3,d);
h4 = add32(h4,e);
}
return Array(h0,h1,h2,h3,h4);
};
}
//}}}
[[Summary]]
[[Links]]
[[Rationale]]
[[Use Cases]]
[[Scope]]
[[Design]]
[[Implementation]]
[[Unresolved Issues]]
/***
|''Name:''|DeprecatedFunctionsPlugin|
|''Description:''|Support for deprecated functions removed from core|
***/
//{{{
if(!version.extensions.DeprecatedFunctionsPlugin) {
version.extensions.DeprecatedFunctionsPlugin = {installed:true};
//--
//-- Deprecated code
//--
// @Deprecated: Use createElementAndWikify and this.termRegExp instead
config.formatterHelpers.charFormatHelper = function(w)
{
w.subWikify(createTiddlyElement(w.output,this.element),this.terminator);
};
// @Deprecated: Use enclosedTextHelper and this.lookaheadRegExp instead
config.formatterHelpers.monospacedByLineHelper = function(w)
{
var lookaheadRegExp = new RegExp(this.lookahead,"mg");
lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var text = lookaheadMatch[1];
if(config.browser.isIE)
text = text.replace(/\n/g,"\r");
createTiddlyElement(w.output,"pre",null,null,text);
w.nextMatch = lookaheadRegExp.lastIndex;
}
};
// @Deprecated: Use <br> or <br /> instead of <<br>>
config.macros.br = {};
config.macros.br.handler = function(place)
{
createTiddlyElement(place,"br");
};
// Find an entry in an array. Returns the array index or null
// @Deprecated: Use indexOf instead
Array.prototype.find = function(item)
{
var i = this.indexOf(item);
return i == -1 ? null : i;
};
// Load a tiddler from an HTML DIV. The caller should make sure to later call Tiddler.changed()
// @Deprecated: Use store.getLoader().internalizeTiddler instead
Tiddler.prototype.loadFromDiv = function(divRef,title)
{
return store.getLoader().internalizeTiddler(store,this,title,divRef);
};
// Format the text for storage in an HTML DIV
// @Deprecated Use store.getSaver().externalizeTiddler instead.
Tiddler.prototype.saveToDiv = function()
{
return store.getSaver().externalizeTiddler(store,this);
};
// @Deprecated: Use store.allTiddlersAsHtml() instead
function allTiddlersAsHtml()
{
return store.allTiddlersAsHtml();
}
// @Deprecated: Use refreshPageTemplate instead
function applyPageTemplate(title)
{
refreshPageTemplate(title);
}
// @Deprecated: Use story.displayTiddlers instead
function displayTiddlers(srcElement,titles,template,unused1,unused2,animate,unused3)
{
story.displayTiddlers(srcElement,titles,template,animate);
}
// @Deprecated: Use story.displayTiddler instead
function displayTiddler(srcElement,title,template,unused1,unused2,animate,unused3)
{
story.displayTiddler(srcElement,title,template,animate);
}
// @Deprecated: Use functions on right hand side directly instead
var createTiddlerPopup = Popup.create;
var scrollToTiddlerPopup = Popup.show;
var hideTiddlerPopup = Popup.remove;
// @Deprecated: Use right hand side directly instead
var regexpBackSlashEn = new RegExp("\\\\n","mg");
var regexpBackSlash = new RegExp("\\\\","mg");
var regexpBackSlashEss = new RegExp("\\\\s","mg");
var regexpNewLine = new RegExp("\n","mg");
var regexpCarriageReturn = new RegExp("\r","mg");
}
//}}}
/***
|''Name:''|GenerateRssByTagPlugin|
|''Description:''|Only tiddlers with a specific tag are inluded in the RSSFeed. If no tiddlers are selected then works as before. (see ticket #270: http://trac.tiddlywiki.org/tiddlywiki/ticket/270). <br>RssTag: <<option txtRssTag>>|
|''Version:''|1.0.3|
|''Date:''|May 17, 2007|
|''Source:''|http://tiddlywiki.bidix.info/#GenerateRssByTagPlugin|
|''Author:''|BidiX (BidiX (at) bidix (dot) info)|
|''License:''|[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D ]]|
|''~CoreVersion:''|2.2.0 (Beta 5)|
***/
//{{{
version.extensions.GenerateRssByTagPlugin = {
major: 1, minor: 0, revision: 3,
date: new Date("May 17, 2007"),
source: 'http://tiddlywiki.bidix.info/#GenerateRssByTagPlugin',
author: 'BidiX (BidiX (at) bidix (dot) info',
coreVersion: '2.2.0 (Beta 5)'
};
if (!window.bidix) window.bidix = {}; // bidix namespace
bidix.generateRssByTag = function()
{
var s = [];
var d = new Date();
var u = store.getTiddlerText("SiteUrl");
// Assemble the header
s.push("<" + "?xml version=\"1.0\"" + " encoding='UTF-8' " + "?" + ">");
s.push("<rss version=\"2.0\">");
s.push("<channel>");
s.push("<title" + ">" + wikifyPlain("SiteTitle").htmlEncode() + "</title" + ">");
if(u)
s.push("<link>" + u.htmlEncode() + "</link>");
s.push("<description>" + wikifyPlain("SiteSubtitle").htmlEncode() + "</description>");
s.push("<language>en-us</language>");
s.push("<copyright>Copyright " + d.getFullYear() + " " + config.options.txtUserName.htmlEncode() + "</copyright>");
s.push("<pubDate>" + d.toGMTString() + "</pubDate>");
s.push("<lastBuildDate>" + d.toGMTString() + "</lastBuildDate>");
s.push("<docs>http://blogs.law.harvard.edu/tech/rss</docs>");
s.push("<generator>TiddlyWiki " + version.major + "." + version.minor + "." + version.revision + "</generator>");
// The body
var tiddlers;
if (config.options.txtRssTag && store.getTaggedTiddlers(config.options.txtRssTag).length > 0)
tiddlers = store.getTaggedTiddlers(config.options.txtRssTag,"modified");
else
tiddlers = store.getTiddlers("modified","excludeLists");
var n = config.numRssItems > tiddlers.length ? 0 : tiddlers.length-config.numRssItems;
for (var t=tiddlers.length-1; t>=n; t--)
s.push(tiddlers[t].saveToRss(u));
// And footer
s.push("</channel>");
s.push("</rss>");
// Save it all
return s.join("\n");
};
//
// Initializations
//
bidix.generateRss = generateRss; // backup core version
generateRss = bidix.generateRssByTag; // install new one
config.options.txtRssTag = "toRSS"; // default RssTag. use <<option txtRssTag>> to overwritte
merge(config.optionsDesc,{txtRssTag: "Only tiddlers with this tag will be included in the RSS Feed."});
//}}}
Implementation ''steps'' and ''considerations''.
/***
|''Name:''|LegacyStrikeThroughPlugin|
|''Description:''|Support for legacy (pre 2.1) strike through formatting|
|''Version:''|1.0.2|
|''Date:''|Jul 21, 2006|
|''Source:''|http://www.tiddlywiki.com/#LegacyStrikeThroughPlugin|
|''Author:''|MartinBudden (mjbudden (at) gmail (dot) com)|
|''License:''|[[BSD open source license]]|
|''CoreVersion:''|2.1.0|
***/
//{{{
// Ensure that the LegacyStrikeThrough Plugin is only installed once.
if(!version.extensions.LegacyStrikeThroughPlugin) {
version.extensions.LegacyStrikeThroughPlugin = {installed:true};
config.formatters.push(
{
name: "legacyStrikeByChar",
match: "==",
termRegExp: /(==)/mg,
element: "strike",
handler: config.formatterHelpers.createElementAndWikify
});
} //# end of "install only once"
//}}}
The list of ~URLs that do not yet exist. A specification must be associated to at least one URL. When the specification is implemented, bytes can be accessed with these URL and they are removed from this list.
The list of ~URLs of interest to the specifications, including email addresses of participants or irc channels.
[[Summary]]
[[Links]]
[[Rationale]]
[[Use Cases]]
[[Scope]]
[[Design]]
[[Implementation]]
[[Unresolved Issues]]
[[Scrapbook|scrapbook/tree]]
[img[Fane|images/small/fane.jpg][images/large/fane.jpg]]<<imagebox>>
/***
|''Name:''|RSSReaderPlugin|
|''Description:''|This plugin provides a RSSReader for TiddlyWiki|
|''Version:''|0.3.0|
|''Date:''|Aug 24, 2006|
|''Source:''|http://tiddlywiki.bidix.info/#RSSReaderPlugin|
|''Documentation:''|http://tiddlywiki.bidix.info/#RSSReaderPluginDoc|
|''Author:''|BidiX (BidiX (at) bidix (dot) info)|
|''Credit:''|BramChen for RssNewsMacro|
|''License:''|[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D ]]|
|''~CoreVersion:''|2.0.0|
|''Browser:''|Firefox 1.5; InternetExplorer 6.0; Safari|
|''Include:''|none|
|''Require:''|none|
***/
//{{{
version.extensions.RSSReaderPlugin = {
major: 0, minor: 3, revision: 0,
date: new Date("Aug 24, 2006"),
author: "BidiX",
credit: "BramChen for RssNewsMacro",
source: "http://TiddlyWiki.bidix.info/#RSSReaderPlugin",
documentation : "http://TiddlyWiki.bidix.info/#RSSReaderPluginDoc",
author: 'BidiX (BidiX (at) bidix (dot) info',
license: '[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D]]',
coreVersion: '2.0.0',
browser: 'Firefox 1.5; InternetExplorer 6.0; Safari'
};
config.macros.rssReader = {
dateFormat: "DDD, DD MMM YYYY",
itemStyle: "display: block;border: 1px solid black;padding: 5px;margin: 5px;", //useed '@@'+itemStyle+itemText+'@@'
msg:{
permissionDenied: "Permission to read preferences was denied.",
noRSSFeed: "No RSS Feed at this address %0",
urlNotAccessible: " Access to %0 is not allowed"
},
cache: [], // url => request
desc: "noDesc",
// feedURL: "",
place:"",
handler: function(place,macroName,params,wikifier,paramString,tiddler){
var desc = params[0];
var feedURL = params[1];
// var toFilter = (params[2] ? params[2] : false);
var toFilter = false;
var filterString;
if (params[2] != undefined) {
toFilter = true;
if (params[2].match(/\w+/))
filterString = params[2];
else
filterString = tiddler.title;
}
var place = createTiddlyElement(place, "div", "RSSReader");
wikify("^^<<rssFeedUpdate "+feedURL+" [[" + tiddler.title + "]]>>^^\n",place);
if (this.cache[feedURL]) {
this.processResponse(this.cache[feedURL], feedURL, place, desc, toFilter, filterString);
}
else {
this.asyncGet(feedURL, place, desc, toFilter, filterString);
}
},
asyncGet: function (feedURL, place, desc, toFilter, filterString){
var xmlhttp;
try {xmlhttp=new XMLHttpRequest();}
catch (e) {
try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {
try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) { displayMessage(e.description?e.description:e.toString());}
}
}
if (!xmlhttp){
return;
}
if (window.netscape){
try {
if (document.location.protocol.indexOf("http") == -1) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
}
}
catch (e) { displayMessage(e.description?e.description:e.toString()); }
}
xmlhttp.onreadystatechange=function (){
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200 || xmlhttp.status===0) {
config.macros.rssReader.processResponse(xmlhttp, feedURL, place, desc, toFilter, filterString);
}
else {
displayMessage("Problem retrieving XML data:" + xmlhttp.statusText);
}
}
};
try {
xmlhttp.open("GET",feedURL,true);
if (config.browser.isIE) {
xmlhttp.send();
}
else {
xmlhttp.send(null);
}
}
catch (e) {
wikify(e.toString()+this.urlNotAccessible.format([feedURL]), place);
}
},
processResponse: function(xmlhttp, feedURL, place, desc, toFilter, filterString){
if (window.netscape){
try {
if (document.location.protocol.indexOf("http") == -1) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
}
}
catch (e) { displayMessage(e.description?e.description:e.toString()); }
}
if (xmlhttp.responseXML){
this.cache[feedURL] = xmlhttp;
this.genRssNews(xmlhttp.responseXML, place, feedURL, desc, toFilter, filterString);
}
else {
var dom = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml");
if (dom) {
this.cache[feedURL] = xmlhttp;
this.genRssNews(dom, place, feedURL, desc, toFilter, filterString);
}
else {
wikify("<html>"+xmlhttp.responseText+"</html>", place);
displayMessage(this.msg.noRSSFeed.format([feedURL]));
}
}
},
genRssNews: function(xml, place, feedURL, desc, toFilter, filterString){
// Channel
var chanelNode = xml.getElementsByTagName('channel').item(0);
var chanelTitleElement = (chanelNode ? chanelNode.getElementsByTagName('title').item(0) : null);
var chanelTitle = "";
if ((chanelTitleElement) && (chanelTitleElement.firstChild)) chanelTitle = chanelTitleElement.firstChild.nodeValue;
var chanelLinkElement = (chanelNode ? chanelNode.getElementsByTagName('link').item(0) : null);
var chanelLink = "";
if (chanelLinkElement) chanelLink = chanelLinkElement.firstChild.nodeValue;
var titleTxt = "!![["+chanelTitle+"|"+chanelLink+"]]\n";
var title = createTiddlyElement(place,"div",null,"ChanelTitle",null);
wikify(titleTxt,title);
// ItemList
var itemList = xml.getElementsByTagName('item');
var article = createTiddlyElement(place,"ul",null,null,null);
var lastDate;
var re;
if (toFilter)
re = new RegExp(filterString.escapeRegExp());
for (var i=0; i<itemList.length; i++){
var titleElm = itemList[i].getElementsByTagName('title').item(0);
var titleText = (titleElm ? titleElm.firstChild.nodeValue : '');
if (toFilter && ! titleText.match(re)) {
continue;
}
var descText = '';
var isWikitext = false;
var descElem = itemList[i].getElementsByTagName('wikitext').item(0);
if (descElem){
try{
isWikitext = true;
descText = "\n"+descElem.firstChild.nodeValue;}
catch(e){}
}
else {
descElem = itemList[i].getElementsByTagName('encoded').item(0);
if (descElem){
try{descText = descElem.firstChild.nodeValue;}
catch(e){}
descText = "<html>"+descText+"</html>";
}
else {
descElem = itemList[i].getElementsByTagName('description').item(0);
if (descElem){
try{descText = descElem.firstChild.nodeValue;}
catch(e){}
descText = descText.replace(/<br \/>/g,'\n');
if (desc == "asHtml")
descText = "<html>"+descText+"</html>";
}
}
}
var linkElm = itemList[i].getElementsByTagName("link").item(0);
var linkURL = linkElm.firstChild.nodeValue;
var pubElm = itemList[i].getElementsByTagName('pubDate').item(0);
var pubDate;
if (!pubElm) {
pubElm = itemList[i].getElementsByTagName('date').item(0); // for del.icio.us
if (pubElm) {
pubDate = pubElm.firstChild.nodeValue;
pubDate = this.formatDateString(this.dateFormat, pubDate);
}
else {
pubDate = '0';
}
}
else {
pubDate = (pubElm ? pubElm.firstChild.nodeValue : 0);
pubDate = this.formatString(this.dateFormat, pubDate);
}
titleText = titleText.replace(/\[|\]/g,'');
var rssText = '** '+'[[' + titleText + '|' + linkURL + ']]' + '\n' ;
if ((desc != "noDesc") && descText){
if (version.extensions.nestedSliders){
rssText = rssText.replace(/\n/g,' ');
descText = '+++[...]\n'
+(isWikitext ? '\n<<rssFeedImportTiddler '+ feedURL + ' [['+titleText+']]>>':'')
+'@@'+this.itemStyle+descText+'\n@@\n'
+'===';
}
rssText = rssText + descText + '\n\n';
}
var story;
if ((lastDate != pubDate) && ( pubDate != '0')) {
story = createTiddlyElement(article,"li",null,"RSSItem",pubDate);
lastDate = pubDate;
}
else {
lastDate = pubDate;
}
story = createTiddlyElement(article,"div",null,"RSSItem",null);
wikify(rssText,story);
}
},
formatString: function(template, theDate){
var dateString = new Date(theDate);
template = template.replace(/hh|mm|ss/g,'');
return dateString.formatString(template);
},
formatDateString: function(template, theDate){
var dateString = new Date(theDate.substr(0,4), theDate.substr(5,2) - 1, theDate.substr(8,2)
/*, theDate.substr(11,2), theDate.substr(14,2), theDate.substr(17,2)*/
);
return dateString.formatString(template);
}
};
//}}}
//{{{
config.macros.rssFeedUpdate = {
label: "Update",
prompt: "Clear the cache and redisplay this RssFeed",
handler: function(place,macroName,params) {
var feedURL = params[0];
var tiddlerTitle = params[1];
createTiddlyButton(place, this.label, this.prompt,
function () {
if (config.macros.rssReader.cache[feedURL]) {
config.macros.rssReader.cache[feedURL] = null;
//story.refreshTiddler(tiddlerTitle,null, true);
}
story.refreshTiddler(tiddlerTitle,null, true);
return false;});
}
};
//}}}
//{{{
config.macros.rssFeedImportTiddler = {
label: "Import",
prompt: "Import this tiddler in this TiddlyWiki",
askReplaceMsg: "Tiddler already exists, replace it ?",
handler: function(place,macroName,params) {
var feedUrl = params[0];
var tiddlerTitle = params[1];
createTiddlyButton(place, this.label, this.prompt,
function () {
if (feedUrl && config.macros.rssReader.cache[feedUrl]) {
var tiddler = config.macros.rssFeedImportTiddler.parseRssNews(config.macros.rssReader.cache[feedUrl].responseXML, tiddlerTitle);
if (tiddler && (! store.getTiddler(tiddlerTitle) || confirm(config.macros.rssFeedImportTiddler.askReplaceMsg))) {
store.addTiddler(tiddler);
store.notify(tiddler.title, true);
store.setDirty(true);
}
}
return false;});
},
// parse a RssFeed for retrieving a Tiddler with title
parseRssNews: function(xml, title) {
// ItemList
if (document.location.protocol.indexOf("http") == -1) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
}
var itemList = xml.getElementsByTagName('item');
for (var i=0; i<itemList.length; i++){
var titleElm = itemList[i].getElementsByTagName('title').item(0);
var titleText = titleElm.firstChild.nodeValue;
if (titleText == title) {
// <tiddlywiki:title>
// titleText
titleText = titleText.htmlDecode();
// <tiddlywiki:wikitext>
var elem = itemList[i].getElementsByTagName('wikitext').item(0);
var text = elem ? elem.firstChild.nodeValue.htmlDecode() : "";
// <tiddlywiki:modifier>
elem = itemList[i].getElementsByTagName('modifier').item(0);
var modifier = elem ? elem.firstChild.nodeValue : "";
// <tiddlywiki:modified>
elem = itemList[i].getElementsByTagName('modified').item(0);
var modified = elem ? Date.convertFromYYYYMMDDHHMM(elem.firstChild.nodeValue) : "";
// <tiddlywiki:created>
elem = itemList[i].getElementsByTagName('created').item(0);
var created = elem ? Date.convertFromYYYYMMDDHHMM(elem.firstChild.nodeValue) : "";
// <tiddlywiki:links>
// Links ?
// <tiddlywiki:tags>
elem = itemList[i].getElementsByTagName('tags').item(0);
var tags = elem ? elem.firstChild.nodeValue.htmlDecode() : "";
var tiddler = new Tiddler();
tiddler.assign(titleText,text,modifier,modified,tags,created);
return tiddler;
}
}
// not found
alert("Tiddler \[[" + title +"]] notFound.");
return null;
}
};
//}}}
''Why'' is this being defined?
''Limits'' of this specifications application.
<<search>><<closeAll>><<permaview>><<newTiddler>><<newJournal 'DD MMM YYYY'>><<saveChanges>><<slider chkSliderOptionsPanel OptionsPanel 'options »' 'Change TiddlyWiki advanced options'>>
using tiddlywiki for [[specifications|http://garden.dachary.org/ieee-830-1998.pdf]]
http://garden.dachary.org/empty.html
/***
|''Name:''|SparklinePlugin|
|''Description:''|Sparklines macro|
***/
//{{{
if(!version.extensions.SparklinePlugin) {
version.extensions.SparklinePlugin = {installed:true};
//--
//-- Sparklines
//--
config.macros.sparkline = {};
config.macros.sparkline.handler = function(place,macroName,params)
{
var data = [];
var min = 0;
var max = 0;
var v;
for(var t=0; t<params.length; t++) {
v = parseInt(params[t]);
if(v < min)
min = v;
if(v > max)
max = v;
data.push(v);
}
if(data.length < 1)
return;
var box = createTiddlyElement(place,"span",null,"sparkline",String.fromCharCode(160));
box.title = data.join(",");
var w = box.offsetWidth;
var h = box.offsetHeight;
box.style.paddingRight = (data.length * 2 - w) + "px";
box.style.position = "relative";
for(var d=0; d<data.length; d++) {
var tick = document.createElement("img");
tick.border = 0;
tick.className = "sparktick";
tick.style.position = "absolute";
tick.src = "data:image/gif,GIF89a%01%00%01%00%91%FF%00%FF%FF%FF%00%00%00%C0%C0%C0%00%00%00!%F9%04%01%00%00%02%00%2C%00%00%00%00%01%00%01%00%40%02%02T%01%00%3B";
tick.style.left = d*2 + "px";
tick.style.width = "2px";
v = Math.floor(((data[d] - min)/(max-min)) * h);
tick.style.top = (h-v) + "px";
tick.style.height = v + "px";
box.appendChild(tick);
}
};
}
//}}}
''What'' is being specified?
/***
|''Name:''|TiddlyLightBox|
|''Date:''|Jan 1, 2006|
|''Version:''|1.0 beta|
|''Author:''|Saq Imtiaz|
|''Location:''|http://tw.lewcid.org/#TiddlyLightBoxPlugin|
|''Documentation:''|http://tw.lewcid.org/#TiddlyLightBoxDocs|
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]]|
|''Based on:''|DC3.LightBox<br>Light Box Gone Wild <br>Ibox|
!!Code
***/
//{{{
config.macros.imagebox ={};
config.macros.imagebox.handler = function (place,macroName,params,wikifier,paramString,tiddler)
{
var e = place.lastChild;
e.onclick = function(){TiddlyLightBox.initBox('image',this,params[1],params[2],params[0]);return false;};
}
config.macros.divbox ={};
config.macros.divbox.handler = function (place,macroName,params,wikifier,paramString,tiddler)
{
if (params[0]!=".")
createTiddlyButton(place,params[0],params[0],function(){TiddlyLightBox.initBox('html',params[1],params[3],params[4],params[2]);return false;});
else
{
var e = place.lastChild;
e.onclick = function(){TiddlyLightBox.initBox('html',params[1],params[3],params[4],params[2]);return false;};
}
}
config.macros.tiddlerbox ={}
config.macros.tiddlerbox.handler = function (place,macroName,params,wikifier,paramString,tiddler)
{
config.macros.divbox.handler(place,macroName,[params[0],"tiddler:"+params[1],params[2],params[3],params[4]]);
return false;
}
store.addNotification("TiddlyLightBoxStyles",refreshStyles);
if (!window.TiddlyLightBox)
window.TiddlyLightBox = {};
var loadingImage = "indicator.gif";
window.TiddlyLightBox =
{
_curBox: null, // [sentinel]
lightBoxHtml : '<div id="lightBoxOverlay" onclick="TiddlyLightBox.hideBox()" style="display:none"></div><div id="lightboxprogress" style="display:none;"><img src=\''+loadingImage+'\' alt=\'loading\' style="width:128px;height:128px;"></div><div class="lightBox" id="lightBox" style="display:none"><div id="lightBoxContent"></div><div id="lightBoxTitle">This is a title</div><div id="lightBoxClose"><a href:"#" onclick="TiddlyLightBox.hideBox();return false;">Click to close</a></div></div>',
createBoxWrapper : function()
{
var wrapper = createTiddlyElement(document.getElementsByTagName("body")[0],"div","tiddlyLightBoxWrapper");
wrapper.innerHTML = this.lightBoxHtml;
},
initBox : function(contentType,url,w,h,text)
{
if (this._curBox)
return;
this.showProgress();
this.hideSelects("hidden");
this.showBg();
this._curBox = true;
this.sizeTheBox(contentType,w,h);
if (contentType == 'image')
this.showImage(url,text);
else if (contentType == 'html')
this.showHtml(url,text);
return false;
},
sizeTheBox : function(contentType,w,h)
{
var box = document.getElementById("lightBoxContent");
if (w && isNaN(parseInt(w)))
{
addClass(box,w);
}
else if (w ||h || contentType == 'html')
{
box.style.width = w? w+ "px" : "450px";
box.style.height = h? h+ "px" : "280px";
if (contentType=='image')
setStylesheet("#lightBoxContent img{height:100%;width:100%;}","lightBoxImageSizeHack");
}
},
showProgress : function()
{
var progress = document.getElementById("lightboxprogress");
progress.style.display='';
this._center(progress);
},
hideProgress: function()
{
var progress = document.getElementById("lightboxprogress");
progress.style.display='none';
},
//this function lifted from Lightbox Gone Wild
hideSelects: function(visibility)
{
var selects = document.getElementsByTagName('select');
for(i = 0; i < selects.length; i++)
{
selects[i].style.visibility = visibility;
}
},
showBg: function()
{
var overlay = document.getElementById('lightBoxOverlay');
if (config.browser.isIE)
{
overlay.style.height = Math.max(document.documentElement.scrollHeight,document.documentElement.offsetHeight);
overlay.style.width = document.documentElement.scrollWidth;
}
overlay.style.display = 'block';
},
showImage: function (url,text)
{
imgPreloader = new Image();
imgPreloader.onload = function ()
{
var lb = document.getElementById("lightBoxContent");
lb.innerHTML = "<img src="+url+">";
lb.onclick = function(){TiddlyLightBox.hideBox();return false;};
TiddlyLightBox.posBox(text);
};
imgPreloader.src = url;
},
showHtml : function(theID,text)
{
var lb = document.getElementById("lightBoxContent");
if (theID.indexOf("tiddler:")==-1)
lb.innerHTML = document.getElementById(theID).innerHTML;
else
{
wikify(store.getTiddlerText(theID.replace("tiddler:","")),lb);
lb.className='tiddler';
}
lb.style.overflow = "auto";
this.posBox(text);
},
posBox: function(text)
{
this.setTitle(text);
this.hideProgress();
var lb = document.getElementById("lightBox");
lb.style.display = "";
lb.style.visibilty = "hidden";
lb.style.position = "absolute";
this._center(lb);
if(!TiddlyLightBox._curBox) return;
lb.style.visibility = "visible";
lb.style.display = "block";
},
setTitle: function(text)
{
document.getElementById("lightBoxTitle").innerHTML= (text==undefined)? '': text;
},
_center: function(lb)
{
var lbSize = new TiddlyLightBox.getElementSize(lb);
lb.style.left = (Math.round(findWindowWidth()/2) - (lbSize.width /2) + findScrollX())+'px';
lb.style.top = (Math.round(findWindowHeight()/2) - (lbSize.height /2) + findScrollY())+'px';
},
//this function lifted from Ibox
getElementSize : function(elem)
{
this.width = elem.offsetWidth || elem.style.pixelWidth;
this.height = elem.offsetHeight || elem.style.pixelHeight;
},
hideBox: function()
{
if(!this._curBox)
return;
document.getElementById("tiddlyLightBoxWrapper").innerHTML= this.lightBoxHtml;
setStylesheet("","lightBoxImageSizeHack");
this._curBox = null;
return false;
}
}
TiddlyLightBox.createBoxWrapper();
Story.prototype.findContainingTiddler = function(e)
{
while(e && (!hasClass(e,"tiddler") || !e.getAttribute("tiddler")))
e = e.parentNode;
return(e);
}
config.shadowTiddlers.TiddlyLightBoxStyles="/*{{{*/\n#lightBoxOverlay {\n position:absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 90; \n background-color: #000;\n -moz-opacity: 0.75;\n opacity: .75;\n filter: alpha(opacity=75);\n}\n#lightBoxOverlay[id]{ \n position: fixed;\n}\n\n#lightboxprogress { \n margin:0;padding:0;\n position: absolute;\n z-index:95;\n}\n\ndiv.lightBox {\n background: #fff;\n color: #fff;\n border: 4px solid #525252;\npadding:20px 20px 25px 20px; position:absolute; z-index:99;\n}\n\n#lightBoxClose {text-align:right; color:#000; font-size:1.0em; position:absolute; bottom:6px; right:20px;}\n#lightBoxClose a{color:#666; border-bottom:1px solid #666;cursor:pointer;}\n#lightBoxClose a:hover {color:#111; border-bottom:1px solid #666; cursor:pointer; background:transparent;}\n\n#lightBoxContent {border:1px solid #525252;color:#000; background:#fff;}\n#lightBox .tiddler {background:#fff;}\n\n#lightBoxContent img {border:0;margin:0;padding:0;display:block;cursor:pointer;}\n\n#lightBoxTitle {padding:0px; font-weight:bold; position:absolute; left:20px;bottom:6px; font-size:1.1em; color:#000;}\n\n/*}}}*/";
//}}}
/***
|''Name:''|TiddlyStaticDavHooksPlugin|
|''Description:''|Enable DAV saving for static file and sitemap|
|''Author:''|Saq Imtiaz ( lewcid@gmail.com )|
|''Source:''|http://tw.lewcid.org/#TiddlyStaticDavHooksPlugin|
|''Code Repository:''|http://tw.lewcid.org/svn/plugins|
|''Version:''|1.0|
|''Date:''|13-09-2007|
|''Copyright holder:''|Loic Dachary|
|''License:''|[[Creative Commons Attribution-ShareAlike 3.0 License|http://creativecommons.org/licenses/by-sa/3.0/]]|
|''~CoreVersion:''|2.2.3|
|''Requires:''|WebDAVSavingPlugin TiddlyStaticPlugin|
***/
// /%
//!BEGIN-PLUGIN-CODE
//{{{
if (bidix && bidix.WebDAVSaving){
bidix.WebDAVSaving.saveMain = function(url,original,posDiv){
var callback = function(status,params,responseText,url,xhr) {
if(status) {
url = (url.indexOf("nocache=") < 0 ? url : url.substring(0,url.indexOf("nocache=")-1));
displayMessage(config.messages.mainSaved,url);
store.setDirty(false);
bidix.WebDAVSaving.saveStatic(params[0],params[1],params[2]);
} else
alert(config.messages.mainFailed);
};
// Save new file
var revised = updateOriginal(original,posDiv);
bidix.httpPut(url,revised,callback,Array(url,original,posDiv));
};
bidix.WebDAVSaving.saveStatic = function(url,original,posDiv){
var callback = function(status,params,responseText,url,xhr) {
if (!status) {
alert(TiddlyStatic.messages.staticError);
return;
}
url = (url.indexOf("nocache=") < 0 ? url : url.substring(0,url.indexOf("nocache=")-1));
displayMessage(TiddlyStatic.messages.staticSaved,url);
bidix.WebDAVSaving.saveSiteMap(params[0],params[1],params[2]);
};
if(config.options.chkSaveStatic) {
var path = url.substr(0,url.lastIndexOf(".")) + "-static.html";
bidix.httpPut(path,convertUnicodeToUTF8(TiddlyStatic.generateStatic()),callback,Array(url,original,posDiv));
} else {
bidix.WebDAVSaving.saveSiteMap(url,original,posDiv);
}
};
bidix.WebDAVSaving.saveSiteMap = function(url,original,posDiv){
var callback = function(status,params,responseText,url,xhr) {
if (!status) {
alert(TiddlyStatic.messages.siteMapError);
return;
}
url = (url.indexOf("nocache=") < 0 ? url : url.substring(0,url.indexOf("nocache=")-1));
displayMessage(TiddlyStatic.messages.siteMapSaved,url);
};
if(config.options.chkSaveSiteMap) {
var sep = (url[1] == ':' ? "\\" : "/");
var path = url.substr(0,url.lastIndexOf(sep)+1) + "sitemap.xml";
bidix.httpPut(path,convertUnicodeToUTF8(TiddlyStatic.createSiteMap(url,sep)),callback,Array(url,original,posDiv));
}
};
}
//}}}
//!END-PLUGIN-CODE
// %/
/***
|''Name:''|TiddlyStatic|
|''Description:''|Create a static file with the content of the TiddlyWiki, and a sitemap file|
|''Author:''|Saq Imtiaz ( lewcid@gmail.com )|
|''Source:''|http://tw.lewcid.org/#TiddlyStaticPlugin|
|''Code Repository:''|http://tw.lewcid.org/svn/plugins|
|''Version:''|1.0|
|''Date:''|13-09-2007|
|''Copyright holder:''|Loic Dachary|
|''License:''|[[Creative Commons Attribution-ShareAlike 3.0 License|http://creativecommons.org/licenses/by-sa/3.0/]]|
|''~CoreVersion:''|2.2.3|
|>| !Configuration Options|
|<<option chkSaveStatic>>|save file with static content |
|<<option chkSaveSiteMap>>|save sitemap file |
|<<option txtTiddlyStaticIncludeTags>>| Include tiddlers with these tags, written as bracketed list|
|<<option txtTiddlyStaticExcludeTags>>| Exclude tiddlers with these tags, written as bracketed list|
Example of a bracketed list: {{{Tag1 Tag2 [[Tag With Spaces]]}}}
If a tiddler both as an include tag, and an exclude tag, the exclude tag takes priority.
The notice at the top of the static page can be customized via the TiddlyStaticBanner shadow tiddler.
You can insert custom markup or scripts into the head of the static page, via the TiddlyStaticMarkupHead tiddler.
***/
// /%
//!BEGIN-PLUGIN-CODE
//{{{
if (!config.options.chkSaveStatic)
config.options.chkSaveStatic = true;
if (!config.options.chkSaveSiteMap)
config.options.chkSaveSiteMap = true;
if(!config.options.txtTiddlyStaticIncludeTags)
config.options.txtTiddlyStaticIncludeTags = '';
if(!config.options.txtTiddlyStaticExcludeTags)
config.options.txtTiddlyStaticExcludeTags = '';
TiddlyStatic = {
messages:{
staticSaved: "Static file saved",
staticError: "There was an error saving the static file",
siteMapSaved: "Sitemap saved",
siteMapError: "There was an error saving the sitemap file"
},
saveStatic : function(localPath){
var path = localPath.substr(0,localPath.lastIndexOf(".")) + "-static.html";
var save = saveFile(path,convertUnicodeToUTF8(this.generateStatic()));
if(save)
displayMessage(this.messages.staticSaved,"file://" + path);
else
alert(this.messages.staticError);
},
generateStatic : function(){
var tiddlers = this.getOutputTiddlers();
var s = [];
s.push('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">');
s.push("<html>\n<head>");
var title = wikifyPlain("SiteTitle").htmlEncode()+" - " + wikifyPlain("SiteSubtitle").htmlEncode();
s.push("<title>"+ title +"</title>");
var styles=document.getElementsByTagName("style");
s.push("<style type='text/css'>");
for(var i=0; i < styles.length; i++)
s.push(styles[i].innerHTML+"\n\n");
s.push("</style>");
s.push(store.getTiddlerText("TiddlyStaticMarkupHead"));
s.push("</head>");
var u = store.getTiddlerText("SiteUrl");
s.push("<body>");
s.push("<h1 class='siteTitle'>" + wikifyStatic(store.getTiddlerText("TiddlyStaticBanner")) + "</h1>");
for (var t=tiddlers.length-1; t>=0; t--)
s.push(tiddlers[t].generateStatic(u));
s.push("</body>\n</html>");
return s.join("\n");
},
getFilteredTiddlers : function(field,excludeTags,includeTags){
var results = [];
store.forEachTiddler(function(title,tiddler){
if(!excludeTags.length || !tiddler.tags.containsAny(excludeTags)){
if(!includeTags.length || tiddler.tags.containsAny(includeTags))
results.push(tiddler);
}
});
if(field)
results.sort(function (a,b) {if(a[field] == b[field]) return(0); else return (a[field] < b[field]) ? -1 : +1; });
return results;
},
getOutputTiddlers : function(){
return this.getFilteredTiddlers("modified",config.options.txtTiddlyStaticExcludeTags.readBracketedList(),config.options.txtTiddlyStaticIncludeTags.readBracketedList());
},
saveSiteMap : function(localPath){
var sep = (localPath[1] == ':' ? "\\" : "/");
var path = localPath.substr(0,localPath.lastIndexOf(sep)+1) + "sitemap.xml";
var save = saveFile(path,convertUnicodeToUTF8(this.createSiteMap(localPath,sep)));
if(save)
displayMessage(this.messages.siteMapSaved,"file://" + path);
else
alert(this.messages.siteMapError);
},
createSiteMap : function (localPath,sep){
var tiddlers = this.getOutputTiddlers();
var s = [];
var url = store.getTiddlerText('SiteUrl');
var staticpath = localPath.substr(0,localPath.lastIndexOf(".")) + "-static.html";
var filename = staticpath.substr(staticpath.lastIndexOf(sep)+1);
s.push('<?xml version="1.0" encoding="UTF-8"?>');
s.push('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
if(config.options.chkSaveStatic)
s.push('<url>\n<loc>'+ url.substr(0,url.lastIndexOf("/"))+ "/" + filename +'</loc>\n</url>');
for(var i=0; i<tiddlers.length; i++){
s.push('<url>\n<loc>'+ url+ '#'+ encodeURIComponent(String.encodeTiddlyLink(tiddlers[i].title))+'</loc>\n</url>');
}
s.push('</urlset>');
return s.join('\n');
},
oldSaveMain : window.saveMain
};
window.saveMain = function(localPath,original,posDiv){
if(config.options.chkSaveStatic)
TiddlyStatic.saveStatic(localPath);
if(config.options.chkSaveSiteMap)
TiddlyStatic.saveSiteMap(localPath);
TiddlyStatic.oldSaveMain.apply(this,arguments);
};
Tiddler.prototype.generateStatic = function(url){
var s = [];
s.push("<div class='tiddler'>");
s.push("<h2 class='title'>" + "<a href='"+url + "#" + encodeURIComponent(String.encodeTiddlyLink(this.title))+"'>"+this.title.htmlEncode()+"</a>" + "</h2>" );
s.push("<h3 class='tagged cat_tag'>Tags: " + this.tags.join(" ,") +"</h3>");
s.push("<div class='viewer'>" + wikifyStatic(this.text,null,this)+"</div>");
s.push("</div>");
return s.join("\n");
};
config.shadowTiddlers.TiddlyStaticBanner = 'This file is a static version of the website ' + store.getTiddlerText('SiteTitle') + '.\n [[Please click here to visit the site instead.|' + store.getTiddlerText('SiteUrl')+']]';
config.shadowTiddlers.TiddlyStaticMarkupHead = '';
//}}}
//!END-PLUGIN-CODE
// %/
''Discuss'' problems and unresolved issues.
* ''Describe'' the current user scenario.
* ''Describe'' the desired user scenario.
* List the steps (technical commands like ls ; cp ) to implement the desired scenario
* Create tiddlers for complex use cases and tag them "Use Cases" so that they are listed automatically
/***
|''Name:''|WebDavPlugin|
|''Description:''|Allows a TiddlyWiki to be saved to a WebDav server|
|''Author:''|Saq Imtiaz ( lewcid@gmail.com )|
|''Co-author:''|Loic Dachary|
|''Source:''|http://tw.lewcid.org/#WebDavPlugin|
|''Code Repository:''|http://tw.lewcid.org/svn/plugins|
|''Version:''|1.0|
|''Date:''|17/11/2007|
|''License:''|[[Creative Commons Attribution-ShareAlike 3.0 License|http://creativecommons.org/licenses/by-sa/3.0/]]|
|''~CoreVersion:''|2.2.3|
***/
// /%
//!BEGIN-PLUGIN-CODE
DAV = {
run : function(type,u,data,cb,params,headers){
var callback = function(status,params,responseText,url,xhr) {
url = url.indexOf("nocache=") < 0 ? url : url.substring(0,url.indexOf("nocache=")-1);
if(params.length){
params.shift().apply(this,[status,params,responseText,url,xhr]);
}
};
params = params||[];
params.unshift(cb);
var r = doHttp.apply(this,[type,u,data,null,null,null,callback,params,headers]);
if (typeof r == "string")
alert(r);
return r;
},
get : function(url,cb,params){
return DAV.run("GET",url,null,cb,params,null);
},
put : function(url,cb,params,data) {
return DAV.run("PUT",url,data,cb,params,null);
},
move : function(url,cb,params,destination) {
return DAV.run("MOVE",url,null,cb,params,{"Destination":destination,"Overwrite":"T"});
},
copy : function(url,cb,params,destination) {
return DAV.run("COPY",url,null,cb,params,{"Destination":destination,"Overwrite":"T","Depth":0});
},
propfind : function(url,cb,params,prop,depth){ // !!!
var xml = '<?xml version="1.0" encoding="UTF-8" ?>' +
'<D:propfind xmlns:D="DAV:">' +
'<D:prop>'+
'<D:'+prop+'/>'+
'</D:prop>'+
'</D:propfind>';
return DAV.run("PROPFIND",url,xml,cb,params,{"Content-type":"text/xml","Depth":depth?depth:0});
},
makeDir : function(url,cb,params){
return DAV.run("MKCOL",url,null,cb,params,null);
},
options : function(url,cb,params){
return DAV.run("OPTIONS",url,null,cb,params,null);
},
safeput : function(url,cb,params,data){
firstcb = function(status,p,responseText,u,xhr){
if(status)
DAV.move(u,cb,p,u.replace("-davsavingtemp",""));
else
cb.apply(firstcb,arguments);
};
return DAV.put(url+"-davsavingtemp",firstcb,params,data);
}
};
config.DavSaver = {
defaultFileName : 'index.html',
messages : {
startSaveMessage : 'saving to server...',
endSaveMessage : 'TiddlyWiki successfuly saved to server',
overwriteNewerPrompt : 'The remote file has changed since you last loaded or saved it.\nDo you wish to overwrite it?',
getModDateError : "Could not get last modified date",
raceError: "Save failed because the remote file is newer than the one you are trying to save"
},
errors:{
raceconflict : 'The save failed because your file is out of date',
getlastmodified : 'The save was aborted because the last modified date of the file could not be retrieved',
davenabled : 'The server does not support WebDav',
saverss : 'There was an error saving the rss file, the save was aborted',
saveempty: 'There was an error saving the empty file, the save was aborted',
savemain : 'Save failed! There was an error saving the main TW file',
savebackup: 'Save failed! There was an error creating a backup file',
makebackupdir: 'Save failed! The backup directory could not be created'
},
timestamp: new Date().toGMTString(),
orig_saveChanges: saveChanges,
saver : null
};
DavSaver = function(){
this.Q = [];
this.reset = function(){
config.DavSaver.saver = null;
};
this.runQ = function(){
if(this.Q.length){
this.Q.shift().apply(this,arguments);
}
else
this.reset();
};
this.posDiv = null;
this.original = null;
this.getOriginalPath = function(){
var p = document.location.toString();
p = convertUriToUTF8(p,config.options.txtFileSystemCharSet);
var argPos = p.indexOf("?");
if(argPos != -1)
p = p.substr(0,argPos);
var hashPos = p.indexOf("#");
if(hashPos != -1)
p = p.substr(0,hashPos);
if (p.charAt(p.length-1) == "/")
p = p + config.DavSaver.defaultFileName;
return p;
};
this.originalPath = this.getOriginalPath();
this.backupPath = null;
this.emptyPath = null;
this.rssPath = null;
this.throwError = function(er){
clearMessage();
this.reset();
alert(config.DavSaver.errors[er]); //clear message, reset and delete
};
};
DavSaver.prototype.getOriginal = function(){
var callback = function(status,params,original,url,xhr) {
var that = params[0];
if(status){
var p = that.posDiv = locateStoreArea(original);
if(!p || (p[0] == -1) || (p[1] == -1)) {
alert(config.messages.invalidFileError.format([url]));
return;
}
that.original = original;
that.runQ();
}
else
that.throwError('getOriginal');
};
DAV.get(this.originalPath,callback,[this]);
};
DavSaver.prototype.checkRace = function(){
var callback = function(status,params,responseText,url,xhr){
var that = params[0];
if(status){
var lastmod = responseText.match(/<(\w*?):getlastmodified>(.*?)<\/\1:getlastmodified>/)[2];
if(Date.parse(lastmod) > Date.parse(config.DavSaver.timestamp)){
if (confirm(config.DavSaver.messages.overwriteNewerPrompt))
that.runQ();
else
that.throwError('raceconflict');
}
else
that.runQ();
}
else
that.throwError('getlastmodified');
};
DAV.propfind(this.originalPath,callback,[this],"getlastmodified",0);
};
DavSaver.prototype.isDavEnabled = function(){
var callback = function(status,params,responseText,url,xhr){
that = params[0];
if(status && !! xhr.getResponseHeader("DAV")){
that.runQ();
}
else
that.throwError('davenabled');
};
DAV.options(this.originalPath,callback,[this]);
};
DavSaver.prototype.saveRss = function(){
var callback = function(status,params,responseText,url,xhr){
var that = params[0];
if(status){
displayMessage(config.messages.rssSaved,that.rssPath);
that.runQ();
}
else
that.throwError('saverss');
};
var u = this.originalPath;
var rssPath = this.rssPath = u.substr(0,u.lastIndexOf(".")) + ".xml";
DAV.safeput(rssPath,callback,[this],convertUnicodeToUTF8(generateRss()));
};
DavSaver.prototype.saveEmpty = function(){
var callback = function(status,params,responseText,url,xhr){
var that = params[0];
if(status){
displayMessage(config.messages.emptySaved,that.emptyPath);
that.runQ();
}
else
that.throwError('saveempty');
};
var u = this.originalPath;
var emptyPath,p;
if((p = u.lastIndexOf("/")) != -1)
emptyPath = u.substr(0,p) + "/empty.html";
else
emptyPath = u + ".empty.html";
this.emptyPath = emptyPath;
var empty = this.original.substr(0,this.posDiv[0] + startSaveArea.length) + this.original.substr(this.posDiv[1]);
DAV.safeput(emptyPath,callback,[this],empty);
};
DavSaver.prototype.saveMain = function(){
var callback = function(status,params,responseText,url,xhr){
var that = params[0];
if(status){
config.DavSaver.timestamp = xhr.getResponseHeader('Date');
displayMessage(config.messages.mainSaved,that.originalPath);
store.setDirty(false);
that.runQ();
}
else
that.throwError('savemain');
};
var revised = updateOriginal(this.original,this.posDiv);
DAV.safeput(this.originalPath,callback,[this],revised);
};
DavSaver.prototype.saveBackup = function(){
var callback = function(status,params,responseText,url,xhr){
var that = params[0];
if(status){
clearMessage();
displayMessage(config.messages.backupSaved,that.backupPath);
that.runQ();
}
else
that.throwError('savebackup');
};
var backupPath = this.backupPath = getBackupPath(this.originalPath);
DAV.copy(this.originalPath,callback,[this],this.backupPath);
};
DavSaver.prototype.makeBackupDir = function(){
var callback = function(status,params,responseText,url,xhr){
var that = params[0];
if(status)
that.runQ();
else
that.throwError('makebackupdir');
};
var u = getBackupPath(this.originalPath);
var backupDirPath = u.substr(0,u.lastIndexOf("/"));
DAV.makeDir(backupDirPath,callback,[this]);
};
DavSaver.prototype.save = function(onlyIfDirty,tiddlers){
if(onlyIfDirty && !store.isDirty())
return;
clearMessage();
displayMessage(config.DavSaver.messages.startSaveMessage);
var Q = this.Q =[];
Q.push(this.isDavEnabled);
Q.push(this.getOriginal);
Q.push(this.checkRace);
if (config.options.chkSaveBackups){
if (config.options.txtBackupFolder!='')
Q.push(this.makeBackupDir);
Q.push(this.saveBackup);
}
Q.push(this.saveMain);
if (config.options.chkGenerateAnRssFeed)
Q.push(this.saveRss);
if (config.options.chkSaveEmptyTemplate)
Q.push(this.saveEmpty);
//Q.push(this.reset);
this.runQ();
};
window.saveChanges = function(onlyIfDirty,tiddlers)
{
var c = config.DavSaver;
if (document.location.protocol.toString() == "http:"){
var saver = c.saver = new DavSaver();
saver.save(onlyIfDirty,tiddlers);
}
else
return c.orig_saveChanges(onlyIfDirty,tiddlers);
};
//!END-PLUGIN-CODE
// %/