Index: modules/comment/comment.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.admin.inc,v retrieving revision 1.9 diff -u -p -r1.9 comment.admin.inc --- modules/comment/comment.admin.inc 14 May 2008 13:12:40 -0000 1.9 +++ modules/comment/comment.admin.inc 25 Jun 2008 15:24:09 -0000 @@ -237,83 +237,3 @@ function comment_multiple_delete_confirm $form_state['redirect'] = 'admin/content/comment'; } -/** - * Menu callback; delete a comment. - * - * @param $cid - * The comment to be deleted. - */ -function comment_delete($cid = NULL) { - $comment = db_fetch_object(db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d', $cid)); - $comment->name = $comment->uid ? $comment->registered_name : $comment->name; - $output = ''; - - if (is_object($comment) && is_numeric($comment->cid)) { - $output = drupal_get_form('comment_confirm_delete', $comment); - } - else { - drupal_set_message(t('The comment no longer exists.')); - } - - return $output; -} - -/** - * Form builder; Builds the confirmation form for deleting a single comment. - * - * @ingroup forms - * @see comment_confirm_delete_submit() - */ -function comment_confirm_delete(&$form_state, $comment) { - $form = array(); - $form['#comment'] = $comment; - return confirm_form( - $form, - t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)), - 'node/' . $comment->nid, - t('Any replies to this comment will be lost. This action cannot be undone.'), - t('Delete'), - t('Cancel'), - 'comment_confirm_delete'); -} - -/** - * Process comment_confirm_delete form submissions. - */ -function comment_confirm_delete_submit($form, &$form_state) { - drupal_set_message(t('The comment and all its replies have been deleted.')); - $comment = $form['#comment']; - // Delete the comment and its replies. - _comment_delete_thread($comment); - _comment_update_node_statistics($comment->nid); - // Clear the cache so an anonymous user sees that his comment was deleted. - cache_clear_all(); - - $form_state['redirect'] = "node/$comment->nid"; -} - -/** - * Perform the actual deletion of a comment and all its replies. - * - * @param $comment - * An associative array describing the comment to be deleted. - */ -function _comment_delete_thread($comment) { - if (!is_object($comment) || !is_numeric($comment->cid)) { - watchdog('content', 'Cannot delete non-existent comment.', array(), WATCHDOG_WARNING); - - return; - } - - // Delete the comment. - db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid); - watchdog('content', 'Comment: deleted %subject.', array('%subject' => $comment->subject)); - comment_invoke_comment($comment, 'delete'); - - // Delete the comment's replies. - $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid); - while ($comment = db_fetch_object($result)) { - $comment->name = $comment->uid ? $comment->registered_name : $comment->name; - _comment_delete_thread($comment); - } -} Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.641 diff -u -p -r1.641 comment.module --- modules/comment/comment.module 20 Jun 2008 16:52:55 -0000 1.641 +++ modules/comment/comment.module 25 Jun 2008 15:24:14 -0000 @@ -195,7 +195,7 @@ function comment_menu() { $items['comment/delete'] = array( 'title' => 'Delete comment', 'page callback' => 'comment_delete', - 'access arguments' => array('administer comments'), + 'access arguments' => array('post comments'), 'type' => MENU_CALLBACK, ); $items['comment/edit'] = array( @@ -649,7 +649,7 @@ function comment_user($type, $edit, &$us * statements based on the replies to their posts. * * @param $op - * The operation that is to be performed on the comment. Only 'edit' is recognized now. + * The operation that is to be performed on the comment. Currently only 'edit' and 'delete' are supported. * @param $comment * The comment object. * @return @@ -658,7 +658,7 @@ function comment_user($type, $edit, &$us function comment_access($op, $comment) { global $user; - if ($op == 'edit') { + if ($op == 'edit' || $op == 'delete') { return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0) || user_access('administer comments'); } } @@ -833,6 +833,12 @@ function comment_links($comment, $return 'href' => "comment/edit/$comment->cid" ); } + if (comment_access('delete', $comment)) { + $links['comment_delete'] = array( + 'title' => t('delete'), + 'href' => "comment/delete/$comment->cid" + ); + } $links['comment_reply'] = array( 'title' => t('reply'), 'href' => "comment/reply/$comment->nid/$comment->cid" Index: modules/comment/comment.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.pages.inc,v retrieving revision 1.6 diff -u -p -r1.6 comment.pages.inc --- modules/comment/comment.pages.inc 24 Jun 2008 17:01:33 -0000 1.6 +++ modules/comment/comment.pages.inc 25 Jun 2008 15:24:14 -0000 @@ -115,6 +115,92 @@ function comment_reply($node, $pid = NUL } /** + * Menu callback; delete a comment. + * + * @param $cid + * The comment to be deleted. + */ +function comment_delete($cid = NULL) { + $comment = db_fetch_object(db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d', $cid)); + $comment->name = $comment->uid ? $comment->registered_name : $comment->name; + $output = ''; + + if (is_object($comment) && is_numeric($comment->cid)) { + $output = drupal_get_form('comment_confirm_delete', $comment); + } + else { + drupal_set_message(t('The comment no longer exists.')); + } + + return $output; +} + +/** + * Form builder; Builds the confirmation form for deleting a single comment. + * + * @ingroup forms + * @see comment_confirm_delete_submit() + */ +function comment_confirm_delete(&$form_state, $comment) { + $form = array(); + $form['#comment'] = $comment; + return confirm_form( + $form, + t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)), + 'node/' . $comment->nid, + // Different messages for an admin, who can delete threads, and a user, + // who can delete only a comment with no replies. + user_access('administer comments') ? t('Any replies to this comment will be lost. This action cannot be undone.') : t('This action cannot be undone.'), + t('Delete'), + t('Cancel'), + 'comment_confirm_delete'); +} + +/** + * Process comment_confirm_delete form submissions. + */ +function comment_confirm_delete_submit($form, &$form_state) { + // Different messages for an admin, who can delete threads, and a user, + // who can delete only a comment with no replies. + $message = user_access('administer comments') ? t('The comment and all its replies have been deleted.') : t('The comment has been deleted.'); + drupal_set_message($message); + $comment = $form['#comment']; + // Delete the comment and its replies. + _comment_delete_thread($comment); + _comment_update_node_statistics($comment->nid); + // Clear the cache so an anonymous user sees that his comment was deleted. + cache_clear_all(); + + $form_state['redirect'] = "node/$comment->nid"; +} + +/** + * Perform the actual deletion of a comment and all its replies. + * + * @param $comment + * An associative array describing the comment to be deleted. + */ +function _comment_delete_thread($comment) { + if (!is_object($comment) || !is_numeric($comment->cid)) { + watchdog('content', 'Cannot delete non-existent comment.', array(), WATCHDOG_WARNING); + + return; + } + + // Delete the comment. + db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid); + watchdog('content', 'Comment: deleted %subject.', array('%subject' => $comment->subject)); + comment_invoke_comment($comment, 'delete'); + + // Delete the comment's replies. + $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid); + while ($comment = db_fetch_object($result)) { + $comment->name = $comment->uid ? $comment->registered_name : $comment->name; + _comment_delete_thread($comment); + } +} + +/** * Publish specified comment. * * @param $cid ID of comment to be published.