From ba576d9f1b2146cec293447b2968e34f0c594a05 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sat, 19 Apr 2014 09:36:08 +0100 Subject: [PATCH] Add support for safe mode --- boot/boot.js | 37 +++++++++++++++++++ editions/tw5.com/tiddlers/Upgrading.tid | 6 ++- .../tw5.com/tiddlers/features/SafeMode.tid | 21 +++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 editions/tw5.com/tiddlers/features/SafeMode.tid diff --git a/boot/boot.js b/boot/boot.js index b4b955609..9e0a0537b 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -1044,6 +1044,37 @@ $tw.Wiki.prototype.defineShadowModules = function() { }); }; +/* +Enable safe mode by deleting any tiddlers that override a shadow tiddler +*/ +$tw.Wiki.prototype.processSafeMode = function() { + var self = this, + overrides = []; + // Find the overriding tiddlers + this.each(function(tiddler,title) { + if(self.isShadowTiddler(title)) { + console.log(title); + overrides.push(title); + } + }); + // Assemble a report tiddler + var titleReportTiddler = "TiddlyWiki Safe Mode", + report = []; + report.push("TiddlyWiki has been started in [[safe mode|http://tiddlywiki.com/static/SafeMode.html]]. Most customisations have been disabled by renaming the following tiddlers:") + // Delete the overrides + overrides.forEach(function(title) { + var tiddler = self.getTiddler(title), + newTitle = "SAFE: " + title; + self.deleteTiddler(title); + self.addTiddler(new $tw.Tiddler(tiddler, {title: newTitle})); + report.push("* [[" + title + "|" + newTitle + "]]"); + }); + report.push() + this.addTiddler(new $tw.Tiddler({title: titleReportTiddler, text: report.join("\n\n")})); + // Set $:/DefaultTiddlers to point to our report + this.addTiddler(new $tw.Tiddler({title: "$:/DefaultTiddlers", text: "[[" + titleReportTiddler + "]]"})); +}; + /* Extracts tiddlers from a typed block of text, specifying default field values */ @@ -1563,6 +1594,8 @@ readBrowserTiddlers: whether to read tiddlers from the HTML file we're executing */ $tw.boot.startup = function(options) { options = options || {}; + // Check for safe mode + $tw.safeMode = $tw.browser && location.hash === "#:safe"; // Initialise some more $tw properties $tw.utils.deepDefaults($tw,{ modules: { // Information about each module @@ -1646,6 +1679,10 @@ $tw.boot.startup = function(options) { $tw.wiki.readPluginInfo(); $tw.wiki.registerPluginTiddlers("plugin"); $tw.wiki.unpackPluginTiddlers(); + // Process "safe mode" + if($tw.safeMode) { + $tw.wiki.processSafeMode(); + } // Register typed modules from the tiddlers we've just loaded $tw.wiki.defineTiddlerModules(); // And any modules within plugins diff --git a/editions/tw5.com/tiddlers/Upgrading.tid b/editions/tw5.com/tiddlers/Upgrading.tid index 0edb495b4..8060ea772 100644 --- a/editions/tw5.com/tiddlers/Upgrading.tid +++ b/editions/tw5.com/tiddlers/Upgrading.tid @@ -1,5 +1,5 @@ created: 20131202102427114 -modified: 20140126135354379 +modified: 20140419082835626 tags: howto title: Upgrading type: text/vnd.tiddlywiki @@ -47,3 +47,7 @@ This will download a file called ''empty.html'' to your computer. This file is t ! Offline upgrading You can also download http://tiddlywiki.com/empty.html locally and perform the same drag-and-drop procedure to upgrade your files. + +! Problems with Upgrades + +Particularly during the beta, it is possible for a customisation applied in a previous version to break when upgraded to the latest version. Use SafeMode to investigate and fix these problems. diff --git a/editions/tw5.com/tiddlers/features/SafeMode.tid b/editions/tw5.com/tiddlers/features/SafeMode.tid new file mode 100644 index 000000000..30563731e --- /dev/null +++ b/editions/tw5.com/tiddlers/features/SafeMode.tid @@ -0,0 +1,21 @@ +created: 20140419082845576 +modified: 20140419083436245 +tags: features +title: SafeMode +type: text/vnd.tiddlywiki + +! Introduction + +Safe mode provides a way to disabling most customisations in TiddlyWiki. This is useful because if TiddlyWiki is customised incorrectly it can be rendered inoperable. A particular issue is that some customisations break when upgrading to a newer core version of TiddlyWiki (especially during the beta). + +! Enabling Safe Mode + +Safe mode is enabled in the browser by starting TiddlyWiki with the URL hash set to the string `#:safe`. For example: + +http://tiddlywiki.com/#:safe + +! How Safe Mode Works + +In safe mode, any tiddlers that override shadow tiddlers are renamed to give them the prefix `SAFE: `, thus restoring the underlying shadow tiddler. + +A report tiddler is displayed that allows you to inspect the tiddlers that were renamed.