From 38b088eabf49e64b35f957c5f4fa45ac21796730 Mon Sep 17 00:00:00 2001 From: bimlas Date: Mon, 10 Dec 2018 09:00:42 +0100 Subject: [PATCH 1/4] Warn when importing core tiddlers See https://groups.google.com/d/msg/tiddlywiki/YZlPGP0qX1o/3tUpyoHXDgAJ --- core/language/en-GB/Import.multids | 1 + core/modules/widgets/navigator.js | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core/language/en-GB/Import.multids b/core/language/en-GB/Import.multids index 083086606..3c7ced320 100644 --- a/core/language/en-GB/Import.multids +++ b/core/language/en-GB/Import.multids @@ -19,3 +19,4 @@ Upgrader/Plugins/Upgraded: Upgraded plugin from <> to <> Upgrader/State/Suppressed: Blocked temporary state tiddler Upgrader/System/Suppressed: Blocked system tiddler Upgrader/ThemeTweaks/Created: Migrated theme tweak from <$text text=<>/> +Warning/Core: You are about importing risky tiddlers (<>). It is strongly recommend in the strongest terms NOT to use any hack that requires overwriting a core module, because it is likely to make the system unusable. Never import such tiddlers into an important wiki, just into a testing environment! diff --git a/core/modules/widgets/navigator.js b/core/modules/widgets/navigator.js index 2bf0ac594..3109fdea9 100755 --- a/core/modules/widgets/navigator.js +++ b/core/modules/widgets/navigator.js @@ -485,7 +485,8 @@ NavigatorWidget.prototype.handleNewTiddlerEvent = function(event) { // Import JSON tiddlers into a pending import tiddler NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) { // Get the tiddlers - var tiddlers = []; + var tiddlers = [], + warning = []; try { tiddlers = JSON.parse(event.param); } catch(e) { @@ -506,10 +507,26 @@ NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) { tiddlerFields.title = $tw.utils.trim(tiddlerFields.title); var title = tiddlerFields.title; if(title) { + if(title.indexOf('$:/core/') === 0) { + warning.push(title); + } incomingTiddlers.push(title); importData.tiddlers[title] = tiddlerFields; } }); + // Show warning about risky tiddlers + if(warning.length) { + var titles = []; + $tw.utils.each(warning,function(title) { + titles.push(title); + }); + var logger = new $tw.utils.Logger("import"); + logger.alert($tw.language.getString( + "Import/Warning/Core", + {variables: { + "titles": titles.join(", "), + }})); + } // Give the active upgrader modules a chance to process the incoming tiddlers var messages = this.wiki.invokeUpgraders(incomingTiddlers,importData.tiddlers); $tw.utils.each(messages,function(message,title) { From 18ed2faf824aff1686f0165d025dd406e04da6a8 Mon Sep 17 00:00:00 2001 From: bimlas Date: Mon, 10 Dec 2018 22:32:32 +0100 Subject: [PATCH 2/4] Implement in $:/core/upgraders instead of navigator.js The core module tiddlers are not blocked, they are only marked. --- core/language/en-GB/Import.multids | 3 ++- core/modules/upgraders/system.js | 17 +++++++++++++++-- core/modules/widgets/navigator.js | 19 +------------------ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/core/language/en-GB/Import.multids b/core/language/en-GB/Import.multids index 3c7ced320..bb8376d44 100644 --- a/core/language/en-GB/Import.multids +++ b/core/language/en-GB/Import.multids @@ -18,5 +18,6 @@ Upgrader/Plugins/Suppressed/Version: Blocked plugin (due to incoming < Upgrader/Plugins/Upgraded: Upgraded plugin from <> to <> Upgrader/State/Suppressed: Blocked temporary state tiddler Upgrader/System/Suppressed: Blocked system tiddler +Upgrader/System/Warning: Warning: Core module tiddler +Upgrader/System/Alert: You are about importing core module tiddlers. It is strongly recommend in the strongest terms NOT to use any hack that requires overwriting a core module, because it is likely to make the system unusable. Never import such tiddlers into an important wiki, just into a testing environment! Upgrader/ThemeTweaks/Created: Migrated theme tweak from <$text text=<>/> -Warning/Core: You are about importing risky tiddlers (<>). It is strongly recommend in the strongest terms NOT to use any hack that requires overwriting a core module, because it is likely to make the system unusable. Never import such tiddlers into an important wiki, just into a testing environment! diff --git a/core/modules/upgraders/system.js b/core/modules/upgraders/system.js index 3dae00422..a5f9970da 100644 --- a/core/modules/upgraders/system.js +++ b/core/modules/upgraders/system.js @@ -13,11 +13,13 @@ Upgrader module that suppresses certain system tiddlers that shouldn't be import "use strict"; var DONT_IMPORT_LIST = ["$:/StoryList","$:/HistoryList"], - DONT_IMPORT_PREFIX_LIST = ["$:/temp/","$:/state/"]; + DONT_IMPORT_PREFIX_LIST = ["$:/temp/","$:/state/"], + WARN_IMPORT_PREFIX_LIST = ["$:/core/modules/"]; exports.upgrade = function(wiki,titles,tiddlers) { var self = this, - messages = {}; + messages = {}, + showAlert = false; // Check for tiddlers on our list $tw.utils.each(titles,function(title) { if(DONT_IMPORT_LIST.indexOf(title) !== -1) { @@ -31,6 +33,17 @@ exports.upgrade = function(wiki,titles,tiddlers) { messages[title] = $tw.language.getString("Import/Upgrader/State/Suppressed"); } } + for(var t=0; t Date: Mon, 4 Feb 2019 22:09:31 +0100 Subject: [PATCH 3/4] Suggested slightly "better English" wording for the warning --- core/language/en-GB/Import.multids | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/language/en-GB/Import.multids b/core/language/en-GB/Import.multids index bb8376d44..ab40f3c77 100644 --- a/core/language/en-GB/Import.multids +++ b/core/language/en-GB/Import.multids @@ -19,5 +19,5 @@ Upgrader/Plugins/Upgraded: Upgraded plugin from <> to <> Upgrader/State/Suppressed: Blocked temporary state tiddler Upgrader/System/Suppressed: Blocked system tiddler Upgrader/System/Warning: Warning: Core module tiddler -Upgrader/System/Alert: You are about importing core module tiddlers. It is strongly recommend in the strongest terms NOT to use any hack that requires overwriting a core module, because it is likely to make the system unusable. Never import such tiddlers into an important wiki, just into a testing environment! +Upgrader/System/Alert: You are about to import a tiddler that will overwrite a core module tiddler. This is a risky action that may make the system unstable. It is strongly recommended that you do NOT overwrite these tiddlers in an important TiddlyWiki; only in a testing environment. Upgrader/ThemeTweaks/Created: Migrated theme tweak from <$text text=<>/> From b08a7e3f0484e5014817b266fdda31ac3115cdf1 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 5 Feb 2019 16:20:44 +0000 Subject: [PATCH 4/4] Wording tweaks --- core/language/en-GB/Import.multids | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/language/en-GB/Import.multids b/core/language/en-GB/Import.multids index ab40f3c77..10a01d7dd 100644 --- a/core/language/en-GB/Import.multids +++ b/core/language/en-GB/Import.multids @@ -18,6 +18,6 @@ Upgrader/Plugins/Suppressed/Version: Blocked plugin (due to incoming < Upgrader/Plugins/Upgraded: Upgraded plugin from <> to <> Upgrader/State/Suppressed: Blocked temporary state tiddler Upgrader/System/Suppressed: Blocked system tiddler -Upgrader/System/Warning: Warning: Core module tiddler -Upgrader/System/Alert: You are about to import a tiddler that will overwrite a core module tiddler. This is a risky action that may make the system unstable. It is strongly recommended that you do NOT overwrite these tiddlers in an important TiddlyWiki; only in a testing environment. +Upgrader/System/Warning: Core module tiddler +Upgrader/System/Alert: You are about to import a tiddler that will overwrite a core module tiddler. This is not recommended as it may make the system unstable Upgrader/ThemeTweaks/Created: Migrated theme tweak from <$text text=<>/>