From 426f30e8d52a736129fe3c1f03116258b8a781a6 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 12 Apr 2024 02:55:32 +0100 Subject: [PATCH] [wiki] fixes --- ext/rating/theme.php | 2 +- ext/wiki/theme.php | 104 ++++++++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/ext/rating/theme.php b/ext/rating/theme.php index 0c3f1f57..fb3e12f2 100644 --- a/ext/rating/theme.php +++ b/ext/rating/theme.php @@ -31,7 +31,7 @@ class RatingsTheme extends Themelet public function get_upload_specific_rater_html(string $suffix): HTMLElement { - return TD($this->get_selection_rater_html(name:"rating${suffix}", selected_options: ["?"])); + return TD($this->get_selection_rater_html(name:"rating{$suffix}", selected_options: ["?"])); } /** diff --git a/ext/wiki/theme.php b/ext/wiki/theme.php index 246b9b26..4b445862 100644 --- a/ext/wiki/theme.php +++ b/ext/wiki/theme.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Shimmie2; +use function MicroHTML\{FORM, INPUT, TABLE, TR, TD, emptyHTML, rawHTML, BR, TEXTAREA, DIV, HR, P, A}; + class WikiTheme extends Themelet { /** @@ -25,7 +27,7 @@ class WikiTheme extends Themelet // only the admin can edit the sidebar if ($user->can(Permissions::WIKI_ADMIN)) { - $tfe->formatted .= "

(Edit)"; + $tfe->formatted .= "

(Edit)"; } // see if title is a category'd tag @@ -75,23 +77,25 @@ class WikiTheme extends Themelet protected function create_edit_html(WikiPage $page): string { - $u_title = url_escape($page->title); - $i_revision = $page->revision + 1; - global $user; - if ($user->can(Permissions::WIKI_ADMIN)) { - $val = $page->is_locked() ? " checked" : ""; - $lock = "
Lock page: "; - } else { - $lock = ""; - } - return make_form(make_link("wiki/$u_title/save"))." - - - $lock -
- - "; + + $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") + ); } protected function create_display_html(WikiPage $page): string @@ -101,41 +105,41 @@ class WikiTheme extends Themelet $u_title = url_escape($page->title); $owner = $page->get_owner(); - $formatted_body = Wiki::format_tag_wiki_page($page); + $formatted_body = rawHTML(Wiki::format_tag_wiki_page($page)); - $edit = ""; - $edit .= Wiki::can_edit($user, $page) ? - " - - " : - ""; - if ($user->can(Permissions::WIKI_ADMIN)) { - $edit .= " - - - "; + $edit = TR(); + if(Wiki::can_edit($user, $page)) { + $edit->appendChild(TD(FORM( + ["action" => make_link("wiki/$u_title/edit", "revision={$page->revision}")], + INPUT(["type" => "submit", "value" => "Edit"]) + ))); + } + if ($user->can(Permissions::WIKI_ADMIN)) { + $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") + ))); } - $edit .= "
".make_form(make_link("wiki/$u_title/edit"))." - - - ".make_form(make_link("wiki/$u_title/delete_revision"))." - - - ".make_form(make_link("wiki/$u_title/delete_all"))." - -
"; - return " -

- $formatted_body -
- -
- "; + 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), + ) + ); } }