From f03af6cfcb438151682617e617d7011691561b0d Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 9 Mar 2012 13:00:32 +0000 Subject: [PATCH 1/4] tag histories should be deleted by foreign key now --- contrib/tag_history/main.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 02f42948..fa117c3e 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -84,11 +84,6 @@ class Tag_History extends Extension { $this->theme->display_history_link($page, $event->image->id); } - public function onImageDeletion(ImageDeletionEvent $event) { - // handle removing of history when an image is deleted - $this->delete_all_tag_history($event->image->id); - } - public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Tag History"); $sb->add_label("Limit to "); @@ -311,15 +306,6 @@ class Tag_History extends Extension { log_info("tag_history", 'Reverted '.count($result).' edits by ip='.$ip.' (from '.$date.' to now).'); } - /* - * this function is called when an image has been deleted - */ - private function delete_all_tag_history(/*int*/ $image_id) - { - global $database; - $database->execute("DELETE FROM tag_histories WHERE image_id = ?", array($image_id)); - } - /* * this function is called just before an images tag are changed */ From 40bcfafc661be626bc22d30915f2a01632943520 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 9 Mar 2012 14:44:02 +0000 Subject: [PATCH 2/4] tag_history paging --- contrib/tag_history/main.php | 36 +++++++++++++++++------------------ contrib/tag_history/theme.php | 12 +++++++++++- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index fa117c3e..a0f29081 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -58,23 +58,22 @@ class Tag_History extends Extension { public function onPageRequest(PageRequestEvent $event) { global $config, $page, $user; - if ($event->page_matches("tag_history")) { - if($event->get_arg(0) == "revert") { - // this is a request to revert to a previous version of the tags - if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) { - if(isset($_POST['revert'])) { - $this->process_revert_request($_POST['revert']); - } + if($event->page_matches("tag_history/revert")) { + // this is a request to revert to a previous version of the tags + if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) { + if(isset($_POST['revert'])) { + $this->process_revert_request($_POST['revert']); } } - else if($event->count_args() == 1) { - // must be an attempt to view a tag history - $image_id = int_escape($event->get_arg(0)); - $this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id)); - } - else { - $this->theme->display_global_page($page, $this->get_global_tag_history()); - } + } + else if($event->page_matches("tag_history/all")) { + $page_id = int_escape($event->get_arg(1)); + $this->theme->display_global_page($page, $this->get_global_tag_history($page_id), $page_id); + } + else if($event->page_matches("tag_history") && $event->count_args() == 1) { + // must be an attempt to view a tag history + $image_id = int_escape($event->get_arg(0)); + $this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id, $page_id)); } } @@ -100,7 +99,7 @@ class Tag_History extends Extension { public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; if($user->is_admin()) { - $event->add_link("Tag Changes", make_link("tag_history")); + $event->add_link("Tag Changes", make_link("tag_history/all/1")); } } @@ -232,7 +231,7 @@ class Tag_History extends Extension { return ($row ? $row : array()); } - public function get_global_tag_history() + public function get_global_tag_history($page_id) { global $database; $row = $database->get_all(" @@ -240,7 +239,8 @@ class Tag_History extends Extension { FROM tag_histories JOIN users ON tag_histories.user_id = users.id ORDER BY tag_histories.id DESC - LIMIT 100"); + LIMIT 100 OFFSET :offset + ", array("offset" => ($page_id-1)*100)); return ($row ? $row : array()); } diff --git a/contrib/tag_history/theme.php b/contrib/tag_history/theme.php index 77ee1ad8..0f6c6ec1 100644 --- a/contrib/tag_history/theme.php +++ b/contrib/tag_history/theme.php @@ -50,7 +50,7 @@ class Tag_HistoryTheme extends Themelet { $page->add_block(new Block("Tag History", $history_html, "main", 10)); } - public function display_global_page(Page $page, /*array*/ $history) { + public function display_global_page(Page $page, /*array*/ $history, /*int*/ $page_number) { $start_string = "
".make_form(make_link("tag_history/revert"))." @@ -89,6 +89,16 @@ class Tag_HistoryTheme extends Themelet { $page->set_heading("Global Tag History"); $page->add_block(new NavBlock()); $page->add_block(new Block("Tag History", $history_html, "main", 10)); + + + $h_prev = ($page_number <= 1) ? "Prev" : + 'Prev'; + $h_index = "Index"; + $h_next = ($page_number >= $total_pages) ? "Next" : + 'Next'; + + $nav = $h_prev.' | '.$h_index.' | '.$h_next; + $page->add_block(new Block("Navigation", $nav, "left")); } public function display_history_link(Page $page, /*int*/ $image_id) { From 461bd6bf6195fe472268042aefb85b5cd232473b Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 9 Mar 2012 15:34:41 +0000 Subject: [PATCH 3/4] IP ban from tag history page --- contrib/tag_history/theme.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/contrib/tag_history/theme.php b/contrib/tag_history/theme.php index 0f6c6ec1..de8ed164 100644 --- a/contrib/tag_history/theme.php +++ b/contrib/tag_history/theme.php @@ -71,10 +71,9 @@ class Tag_HistoryTheme extends Themelet { $image_id = $fields['image_id']; $current_tags = html_escape($fields['tags']); $name = $fields['name']; - $setter = "".html_escape($name).""; - if($user->is_admin()) { - $setter .= " / " . $fields['user_ip']; - } + $h_ip = $user->can("view_ip") ? " ".show_ip($fields['user_ip'], "Tagging Image #$image_id as '$current_tags'") : ""; + $setter = "".html_escape($name)."$h_ip"; + $history_list .= '
  • From dc6c85975b7b25179920b0257eb751a6c8a1a637 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 9 Mar 2012 15:55:17 +0000 Subject: [PATCH 4/4] working navigation for tag history --- contrib/tag_history/main.php | 2 +- contrib/tag_history/theme.php | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index a0f29081..1be0546c 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -67,7 +67,7 @@ class Tag_History extends Extension { } } else if($event->page_matches("tag_history/all")) { - $page_id = int_escape($event->get_arg(1)); + $page_id = int_escape($event->get_arg(0)); $this->theme->display_global_page($page, $this->get_global_tag_history($page_id), $page_id); } else if($event->page_matches("tag_history") && $event->count_args() == 1) { diff --git a/contrib/tag_history/theme.php b/contrib/tag_history/theme.php index de8ed164..7387d6d9 100644 --- a/contrib/tag_history/theme.php +++ b/contrib/tag_history/theme.php @@ -86,15 +86,13 @@ class Tag_HistoryTheme extends Themelet { $history_html = $start_string . $history_list . $end_string; $page->set_title("Global Tag History"); $page->set_heading("Global Tag History"); - $page->add_block(new NavBlock()); $page->add_block(new Block("Tag History", $history_html, "main", 10)); $h_prev = ($page_number <= 1) ? "Prev" : - 'Prev'; + 'Prev'; $h_index = "Index"; - $h_next = ($page_number >= $total_pages) ? "Next" : - 'Next'; + $h_next = 'Next'; $nav = $h_prev.' | '.$h_index.' | '.$h_next; $page->add_block(new Block("Navigation", $nav, "left"));