delete by query on admin page -> delete these images on search results
This commit is contained in:
parent
3801ce1bec
commit
82414b279d
3 changed files with 43 additions and 42 deletions
|
@ -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() {
|
||||
|
|
|
@ -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 .= "<input type='checkbox' onclick='$(\"#$action\").attr(\"disabled\", !$(this).is(\":checked\"))'>";
|
||||
}
|
||||
$html .= "<input type='hidden' value='$action'>";
|
||||
if($protected) {
|
||||
$html .= "<input type='submit' id='$action' value='$name' disabled='true'>";
|
||||
}
|
||||
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 = "
|
||||
<script type='text/javascript'>
|
||||
function checkform(){
|
||||
return confirm('Are you sure you wish to delete all images using these tags?');
|
||||
}
|
||||
</script>"
|
||||
|
||||
.make_form(make_link("admin_utils"),"post",false,false,"return checkform()")."
|
||||
<input type='checkbox' id='dbqcheck' name='action' onclick='$dbqcheck'>
|
||||
<input type='hidden' name='action' value='delete by query'>
|
||||
<input type='text' id='dbqtags' disabled='true' name='query'>
|
||||
<input type='submit' id='dbqsubmit' disabled='true' value='Go'>
|
||||
}
|
||||
|
||||
public function display_dbq($terms) {
|
||||
global $page;
|
||||
|
||||
$h_terms = html_escape($terms);
|
||||
|
||||
$html = make_form(make_link("admin/delete_by_query"), "POST") . "
|
||||
<input type='button' class='shm-unlocker' data-unlock-id='dbqsubmit' value='Unlock'>
|
||||
<input type='hidden' name='query' value='$h_terms'>
|
||||
<input type='submit' id='dbqsubmit' disabled='true' value='Delete All These Images'>
|
||||
</form>
|
||||
";
|
||||
$page->add_block(new Block("Delete by Query", $html));
|
||||
$page->add_block(new Block("List Controls", $html, "left"));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -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");
|
||||
|
|
Reference in a new issue