Jump to content

Lorebooks2MediaWiki: Difference between revisions

From example
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
= From Lorebooks to MediaWiki: quick tour =
= 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.
'''notice: this page, including related templates and scripts, are generated by LLM and slightly modified manually'''
 
This page shows how a SillyTavern-style lorebook can live inside MediaWiki with Semantic MediaWiki (SMW) and Scribunto.


References for context:
References for context:
Line 9: Line 11:
== TL;DR demo ==
== TL;DR demo ==
# Visit the example world page [[Farlandia]] and a concept such as [[Slime]].
# Visit the example world page [[Farlandia]] and a concept such as [[Slime]].
# Run {{#invoke:Lorebook|inject|world=Farlandia|context=Slime in Mossford}}
# Run <pre>{{#invoke:Lorebook|inject|world=Farlandia|context=Slime in Mossford}}</pre>
# You get context like:
# You get context like:
<pre>[Farlandia's monsters: slimes, dragons]
<code>{{#invoke:Lorebook|inject|world=Farlandia|context=Slime in Mossford}}</code>
[slime: enemy, slimeball, made of gelatin, bounces to move, annoyance]
{{char}}: "Oh... Those things." She blushes, remembering their first battle.</pre>
That output mirrors the original lorebook behaviour while everything remains queryable inside the wiki.
That output mirrors the original lorebook behaviour while everything remains queryable inside the wiki.


Line 20: Line 20:
* SMW properties index every chunk for queries and recursion.
* SMW properties index every chunk for queries and recursion.
* The Scribunto module reads those annotations, applies key logic, and emits prompt text or JSON.
* The Scribunto module reads those annotations, applies key logic, and emits prompt text or JSON.
* Optional local tooling (<code>scripts/lorebook.lua</code>) lets you unit-test the logic before publishing.


== Files in this demo repo ==
== Why it works ==
* [[Template:World]] – world header template (see <code>content/Template_World.wikitext</code>).
=== Template ===
* [[Template:Concept]] – lore/environment entries (see <code>content/Template_Concept.wikitext</code>).
MediaWiki allows users to create custom templates, which is easily reusable. We created two templates [[Template:World]] and [[Template:Concept]] to mimic actual lorebooks. Here are some example pages using these templates: [[Farlandia]], [[Farlandia:Monsters]], [[Slime]], [[Mossford]]. The custom styles also renders them beautifully.
* [[SMW Lorebook Properties]] – list of property pages to create.
* Example pages: [[Farlandia]], [[Farlandia:Monsters]], [[Slime]], [[Mossford]].
* Scribunto module source: <code>scripts/module_lorebook.lua</code> (upload as [[Module:Lorebook]]).
* Optional pure-Lua harness + tests: <code>scripts/lorebook.lua</code> and <code>scripts/test_lorebook.lua</code>.


== Setup checklist ==
# Create the properties described in [[SMW Lorebook Properties]].
# Upload [[Template:World]] and [[Template:Concept]].
# Copy <code>scripts/module_lorebook.lua</code> into [[Module:Lorebook]].
# Import the example pages (world + concepts) to see immediate results: [[Farlandia]], [[Farlandia:Monsters]], [[Slime]], [[Mossford]].
# (Optional) Run <code>lua scripts/test_lorebook.lua</code> locally to verify the logic.
== Why it works ==
=== Semantic MediaWiki ===
=== 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.
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 ===
=== 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.
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. Here is the vibe coded script used in this example [[Module:Lorebook]]
 
=== 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 ==
''We are trying to find more ways to fully utilize the potential of MediaWiki, you can find more in process works [https://github.com/pubwiki here]''
* 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.

Latest revision as of 19:45, 17 October 2025

From Lorebooks to MediaWiki: quick tour

notice: this page, including related templates and scripts, are generated by LLM and slightly modified manually

This page shows how a SillyTavern-style lorebook can live inside MediaWiki with Semantic MediaWiki (SMW) and Scribunto.

References for context:

TL;DR demo

  1. Visit the example world page Farlandia and a concept such as Slime.
  2. Run
    {{#invoke:Lorebook|inject|world=Farlandia|context=Slime in Mossford}}
  3. 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.

Why it works

Template

MediaWiki allows users to create custom templates, which is easily reusable. We created two templates Template:World and Template:Concept to mimic actual lorebooks. Here are some example pages using these templates: Farlandia, Farlandia:Monsters, Slime, Mossford. The custom styles also renders them beautifully.

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. Here is the vibe coded script used in this example Module:Lorebook

We are trying to find more ways to fully utilize the potential of MediaWiki, you can find more in process works here