Plugins
A plugin is a program compiled to WebAssembly. It can provide modules, respond to events on the site, and show content on profiles. Plugins run in a sandbox and can use only the permissions they declare.
Plugins are still in beta. To request more functions for plugins to call, or to report other problems, contact WikitTeam directly.
Installing a plugin
Put the plugin in a folder named after it under plugins/ in the data directory:
plugins/
scpper/
plugin.json
plugin.wasm
config.jsonIf the plugin needs settings, create config.json in the same folder:
{
"config": { "scpper_url": "http://127.0.0.1:8100" },
"allowed_hosts": ["127.0.0.1"]
}The keys under config are passed to the plugin as they are. allowed_hosts sets the hosts the plugin can reach, and applies only to plugins with the http permission.
Restart pwikit after adding, updating or removing a plugin. A newly installed plugin is disabled on every site. Enable it under Plugins in each site's admin panel.
Writing a plugin
Plugins can be written in any language that compiles to WASI, and talk to pwikit through the Extism PDK. In Go:
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o plugin.wasm .plugin.json
| Field | Description |
|---|---|
name | Plugin name, the same as its folder |
version | Version number |
api | Interface version, currently 1 |
title, description | Name and description shown in the admin panel |
modules | Modules it provides, such as [{"name": "coinrank"}]. Add "content": true to a module that takes a body |
events | Events it subscribes to: page.created, page.edited, page.deleted, vote.changed, post.created |
permissions | kv, pages.read, http |
allowed_hosts | Hosts it can reach |
profile_title | When set, profiles show a block with this title at the bottom |
profile_badge | When true, profiles show a badge next to the username |
memory_pages | Memory limit in 64 KB pages, 256 by default, at most 1024 |
timeout_ms | Time limit per call, 1000 by default, at most 5000 |
Exports
Each export takes a JSON object as input. Its output is rendered as wikitext.
| Export | Called when |
|---|---|
module | A page uses one of the plugin's modules |
event | A subscribed event happens |
profile | A profile shows the plugin's block |
badge | A profile shows the plugin's badge |
Host functions
| Function | Permission | Purpose |
|---|---|---|
kv_get, kv_set, kv_delete | kv | Read and write the plugin's key-value store on the current site |
page_get | pages.read | Get a public page's title, tags, authors and rating |
Example: installing the scpper plugin
The scpper plugin shows a member's coin ranking and holdings next to the username on profiles, and provides a wealth ranking module and a tip button. Deploy scpper first, as described in Mounting other programs. These steps assume pwikit is installed in /opt/pwikit.
Download
scpper.zipfrom the releases of pwikit-plugins and unpack it into the plugin folder:shsudo apt install unzip sudo wget -O /tmp/scpper.zip https://github.com/scpwikicloud/pwikit-plugins/releases/latest/download/scpper.zip sudo mkdir -p /opt/pwikit/plugins/scpper sudo unzip -o /tmp/scpper.zip -d /opt/pwikit/plugins/scpperCreate the settings file:
shsudo cp /opt/pwikit/plugins/scpper/config.example.json /opt/pwikit/plugins/scpper/config.jsonscpper_urlis the address pwikit reaches scpper at, the same as theupstreamof the[[mount]].scpper_pathis thepathof the[[mount]]without the trailing/.allowed_hostsholds the host inscpper_url. If you followed Mounting other programs, nothing needs changing.Restart pwikit:
shsudo /opt/pwikit/pwikit service restartIn the site's admin panel, open Plugins, tick On this site for scpper, and click Save.
Once enabled, profiles show the coin badge next to the username. Pages can use these modules:
[[module CoinRank limit="10"]]
[[module Tip]]CoinRank shows the wealth ranking. limit sets how many members it lists, 10 by default and at most 100. Tip shows the tip button for the current page and the tips it has received.
To update the plugin, download and unpack it again as in step 1, then restart pwikit. config.json is left as it is.
