From 82414b279d31d9a79f6e70e6b7da251ecee55364 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 18:50:10 +0000 Subject: [PATCH] delete by query on admin page -> delete these images on search results --- contrib/admin/main.php | 17 ++++++++---- contrib/admin/theme.php | 59 +++++++++++++++-------------------------- lib/shimmie.js | 9 +++++++ 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/contrib/admin/main.php b/contrib/admin/main.php index 3122ad1c..5fe7cc41 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -75,9 +75,8 @@ class AdminPage extends Extension { } public function onAdminBuilding(AdminBuildingEvent $event) { - global $page; - $this->theme->display_page($page); - $this->theme->display_form($page); + $this->theme->display_page(); + $this->theme->display_form(); } public function onUserBlockBuilding(UserBlockBuildingEvent $event) { @@ -89,11 +88,17 @@ class AdminPage extends Extension { public function onAdminAction(AdminActionEvent $event) { $action = $event->action; - if(function_exists($this, $action)) { + if(method_exists($this, $action)) { $event->redirect = $this->$action(); } } + public function onPostListBuilding(PostListBuildingEvent $event) { + global $user; + if($user->is_admin() && !empty($event->search_terms)) { + $this->theme->display_dbq(implode(" ", $event->search_terms)); + } + } private function delete_by_query() { global $page, $user; @@ -104,7 +109,9 @@ class AdminPage extends Extension { send_event(new ImageDeletionEvent($image)); } - return true; + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list")); + return false; } private function lowercase_all_tags() { diff --git a/contrib/admin/theme.php b/contrib/admin/theme.php index 6688cc98..a396bc8e 100644 --- a/contrib/admin/theme.php +++ b/contrib/admin/theme.php @@ -4,7 +4,9 @@ class AdminPageTheme extends Themelet { /* * Show the basics of a page, for other extensions to add to */ - public function display_page(Page $page) { + public function display_page() { + global $page; + $page->set_title("Admin Tools"); $page->set_heading("Admin Tools"); $page->add_block(new NavBlock()); @@ -12,12 +14,9 @@ class AdminPageTheme extends Themelet { protected function button(/*string*/ $name, /*string*/ $action, /*boolean*/ $protected=false) { $c_protected = $protected ? " protected" : ""; - $html = make_form(make_link("admin_utils"), "POST", false, false, false, "admin$c_protected"); + $html = make_form(make_link("admin/$action"), "POST", false, false, false, "admin$c_protected"); if($protected) { $html .= ""; - } - $html .= ""; - if($protected) { $html .= ""; } else { @@ -33,47 +32,33 @@ class AdminPageTheme extends Themelet { * 'recount tag use' * 'purge unused tags' */ - public function display_form(Page $page) { - global $user; + public function display_form() { + global $page, $database; $html = ""; $html .= $this->button("All tags to lowercase", "lowercase_all_tags", true); $html .= $this->button("Recount tag use", "recount_tag_user", false); $html .= $this->button("Purge unused tags", "purge_unused_tags", true); - $html .= $this->button("Download database contents", "database_dump", false); - $html .= $this->button("Reset image IDs", "reset_image_ids", true); $html .= $this->button("Download all images", "image_dump", false); + if($database->engine->name == "mysql") { + $html .= $this->button("Download database contents", "database_dump", false); + $html .= $this->button("Reset image IDs", "reset_image_ids", true); + } $page->add_block(new Block("Misc Admin Tools", $html)); - - /* First check - Requires you to click the checkbox to enable the delete by query form */ - $dbqcheck = 'javascript:$(function() { - if($("#dbqcheck:checked").length != 0){ - $("#dbqtags").attr("disabled", false); - $("#dbqsubmit").attr("disabled", false); - }else{ - $("#dbqtags").attr("disabled", true); - $("#dbqsubmit").attr("disabled", true); - } - });'; - - /* Second check - Requires you to confirm the deletion by clicking ok. */ - $html = " - " - - .make_form(make_link("admin_utils"),"post",false,false,"return checkform()")." - - - - + } + + public function display_dbq($terms) { + global $page; + + $h_terms = html_escape($terms); + + $html = make_form(make_link("admin/delete_by_query"), "POST") . " + + + "; - $page->add_block(new Block("Delete by Query", $html)); + $page->add_block(new Block("List Controls", $html, "left")); } } ?> diff --git a/lib/shimmie.js b/lib/shimmie.js index 8f19cd7c..de395fef 100644 --- a/lib/shimmie.js +++ b/lib/shimmie.js @@ -76,6 +76,15 @@ $(document).ready(function() { }) }); + $(".shm-unlocker").each(function(idx, elm) { + var tid = $(elm).data("unlock-id"); + var tob = $("#"+tid); + $(elm).click(function(e) { + $(elm).attr("disabled", true); + tob.attr("disabled", false); + }); + }); + if(document.location.hash.length > 3) { query = document.location.hash.substring(1); a = document.getElementById("prevlink");