Making something similar to the creator and modifier fields?

The created, creator, modified and modifier fields are handled automatically in tiddlywiki. I Imagin they are a function of the editor, but they can also be updated when other tiddlywiki actions modify or create the tiddler.

I would like to reproduce this method to set a created-in wikiname and modified in wikiname and possibly other values. If that value is available in an $:/info or config tiddler.

If any one has some insight as to how to achieve this, please let me know.

  • If in passing you can explain how when transcluded the created and modified fields receive their formatting that would also help, but is not essential.

Look in $:/core/modules/wiki.js for exports.getCreationFields and exports.getModificationFields

2 Likes

Thanks Eric that looks right on target. I suppose I need to redefine those functions in $:/core/modules/wiki.js or is there a way to copy them to a new tiddler before modification so the revised functions override the core functions?

I have found the code and attempted as a script kiddy to make changes, however this is failing;

If anyone can help it would be appreciated.

The following contains what is needed but the resulting wiki fails with;

ReferenceError: assignment to undeclared variable wikicreator

/*
Return a hashmap of the fields that should be set when a tiddler is created
*/
exports.getCreationFields = function() {
	if(this.getTiddlerText(TIMESTAMP_DISABLE_TITLE,"").toLowerCase() !== "yes") {
		var fields = {
				created: new Date()
			},
			creator = this.getTiddlerText(USER_NAME_TITLE);
			wikicreator = this.getTiddlerText(WIKI_NAME_TITLE);
		if(creator) {
			fields.creator = creator; 
            fields.creatorwiki = creatorwiki;
		}
		return fields;
	} else {
		return {};
	}
};
  • here my only mods were the lines containing wikicreator

Earlier I added the last var in this set;

var widget = require("$:/core/modules/widgets/widget.js");

var USER_NAME_TITLE = "$:/status/UserName",
	TIMESTAMP_DISABLE_TITLE = "$:/config/TimestampDisable";

var WIKI_NAME_TITLE = "$:/status/WikiName";

Once I have the correct pattern I will replicate for exports.getModificationFields

I have succeeded thanks with the following code modified/added

var USER_NAME_TITLE = "$:/status/UserName",
	TIMESTAMP_DISABLE_TITLE = "$:/config/TimestampDisable",
    WIKI_NAME_TITLE = "$:/status/WikiName";

...

exports.getCreationFields = function() {
	if(this.getTiddlerText(TIMESTAMP_DISABLE_TITLE,"").toLowerCase() !== "yes") {
		var fields = {
				created: new Date()
			},
			creator = this.getTiddlerText(USER_NAME_TITLE),
			creatorwiki = this.getTiddlerText(WIKI_NAME_TITLE);
		if(creator) {
			fields.Creator = creator;
		}
		if(creatorwiki) {
			fields.creatorwiki = creatorwiki;
		}
		return fields;
	} else {
		return {};
	}
};

...

[Edited]

I discovered a use case for tiddltwiki.com when modifying core system tiddlers loaded at boot, since I can’t save, only download,

  • modify tiddlywiki system files then download .
  • Open the downloaded file in the browser
  • If that fails return to tiddlywiki.com modify and try again
  • If that does not fail see if the change work.
  • Repeat this list for the next change.

Slightly different code in the exports.getModificationFields but I have it all working thanks again @EricShulman

For those 2 lines you should also add at string-trim function to remove preceding and trailing whitespace, just to be sure.

			creator = this.getTiddlerText(USER_NAME_TITLE).trim(),
			creatorwiki = this.getTiddlerText(WIKI_NAME_TITLE).trim();

see: String.prototype.trim() - JavaScript | MDN