==== Wikka Mod 012 ==== Type: Feature Addition ---- ===Credit:=== **[[http://web.archive.org/web/20040603194747/http://www.wakkawiki.com/GenkiCodeguru | GenkiCodeguru]]** and **[[http://web.archive.org/web/20040826080955/http://www.wakkawiki.com/TobiasHesselmann | TobiasHesselmann]]** [[http://web.archive.org/web/20040820215904/http://www.wakkawiki.com/DeletingComments | DeletingComments @ WakkaWiki]] ---- - Users can delete their own comments. - Page owners can delete any comments on their pages. - Admins can delete any comments. ---- ===Deleting Comments=== Hi all, I figured out a way to have an owner delete his own comments off of his pages. First you have to edit **handlers/page/show.php** and add the following lines, all __old__ lines commented out, so only add those lines without the comment between those lines in the original show.php. %%(php) UserIsOwner()) $allowed_to_delete=1; // foreach ($comments as $comment) // { // print("\n"); // print("
\n"); // print($this->Format($comment["body"])."\n"); // print("
\n-- ".$this->Format($comment["user"])." (".$comment["time"].")"); if ($allowed_to_delete==1 && $comment["owner"]==$this->GetPageOwner()) { ?> FormOpen("delcomment"); ?> "> FormClose(); ?> \n"); // print("
\n"); // } // } ?> %% These above lines add a Delete Comment button to each comment if you are the owner of the page. Next you have to create the file **delcomment.php** in handlers/page/ %%(php) "); print_r($_REQUEST); exit; if ($this->UserIsOwner()) { //select comment and delete it $comment_number=intval(trim($_POST["comment_number"])); $Commenttodel = $this->LoadSingle("select tag, owner from ".$this->config["table_prefix"]."pages where comment_on != '' AND id = '".$comment_number."' order by id desc limit 1"); if ($Commenttodel["owner"]==$this->GetPageOwner()) { $deleted = $this->LoadSingle("delete from ".$this->config["table_prefix"]."pages where comment_on != '' AND id = '".$comment_number."' limit 1"); $deleted = $this->LoadSingle("delete from ".$this->config["table_prefix"]."acls where page_tag = '".$Commenttodel["tag"]."' limit 3"); } // redirect to page $this->redirect($this->href()); } else { print("
Sorry, you're not allowed to delete comments on this page.
\n"); } ?> %% The above lines actually delete the Comment entrie in prefix_pages and the entries in prefix_acls. the only drawback is the "hole" the deleted comments leave in the prefix_pages table because of the auto incremented id but as far as I have tested WakkaWiki has now problems with that. Please tell me what you think about it or maybe you have even a better sollution, fix, improvment for it. by [[http://web.archive.org/web/20040603194747/http://www.wakkawiki.com/GenkiCodeguru | GenkiCodeguru]] ---- Hi, Thanks for this modification, I've requested it to be added to Wakka 0.1.3. I have an improvement that I've made above - because you can only delete your own comments, I've made the "Delete Comments" button only show up for comments the page owner 'owns'. Also this is great integrated into [[http://web.archive.org/web/20040813204526/http://www.wakkawiki.com/PsudoAdminUser | PsudoAdminUser]] - If you've got that mod installed then change delcomment.php to: %%(php) "); print_r($_REQUEST); exit; if ($this->IsAdmin() || $this->UserIsOwner()) { //select comment and delete it $comment_number=intval(trim($_POST["comment_number"])); $Commenttodel = $this->LoadSingle("select tag, owner from ".$this->config["table_prefix"]."pages where comment_on != '' AND id = '".$comment_number."' order by id desc limit 1"); if ($Commenttodel["owner"]==$this->GetPageOwner() || $this->IsAdmin()) { $deleted = $this->LoadSingle("delete from ".$this->config["table_prefix"]."pages where comment_on != '' AND id = '".$comment_number."' limit 1"); $deleted = $this->LoadSingle("delete from ".$this->config["table_prefix"]."acls where page_tag = '".$Commenttodel["tag"]."' limit 3"); } // redirect to page $this->redirect($this->href()); } else { print("

Sorry, you're not allowed to delete comments on this page.
\n"); } ?> %% and the show.php line should be: %%(php) if ($allowed_to_delete==1 && $comment["owner"]==$this->GetPageOwner() || $this->IsAdmin()) %% That way, an admin can delete ANY comment on any page. ---- If you want to allow **users delete their own comments** from any page, as well as letting the **page owner delete any comment** on his page (which IMHO makes the most sense), you can use the following code: My handlers/page/show.php looks like this: %%(php) ... \n"); print("
\n"); print($this->Format($comment["body"])."\n"); print("
\n-- ".$this->Format($comment["user"])." (".$comment["time"].")\n
\n"); $cur_user=$this->GetUser(); if ($this->UserIsOwner() || ($cur_user['name'] == $comment["owner"])) { ?> FormOpen("delcomment"); ?> "> FormClose(); ?> \n"); } } ?> ... %% and my delcomment.php looks like this: %%(php) if (1==1) //if ($this->UserIsOwner()) { //select comment and delete it $comment_number=intval(trim($_POST["comment_number"])); $Commenttodel = $this->LoadSingle("select tag, owner from ".$this->config["table_prefix"]."pages where comment_on != '' AND id = '".$comment_number."' order by id desc limit 1"); $cur_user=$this->GetUser(); if ($this->UserIsOwner() || ($Commenttodel["owner"]==$cur_user['name'])) { $deleted = $this->LoadSingle("delete from ".$this->config["table_prefix"]."pages where comment_on != '' AND id = '".$comment_number."' limit 1"); $deleted = $this->LoadSingle("delete from ".$this->config["table_prefix"]."acls where page_tag = '".$Commenttodel["tag"]."' limit 3"); } // redirect to page $this->redirect($this->href()); } else { print("
Sorry, you're not allowed to delete this comment!
\n"); } ?> ... %% Also, i think it would look better to substitute the button with a standard link like in "Edit this page" in the footer. --[[http://web.archive.org/web/20040826080955/http://www.wakkawiki.com/TobiasHesselmann | TobiasHesselmann]]