Merge branch 'master' of github.com:shish/shimmie2

This commit is contained in:
Shish 2012-03-09 15:55:12 +00:00
commit 8996c95a47
2 changed files with 31 additions and 38 deletions

View file

@ -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(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) {
// 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));
}
}
@ -84,11 +83,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 ");
@ -105,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"));
}
}
@ -237,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("
@ -245,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());
}
@ -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
*/

View file

@ -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 = "
<div style='text-align: left'>
".make_form(make_link("tag_history/revert"))."
@ -71,10 +71,9 @@ class Tag_HistoryTheme extends Themelet {
$image_id = $fields['image_id'];
$current_tags = html_escape($fields['tags']);
$name = $fields['name'];
$setter = "<a href='".make_link("user/".url_escape($name))."'>".html_escape($name)."</a>";
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 = "<a href='".make_link("user/".url_escape($name))."'>".html_escape($name)."</a>$h_ip";
$history_list .= '
<li>
<input type="radio" name="revert" value="'.$current_id.'">
@ -87,8 +86,16 @@ 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" :
'<a href="'.make_link('tag_history/all/'.($page_number-1)).'">Prev</a>';
$h_index = "<a href='".make_link()."'>Index</a>";
$h_next = '<a href="'.make_link('tag_history/all/'.($page_number+1)).'">Next</a>';
$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) {