LuminaWebsite/wiki.php
Maaxxs 719dc82fb5 Wiki: pictures open in the large view on click; the editor previews the page as it will look
Asked for: "wenn man eingebundene bilder anklickt, maximiert werden (Großansicht)" and "im editor eine Vorschau
haben. damit ich sehe wie es dann am ende aussieht".

- assets/js/lightbox.js: event delegation for containers with data-lightbox-images - every picture in a wiki page
  opens the gallery's large view, paging through all pictures of the page with the alt text as caption; a picture
  that is itself a link keeps following the link. wiki.php loads it for the page content.
- wiki_edit.php / assets/js/wiki-editor.js: view switch "Schreiben" / "Nebeneinander" / "Vorschau" (side by side is
  hidden below 900 px). The preview shows the page as the wiki will: same width next to a note instead of the table
  of contents, with path, number (new pages get the next free one), title and WIP mark from the form.
- 'eye' icon, styles, patch note, README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 01:36:30 +02:00

340 lines
18 KiB
PHP
Raw Permalink 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>
<span class="wiki-toc-title"><?= e($chapter['title']) ?></span>
<?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>
<span class="wiki-toc-title"><?= e($child['title']) ?></span>
<?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"
data-confirm="Diese Seite<?= $page['parent_id'] === null ? ' samt allen Unterseiten' : '' ?> wirklich löschen?" data-confirm-title="Wiki-Seite löschen" data-confirm-danger data-confirm-ok="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: ?>
<?php // Bilder oeffnen per Klick die Grossansicht (assets/js/lightbox.js) ?>
<div class="wiki-content" data-lightbox-images="wiki"><?= 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 class="wiki-subpage-title"><?= 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" data-confirm="<?= e($nameOf($contributor) . ' als Mitwirkende/n entfernen?') ?>" data-confirm-title="Mitwirkende entfernen" data-confirm-danger data-confirm-ok="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">+ 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>
<script>
// "In diesem Kapitel": Kacheln gleichmaessig auf die Zeilen verteilen (8 bei Platz fuer 5 -> 4/4 statt 5/3)
(function () {
var grids = document.querySelectorAll('.wiki-subpage-grid');
if (!grids.length) return;
var MIN_WIDTH = 220; // wie minmax(220px, 1fr) im CSS
function balance(grid) {
var count = grid.children.length;
var gap = parseFloat(getComputedStyle(grid).columnGap) || 0;
var maxCols = Math.max(1, Math.floor((grid.clientWidth + gap) / (MIN_WIDTH + gap)));
// Am liebsten eine Spaltenzahl, die glatt aufgeht (8 -> 4/4 oder 2/2/2/2) - solange sie
// mindestens die halbe Breite nutzt. Sonst so gleichmaessig wie moeglich (7 -> 4/3).
var cols = 0;
for (var c = Math.min(maxCols, count); c >= Math.ceil(Math.min(maxCols, count) / 2); c--) {
if (count % c === 0) { cols = c; break; }
}
if (!cols) cols = Math.ceil(count / Math.ceil(count / maxCols));
grid.style.gridTemplateColumns = 'repeat(' + cols + ', minmax(0, 1fr))';
}
grids.forEach(function (grid) {
balance(grid);
if (window.ResizeObserver) new ResizeObserver(function () { balance(grid); }).observe(grid);
});
})();
</script>
<?php if ($page): ?><script src="<?= e(asset_url('/assets/js/lightbox.js')) ?>" defer></script><?php endif; ?>
<?php include __DIR__ . '/includes/footer.php'; ?>