| 1 | 508a509,994 |
|---|
| 2 | > <div title="ConfigTweaks" modifier="Zooko" created="200812152209" modified="200812152226" tags="systemConfig" changecount="3"> |
|---|
| 3 | > <pre>//{{{ |
|---|
| 4 | > config.options.txtTheme = "WritableTheme"; |
|---|
| 5 | > //}}}</pre> |
|---|
| 6 | > </div> |
|---|
| 7 | > <div title="HTTPSavingPlugin" modifier="Zooko" created="200812152200" modified="200812152200" tags="systemConfig" changecount="4"> |
|---|
| 8 | > <pre>/*** |
|---|
| 9 | > |''Name''|HTTPSavingPlugin| |
|---|
| 10 | > |''Description''|<...>| |
|---|
| 11 | > |''Author''|Zooko| |
|---|
| 12 | > |''Contributors''|FND| |
|---|
| 13 | > |''Version''|0.2.1| |
|---|
| 14 | > |''Status''|@@experimental@@| |
|---|
| 15 | > |''Source''|http://allmydata.org/trac/tiddly_on_tahoe| |
|---|
| 16 | > |''CodeRepository''|http://allmydata.org/source/tiddly_on_tahoe/trunk/| |
|---|
| 17 | > |''License''|GPLv2+ or TGPPLv1.0+| |
|---|
| 18 | > |''Keywords''|<...>| |
|---|
| 19 | > !Description |
|---|
| 20 | > <...> |
|---|
| 21 | > !Notes |
|---|
| 22 | > This plugin is being developed for [[Tiddly on Tahoe|http://allmydata.org/trac/tiddly_on_tahoe]]. |
|---|
| 23 | > ***/ |
|---|
| 24 | > /* The following comment is to let jslint know which variables are supposed to be global. */ |
|---|
| 25 | > /*global clearMessage, config, getPath, readOnly, saveChanges, saveTest, showBackstage, store, story, version, convertUriToUTF8, convertUnicodeToFileFormat, getLocalPath, loadRemoteFile, locateStoreArea, saveBackup, saveEmpty, saveFile, saveMain, saveRss, unescape, displayMessage, httpReq */ |
|---|
| 26 | > //{{{ |
|---|
| 27 | > if (!version.extensions.HTTPSavingPlugin) { //# ensure that the plugin is only installed once |
|---|
| 28 | > version.extensions.HTTPSavingPlugin = { installed: true }; |
|---|
| 29 | > |
|---|
| 30 | > (function () { //# wrapper |
|---|
| 31 | > readOnly = false; |
|---|
| 32 | > config.options.chkHttpReadOnly = false; |
|---|
| 33 | > showBackstage = true; |
|---|
| 34 | > |
|---|
| 35 | > saveTest = function () { |
|---|
| 36 | > var s = document.getElementById("saveTest"); |
|---|
| 37 | > /*if (s.hasChildNodes()) { |
|---|
| 38 | > alert(config.messages.savedSnapshotError); |
|---|
| 39 | > }*/ |
|---|
| 40 | > s.appendChild(document.createTextNode("savetest")); |
|---|
| 41 | > }; |
|---|
| 42 | > |
|---|
| 43 | > // Save this TiddlyWiki with the pending changes |
|---|
| 44 | > saveChanges = function (onlyIfDirty, tiddlers) { |
|---|
| 45 | > var originalPath, localCallback, result; |
|---|
| 46 | > if (onlyIfDirty && !store.isDirty()) { |
|---|
| 47 | > return; |
|---|
| 48 | > } |
|---|
| 49 | > clearMessage(); |
|---|
| 50 | > // Get the URL of the document |
|---|
| 51 | > originalPath = getPath(document.location.toString()); |
|---|
| 52 | > // Load the original file |
|---|
| 53 | > localCallback = function (status, context, original, url, xhr) { |
|---|
| 54 | > //log("loaded remote file from ", originalPath); |
|---|
| 55 | > /*log("got callback status ", status, "\n", context: ", context, "\n", |
|---|
| 56 | > URL: ", url, "\n", XHR: ", xhr);*/ |
|---|
| 57 | > if (original === null) { |
|---|
| 58 | > alert(config.messages.cantSaveError); |
|---|
| 59 | > if (store.tiddlerExists(config.messages.saveInstructions)) { |
|---|
| 60 | > story.displayTiddler(null, config.messages.saveInstructions); |
|---|
| 61 | > } |
|---|
| 62 | > return; |
|---|
| 63 | > } |
|---|
| 64 | > // Locate the storeArea div's |
|---|
| 65 | > var posDiv = locateStoreArea(original); |
|---|
| 66 | > if (!posDiv) { |
|---|
| 67 | > alert(config.messages.invalidFileError.format([originalPath])); |
|---|
| 68 | > return; |
|---|
| 69 | > } |
|---|
| 70 | > saveRss(originalPath); |
|---|
| 71 | > saveEmpty(originalPath, original, posDiv); |
|---|
| 72 | > saveMain(originalPath, original, posDiv); |
|---|
| 73 | > }; |
|---|
| 74 | > result = loadRemoteFile(originalPath, localCallback); |
|---|
| 75 | > //log("result from loadRemoteFile: ", result); |
|---|
| 76 | > return true; |
|---|
| 77 | > }; |
|---|
| 78 | > |
|---|
| 79 | > // override and disable saveBackup() |
|---|
| 80 | > saveBackup = function (localPath, original) {}; |
|---|
| 81 | > |
|---|
| 82 | > // override and disable getLocalPath() |
|---|
| 83 | > getLocalPath = function (origPath) {}; |
|---|
| 84 | > |
|---|
| 85 | > // override getPath() |
|---|
| 86 | > getPath = function (origPath) { |
|---|
| 87 | > var originalPath, argPos, hashPos, resultPath; |
|---|
| 88 | > originalPath = convertUriToUTF8(origPath, config.options.txtFileSystemCharSet); |
|---|
| 89 | > // Remove any location or query part of the URL |
|---|
| 90 | > argPos = originalPath.indexOf("?"); |
|---|
| 91 | > if (argPos !== -1) { |
|---|
| 92 | > originalPath = originalPath.substr(0, argPos); |
|---|
| 93 | > } |
|---|
| 94 | > hashPos = originalPath.indexOf("#"); |
|---|
| 95 | > if (hashPos !== -1) { |
|---|
| 96 | > originalPath = originalPath.substr(0, hashPos); |
|---|
| 97 | > } |
|---|
| 98 | > // Convert file://localhost/ to file:/// |
|---|
| 99 | > if (originalPath.indexOf("file://localhost/") === 0) { |
|---|
| 100 | > originalPath = "file://" + originalPath.substr(16); |
|---|
| 101 | > } |
|---|
| 102 | > // Convert to a native file format |
|---|
| 103 | > if (originalPath.indexOf("http://") === 0) { // HTTP file |
|---|
| 104 | > resultPath = originalPath; |
|---|
| 105 | > } else if (originalPath.charAt(9) === ":") { // PC local file |
|---|
| 106 | > resultPath = unescape(originalPath.substr(8)).replace(new RegExp("/", "g"), "\\"); |
|---|
| 107 | > } else if (originalPath.indexOf("file://///") === 0) { // Firefox PC network file |
|---|
| 108 | > resultPath = "\\\\" + unescape(originalPath.substr(10)).replace(new RegExp("/", "g"), "\\"); |
|---|
| 109 | > } else if (originalPath.indexOf("file:///") === 0) { // *nix local file |
|---|
| 110 | > resultPath = unescape(originalPath.substr(7)); |
|---|
| 111 | > } else if (originalPath.indexOf("file:/") === 0) { // *nix local file |
|---|
| 112 | > resultPath = unescape(originalPath.substr(5)); |
|---|
| 113 | > } else { // PC local file |
|---|
| 114 | > resultPath = "\\\\" + unescape(originalPath.substr(7)).replace(new RegExp("/", "g"), "\\"); |
|---|
| 115 | > } |
|---|
| 116 | > return resultPath; |
|---|
| 117 | > }; |
|---|
| 118 | > |
|---|
| 119 | > // override saveFile() |
|---|
| 120 | > saveFile = function (fileUrl, content, callb) { |
|---|
| 121 | > displayMessage("saving... please wait"); // XXX: belongs into command handler -- TODO: i18n |
|---|
| 122 | > //alert("whee! about to save to " + fileUrl); |
|---|
| 123 | > var localCallback = function (status, params, responseText, url, xhr) { |
|---|
| 124 | > if (!status) { |
|---|
| 125 | > displayMessage("saving failed: " + responseText); |
|---|
| 126 | > } |
|---|
| 127 | > }; |
|---|
| 128 | > return httpReq("PUT", fileUrl, localCallback, null, null, content, "text/html;charset=utf-8"); |
|---|
| 129 | > }; |
|---|
| 130 | > |
|---|
| 131 | > // override convertUnicodeToFileFormat() |
|---|
| 132 | > convertUnicodeToFileFormat = function (s) |
|---|
| 133 | > { |
|---|
| 134 | > return s; |
|---|
| 135 | > }; |
|---|
| 136 | > |
|---|
| 137 | > })(); //# end of wrapper |
|---|
| 138 | > } //# end of "install only once" |
|---|
| 139 | > //}}} |
|---|
| 140 | > </pre> |
|---|
| 141 | > </div> |
|---|
| 142 | > <div title="PageTemplate" modifier="Zooko" created="200812152204" changecount="4"> |
|---|
| 143 | > <pre><!--{{{--> |
|---|
| 144 | > <div class='header' macro='gradient vert [[ColorPalette::PrimaryLight]] [[ColorPalette::PrimaryMid]]'> |
|---|
| 145 | > <div class='headerShadow'> |
|---|
| 146 | > <div id='accessControlExplanationDivId' macro='accessControlExplanation'></div> |
|---|
| 147 | > <span class='siteTitle' refresh='content' tiddler='SiteTitle'></span>&nbsp; |
|---|
| 148 | > <span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'></span> |
|---|
| 149 | > </div> |
|---|
| 150 | > <div class='headerForeground'> |
|---|
| 151 | > <div id='accessControlExplanationDivId' macro='accessControlExplanation'></div> |
|---|
| 152 | > <span class='siteTitle' refresh='content' tiddler='SiteTitle'></span>&nbsp; |
|---|
| 153 | > <span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'></span> |
|---|
| 154 | > </div> |
|---|
| 155 | > </div> |
|---|
| 156 | > <div id='mainMenu' refresh='content' tiddler='MainMenu'></div> |
|---|
| 157 | > <div id='sidebar'> |
|---|
| 158 | > <div id='sidebarOptions' refresh='content' tiddler='SideBarOptions'></div> |
|---|
| 159 | > <div id='sidebarTabs' refresh='content' force='true' tiddler='SideBarTabs'></div> |
|---|
| 160 | > </div> |
|---|
| 161 | > <div id='displayArea'> |
|---|
| 162 | > <div id='messageArea'></div> |
|---|
| 163 | > <div id='tiddlerDisplay'></div> |
|---|
| 164 | > </div> |
|---|
| 165 | > <!--}}}--></pre> |
|---|
| 166 | > </div> |
|---|
| 167 | > <div title="TahoePlugin" modifier="Zooko" created="200812152200" modified="200812152206" tags="systemConfig" changecount="5"> |
|---|
| 168 | > <pre>/*** |
|---|
| 169 | > |''Name''|HTTPSavingPlugin| |
|---|
| 170 | > |''Description''|<...>| |
|---|
| 171 | > |''Author''|Zooko| |
|---|
| 172 | > |''Contributors''|FND| |
|---|
| 173 | > |''Version''|0.2.1| |
|---|
| 174 | > |''Status''|@@experimental@@| |
|---|
| 175 | > |''Source''|http://allmydata.org/trac/tiddly_on_tahoe| |
|---|
| 176 | > |''CodeRepository''|http://allmydata.org/source/tiddly_on_tahoe/trunk/| |
|---|
| 177 | > |''License''|GPLv2+ or TGPPLv1.0+| |
|---|
| 178 | > |''Keywords''|<...>| |
|---|
| 179 | > !Description |
|---|
| 180 | > <...> |
|---|
| 181 | > !Notes |
|---|
| 182 | > This plugin is being developed for [[Tiddly on Tahoe|http://allmydata.org/trac/tiddly_on_tahoe]]. |
|---|
| 183 | > ***/ |
|---|
| 184 | > /* The following comment is to let jslint know which variables are supposed to be global. */ |
|---|
| 185 | > /*global clearMessage, config, getPath, readOnly, saveChanges, saveTest, showBackstage, store, story, version, convertUriToUTF8, convertUnicodeToFileFormat, getLocalPath, loadRemoteFile, locateStoreArea, saveBackup, saveEmpty, saveFile, saveMain, saveRss, unescape, displayMessage, httpReq */ |
|---|
| 186 | > //{{{ |
|---|
| 187 | > if (!version.extensions.HTTPSavingPlugin) { //# ensure that the plugin is only installed once |
|---|
| 188 | > version.extensions.HTTPSavingPlugin = { installed: true }; |
|---|
| 189 | > |
|---|
| 190 | > (function () { //# wrapper |
|---|
| 191 | > readOnly = false; |
|---|
| 192 | > config.options.chkHttpReadOnly = false; |
|---|
| 193 | > showBackstage = true; |
|---|
| 194 | > |
|---|
| 195 | > saveTest = function () { |
|---|
| 196 | > var s = document.getElementById("saveTest"); |
|---|
| 197 | > /*if (s.hasChildNodes()) { |
|---|
| 198 | > alert(config.messages.savedSnapshotError); |
|---|
| 199 | > }*/ |
|---|
| 200 | > s.appendChild(document.createTextNode("savetest")); |
|---|
| 201 | > }; |
|---|
| 202 | > |
|---|
| 203 | > // Save this TiddlyWiki with the pending changes |
|---|
| 204 | > saveChanges = function (onlyIfDirty, tiddlers) { |
|---|
| 205 | > var originalPath, localCallback, result; |
|---|
| 206 | > if (onlyIfDirty && !store.isDirty()) { |
|---|
| 207 | > return; |
|---|
| 208 | > } |
|---|
| 209 | > clearMessage(); |
|---|
| 210 | > // Get the URL of the document |
|---|
| 211 | > originalPath = getPath(document.location.toString()); |
|---|
| 212 | > // Load the original file |
|---|
| 213 | > localCallback = function (status, context, original, url, xhr) { |
|---|
| 214 | > //log("loaded remote file from ", originalPath); |
|---|
| 215 | > /*log("got callback status ", status, "\n", context: ", context, "\n", |
|---|
| 216 | > URL: ", url, "\n", XHR: ", xhr);*/ |
|---|
| 217 | > if (original === null) { |
|---|
| 218 | > alert(config.messages.cantSaveError); |
|---|
| 219 | > if (store.tiddlerExists(config.messages.saveInstructions)) { |
|---|
| 220 | > story.displayTiddler(null, config.messages.saveInstructions); |
|---|
| 221 | > } |
|---|
| 222 | > return; |
|---|
| 223 | > } |
|---|
| 224 | > // Locate the storeArea div's |
|---|
| 225 | > var posDiv = locateStoreArea(original); |
|---|
| 226 | > if (!posDiv) { |
|---|
| 227 | > alert(config.messages.invalidFileError.format([originalPath])); |
|---|
| 228 | > return; |
|---|
| 229 | > } |
|---|
| 230 | > saveRss(originalPath); |
|---|
| 231 | > saveEmpty(originalPath, original, posDiv); |
|---|
| 232 | > saveMain(originalPath, original, posDiv); |
|---|
| 233 | > }; |
|---|
| 234 | > result = loadRemoteFile(originalPath, localCallback); |
|---|
| 235 | > //log("result from loadRemoteFile: ", result); |
|---|
| 236 | > return true; |
|---|
| 237 | > }; |
|---|
| 238 | > |
|---|
| 239 | > // override and disable saveBackup() |
|---|
| 240 | > saveBackup = function (localPath, original) {}; |
|---|
| 241 | > |
|---|
| 242 | > // override and disable getLocalPath() |
|---|
| 243 | > getLocalPath = function (origPath) {}; |
|---|
| 244 | > |
|---|
| 245 | > // override getPath() |
|---|
| 246 | > getPath = function (origPath) { |
|---|
| 247 | > var originalPath, argPos, hashPos, resultPath; |
|---|
| 248 | > originalPath = convertUriToUTF8(origPath, config.options.txtFileSystemCharSet); |
|---|
| 249 | > // Remove any location or query part of the URL |
|---|
| 250 | > argPos = originalPath.indexOf("?"); |
|---|
| 251 | > if (argPos !== -1) { |
|---|
| 252 | > originalPath = originalPath.substr(0, argPos); |
|---|
| 253 | > } |
|---|
| 254 | > hashPos = originalPath.indexOf("#"); |
|---|
| 255 | > if (hashPos !== -1) { |
|---|
| 256 | > originalPath = originalPath.substr(0, hashPos); |
|---|
| 257 | > } |
|---|
| 258 | > // Convert file://localhost/ to file:/// |
|---|
| 259 | > if (originalPath.indexOf("file://localhost/") === 0) { |
|---|
| 260 | > originalPath = "file://" + originalPath.substr(16); |
|---|
| 261 | > } |
|---|
| 262 | > // Convert to a native file format |
|---|
| 263 | > if (originalPath.indexOf("http://") === 0) { // HTTP file |
|---|
| 264 | > resultPath = originalPath; |
|---|
| 265 | > } else if (originalPath.charAt(9) === ":") { // PC local file |
|---|
| 266 | > resultPath = unescape(originalPath.substr(8)).replace(new RegExp("/", "g"), "\\"); |
|---|
| 267 | > } else if (originalPath.indexOf("file://///") === 0) { // Firefox PC network file |
|---|
| 268 | > resultPath = "\\\\" + unescape(originalPath.substr(10)).replace(new RegExp("/", "g"), "\\"); |
|---|
| 269 | > } else if (originalPath.indexOf("file:///") === 0) { // *nix local file |
|---|
| 270 | > resultPath = unescape(originalPath.substr(7)); |
|---|
| 271 | > } else if (originalPath.indexOf("file:/") === 0) { // *nix local file |
|---|
| 272 | > resultPath = unescape(originalPath.substr(5)); |
|---|
| 273 | > } else { // PC local file |
|---|
| 274 | > resultPath = "\\\\" + unescape(originalPath.substr(7)).replace(new RegExp("/", "g"), "\\"); |
|---|
| 275 | > } |
|---|
| 276 | > return resultPath; |
|---|
| 277 | > }; |
|---|
| 278 | > |
|---|
| 279 | > // override saveFile() |
|---|
| 280 | > saveFile = function (fileUrl, content, callb) { |
|---|
| 281 | > displayMessage("saving... please wait"); // XXX: belongs into command handler -- TODO: i18n |
|---|
| 282 | > //alert("whee! about to save to " + fileUrl); |
|---|
| 283 | > var localCallback = function (status, params, responseText, url, xhr) { |
|---|
| 284 | > if (!status) { |
|---|
| 285 | > displayMessage("saving failed: " + responseText); |
|---|
| 286 | > } |
|---|
| 287 | > }; |
|---|
| 288 | > return httpReq("PUT", fileUrl, localCallback, null, null, content, "text/html;charset=utf-8"); |
|---|
| 289 | > }; |
|---|
| 290 | > |
|---|
| 291 | > // override convertUnicodeToFileFormat() |
|---|
| 292 | > convertUnicodeToFileFormat = function (s) |
|---|
| 293 | > { |
|---|
| 294 | > return s; |
|---|
| 295 | > }; |
|---|
| 296 | > |
|---|
| 297 | > })(); //# end of wrapper |
|---|
| 298 | > } //# end of "install only once" |
|---|
| 299 | > //}}} |
|---|
| 300 | > /*** |
|---|
| 301 | > |''Name''|TahoePlugin| |
|---|
| 302 | > |''Description''|<...>| |
|---|
| 303 | > |''Author''|Zooko| |
|---|
| 304 | > |''Contributors''|FND, EricShulman| |
|---|
| 305 | > |''Version''|0.2.0| |
|---|
| 306 | > |''Requires''|HTTPSavingPlugin| |
|---|
| 307 | > |''Status''|@@experimental@@| |
|---|
| 308 | > |''Source''|http://allmydata.org/trac/tiddly_on_tahoe| |
|---|
| 309 | > |''CodeRepository''|http://allmydata.org/source/tiddly_on_tahoe/trunk/| |
|---|
| 310 | > |''License''|GPLv2+ or TGPPLv1.0+| |
|---|
| 311 | > |''Keywords''|<...>| |
|---|
| 312 | > !Description |
|---|
| 313 | > <...> |
|---|
| 314 | > !Notes |
|---|
| 315 | > This plugin is being developed for [[Tiddly on Tahoe|http://allmydata.org/trac/tiddly_on_tahoe]]. |
|---|
| 316 | > ***/ |
|---|
| 317 | > //{{{ |
|---|
| 318 | > /* The following comment is to let jslint know which variables are supposed to be global. */ |
|---|
| 319 | > /*global version, readOnly, showBackstage, config, loadRemoteFile, wikify */ |
|---|
| 320 | > if (!version.extensions.TahoePlugin) { //# ensure that the plugin is only installed once |
|---|
| 321 | > version.extensions.TahoePlugin = { installed: true }; |
|---|
| 322 | > |
|---|
| 323 | > (function () { //# wrapper |
|---|
| 324 | > var BASE32CHAR, BASE32CHAR_3bits, BASE32CHAR_1bits, SEP, NUMBER, HTTPLEAD, BASE32STR_128bits, BASE32STR_256bits, ALPHANUMERIC_STRING, TAHOE_FUTURE_IMMUTABLE_CAP_RE_STR, TAHOE_FUTURE_READONLY_CAP_RE_STR, TAHOE_FUTURE_WRITABLE_CAP_RE_STR, TAHOE_IMMUTABLE_CAP_RE_STR, TAHOE_READONLY_FILE_CAP_RE_STR, TAHOE_READONLY_DIR_CAP_RE_STR, TAHOE_WRITABLE_FILE_CAP_RE_STR, TAHOE_WRITABLE_DIR_CAP_RE_STR, TAHOE_NONWRITABLE_THING_CAP_RE_STR, TAHOE_WRITABLE_THING_CAP_RE_STR, TAHOE_ANY_CAP_RE_STR, splitTahoeURL, scrapeOutReadonlyCap, diminishToReadonlyCap, getReadonlyURLToThisPage; |
|---|
| 325 | > |
|---|
| 326 | > BASE32CHAR = '[abcdefghijklmnopqrstuvwxyz234567]'; |
|---|
| 327 | > BASE32CHAR_3bits = '[aqiyemu4]'; |
|---|
| 328 | > BASE32CHAR_1bits = '[aq]'; |
|---|
| 329 | > SEP = '(?::|%3A)'; |
|---|
| 330 | > NUMBER = '[0-9]+'; |
|---|
| 331 | > HTTPLEAD = 'https?://(?:[^:/]+)(?::' + NUMBER + ')?/(uri|file|cap)/?'; |
|---|
| 332 | > |
|---|
| 333 | > BASE32STR_128bits = '(' + BASE32CHAR + '{25}' + BASE32CHAR_3bits + ')'; |
|---|
| 334 | > BASE32STR_256bits = '(' + BASE32CHAR + '{51}' + BASE32CHAR_1bits + ')'; |
|---|
| 335 | > |
|---|
| 336 | > ALPHANUMERIC_STRING = '[A-Za-z0-9]+'; |
|---|
| 337 | > |
|---|
| 338 | > // This is speculative: maybe in the future there will be a version of Tahoe where caps |
|---|
| 339 | > // start with these symbols, and if so then this JavaScript code will magically work with |
|---|
| 340 | > // that version of Tahoe. |
|---|
| 341 | > TAHOE_FUTURE_IMMUTABLE_CAP_RE_STR = "i_" + ALPHANUMERIC_STRING; |
|---|
| 342 | > TAHOE_FUTURE_READONLY_CAP_RE_STR = "r_" + ALPHANUMERIC_STRING; |
|---|
| 343 | > TAHOE_FUTURE_WRITABLE_CAP_RE_STR = "W_" + ALPHANUMERIC_STRING; |
|---|
| 344 | > |
|---|
| 345 | > TAHOE_IMMUTABLE_CAP_RE_STR = "(?:URI" + SEP + "CHK" + SEP + BASE32STR_128bits + SEP + BASE32STR_256bits + SEP + NUMBER + SEP + NUMBER + SEP + NUMBER + '|' + TAHOE_FUTURE_IMMUTABLE_CAP_RE_STR + ')'; |
|---|
| 346 | > TAHOE_READONLY_FILE_CAP_RE_STR = "URI" + SEP + "SSK-RO" + SEP + BASE32STR_128bits + SEP + BASE32STR_256bits; |
|---|
| 347 | > TAHOE_READONLY_DIR_CAP_RE_STR = "URI" + SEP + "DIR2-RO" + SEP + BASE32STR_128bits + SEP + BASE32STR_256bits; |
|---|
| 348 | > TAHOE_WRITABLE_FILE_CAP_RE_STR = "URI" + SEP + "SSK" + SEP + BASE32STR_128bits + SEP + BASE32STR_256bits; |
|---|
| 349 | > TAHOE_WRITABLE_DIR_CAP_RE_STR = "URI" + SEP + "DIR2" + SEP + BASE32STR_128bits + SEP + BASE32STR_256bits; |
|---|
| 350 | > |
|---|
| 351 | > TAHOE_NONWRITABLE_THING_CAP_RE_STR = '(' + TAHOE_READONLY_FILE_CAP_RE_STR + '|' + TAHOE_READONLY_DIR_CAP_RE_STR + '|' + TAHOE_IMMUTABLE_CAP_RE_STR + '|' + TAHOE_FUTURE_IMMUTABLE_CAP_RE_STR + '|' + TAHOE_FUTURE_READONLY_CAP_RE_STR + ')'; |
|---|
| 352 | > TAHOE_WRITABLE_THING_CAP_RE_STR = '(' + TAHOE_WRITABLE_DIR_CAP_RE_STR + '|' + TAHOE_WRITABLE_FILE_CAP_RE_STR + '|' + TAHOE_FUTURE_WRITABLE_CAP_RE_STR + ')'; |
|---|
| 353 | > |
|---|
| 354 | > TAHOE_ANY_CAP_RE_STR = '(' + TAHOE_NONWRITABLE_THING_CAP_RE_STR + '|' + TAHOE_WRITABLE_THING_CAP_RE_STR + ')'; |
|---|
| 355 | > |
|---|
| 356 | > readOnly = document.location.toString().match(new RegExp(HTTPLEAD + TAHOE_NONWRITABLE_THING_CAP_RE_STR)); |
|---|
| 357 | > showBackstage = !readOnly; |
|---|
| 358 | > config.options.chkHttpReadOnly = false; |
|---|
| 359 | > |
|---|
| 360 | > /* Returns server (which is "http://$HOST:$PORT/uri"), cap, and suffix, which can be a |
|---|
| 361 | > path from the cap through the tahoe filesystem and/or trailing extra arguments. */ |
|---|
| 362 | > splitTahoeURL = function (someURL) { |
|---|
| 363 | > var u, urlSuffix, candidate_cap, urlPrefix; |
|---|
| 364 | > |
|---|
| 365 | > u = someURL.split('/'); |
|---|
| 366 | > urlSuffix = []; |
|---|
| 367 | > candidate_cap = u.pop(); |
|---|
| 368 | > urlPrefix = u.join('/'); |
|---|
| 369 | > while ((u.length > 0) && (!urlPrefix.match(new RegExp("^" + HTTPLEAD + "$")))) { |
|---|
| 370 | > urlSuffix.unshift(candidate_cap); |
|---|
| 371 | > candidate_cap = u.pop(); |
|---|
| 372 | > urlPrefix = u.join('/'); |
|---|
| 373 | > } |
|---|
| 374 | > // Okay we've found the HTTPLEAD. Is the following thing shaped like a Tahoe capability? |
|---|
| 375 | > if (candidate_cap.match(new RegExp(TAHOE_ANY_CAP_RE_STR))) { |
|---|
| 376 | > // Yes! |
|---|
| 377 | > return {'urlPrefix': urlPrefix, 'cap': candidate_cap, 'urlSuffix': urlSuffix}; |
|---|
| 378 | > } else { |
|---|
| 379 | > // No! |
|---|
| 380 | > return; |
|---|
| 381 | > } |
|---|
| 382 | > }; |
|---|
| 383 | > |
|---|
| 384 | > scrapeOutReadonlyCap = function (metadata) { |
|---|
| 385 | > // example of tahoe-lafs json-encoded metadata: |
|---|
| 386 | > // [ |
|---|
| 387 | > // "dirnode", |
|---|
| 388 | > // { |
|---|
| 389 | > // "rw_uri": "URI:DIR2:ouojn4oj2fa7fphdf54hz5bfaq:rf56nzb6klj3ctvssqghy2ugalp6wundystbysxujodttrhxbqwa", |
|---|
| 390 | > // "ro_uri": "URI:DIR2-RO:sznrgoyz7lbjorhe4ipzcnmluy:rf56nzb6klj3ctvssqghy2ugalp6wundystbysxujodttrhxbqwa", |
|---|
| 391 | > // "children": { |
|---|
| 392 | > // "tw_empty.html": [ |
|---|
| 393 | > // "filenode", |
|---|
| 394 | > // { |
|---|
| 395 | > // "mutable": false, |
|---|
| 396 | > // "metadata": { |
|---|
| 397 | > // "ctime": 1229263396.69, |
|---|
| 398 | > // "mtime": 1229263396.69 |
|---|
| 399 | > // }, |
|---|
| 400 | > // "ro_uri": "URI:CHK:cofm2lm3ywu4r4efeqwjzuzyeq:dfw7oi65smf7dhtcx6wvr4ouazswprhwkvc3uopqtmvn3e7cactq:3:10:295520", |
|---|
| 401 | > // "size": 295520 |
|---|
| 402 | > // } |
|---|
| 403 | > // ] |
|---|
| 404 | > // }, |
|---|
| 405 | > // "mutable": true |
|---|
| 406 | > // } |
|---|
| 407 | > //] |
|---|
| 408 | > |
|---|
| 409 | > // another example: |
|---|
| 410 | > // [ |
|---|
| 411 | > // "filenode", |
|---|
| 412 | > // { |
|---|
| 413 | > // "rw_uri": "URI:SSK:ouojn4oj2fa7fphdf54hz5bfaq:rf56nzb6klj3ctvssqghy2ugalp6wundystbysxujodttrhxbqwa", |
|---|
| 414 | > // "mutable": true, |
|---|
| 415 | > // "ro_uri": "URI:SSK-RO:sznrgoyz7lbjorhe4ipzcnmluy:rf56nzb6klj3ctvssqghy2ugalp6wundystbysxujodttrhxbqwa", |
|---|
| 416 | > // "size": "?" |
|---|
| 417 | > // } |
|---|
| 418 | > // ] |
|---|
| 419 | > var matchobj = metadata.match(new RegExp("^\\s*\\[[^\\[]*\"ro_uri\"\\s*:\\s*\"([^\"]*)\"")); |
|---|
| 420 | > if (matchobj) { |
|---|
| 421 | > return matchobj[1]; |
|---|
| 422 | > } |
|---|
| 423 | > }; |
|---|
| 424 | > |
|---|
| 425 | > diminishToReadonlyCap = function (urlPrefix, writableCap, callback) { |
|---|
| 426 | > var queryURL = [urlPrefix, writableCap, "?t=json"].join("/"); |
|---|
| 427 | > |
|---|
| 428 | > loadRemoteFile(queryURL, function (success, param, txt, src, xhr) { |
|---|
| 429 | > if (success) { |
|---|
| 430 | > callback(scrapeOutReadonlyCap(txt)); |
|---|
| 431 | > } |
|---|
| 432 | > }); |
|---|
| 433 | > }; |
|---|
| 434 | > |
|---|
| 435 | > getReadonlyURLToThisPage = function (callback) { |
|---|
| 436 | > if (document.location.tahoeDiminishedCapabilityURL) { |
|---|
| 437 | > return callback(document.location.tahoeDiminishedCapabilityURL); |
|---|
| 438 | > } else { |
|---|
| 439 | > var pieces = splitTahoeURL(document.location.toString()); |
|---|
| 440 | > diminishToReadonlyCap(pieces.urlPrefix, pieces.cap, function (diminishedCap) { |
|---|
| 441 | > var diminishedURL = pieces.urlPrefix + "/" + diminishedCap + "/" + pieces.urlSuffix; |
|---|
| 442 | > document.location.tahoeDiminishedCapabilityURL = diminishedURL; |
|---|
| 443 | > callback(diminishedURL); |
|---|
| 444 | > }); |
|---|
| 445 | > } |
|---|
| 446 | > }; |
|---|
| 447 | > |
|---|
| 448 | > config.macros.accessControlExplanation = { |
|---|
| 449 | > |
|---|
| 450 | > handler: function (place, macroName, params, wikifier, paramString, tiddler) { |
|---|
| 451 | > if (document.location.toString().match(new RegExp(HTTPLEAD + TAHOE_IMMUTABLE_CAP_RE_STR))) { |
|---|
| 452 | > wikify("This is an immutable view of this page. Using this link will always give this exact same page, even if a newer version has been uploaded.", place); |
|---|
| 453 | > } else if (document.location.toString().match(new RegExp(HTTPLEAD + TAHOE_NONWRITABLE_THING_CAP_RE_STR))) { |
|---|
| 454 | > wikify("This is a read-only view of this page. Using this link will give the most recent version of this page, but doesn't allow the user to change the page.", place); |
|---|
| 455 | > } else if (document.location.toString().match(new RegExp(HTTPLEAD + TAHOE_WRITABLE_THING_CAP_RE_STR))) { |
|---|
| 456 | > getReadonlyURLToThisPage(function (readonlyCap) { |
|---|
| 457 | > wikify("You are accessing this page with a writable link. If you share this link with someone else, they will gain the ability to write to this page. Click here for a [[read-only link to this page|" + readonlyCap + "]].", place); |
|---|
| 458 | > }); |
|---|
| 459 | > } else { |
|---|
| 460 | > wikify("You are accessing this page not through the Tahoe-LAFS secure, distributed filesystem.", place); |
|---|
| 461 | > } |
|---|
| 462 | > } |
|---|
| 463 | > }; |
|---|
| 464 | > })(); //# end of wrapper |
|---|
| 465 | > } //# end of "install only once" |
|---|
| 466 | > //}}} |
|---|
| 467 | > </pre> |
|---|
| 468 | > </div> |
|---|
| 469 | > <div title="WritableTheme" modifier="Zooko" created="200812152209" modified="200812152255" tags="systemTheme" changecount="12"> |
|---|
| 470 | > <pre>|StyleSheet|##AuthorStyles| |
|---|
| 471 | > |StyleSheetReadOnly|##ReaderStyles| |
|---|
| 472 | > |
|---|
| 473 | > !AuthorStyles |
|---|
| 474 | > /*{{{*/ |
|---|
| 475 | > [[StyleSheet]] |
|---|
| 476 | > body { |
|---|
| 477 | > background: #eee; |
|---|
| 478 | > } |
|---|
| 479 | > /*}}}*/ |
|---|
| 480 | > |
|---|
| 481 | > !ReaderStyles |
|---|
| 482 | > /*{{{*/ |
|---|
| 483 | > [[StyleSheet]] |
|---|
| 484 | > body { |
|---|
| 485 | > } |
|---|
| 486 | > /*}}}*/</pre> |
|---|
| 487 | > </div> |
|---|