Jump to content

Lorebooks2MediaWiki

From example
Revision as of 19:03, 17 October 2025 by M4tsuri (talk | contribs)

From Lorebooks to MediaWiki: quick tour

This page shows how a SillyTavern-style lorebook can live inside MediaWiki with Semantic MediaWiki (SMW) and Scribunto. Start with the finished experience, then dig into the pieces that make it work.

References for context:

TL;DR demo

  1. Visit the example world page Farlandia and a concept such as Slime.
  2. Run
    [slime: enemy, slimeball, made of gelatin, bounces to move, annoyance]

[Mossford(The town of Moss): town, mossy buildings, moss used for(magic, power), has(tavern, bank, inn, castle), kind people, wealthy] [Farlandia's monsters: slimes, dragons] {{user}}: Slime? {{char}}: "Oh... Those things." She blushes, remembering their first battle.

  1. You get context like:
[slime: enemy, slimeball, made of gelatin, bounces to move, annoyance]
[Mossford(The town of Moss): town, mossy buildings, moss used for(magic, power), has(tavern, bank, inn, castle), kind people, wealthy]
[Farlandia's monsters: slimes, dragons]

{{user}}: Slime?
{{char}}: "Oh... Those things." She blushes, remembering their first battle.

That output mirrors the original lorebook behaviour while everything remains queryable inside the wiki.

Architecture snapshot

  • Templates capture lore in structured form (worlds and concepts).
  • SMW properties index every chunk for queries and recursion.
  • The Scribunto module reads those annotations, applies key logic, and emits prompt text or JSON.
  • Optional local tooling (scripts/lorebook.lua) lets you unit-test the logic before publishing.

Files in this demo repo

Setup checklist

  1. Create the properties described in SMW Lorebook Properties.
  2. Upload Template:World and Template:Concept.
  3. Copy scripts/module_lorebook.lua into Module:Lorebook.
  4. Import the example pages (world + concepts) to see immediate results: Farlandia, Farlandia:Monsters, Slime, Mossford.
  5. (Optional) Run lua scripts/test_lorebook.lua locally to verify the logic.

Why it works

Semantic MediaWiki

SMW stores each lore snippet as property triples (world ownership, keys, recursion hints). Queries can list all concepts in a world, filter by keys, or export structured JSON.

Scribunto

The module mirrors Lorebook matching rules: ANY/AND/NOT key logic, constant/conditional entries, and recursive parent/child traversal. It can output prompt text or JSON for downstream tools.

Gradual migration

Because everything is on wiki pages, writers can iterate in the wiki UI while engineers consume the same data via queries or the module export.

Next steps

  • Add more concepts with stacked lorebooks or character-specific filters.
  • Expand the module to honour placement hints (before/after character, depth buckets).
  • Generate exports for SillyTavern or other front-ends directly from the wiki.