A fair warning (thanks @Charlie_Veniot !) : this cannot prevent anyone from downloading your wiki (ctrl-S), or making it appear like your TiddlyWiki at that URL contains content that it doesn’t actually have (using the browser developer tools for example).
If your goal is to prevent users from accidentally messing with your wiki or to remove clutter from the UI, this is good enough, but a true read-only wiki would require a much more complex solution (if at all possible).
Since TW 5.1.14, there is an easy way to check if the wiki is online or served locally, thanks to the InfoMechanism :
This wiki is {{{ [{$:/info/url/protocol}match[file:]then[local]else[online]] }}}
.
Using this, we can hide the edit buttons only when the protocol isn’t file:
, with CSS.
Create a tiddler with the tag $:/tags/Stylesheet
, then copy/paste the following wikitext:
<$reveal type="match" default={{{ [{$:/info/url/protocol}match[file:]] }}} text="">
button:is(
[aria-label="edit"],
[aria-label="delete"],
[aria-label*="new"],
[aria-label="clone"],
[aria-label="set"] ) {
display:none;
}
</$reveal>
When the url protocol doesn’t match file:
, thus when your wiki is online, the CSS above hide all the buttons with the specified aria-label. *=
means that if there is the word “new” somewhere inside the aria label, then it must be hidden. That way we can hide both the new tiddler
and new journal
buttons. Learn more about CSS selectors here.
If you want to make your wiki editable when run in safe mode, use this filter instead :
{{{[[TiddlyWiki Safe Mode]is[tiddler]][{$:/info/url/protocol}match[file:]]}}}
You can also use $:/status/IsLoggedIn
if applicable. See https://tiddlywiki.com/#WidgetMessage%3A%20tm-login
Maybe this is common knowledge, but since I’ve struggled for a bit to find a solution and the one I found involved using a plugin, I thought this may be helpful for others
Online demo : TiddlyTweaks — Small tweaks for TiddlyWiki
This trick could also be used to set a “reader” layout on startup using the tag $:/tags/StartupAction/Browser
More steps you can do to restrict your wiki :
Disable Drag and Drop
Set $:/config/DragAndDrop/Enable
to no
to prevent users from drag&dropping tiddlers in the wiki.