2014-07-12 08:09:36 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/upgraders/plugins.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: upgrader
|
|
|
|
|
|
|
|
Upgrader module that checks that plugins are newer than any already installed version
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var UPGRADE_LIBRARY_TITLE = "$:/UpgradeLibrary";
|
|
|
|
|
2014-08-02 11:42:05 +00:00
|
|
|
var BLOCKED_PLUGINS = {
|
2014-12-21 16:04:40 +00:00
|
|
|
"$:/themes/tiddlywiki/stickytitles": {
|
|
|
|
versions: ["*"]
|
|
|
|
},
|
2014-08-02 11:42:05 +00:00
|
|
|
"$:/plugins/tiddlywiki/fullscreen": {
|
|
|
|
versions: ["*"]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-12 08:09:36 +00:00
|
|
|
exports.upgrade = function(wiki,titles,tiddlers) {
|
|
|
|
var self = this,
|
|
|
|
messages = {},
|
|
|
|
upgradeLibrary,
|
|
|
|
getLibraryTiddler = function(title) {
|
|
|
|
if(!upgradeLibrary) {
|
|
|
|
upgradeLibrary = wiki.getTiddlerData(UPGRADE_LIBRARY_TITLE,{});
|
|
|
|
upgradeLibrary.tiddlers = upgradeLibrary.tiddlers || {};
|
|
|
|
}
|
2014-08-02 11:42:05 +00:00
|
|
|
return upgradeLibrary.tiddlers[title];
|
2014-07-12 08:09:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Go through all the incoming tiddlers
|
|
|
|
$tw.utils.each(titles,function(title) {
|
|
|
|
var incomingTiddler = tiddlers[title];
|
|
|
|
// Check if we're dealing with a plugin
|
2019-09-17 07:49:39 +00:00
|
|
|
if(incomingTiddler && incomingTiddler["plugin-type"]) {
|
|
|
|
// Check whether the plugin contains JS modules
|
2020-05-06 10:27:50 +00:00
|
|
|
var requiresReload = wiki.doesPluginInfoRequireReload(JSON.parse(incomingTiddler.text)) ? (wiki.getTiddlerText("$:/language/ControlPanel/Plugins/PluginWillRequireReload") + " ") : "";
|
2019-09-27 15:47:55 +00:00
|
|
|
messages[title] = requiresReload;
|
2019-09-17 07:49:39 +00:00
|
|
|
if(incomingTiddler.version) {
|
|
|
|
// Upgrade the incoming plugin if it is in the upgrade library
|
|
|
|
var libraryTiddler = getLibraryTiddler(title);
|
|
|
|
if(libraryTiddler && libraryTiddler["plugin-type"] && libraryTiddler.version) {
|
|
|
|
tiddlers[title] = libraryTiddler;
|
2019-09-27 15:47:55 +00:00
|
|
|
messages[title] = requiresReload + $tw.language.getString("Import/Upgrader/Plugins/Upgraded",{variables: {incoming: incomingTiddler.version, upgraded: libraryTiddler.version}});
|
2014-08-02 11:42:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-09-17 07:49:39 +00:00
|
|
|
// Suppress the incoming plugin if it is older than the currently installed one
|
|
|
|
var existingTiddler = wiki.getTiddler(title);
|
|
|
|
if(existingTiddler && existingTiddler.hasField("plugin-type") && existingTiddler.hasField("version")) {
|
|
|
|
// Reject the incoming plugin by blanking all its fields
|
|
|
|
if($tw.utils.checkVersions(existingTiddler.fields.version,incomingTiddler.version)) {
|
|
|
|
tiddlers[title] = Object.create(null);
|
2020-11-17 19:12:41 +00:00
|
|
|
messages[title] = $tw.language.getString("Import/Upgrader/Plugins/Suppressed/Version",{variables: {incoming: incomingTiddler.version, existing: existingTiddler.fields.version}});
|
2019-09-17 07:49:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-08-02 11:42:05 +00:00
|
|
|
}
|
|
|
|
// Check whether the plugin is on the blocked list
|
|
|
|
var blockInfo = BLOCKED_PLUGINS[title];
|
|
|
|
if(blockInfo) {
|
|
|
|
if(blockInfo.versions.indexOf("*") !== -1 || (incomingTiddler.version && blockInfo.versions.indexOf(incomingTiddler.version) !== -1)) {
|
|
|
|
tiddlers[title] = Object.create(null);
|
|
|
|
messages[title] = $tw.language.getString("Import/Upgrader/Plugins/Suppressed/Incompatible");
|
2014-07-12 08:09:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return messages;
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|