How can I change comment text to "DELETED" instead of actually deleting the comment? I'm using threaded comments on my Drupal 7 site, and I'd like to be able to publicly preserve the fact that so-and-so commented here, and these were the replies. However, when a comment is deleted, all the replies are removed too. When a comment is deleted, I want the comment text to be changed to "DELETED" instead of actually deleting the comments.

I know about the un-publishing and hidden-comment kind of solutions, but I'd like the specific functionality I described instead of a workaround like those.
I use module Comment Delete, rewritten for Drupal 7.
Here is the code that is responsible for what you need:

$num_replies = db_query('SELECT COUNT(cid) FROM {comment} WHERE pid = :cid AND status = :status', array(':cid' =&gt; $comment-&gt;cid, ':status' =&gt; COMMENT_PUBLISHED))-&gt;fetchField();
if ($num_replies) {
  $comment-&gt;comment_body[LANGUAGE_NONE][0]['value'] = t('[The comment subject/body has been deleted, all replies will remain]');
  comment_save($comment);
  drupal_set_message(t('The comment subject/body has been deleted, all replies will remain.'));
}
else {
  comment_delete($comment-&gt;cid);
  drupal_set_message(t('The comment has been deleted.'));
}