LuminaWebsite/wiki.php
Maaxxs 392994e1cd Activity check (website + bot), videos in the wiki, contributor search list
- Activity check: created on the website (activity.php, activity.manage) or with /aktivitaetscheck; the bot posts "I'm in" / "I'm out" buttons; title, text, color, image and button labels are configurable with a live preview; deadline; consequences for non-responders (DM, remove/add role, optionally also for "I'm out"); close early or cancel; overview of in / out / pending
- Wiki: a video link alone on a line (YouTube incl. Shorts/start time, Twitch, Vimeo, .mp4/.webm) becomes an embedded player, plus a "Video" button in the editor
- Wiki: "Add contributor" as a search list with avatar, group and class instead of a dropdown

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 01:11:49 +02:00

311 lines
17 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/wiki.php';
require_permission('wiki.view');
$canEdit = wiki_can_edit();
$canManage = wiki_can_manage();
$tree = wiki_tree();
$slug = (string) ($_GET['page'] ?? '');
$query = trim((string) ($_GET['q'] ?? ''));
$page = $slug !== '' ? wiki_page_by_slug($slug) : null;
if ($slug !== '' && !$page) {
show_not_found();
}
// Position der Seite im Baum: Nummer, Kapitel, Vorgaenger/Nachfolger in Lesereihenfolge
$flat = [];
foreach ($tree as $chapter) {
$flat[] = $chapter;
foreach ($chapter['children'] as $child) {
$flat[] = $child + ['chapter' => $chapter];
}
}
$current = null;
$prev = null;
$next = null;
$chapterOfPage = null;
if ($page) {
foreach ($flat as $index => $entry) {
if ((int) $entry['id'] === (int) $page['id']) {
$current = $entry;
$prev = $flat[$index - 1] ?? null;
$next = $flat[$index + 1] ?? null;
$chapterOfPage = $entry['chapter'] ?? null;
break;
}
}
}
$childrenOfPage = [];
if ($page && $page['parent_id'] === null) {
foreach ($tree as $chapter) {
if ((int) $chapter['id'] === (int) $page['id']) {
$childrenOfPage = $chapter['children'];
}
}
}
$results = $query !== '' ? wiki_search($query) : [];
// Mitwirkende: hinzugefuegte Mitglieder
$contributors = db()->query(
"SELECT u.id, u.username, u.display_name, u.discord_id, u.avatar_filename, u.class_name
FROM wiki_contributors c JOIN users u ON u.id = c.user_id
ORDER BY COALESCE(NULLIF(u.display_name, ''), u.username)"
)->fetchAll();
$addableMembers = [];
if ($canManage && !$page && $query === '') {
$addableMembers = db()->query(
"SELECT u.id, COALESCE(NULLIF(u.display_name, ''), u.username) AS name, u.avatar_filename, u.class_name,
(SELECT COALESCE(NULLIF(r.display_name, ''), r.name) FROM user_roles ur JOIN roles r ON r.id = ur.role_id
WHERE ur.user_id = u.id ORDER BY COALESCE(r.roster_order, 999), r.name LIMIT 1) AS top_role
FROM users u
WHERE u.status = 'active' AND u.id NOT IN (SELECT user_id FROM wiki_contributors)
ORDER BY name"
)->fetchAll();
}
// Fuer die Suchliste (assets/js/item-picker.js): Avatar, Name, Gruppe und Klasse
$contributorPickerItems = [];
foreach ($addableMembers as $member) {
$contributorPickerItems[] = [
'id' => (int) $member['id'],
'name' => (string) $member['name'],
'category' => trim(($member['top_role'] ?? 'Mitglied') . (!empty($member['class_name']) ? ' · ' . $member['class_name'] : '')),
'icon' => !empty($member['avatar_filename']) ? '/assets/uploads/avatars/' . rawurlencode((string) $member['avatar_filename']) : null,
'qty' => null,
];
}
$pageCount = count($flat);
$pageTitle = $page ? $page['title'] . ' - Wiki' : 'Wiki';
$containerWide = true;
include __DIR__ . '/includes/header.php';
$nameOf = static fn (array $u): string => $u['display_name'] !== '' ? $u['display_name'] : $u['username'];
?>
<div class="wiki-layout">
<aside class="panel wiki-nav" aria-label="Inhaltsverzeichnis">
<a class="wiki-nav-home<?= !$page && $query === '' ? ' active' : '' ?>" href="/wiki.php"><?= icon('book') ?> Einsteiger-Guide</a>
<form class="wiki-search" method="get" action="/wiki.php" role="search">
<input type="search" name="q" value="<?= e($query) ?>" placeholder="Im Wiki suchen …" aria-label="Im Wiki suchen">
</form>
<details class="wiki-toc-wrap" id="wiki-toc-wrap" open>
<summary class="wiki-toc-summary">Inhaltsverzeichnis</summary>
<nav class="wiki-toc">
<?php foreach ($tree as $chapter): ?>
<?php $open = $page && ((int) $chapter['id'] === (int) $page['id'] || (int) $chapter['id'] === (int) ($page['parent_id'] ?? 0)); ?>
<details class="wiki-toc-chapter"<?= $open ? ' open' : '' ?>>
<summary>
<a href="/wiki.php?page=<?= e(rawurlencode($chapter['slug'])) ?>" class="<?= $page && (int) $page['id'] === (int) $chapter['id'] ? 'active' : '' ?>">
<span class="wiki-num"><?= e($chapter['number']) ?></span> <?= e($chapter['title']) ?>
<?php if ($chapter['is_wip']): ?><span class="wiki-wip">WIP</span><?php endif; ?>
</a>
</summary>
<?php if (!empty($chapter['children'])): ?>
<ul>
<?php foreach ($chapter['children'] as $child): ?>
<li>
<a href="/wiki.php?page=<?= e(rawurlencode($child['slug'])) ?>" class="<?= $page && (int) $page['id'] === (int) $child['id'] ? 'active' : '' ?>">
<span class="wiki-num"><?= e($child['number']) ?></span> <?= e($child['title']) ?>
<?php if ($child['is_wip']): ?><span class="wiki-wip">WIP</span><?php endif; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</details>
<?php endforeach; ?>
</nav>
<?php if ($canEdit): ?>
<a class="button button-secondary button-small wiki-new-chapter" href="/wiki_edit.php?new=1">+ Neues Kapitel</a>
<?php endif; ?>
</details>
<?php if ($page || $query !== ''): ?>
<script>
// Handy: beim Lesen einer Seite das Inhaltsverzeichnis zuklappen, damit der Text oben steht.
if (window.matchMedia('(max-width: 900px)').matches) {
document.getElementById('wiki-toc-wrap').open = false;
}
</script>
<?php endif; ?>
</aside>
<main class="wiki-main">
<?php if ($query !== ''): ?>
<div class="panel">
<h1>Suche: „<?= e($query) ?>“</h1>
<?php if (mb_strlen($query) < 2): ?>
<p class="text-muted">Bitte mindestens zwei Zeichen eingeben.</p>
<?php elseif (empty($results)): ?>
<p class="text-muted">Nichts gefunden. Vielleicht mit einem anderen Begriff?</p>
<?php else: ?>
<ul class="wiki-results">
<?php foreach ($results as $result): ?>
<li>
<a href="/wiki.php?page=<?= e(rawurlencode($result['slug'])) ?>"><?= e($result['title']) ?></a>
<p class="text-muted"><?= e($result['snippet']) ?></p>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<?php elseif ($page): ?>
<article class="panel wiki-article">
<nav class="wiki-breadcrumb" aria-label="Pfad">
<a href="/wiki.php">Wiki</a>
<?php if ($chapterOfPage): ?>
<span>›</span> <a href="/wiki.php?page=<?= e(rawurlencode($chapterOfPage['slug'])) ?>"><?= e($chapterOfPage['title']) ?></a>
<?php endif; ?>
</nav>
<header class="wiki-article-head">
<h1><span class="wiki-num"><?= e($current['number'] ?? '') ?></span> <?= e($page['title']) ?>
<?php if ($page['is_wip']): ?><span class="wiki-wip wiki-wip-large" title="Dieser Abschnitt ist noch in Arbeit">WIP</span><?php endif; ?>
</h1>
<div class="wiki-article-actions">
<?php if ($canEdit): ?>
<a class="button button-small" href="/wiki_edit.php?id=<?= (int) $page['id'] ?>"><?= icon('edit') ?> Bearbeiten</a>
<?php if ($page['parent_id'] === null): ?>
<a class="button button-secondary button-small" href="/wiki_edit.php?parent=<?= (int) $page['id'] ?>">+ Unterseite</a>
<?php endif; ?>
<?php endif; ?>
<a class="button button-secondary button-small" href="/wiki_history.php?id=<?= (int) $page['id'] ?>">Verlauf</a>
<?php if ($canManage): ?>
<form method="post" action="/wiki_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="move">
<input type="hidden" name="id" value="<?= (int) $page['id'] ?>">
<button type="submit" name="direction" value="up" class="icon-button" title="Nach oben verschieben">▲</button>
<button type="submit" name="direction" value="down" class="icon-button" title="Nach unten verschieben">▼</button>
</form>
<form method="post" action="/wiki_action.php" class="inline-form"
onsubmit="return confirm('Diese Seite<?= $page['parent_id'] === null ? ' samt allen Unterseiten' : '' ?> wirklich löschen?');">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?= (int) $page['id'] ?>">
<button type="submit" class="icon-button icon-button-danger" title="Löschen"><?= icon('trash') ?></button>
</form>
<?php endif; ?>
</div>
</header>
<?php if (trim($page['content']) === ''): ?>
<p class="wiki-empty">Dieser Abschnitt ist noch leer.<?= $canEdit ? ' Magst du ihn schreiben?' : ' Er wird gerade noch geschrieben.' ?></p>
<?php else: ?>
<div class="wiki-content"><?= wiki_render($page['content']) ?></div>
<?php endif; ?>
<?php if (!empty($childrenOfPage)): ?>
<div class="wiki-subpages">
<h2>In diesem Kapitel</h2>
<div class="wiki-subpage-grid">
<?php foreach ($childrenOfPage as $child): ?>
<a class="wiki-subpage" href="/wiki.php?page=<?= e(rawurlencode($child['slug'])) ?>">
<span class="wiki-num"><?= e($child['number']) ?></span>
<span><?= e($child['title']) ?></span>
<?php if ($child['is_wip']): ?><span class="wiki-wip">WIP</span><?php endif; ?>
</a>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<footer class="wiki-article-foot">
<span class="text-muted">
Zuletzt bearbeitet<?= $page['updated_by_name'] ? ' von ' . e($page['updated_by_name']) : '' ?>
am <?= e(date('d.m.Y H:i', strtotime($page['updated_at']))) ?> Uhr
</span>
<nav class="wiki-pager">
<?php if ($prev): ?>
<a href="/wiki.php?page=<?= e(rawurlencode($prev['slug'])) ?>">← <?= e($prev['number'] . ' ' . $prev['title']) ?></a>
<?php endif; ?>
<?php if ($next): ?>
<a href="/wiki.php?page=<?= e(rawurlencode($next['slug'])) ?>"><?= e($next['number'] . ' ' . $next['title']) ?> →</a>
<?php endif; ?>
</nav>
</footer>
</article>
<?php else: ?>
<div class="panel wiki-hero">
<h1><?= icon('book') ?> Einsteiger-Guide</h1>
<p>Informationen und Tipps rund um Aion 2 - von Mitgliedern für Mitglieder. Der Guide wächst mit jedem, der mitschreibt.</p>
<p class="text-muted"><?= $pageCount ?> Seiten<?= !empty($contributors) ? ' · ' . count($contributors) . ' Mitwirkende' : '' ?></p>
</div>
<?php if (empty($tree)): ?>
<div class="panel">
<p>Das Wiki ist noch leer.</p>
<div class="actions">
<?php if ($canManage): ?>
<form method="post" action="/wiki_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="import">
<button type="submit">Einsteiger-Guide aus dem Spreadsheet übernehmen</button>
</form>
<?php endif; ?>
<?php if ($canEdit): ?>
<a class="button button-secondary" href="/wiki_edit.php?new=1">Erstes Kapitel schreiben</a>
<?php endif; ?>
</div>
</div>
<?php else: ?>
<div class="wiki-chapter-grid">
<?php foreach ($tree as $chapter): ?>
<a class="panel wiki-chapter-card" href="/wiki.php?page=<?= e(rawurlencode($chapter['slug'])) ?>">
<span class="wiki-chapter-no"><?= e(rtrim($chapter['number'], '.')) ?></span>
<h2><?= e($chapter['title']) ?><?php if ($chapter['is_wip']): ?> <span class="wiki-wip">WIP</span><?php endif; ?></h2>
<?php if (!empty($chapter['children'])): ?>
<p class="text-muted"><?= e(implode(' · ', array_map(static fn ($c) => $c['title'], $chapter['children']))) ?></p>
<?php endif; ?>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="panel wiki-contributors" id="mitwirkende">
<h2>Mitwirkende</h2>
<p class="text-muted">Diese Mitglieder schreiben am Guide mit. <?= $canManage ? 'Weitere Mitglieder kannst du unten hinzufügen - sie dürfen dann Seiten anlegen und bearbeiten.' : 'Du möchtest mithelfen? Sprich die Leitung an.' ?></p>
<?php if (empty($contributors)): ?>
<p class="text-muted">Noch niemand hinzugefügt.</p>
<?php else: ?>
<div class="wiki-contributor-list">
<?php foreach ($contributors as $contributor): ?>
<div class="wiki-contributor">
<?= avatar_html($contributor, 34) ?>
<span><?= e($nameOf($contributor)) ?></span>
<?= class_badge_html($contributor['class_name'] ?? null, 18) ?>
<?php if ($canManage): ?>
<form method="post" action="/wiki_action.php" class="inline-form" onsubmit="return confirm('<?= e($nameOf($contributor)) ?> als Mitwirkende/n entfernen?');">
<?= csrf_field() ?>
<input type="hidden" name="action" value="contributor_remove">
<input type="hidden" name="user_id" value="<?= (int) $contributor['id'] ?>">
<button type="submit" class="icon-button icon-button-danger" title="Entfernen"><?= icon('x') ?></button>
</form>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($canManage && !empty($addableMembers)): ?>
<form method="post" action="/wiki_action.php" class="wiki-contributor-add">
<?= csrf_field() ?>
<input type="hidden" name="action" value="contributor_add">
<div class="item-picker" data-picker-items="wiki-contributor-list" data-picker-mode="id" data-picker-round data-picker-empty="Kein Mitglied gefunden." data-picker-invalid="Bitte ein Mitglied aus der Liste wählen.">
<input type="hidden" name="user_id">
<label class="search-field">
<span class="item-picker-icon"><?= icon('search') ?></span>
<input type="text" class="item-picker-input" id="wiki-contributor-search" required placeholder="Mitglied suchen …" aria-label="Mitglied auswählen">
</label>
</div>
<button type="submit" class="button-small">+ Hinzufügen</button>
</form>
<script type="application/json" id="wiki-contributor-list"><?= json_encode($contributorPickerItems, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP) ?></script>
<script src="<?= e(asset_url('/assets/js/item-picker.js')) ?>"></script>
<?php endif; ?>
</div>
<?php endif; ?>
</main>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>