mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-05-30 09:12:17 +00:00
Merge branch 'master' into external-tasks
This commit is contained in:
@@ -59,7 +59,7 @@ Command.prototype.execute = function() {
|
||||
title: upgradeLibraryTitle,
|
||||
type: "application/json",
|
||||
"plugin-type": "library",
|
||||
"text": JSON.stringify({tiddlers: tiddlers},null,$tw.config.preferences.jsonSpaces)
|
||||
"text": JSON.stringify({tiddlers: tiddlers})
|
||||
};
|
||||
wiki.addTiddler(new $tw.Tiddler(pluginFields));
|
||||
return null;
|
||||
|
||||
@@ -65,10 +65,11 @@ Command.prototype.execute = function() {
|
||||
// Save each JSON file and collect the skinny data
|
||||
var pathname = path.resolve(self.commander.outputPath,basepath + encodeURIComponent(title) + ".json");
|
||||
$tw.utils.createFileDirectories(pathname);
|
||||
fs.writeFileSync(pathname,JSON.stringify(tiddler,null,$tw.config.preferences.jsonSpaces),"utf8");
|
||||
fs.writeFileSync(pathname,JSON.stringify(tiddler),"utf8");
|
||||
// Collect the skinny list data
|
||||
var pluginTiddlers = JSON.parse(tiddler.text),
|
||||
readmeContent = (pluginTiddlers.tiddlers[title + "/readme"] || {}).text,
|
||||
doesContainJavaScript = !!$tw.wiki.doesPluginInfoContainModules(pluginTiddlers),
|
||||
iconTiddler = pluginTiddlers.tiddlers[title + "/icon"] || {},
|
||||
iconType = iconTiddler.type,
|
||||
iconText = iconTiddler.text,
|
||||
@@ -76,7 +77,12 @@ Command.prototype.execute = function() {
|
||||
if(iconType && iconText) {
|
||||
iconContent = $tw.utils.makeDataUri(iconText,iconType);
|
||||
}
|
||||
skinnyList.push($tw.utils.extend({},tiddler,{text: undefined, readme: readmeContent, icon: iconContent}));
|
||||
skinnyList.push($tw.utils.extend({},tiddler,{
|
||||
text: undefined,
|
||||
readme: readmeContent,
|
||||
"contains-javascript": doesContainJavaScript ? "yes" : "no",
|
||||
icon: iconContent
|
||||
}));
|
||||
});
|
||||
// Save the catalogue tiddler
|
||||
if(skinnyListTitle) {
|
||||
|
||||
@@ -53,7 +53,7 @@ exports.field = function(source,operator,options) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if(source.byField) {
|
||||
if(source.byField && operator.operand) {
|
||||
indexedResults = source.byField(fieldname,operator.operand);
|
||||
if(indexedResults) {
|
||||
return indexedResults
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/is/binary.js
|
||||
type: application/javascript
|
||||
module-type: isfilteroperator
|
||||
|
||||
Filter function for [is[binary]]
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter function
|
||||
*/
|
||||
exports.binary = function(source,prefix,options) {
|
||||
var results = [];
|
||||
if(prefix === "!") {
|
||||
source(function(tiddler,title) {
|
||||
if(!options.wiki.isBinaryTiddler(title)) {
|
||||
results.push(title);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
source(function(tiddler,title) {
|
||||
if(options.wiki.isBinaryTiddler(title)) {
|
||||
results.push(title);
|
||||
}
|
||||
});
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -27,8 +27,6 @@ exports.init = function(parser) {
|
||||
};
|
||||
|
||||
exports.parse = function() {
|
||||
// Move past the match
|
||||
this.parser.pos = this.matchRegExp.lastIndex;
|
||||
// Move past the match
|
||||
this.parser.pos = this.matchRegExp.lastIndex;
|
||||
// Get the match details
|
||||
|
||||
@@ -60,6 +60,8 @@ PluginSwitcher.prototype.switchPlugins = function() {
|
||||
}
|
||||
};
|
||||
accumulatePlugin(selectedPluginTitle);
|
||||
// Read the plugin info for the incoming plugins
|
||||
var changes = $tw.wiki.readPluginInfo(plugins);
|
||||
// Unregister any existing theme tiddlers
|
||||
var unregisteredTiddlers = $tw.wiki.unregisterPluginTiddlers(this.pluginType);
|
||||
// Register any new theme tiddlers
|
||||
|
||||
@@ -48,12 +48,9 @@ GitLabSaver.prototype.save = function(text,method,callback) {
|
||||
var uri = endpoint + "/projects/" + encodeURIComponent(repo) + "/repository/";
|
||||
// Perform a get request to get the details (inc shas) of files in the same path as our file
|
||||
$tw.utils.httpRequest({
|
||||
url: uri + "tree/" + encodeURIComponent(path.replace(/^\/+|\/$/g, '')),
|
||||
url: uri + "tree/?path=" + encodeURIComponent(path.replace(/^\/+|\/$/g, '')) + "&branch=" + encodeURIComponent(branch.replace(/^\/+|\/$/g, '')),
|
||||
type: "GET",
|
||||
headers: headers,
|
||||
data: {
|
||||
ref: branch
|
||||
},
|
||||
callback: function(err,getResponseDataJson,xhr) {
|
||||
var getResponseData,sha = "";
|
||||
if(err && xhr.status !== 404) {
|
||||
@@ -71,7 +68,7 @@ GitLabSaver.prototype.save = function(text,method,callback) {
|
||||
}
|
||||
var data = {
|
||||
commit_message: $tw.language.getRawString("ControlPanel/Saving/GitService/CommitMessage"),
|
||||
content: $tw.utils.base64Encode(text),
|
||||
content: text,
|
||||
branch: branch,
|
||||
sha: sha
|
||||
};
|
||||
|
||||
@@ -12,22 +12,21 @@ GET /
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var zlib = require('zlib');
|
||||
var zlib = require("zlib");
|
||||
|
||||
exports.method = "GET";
|
||||
|
||||
exports.path = /^\/$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
var acceptEncoding = request.headers['accept-encoding'];
|
||||
if (!acceptEncoding) { acceptEncoding = ''; }
|
||||
|
||||
var text = state.wiki.renderTiddler(state.server.get("root-render-type"),state.server.get("root-tiddler"));
|
||||
|
||||
var responseHeaders = {
|
||||
var acceptEncoding = request.headers["accept-encoding"];
|
||||
if(!acceptEncoding) {
|
||||
acceptEncoding = "";
|
||||
}
|
||||
var text = state.wiki.renderTiddler(state.server.get("root-render-type"),state.server.get("root-tiddler")),
|
||||
responseHeaders = {
|
||||
"Content-Type": state.server.get("root-serve-type")
|
||||
};
|
||||
|
||||
/*
|
||||
If the gzip=yes flag for `listen` is set, check if the user agent permits
|
||||
compression. If so, compress our response. Note that we use the synchronous
|
||||
@@ -36,15 +35,14 @@ exports.handler = function(request,response,state) {
|
||||
*/
|
||||
if(state.server.enableGzip) {
|
||||
if (/\bdeflate\b/.test(acceptEncoding)) {
|
||||
responseHeaders['Content-Encoding'] = 'deflate';
|
||||
responseHeaders["Content-Encoding"] = "deflate";
|
||||
text = zlib.deflateSync(text);
|
||||
} else if (/\bgzip\b/.test(acceptEncoding)) {
|
||||
responseHeaders['Content-Encoding'] = 'gzip';
|
||||
responseHeaders["Content-Encoding"] = "gzip";
|
||||
text = zlib.gzipSync(text);
|
||||
}
|
||||
}
|
||||
|
||||
response.writeHead(200, responseHeaders);
|
||||
response.writeHead(200,responseHeaders);
|
||||
response.end(text);
|
||||
};
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ exports.before = ["startup"];
|
||||
exports.after = ["load-modules"];
|
||||
exports.synchronous = true;
|
||||
|
||||
var TITLE_INFO_PLUGIN = "$:/temp/info-plugin";
|
||||
|
||||
exports.startup = function() {
|
||||
// Collect up the info tiddlers
|
||||
var infoTiddlerFields = {};
|
||||
@@ -32,15 +34,15 @@ exports.startup = function() {
|
||||
});
|
||||
}
|
||||
});
|
||||
// Bake the info tiddlers into a plugin
|
||||
// Bake the info tiddlers into a plugin. We use the non-standard plugin-type "info" because ordinary plugins are only registered asynchronously after being loaded dynamically
|
||||
var fields = {
|
||||
title: "$:/temp/info-plugin",
|
||||
title: TITLE_INFO_PLUGIN,
|
||||
type: "application/json",
|
||||
"plugin-type": "info",
|
||||
text: JSON.stringify({tiddlers: infoTiddlerFields},null,$tw.config.preferences.jsonSpaces)
|
||||
};
|
||||
$tw.wiki.addTiddler(new $tw.Tiddler(fields));
|
||||
$tw.wiki.readPluginInfo();
|
||||
$tw.wiki.readPluginInfo([TITLE_INFO_PLUGIN]);
|
||||
$tw.wiki.registerPluginTiddlers("info");
|
||||
$tw.wiki.unpackPluginTiddlers();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*\
|
||||
title: $:/core/modules/startup/plugins.js
|
||||
type: application/javascript
|
||||
module-type: startup
|
||||
|
||||
Startup logic concerned with managing plugins
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
// Export name and synchronous status
|
||||
exports.name = "plugins";
|
||||
exports.after = ["load-modules"];
|
||||
exports.synchronous = true;
|
||||
|
||||
var TITLE_REQUIRE_RELOAD_DUE_TO_PLUGIN_CHANGE = "$:/status/RequireReloadDueToPluginChange";
|
||||
|
||||
var PREFIX_CONFIG_REGISTER_PLUGIN_TYPE = "$:/config/RegisterPluginType/";
|
||||
|
||||
exports.startup = function() {
|
||||
$tw.wiki.addTiddler({title: TITLE_REQUIRE_RELOAD_DUE_TO_PLUGIN_CHANGE,text: "no"});
|
||||
$tw.wiki.addEventListener("change",function(changes) {
|
||||
var changesToProcess = [],
|
||||
requireReloadDueToPluginChange = false;
|
||||
$tw.utils.each(Object.keys(changes),function(title) {
|
||||
var tiddler = $tw.wiki.getTiddler(title),
|
||||
containsModules = $tw.wiki.doesPluginContainModules(title);
|
||||
if(containsModules) {
|
||||
requireReloadDueToPluginChange = true;
|
||||
} else if(tiddler) {
|
||||
var pluginType = tiddler.fields["plugin-type"];
|
||||
if($tw.wiki.getTiddlerText(PREFIX_CONFIG_REGISTER_PLUGIN_TYPE + (tiddler.fields["plugin-type"] || ""),"no") === "yes") {
|
||||
changesToProcess.push(title);
|
||||
}
|
||||
}
|
||||
});
|
||||
if(requireReloadDueToPluginChange) {
|
||||
$tw.wiki.addTiddler({title: TITLE_REQUIRE_RELOAD_DUE_TO_PLUGIN_CHANGE,text: "yes"});
|
||||
}
|
||||
// Read or delete the plugin info of the changed tiddlers
|
||||
if(changesToProcess.length > 0) {
|
||||
var changes = $tw.wiki.readPluginInfo(changesToProcess);
|
||||
if(changes.modifiedPlugins.length > 0 || changes.deletedPlugins.length > 0) {
|
||||
// (Re-)register any modified plugins
|
||||
$tw.wiki.registerPluginTiddlers(null,changes.modifiedPlugins);
|
||||
// Unregister any deleted plugins
|
||||
$tw.wiki.unregisterPluginTiddlers(null,changes.deletedPlugins);
|
||||
// Unpack the shadow tiddlers
|
||||
$tw.wiki.unpackPluginTiddlers();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -39,26 +39,29 @@ exports.upgrade = function(wiki,titles,tiddlers) {
|
||||
$tw.utils.each(titles,function(title) {
|
||||
var incomingTiddler = tiddlers[title];
|
||||
// Check if we're dealing with a plugin
|
||||
if(incomingTiddler && incomingTiddler["plugin-type"] && 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;
|
||||
messages[title] = $tw.language.getString("Import/Upgrader/Plugins/Upgraded",{variables: {incoming: incomingTiddler.version, upgraded: libraryTiddler.version}});
|
||||
return;
|
||||
}
|
||||
// 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);
|
||||
messages[title] = $tw.language.getString("Import/Upgrader/Plugins/Suppressed/Version",{variables: {incoming: incomingTiddler.version, existing: existingTiddler.fields.version}});
|
||||
if(incomingTiddler && incomingTiddler["plugin-type"]) {
|
||||
// Check whether the plugin contains JS modules
|
||||
var doesContainJavaScript = $tw.wiki.doesPluginInfoContainModules(JSON.parse(incomingTiddler.text)) ? ($tw.wiki.getTiddlerText("$:/language/ControlPanel/Plugins/PluginWillRequireReload") + " ") : "";
|
||||
messages[title] = doesContainJavaScript;
|
||||
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;
|
||||
messages[title] = doesContainJavaScript + $tw.language.getString("Import/Upgrader/Plugins/Upgraded",{variables: {incoming: incomingTiddler.version, upgraded: libraryTiddler.version}});
|
||||
return;
|
||||
}
|
||||
// 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);
|
||||
messages[title] = doesContainJavaScript + $tw.language.getString("Import/Upgrader/Plugins/Suppressed/Version",{variables: {incoming: incomingTiddler.version, existing: existingTiddler.fields.version}});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(incomingTiddler && incomingTiddler["plugin-type"]) {
|
||||
// Check whether the plugin is on the blocked list
|
||||
var blockInfo = BLOCKED_PLUGINS[title];
|
||||
if(blockInfo) {
|
||||
|
||||
@@ -35,17 +35,17 @@ exports.upgrade = function(wiki,titles,tiddlers) {
|
||||
}
|
||||
for(var t=0; t<WARN_IMPORT_PREFIX_LIST.length; t++) {
|
||||
var prefix = WARN_IMPORT_PREFIX_LIST[t];
|
||||
if(title.substr(0,prefix.length) === prefix) {
|
||||
if(title.substr(0,prefix.length) === prefix && wiki.isShadowTiddler(title)) {
|
||||
showAlert = true;
|
||||
messages[title] = $tw.language.getString("Import/Upgrader/System/Warning");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(showAlert) {
|
||||
var logger = new $tw.utils.Logger("import");
|
||||
logger.alert($tw.language.getString("Import/Upgrader/System/Alert"));
|
||||
}
|
||||
});
|
||||
if(showAlert) {
|
||||
var logger = new $tw.utils.Logger("import");
|
||||
logger.alert($tw.language.getString("Import/Upgrader/System/Alert"));
|
||||
}
|
||||
return messages;
|
||||
};
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ DeleteFieldWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
tiddler = this.wiki.getTiddler(self.actionTiddler),
|
||||
removeFields = {},
|
||||
hasChanged = false;
|
||||
if(this.actionField) {
|
||||
if(this.actionField && tiddler) {
|
||||
removeFields[this.actionField] = undefined;
|
||||
if(this.actionField in tiddler.fields) {
|
||||
hasChanged = true;
|
||||
|
||||
@@ -221,6 +221,16 @@ exports.isImageTiddler = function(title) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.isBinaryTiddler = function(title) {
|
||||
var tiddler = this.getTiddler(title);
|
||||
if(tiddler) {
|
||||
var contentTypeInfo = $tw.config.contentTypeInfo[tiddler.fields.type || "text/vnd.tiddlywiki"];
|
||||
return !!contentTypeInfo && contentTypeInfo.encoding === "base64";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Like addTiddler() except it will silently reject any plugin tiddlers that are older than the currently loaded version. Returns true if the tiddler was imported
|
||||
*/
|
||||
@@ -1450,5 +1460,25 @@ exports.invokeUpgraders = function(titles,tiddlers) {
|
||||
return messages;
|
||||
};
|
||||
|
||||
// Determine whether a plugin by title contains JS modules.
|
||||
exports.doesPluginContainModules = function(title) {
|
||||
return this.doesPluginInfoContainModules(this.getPluginInfo(title) || this.getTiddlerDataCached(title));
|
||||
};
|
||||
|
||||
// Determine whether a plugin info structure contains JS modules.
|
||||
exports.doesPluginInfoContainModules = function(pluginInfo) {
|
||||
if(pluginInfo) {
|
||||
var foundModule = false;
|
||||
$tw.utils.each(pluginInfo.tiddlers,function(tiddler) {
|
||||
if(tiddler.type === "application/javascript" && $tw.utils.hop(tiddler,"module-type")) {
|
||||
foundModule = true;
|
||||
}
|
||||
});
|
||||
return foundModule;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user