crude wiki history

This commit is contained in:
Shish 2021-12-21 23:36:30 +00:00
parent a7e775de2b
commit 61068bc0d0
2 changed files with 32 additions and 1 deletions

View file

@ -198,6 +198,9 @@ class Wiki extends Extension
} else {
$this->theme->display_permission_denied();
}
} elseif ($event->page_matches("wiki_admin/history")) {
$history = $this->get_history($_GET['title']);
$this->theme->display_page_history($page, $_GET['title'], $history);
} elseif ($event->page_matches("wiki_admin/delete_revision")) {
if ($user->can(Permissions::WIKI_ADMIN)) {
send_event(new WikiDeleteRevisionEvent($_POST["title"], (int)$_POST["revision"]));
@ -301,6 +304,20 @@ class Wiki extends Extension
return false;
}
public static function get_history(string $title): array
{
global $database;
// first try and get the actual page
return $database->get_all(
"
SELECT revision, date
FROM wiki_pages
WHERE LOWER(title) LIKE LOWER(:title)
ORDER BY revision DESC
",
["title"=>$title]
);
}
public static function get_page(string $title, int $revision=-1): WikiPage
{
global $database;

View file

@ -42,6 +42,20 @@ class WikiTheme extends Themelet
$page->add_block(new Block($title_html, $this->create_display_html($wiki_page)));
}
public function display_page_history(Page $page, string $title, array $history)
{
$html = "<table class='zebra'>";
foreach ($history as $row) {
$rev = $row['revision'];
$html .= "<tr><td><a href='".make_link("wiki/$title", "revision=$rev")."'>{$rev}</a></td><td>{$row['date']}</td></tr>";
}
$html .= "</table>";
$page->set_title(html_escape($title));
$page->set_heading(html_escape($title));
$page->add_block(new NavBlock());
$page->add_block(new Block(html_escape($title), $html));
}
public function display_page_editor(Page $page, WikiPage $wiki_page)
{
$page->set_title(html_escape($wiki_page->title));
@ -111,7 +125,7 @@ class WikiTheme extends Themelet
$formatted_body
<hr>
<p class='wiki-footer'>
Revision {$page->revision}
Revision <a href='".make_link("wiki_admin/history", "title={$page->title}")."'>{$page->revision}</a>
by <a href='".make_link("user/{$owner->name}")."'>{$owner->name}</a>
at {$page->date}
$edit