Wiki Phase 4: full-text search + revision history
Final phase of the wiki upgrade (see WIKI_UPGRADE.md). Schema (additive): wiki_revisions table (per-save content snapshots). The FULLTEXT index on wiki_pages(title, body) shipped in Phase 1. Search: - MATCH ... AGAINST natural-language search over title + body, ordered by relevance - public: GET /public/wiki?q= (published only); admin: GET /admin/wiki?q= (all statuses) - public wiki index gains a search box; admin list gains a search field Revision history: - every create/update snapshots the page into wiki_revisions - admin endpoints: list revisions, get one, and restore (restore overwrites the page, rebuilds links, and appends a new revision — history stays append-only); logged as wiki.revision.restore - editor gains a History modal: revision list + word-level diff (jsdiff) of a chosen revision against the current page, with one-click restore Verified end-to-end: search matches body and title; two edits produce three revisions; diff renders added/removed words; restore reverts and records a new revision. No console errors. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -172,6 +172,9 @@ async function uploadFile(req, res) {
|
||||
// ── Wiki pages ─────────────────────────────────────────────────────────
|
||||
async function listWiki(req, res) {
|
||||
try {
|
||||
const q = (req.query.q || '').trim()
|
||||
if (q) return res.json(await wiki.search(q, { publishedOnly: false }))
|
||||
|
||||
const filters = {}
|
||||
if (req.query.category) {
|
||||
const category = await wiki.getCategoryBySlug(req.query.category)
|
||||
@@ -246,6 +249,7 @@ async function updateWiki(req, res) {
|
||||
if ('body' in req.body) input.body = req.body.body || null
|
||||
if ('excerpt' in req.body) input.excerpt = req.body.excerpt || null
|
||||
if ('published' in req.body) input.published = Boolean(req.body.published)
|
||||
if ('change_note' in req.body) input.changeNote = req.body.change_note
|
||||
if ('tags' in req.body) input.tags = Array.isArray(req.body.tags) ? req.body.tags : []
|
||||
if ('category_id' in req.body) {
|
||||
const cat = await resolveCategoryId(req.body)
|
||||
@@ -288,6 +292,45 @@ async function deleteWiki(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Wiki revisions ─────────────────────────────────────────────────────
|
||||
async function listWikiRevisions(req, res) {
|
||||
try {
|
||||
const revisions = await wiki.listRevisions(req.params.slug)
|
||||
if (revisions == null) return res.status(404).json({ message: 'Not found' })
|
||||
return res.json(revisions)
|
||||
} catch (err) {
|
||||
log.error('listWikiRevisions', err)
|
||||
return res.status(500).json({ message: 'Internal Server Error' })
|
||||
}
|
||||
}
|
||||
|
||||
async function getWikiRevision(req, res) {
|
||||
try {
|
||||
const rev = await wiki.getRevision(req.params.slug, Number(req.params.id))
|
||||
if (!rev) return res.status(404).json({ message: 'Not found' })
|
||||
return res.json(rev)
|
||||
} catch (err) {
|
||||
log.error('getWikiRevision', err)
|
||||
return res.status(500).json({ message: 'Internal Server Error' })
|
||||
}
|
||||
}
|
||||
|
||||
async function restoreWikiRevision(req, res) {
|
||||
try {
|
||||
const page = await wiki.restoreRevision(req.params.slug, Number(req.params.id), req.user.id)
|
||||
if (!page) return res.status(404).json({ message: 'Not found' })
|
||||
await activity.log({
|
||||
req,
|
||||
action: 'wiki.revision.restore',
|
||||
detail: { slug: req.params.slug, revision: Number(req.params.id) },
|
||||
})
|
||||
return res.json(page)
|
||||
} catch (err) {
|
||||
log.error('restoreWikiRevision', err)
|
||||
return res.status(500).json({ message: 'Internal Server Error' })
|
||||
}
|
||||
}
|
||||
|
||||
// ── Wiki tags ──────────────────────────────────────────────────────────
|
||||
async function listWikiTags(req, res) {
|
||||
try {
|
||||
@@ -488,6 +531,9 @@ module.exports = {
|
||||
updateWiki,
|
||||
publishWiki,
|
||||
deleteWiki,
|
||||
listWikiRevisions,
|
||||
getWikiRevision,
|
||||
restoreWikiRevision,
|
||||
listWikiTags,
|
||||
listWikiCategories,
|
||||
createWikiCategory,
|
||||
|
||||
@@ -114,6 +114,7 @@ adminRouter.put(
|
||||
body('category_id').optional({ values: 'null' }).isInt(),
|
||||
body('published').optional().isBoolean(),
|
||||
body('tags').optional().isArray(),
|
||||
body('change_note').optional({ values: 'falsy' }).isString().isLength({ max: 280 }),
|
||||
validate,
|
||||
ctrl.updateWiki,
|
||||
)
|
||||
@@ -123,6 +124,14 @@ adminRouter.patch(
|
||||
validate,
|
||||
ctrl.publishWiki,
|
||||
)
|
||||
adminRouter.get('/wiki/:slug/revisions', ctrl.listWikiRevisions)
|
||||
adminRouter.get('/wiki/:slug/revisions/:id', param('id').isInt(), validate, ctrl.getWikiRevision)
|
||||
adminRouter.post(
|
||||
'/wiki/:slug/revisions/:id/restore',
|
||||
param('id').isInt(),
|
||||
validate,
|
||||
ctrl.restoreWikiRevision,
|
||||
)
|
||||
adminRouter.delete('/wiki/:slug', ctrl.deleteWiki)
|
||||
|
||||
// ── Settings ──────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user