2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2007-07-19 12:51:12 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2024-04-12 01:55:32 +00:00
|
|
|
use function MicroHTML\{FORM, INPUT, TABLE, TR, TD, emptyHTML, rawHTML, BR, TEXTAREA, DIV, HR, P, A};
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class WikiTheme extends Themelet
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Show a page.
|
|
|
|
*
|
|
|
|
* $wiki_page The wiki page, has ->title and ->body
|
|
|
|
* $nav_page A wiki page object with navigation, has ->body
|
|
|
|
*/
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_page(Page $page, WikiPage $wiki_page, ?WikiPage $nav_page = null): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $user;
|
2014-04-28 07:16:09 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
if (is_null($nav_page)) {
|
|
|
|
$nav_page = new WikiPage();
|
|
|
|
$nav_page->body = "";
|
|
|
|
}
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2023-02-04 20:50:26 +00:00
|
|
|
$tfe = send_event(new TextFormattingEvent($nav_page->body));
|
2007-07-19 12:51:12 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
// only the admin can edit the sidebar
|
2019-09-29 18:00:51 +00:00
|
|
|
if ($user->can(Permissions::WIKI_ADMIN)) {
|
2024-04-12 01:55:32 +00:00
|
|
|
$tfe->formatted .= "<p>(<a href='".make_link("wiki/wiki:sidebar/edit")."'>Edit</a>)";
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2007-07-19 12:51:12 +00:00
|
|
|
|
2020-03-23 12:45:31 +00:00
|
|
|
// see if title is a category'd tag
|
|
|
|
$title_html = html_escape($wiki_page->title);
|
2024-01-20 01:03:01 +00:00
|
|
|
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
|
2023-02-03 16:44:16 +00:00
|
|
|
$tagcategories = new TagCategories();
|
|
|
|
$tag_category_dict = $tagcategories->getKeyedDict();
|
|
|
|
$title_html = $tagcategories->getTagHtml($title_html, $tag_category_dict);
|
2020-03-23 12:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-12-31 04:06:39 +00:00
|
|
|
if (!$wiki_page->exists) {
|
2021-11-21 14:10:03 +00:00
|
|
|
$page->set_code(404);
|
|
|
|
}
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_title(html_escape($wiki_page->title));
|
|
|
|
$page->set_heading(html_escape($wiki_page->title));
|
|
|
|
$page->add_block(new NavBlock());
|
|
|
|
$page->add_block(new Block("Wiki Index", $tfe->formatted, "left", 20));
|
2020-03-23 12:45:31 +00:00
|
|
|
$page->add_block(new Block($title_html, $this->create_display_html($wiki_page)));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2007-07-19 12:51:12 +00:00
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @param array<array{revision: string, date: string}> $history
|
|
|
|
*/
|
|
|
|
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_page_history(Page $page, string $title, array $history): void
|
2021-12-21 23:36:30 +00:00
|
|
|
{
|
|
|
|
$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));
|
|
|
|
}
|
|
|
|
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_page_editor(Page $page, WikiPage $wiki_page): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$page->set_title(html_escape($wiki_page->title));
|
|
|
|
$page->set_heading(html_escape($wiki_page->title));
|
|
|
|
$page->add_block(new NavBlock());
|
|
|
|
$page->add_block(new Block("Editor", $this->create_edit_html($wiki_page)));
|
|
|
|
}
|
2007-07-19 12:51:12 +00:00
|
|
|
|
2021-03-14 23:43:50 +00:00
|
|
|
protected function create_edit_html(WikiPage $page): string
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $user;
|
2024-04-12 01:55:32 +00:00
|
|
|
|
|
|
|
$lock = $user->can(Permissions::WIKI_ADMIN) ?
|
|
|
|
emptyHTML(
|
|
|
|
BR(),
|
|
|
|
"Lock page: ",
|
|
|
|
INPUT(["type" => "checkbox", "name" => "lock", "checked" => $page->is_locked()])
|
|
|
|
) :
|
|
|
|
emptyHTML();
|
|
|
|
|
|
|
|
$u_title = url_escape($page->title);
|
|
|
|
return (string)SHM_SIMPLE_FORM(
|
|
|
|
"wiki/$u_title/save",
|
|
|
|
INPUT(["type" => "hidden", "name" => "revision", "value" => $page->revision + 1]),
|
|
|
|
TEXTAREA(["name" => "body", "style" => "width: 100%", "rows" => 20], $page->body),
|
|
|
|
$lock,
|
|
|
|
BR(),
|
|
|
|
SHM_SUBMIT("Save")
|
|
|
|
);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2007-07-19 12:51:12 +00:00
|
|
|
|
2021-03-14 23:43:50 +00:00
|
|
|
protected function create_display_html(WikiPage $page): string
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-12-01 01:07:18 +00:00
|
|
|
global $user;
|
2014-04-28 07:16:09 +00:00
|
|
|
|
2024-02-10 16:40:38 +00:00
|
|
|
$u_title = url_escape($page->title);
|
2019-05-28 16:59:38 +00:00
|
|
|
$owner = $page->get_owner();
|
2007-07-19 12:51:12 +00:00
|
|
|
|
2024-04-12 01:55:32 +00:00
|
|
|
$formatted_body = rawHTML(Wiki::format_tag_wiki_page($page));
|
|
|
|
|
|
|
|
$edit = TR();
|
2024-08-31 16:05:18 +00:00
|
|
|
if (Wiki::can_edit($user, $page)) {
|
2024-04-12 01:55:32 +00:00
|
|
|
$edit->appendChild(TD(FORM(
|
|
|
|
["action" => make_link("wiki/$u_title/edit", "revision={$page->revision}")],
|
|
|
|
INPUT(["type" => "submit", "value" => "Edit"])
|
|
|
|
)));
|
|
|
|
}
|
2019-09-29 18:00:51 +00:00
|
|
|
if ($user->can(Permissions::WIKI_ADMIN)) {
|
2024-04-12 01:55:32 +00:00
|
|
|
$edit->appendChild(
|
|
|
|
TD(SHM_SIMPLE_FORM(
|
|
|
|
"wiki/$u_title/delete_revision",
|
|
|
|
INPUT(["type" => "hidden", "name" => "revision", "value" => $page->revision]),
|
|
|
|
SHM_SUBMIT("Delete")
|
|
|
|
))
|
|
|
|
);
|
|
|
|
$edit->appendChild(TD(SHM_SIMPLE_FORM(
|
|
|
|
"wiki/$u_title/delete_all",
|
|
|
|
SHM_SUBMIT("Delete All")
|
|
|
|
)));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2024-04-12 01:55:32 +00:00
|
|
|
|
|
|
|
return (string)DIV(
|
|
|
|
["class" => "wiki-page"],
|
|
|
|
$formatted_body,
|
|
|
|
HR(),
|
|
|
|
P(
|
|
|
|
["class" => "wiki-footer"],
|
|
|
|
A(["href" => make_link("wiki/$u_title/history")], "Revision {$page->revision}"),
|
|
|
|
" by ",
|
|
|
|
A(["href" => make_link("user/{$owner->name}")], $owner->name),
|
|
|
|
" at {$page->date}",
|
|
|
|
TABLE($edit),
|
|
|
|
)
|
|
|
|
);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2007-07-19 12:51:12 +00:00
|
|
|
}
|