delete comments by IP

This commit is contained in:
Shish 2012-06-09 16:08:29 +01:00
parent 5186601805
commit 82cc77817a
2 changed files with 40 additions and 1 deletions

View File

@ -119,7 +119,7 @@ class CommentList extends Extension {
}
public function onPageRequest(PageRequestEvent $event) {
global $page, $user;
global $page, $user, $database;
if($event->page_matches("comment")) {
if($event->get_arg(0) === "add") {
if(isset($_POST['image_id']) && isset($_POST['comment'])) {
@ -153,6 +153,24 @@ class CommentList extends Extension {
$this->theme->display_permission_denied();
}
}
else if($event->get_arg(0) === "bulk_delete") {
if($user->can("delete_comment") && !empty($_POST["ip"])) {
$ip = $_POST['ip'];
$cids = $database->get_col("SELECT id FROM comments WHERE owner_ip=:ip", array("ip"=>$ip));
$num = count($cids);
log_warning("comment", "Deleting $num comments from $ip");
foreach($cids as $cid) {
send_event(new CommentDeletionEvent($cid));
}
$page->set_mode("redirect");
$page->set_redirect(make_link("admin"));
}
else {
$this->theme->display_permission_denied();
}
}
else if($event->get_arg(0) === "list") {
$page_num = int_escape($event->get_arg(1));
$this->build_page($page_num);
@ -160,6 +178,10 @@ class CommentList extends Extension {
}
}
public function onAdminBuilding(AdminBuildingEvent $event) {
$this->theme->display_admin_block();
}
public function onPostListBuilding(PostListBuildingEvent $event) {
global $config, $database;
$cc = $config->get_int("comment_count");

View File

@ -101,6 +101,23 @@ class CommentListTheme extends Themelet {
}
public function display_admin_block() {
global $page;
$html = '
Delete comments by IP.
<br><br>'.make_form(make_link("comment/bulk_delete"), 'POST')."
<table class='form'>
<tr><th>IP&nbsp;Address</th> <td><input type='text' name='ip' size='15'></td></tr>
<tr><td colspan='2'><input type='submit' value='Delete'></td></tr>
</table>
</form>
";
$page->add_block(new Block("Mass Comment Delete", $html));
}
/**
* Add some comments to the page, probably in a sidebar
*