From f6112d26a20ecae43a7b0ba407ec4fcd8a281272 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 12 Apr 2020 12:42:37 +0100 Subject: [PATCH] unify single and global history pages --- ext/source_history/main.php | 2 +- ext/source_history/theme.php | 129 ++++++++++++++------------------- ext/tag_history/theme.php | 137 +++++++++++++++-------------------- 3 files changed, 115 insertions(+), 153 deletions(-) diff --git a/ext/source_history/main.php b/ext/source_history/main.php index 4c2a043e..0867fd77 100644 --- a/ext/source_history/main.php +++ b/ext/source_history/main.php @@ -151,7 +151,7 @@ class SourceHistory extends Extension // lets get the values out of the result //$stored_result_id = $result['id']; - $stored_image_id = $result['image_id']; + $stored_image_id = (int)$result['image_id']; $stored_source = $result['source']; log_debug("source_history", 'Reverting source of Image #'.$stored_image_id.' to ['.$stored_source.']'); diff --git a/ext/source_history/theme.php b/ext/source_history/theme.php index 9772737d..ec106878 100644 --- a/ext/source_history/theme.php +++ b/ext/source_history/theme.php @@ -1,49 +1,13 @@ - ".make_form(make_link("source_history/revert"))." - - - - - "; - $history_html = $start_string . $history_list . $end_string; + $history_html = $this->history_list($history, true); $page->set_title('Image '.$image_id.' Source History'); $page->set_heading('Source History: '.$image_id); @@ -53,43 +17,12 @@ class SourceHistoryTheme extends Themelet public function display_global_page(Page $page, array $history, int $page_number) { - $start_string = " -
- ".make_form(make_link("source_history/revert"))." - - - -
- "; + $history_html = $this->history_list($history, false); - global $user; - $history_list = ""; - foreach ($history as $fields) { - $current_id = $fields['id']; - $image_id = $fields['image_id']; - $current_source = html_escape($fields['source']); - $name = $fields['name']; - $h_ip = $user->can(Permissions::VIEW_IP) ? " ".show_ip($fields['user_ip'], "Sourcing Image #$image_id as '$current_source'") : ""; - $setter = "".html_escape($name)."$h_ip"; - - $history_list .= ' -
  • - - '.$image_id.': - '.$current_source.' (Set by '.$setter.') -
  • - '; - } - - $history_html = $start_string . $history_list . $end_string; $page->set_title("Global Source History"); $page->set_heading("Global Source History"); $page->add_block(new Block("Source History", $history_html, "main", 10)); - $h_prev = ($page_number <= 1) ? "Prev" : 'Prev'; $h_index = "Index"; @@ -105,11 +38,11 @@ class SourceHistoryTheme extends Themelet public function display_admin_block(string $validation_msg='') { global $page; - + if (!empty($validation_msg)) { $validation_msg = '
    '. $validation_msg .''; } - + $html = ' Revert source changes by a specific IP address or username, optionally limited to recent changes. '.$validation_msg.' @@ -125,7 +58,7 @@ class SourceHistoryTheme extends Themelet "; $page->add_block(new Block("Mass Source Revert", $html)); } - + /* * Show a standard page for results to be put into */ @@ -140,4 +73,52 @@ class SourceHistoryTheme extends Themelet { $this->messages[] = '

    '. $title .'
    '. $body .'

    '; } + + protected function history_list(array $history, bool $select_2nd): string + { + $history_list = ""; + foreach ($history as $n => $fields) { + $history_list .= $this->history_entry($fields, $select_2nd && $n == 1); + } + + return " +
    + " . make_form(make_link("source_history/revert")) . " + + + +
    + "; + } + + protected function history_entry(array $fields, bool $selected): string + { + global $user; + $image_id = $fields['image_id']; + $current_id = $fields['id']; + $current_source = html_escape($fields['source']); + $name = $fields['name']; + $date_set = rawHTML(autodate($fields['date_set'])); + $ip = $user->can(Permissions::VIEW_IP) ? + rawHTML(" " . show_ip($fields['user_ip'], "Sourcing Image #$image_id as '$current_source'")) + : null; + $setter = A(["href"=>make_link("user/" . url_escape($name))], $name); + + return (string)LI( + INPUT(["type"=>"radio", "name"=>"revert", "id"=>"$current_id", "value"=>"$current_id", "checked"=>$selected]), + A(["href"=>make_link("post/view/$image_id")], $image_id), + ": ", + LABEL( + ["for"=>"$current_id"], + $current_source, + " - ", + $setter, + $ip, + " - ", + $date_set + ) + ); + } } diff --git a/ext/tag_history/theme.php b/ext/tag_history/theme.php index f27c705e..d702c2ca 100644 --- a/ext/tag_history/theme.php +++ b/ext/tag_history/theme.php @@ -1,56 +1,13 @@ - ".make_form(make_link("tag_history/revert"))." - - - - - "; - $history_html = $start_string . $history_list . $end_string; + $history_html = $this->history_list($history, true); $page->set_title('Image '.$image_id.' Tag History'); $page->set_heading('Tag History: '.$image_id); @@ -60,43 +17,12 @@ class TagHistoryTheme extends Themelet public function display_global_page(Page $page, array $history, int $page_number) { - $start_string = " -
    - ".make_form(make_link("tag_history/revert"))." - - - -
    - "; + $history_html = $this->history_list($history, false); - global $user; - $history_list = ""; - foreach ($history as $fields) { - $current_id = $fields['id']; - $image_id = $fields['image_id']; - $current_tags = html_escape($fields['tags']); - $name = $fields['name']; - $h_ip = $user->can(Permissions::VIEW_IP) ? " ".show_ip($fields['user_ip'], "Tagging Image #$image_id as '$current_tags'") : ""; - $setter = "".html_escape($name)."$h_ip"; - - $history_list .= ' -
  • - - '.$image_id.': - '.$current_tags.' (Set by '.$setter.') -
  • - '; - } - - $history_html = $start_string . $history_list . $end_string; $page->set_title("Global Tag History"); $page->set_heading("Global Tag History"); $page->add_block(new Block("Tag History", $history_html, "main", 10)); - $h_prev = ($page_number <= 1) ? "Prev" : 'Prev'; $h_index = "Index"; @@ -147,4 +73,59 @@ class TagHistoryTheme extends Themelet { $this->messages[] = '

    '. $title .'
    '. $body .'

    '; } + + protected function history_list(array $history, bool $select_2nd): string + { + $history_list = ""; + foreach ($history as $n => $fields) { + $history_list .= $this->history_entry($fields, $select_2nd && $n == 1); + } + + return " +
    + " . make_form(make_link("tag_history/revert")) . " + + + +
    + "; + } + + protected function history_entry(array $fields, bool $selected): string + { + global $user; + $image_id = $fields['image_id']; + $current_id = $fields['id']; + $current_tags = html_escape($fields['tags']); + $name = $fields['name']; + $date_set = rawHTML(autodate($fields['date_set'])); + $ip = $user->can(Permissions::VIEW_IP) ? + rawHTML(" " . show_ip($fields['user_ip'], "Tagging Image #$image_id as '$current_tags'")) + : null; + $setter = A(["href"=>make_link("user/" . url_escape($name))], $name); + + $current_tags = Tag::explode($current_tags); + $taglinks = SPAN(); + foreach ($current_tags as $tag) { + $taglinks->appendChild(A(["href"=>make_link("post/list/$tag/1")], $tag)); + $taglinks->appendChild(" "); + } + + return (string)LI( + INPUT(["type"=>"radio", "name"=>"revert", "id"=>"$current_id", "value"=>"$current_id", "checked"=>$selected]), + A(["href"=>make_link("post/view/$image_id")], $image_id), + ": ", + LABEL( + ["for"=>"$current_id"], + $taglinks, + " - ", + $setter, + $ip, + " - ", + $date_set + ) + ); + } }