From 0e47a5e2fae13891794c205424a0eeee328dd1fc Mon Sep 17 00:00:00 2001 From: discomrade <83621080+discomrade@users.noreply.github.com> Date: Fri, 7 Jun 2024 00:41:33 +0000 Subject: [PATCH] [notes] add view note history page --- ext/notes/main.php | 31 +++++++++++++++++++++++++++++++ ext/notes/theme.php | 16 ++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/ext/notes/main.php b/ext/notes/main.php index 2a9fa98e2..9f0dec627 100644 --- a/ext/notes/main.php +++ b/ext/notes/main.php @@ -107,6 +107,9 @@ public function onPageRequest(PageRequestEvent $event): void if ($event->page_matches("note/history/{note_id}", paged: true)) { $this->get_history($event->get_iarg('note_id'), $event->get_iarg('page_num', 1) - 1); } + if ($event->page_matches("note_history/{image_id}", paged: true)) { + $this->get_image_history($event->get_iarg('image_id'), $event->get_iarg('page_num', 1) - 1); + } if ($event->page_matches("note/revert/{noteID}/{reviewID}", permission: Permissions::NOTES_EDIT)) { $noteID = $event->get_iarg('noteID'); $reviewID = $event->get_iarg('reviewID'); @@ -152,6 +155,11 @@ public function onPageRequest(PageRequestEvent $event): void } } + public function onRobotsBuilding(RobotsBuildingEvent $event): void + { + $event->add_disallow("note_history"); + } + /* * HERE WE LOAD THE NOTES IN THE IMAGE @@ -183,6 +191,8 @@ public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event): if ($user->can(Permissions::NOTES_REQUEST)) { $event->add_part($this->theme->request_button($event->image->id)); } + + $event->add_button("View Note History", "note_history/{$event->image->id}", 20); } @@ -471,6 +481,27 @@ private function get_history(int $noteID, int $pageNumber): void $this->theme->display_history($histories, $pageNumber + 1, $totalPages); } + private function get_image_history(int $imageID, int $pageNumber): void + { + global $config, $database; + + $historiesPerPage = $config->get_int('notesHistoriesPerPage'); + + $histories = $database->get_all( + "SELECT h.note_id, h.review_id, h.image_id, h.date, h.note, u.name AS user_name " . + "FROM note_histories AS h " . + "INNER JOIN users AS u " . + "ON u.id = h.user_id " . + "WHERE image_id = :image_id " . + "ORDER BY date DESC, note_id DESC LIMIT :limit OFFSET :offset", + ['image_id' => $imageID, 'offset' => $pageNumber * $historiesPerPage, 'limit' => $historiesPerPage] + ); + + $totalPages = (int) ceil($database->get_one("SELECT COUNT(*) FROM note_histories WHERE image_id = :image_id", ['image_id' => $imageID]) / $historiesPerPage); + + $this->theme->display_image_history($histories, $imageID, $pageNumber + 1, $totalPages); + } + /** * HERE GO BACK IN HISTORY AND SET THE OLD NOTE. IF WAS REMOVED WE RE-ADD IT. */ diff --git a/ext/notes/theme.php b/ext/notes/theme.php index 64d9dfffd..0ca1b476e 100644 --- a/ext/notes/theme.php +++ b/ext/notes/theme.php @@ -187,6 +187,22 @@ public function display_history(array $histories, int $pageNumber, int $totalPag $this->display_paginator($page, "note/updated", null, $pageNumber, $totalPages); } + /** + * @param NoteHistory[] $histories + */ + public function display_image_history(array $histories, int $imageID, int $pageNumber, int $totalPages): void + { + global $page; + + $html = $this->get_history($histories); + + $page->set_title("Note History #$imageID"); + $page->set_heading("Note History #$imageID"); + $page->add_block(new Block("Note History #$imageID", $html, "main", 10)); + + $this->display_paginator($page, "note_history/$imageID", null, $pageNumber, $totalPages); + } + public function get_help_html(): string { return '

Search for posts with notes.