Wiki.
The tinyfiles.tv wiki — everything about this place, explained like you actually live here. Search, click blue links, fall down a rabbit hole.
Categories
Wiki is community-edited (eventually). For now, these pages are written by tinyfiles. If something is wrong, it is probably a joke.
⬇ Backend — Wiki Backend — Template
Right now Wiki is local-only — all articles live in a hardcoded let articles = {...} in JS, search / nav / random all run off that one object, and there is no edit history. The sidebar even says “Wiki is community-edited (eventually)” — right now it isn’t. This backend is the map to make it real: articles live on the server, search is server-side, edits create revisions, and the browser just renders what the server sends. Proposed, not connected.
01 / Files to create
api/wiki/articles.php GET /api/wiki/articles?cat= api/wiki/article.php GET /api/wiki/article?slug=... api/wiki/search.php GET /api/wiki/search?q=... api/wiki/admin-save.php POST /api/wiki/admin-save (admin only) sql/wiki_tables.sql
Keep the tinyfiles PHP pattern: each endpoint loads /api/bootstrap.php, uses json_in() / json_out(), prepared PDO statements.
02 / Database tables
-- sql/wiki_tables.sql
wiki_articles
id INT AUTO_INCREMENT PRIMARY KEY
slug VARCHAR(100) UNIQUE NOT NULL -- "roger", "tinymap", "c-mail"
title VARCHAR(120) NOT NULL -- "Roger", "TinyMap", "C-Mail"
cat ENUM('Main','Apps','Games','People','Crypto','Lore') NOT NULL
body_html MEDIUMTEXT NOT NULL -- the article body, sanitized HTML
infobox_json JSON NOT NULL -- { "Type": "Wiki", "Founded": "..." }
created_at DATETIME NOT NULL
updated_at DATETIME NOT NULL
wiki_revisions
id INT AUTO_INCREMENT PRIMARY KEY
article_id INT NOT NULL -- FK -> wiki_articles.id
body_html MEDIUMTEXT NOT NULL -- snapshot before this edit
infobox_json JSON NOT NULL
editor VARCHAR(80) NOT NULL -- "@tinyfiles" / admin name
note VARCHAR(255) NOT NULL DEFAULT '' -- "fixed typo", "added lore"
created_at DATETIME NOT NULL
wiki_categories
slug VARCHAR(40) PRIMARY KEY -- "apps", "games", "people"
label VARCHAR(60) NOT NULL -- "Apps", "Games", "People"
One row per article. Every edit first copies the old body_html + infobox_json into wiki_revisions, then updates wiki_articles — so nothing is ever truly lost.
03 / API endpoints & request flow
GET /api/wiki/articles?cat=all
- returns { "ok": true, "articles": [ { slug, title, cat }, ... ] }
- cat in [all, Main, Apps, Games, People, Crypto, Lore]
- list only, no body — nav is cheap
GET /api/wiki/article?slug=roger
- returns { "ok": true, "article": { slug, title, cat,
body_html, infobox, updated_at } }
- if slug not found: { "ok": false, "error": "not-found" }
GET /api/wiki/search?q=roger
- q = search in title + body_html, LIKE %q%, cap 100 chars
- returns { "ok": true, "results": [ { slug, title, cat,
snippet: "..." }, ... ] } — max 20
- snippet is ~120 chars around the match, HTML stripped
POST /api/wiki/admin-save (admin only, session check)
{ "slug": "roger", "title": "Roger", "cat": "People",
"body_html": "...", "infobox": { ... }, "note": "fixed typo" }
- validates slug, title, cat allow-list, body length
- INSERT revision, then INSERT ... ON DUPLICATE KEY UPDATE article
Nav / search / random never need the full article bodies — they use the light list + search endpoints, then fetch one article at a time.
04 / Links, sanitizing & validation (server owns this)
// Blue links on this page are onclick="openArticle('Roger')".
// Server stores them as data, not as JS:
// body_html may contain <a data-wiki="roger">Roger</a>
// frontend rewrites data-wiki links to openArticle(slug)
// Server sanitizes body_html on save — allow-list only:
// allow: p, h1, h2, h3, ul, ol, li, b, i, a, hr, br
// allow on <a>: href, data-wiki only — no onclick, no javascript:
// strip: script, iframe, style, img onerror, any on* attribute
// infobox values are plain text, never HTML
// Server validates on save:
// slug: ^[a-z0-9-]+$ , 1-100 chars, unique
// title: 1-120 chars, cat must be in allow-list
// body_html: 1 - 200,000 chars, infobox: valid JSON, <= 30 keys
Keep the joke — “If something is wrong, it is probably a joke” — in the article text, not in the sanitizer. The sanitizer is serious: no <script>, no onclick, no javascript: ever gets saved.
05 / Frontend wiring
// Replace the hardcoded let articles = {...} in this page:
let articles = {}; // filled from server, same shape as now
async function loadWiki(){
const res = await fetch('/api/wiki/articles?cat=all');
const data = await res.json();
// data.articles -> renderNav() list, same .wiki-link HTML as now
}
// Replace openArticle(title):
async function openArticle(slug){
const res = await fetch('/api/wiki/article?slug=' + slug);
const data = await res.json();
// data.article -> same #wikiArticle HTML as now
// infobox from data.article.infobox, body from body_html
// rewrite <a data-wiki> to openArticle() on click
}
// Replace searchWiki():
async function searchWiki(){
const q = document.getElementById('wikiSearch').value;
const res = await fetch('/api/wiki/search?q=' + encodeURIComponent(q));
const data = await res.json();
// data.results -> renderNav() filtered list
// if q matches a slug exactly, openArticle(slug)
}
// Replace randomArticle():
// GET /api/wiki/articles -> pick random slug -> openArticle(slug)
// On load: loadWiki() then openArticle('main-page')
// If API fails, fall back to current hardcoded articles object.
Keep the current hardcoded articles playable with no backend — if /api/wiki/articles fails, use the in-page object as the fallback.
api/wiki/ + sql/wiki_tables.sql — no GitHub needed. The <pre> blocks are the backend spec: server-owned articles + revisions, server-side search, sanitized HTML, community editing only after this is wired — right now every page is still written by tinyfiles.