Ticket #4529: delete-comment.4.diff

File delete-comment.4.diff, 14.0 KB (added by caesarsgrunt, 4 years ago)

Patch against 11707

Line 
1Index: wp-includes/comment.php
2===================================================================
3--- wp-includes/comment.php     (revision 11707)
4+++ wp-includes/comment.php     (working copy)
5@@ -208,6 +208,8 @@
6                $approved = "comment_approved = '1'";
7        elseif ( 'spam' == $status )
8                $approved = "comment_approved = 'spam'";
9+       elseif ( 'deleted' == $status )
10+               $approved = "comment_approved = 'deleted'";
11        else
12                $approved = "( comment_approved = '0' OR comment_approved = '1' )";
13 
14@@ -699,7 +701,7 @@
15        $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
16 
17        $total = 0;
18-       $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam');
19+       $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'deleted' => 'deleted');
20        $known_types = array_keys( $approved );
21        foreach( (array) $count as $row_num => $row ) {
22                $total += $row['num_comments'];
23@@ -735,6 +737,9 @@
24  * @return bool False if delete comment query failure, true on success.
25  */
26 function wp_delete_comment($comment_id) {
27+       if (wp_get_comment_status($comment_id) != 'deleted')
28+               return wp_set_comment_status($comment_id, 'delete');
29+       
30        global $wpdb;
31        do_action('delete_comment', $comment_id);
32 
33@@ -784,6 +789,8 @@
34                return 'unapproved';
35        elseif ( $approved == 'spam' )
36                return 'spam';
37+       elseif ( $approved == 'deleted' )
38+               return 'deleted';
39        else
40                return false;
41 }
42@@ -1045,7 +1052,9 @@
43                        $status = 'spam';
44                        break;
45                case 'delete':
46-                       return wp_delete_comment($comment_id);
47+                       $status = 'deleted';                   
48+                       if (wp_get_comment_status($comment_id) == 'deleted')
49+                               return wp_delete_comment($comment_id);
50                        break;
51                default:
52                        return false;
53Index: wp-admin/edit-comments.php
54===================================================================
55--- wp-admin/edit-comments.php  (revision 11707)
56+++ wp-admin/edit-comments.php  (working copy)
57@@ -86,7 +86,7 @@
58 $mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']);
59 
60 $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
61-if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam')) )
62+if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'deleted')) )
63        $comment_status = 'all';
64 
65 $comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : '';
66@@ -141,7 +141,8 @@
67                'all' => _n_noop('All', 'All'), // singular not used
68                'moderated' => _n_noop('Pending (<span class="pending-count">%s</span>)', 'Pending (<span class="pending-count">%s</span>)'),
69                'approved' => _n_noop('Approved', 'Approved'), // singular not used
70-               'spam' => _n_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)')
71+               'spam' => _n_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)'),
72+               'deleted' => _n_noop('Deleted (<span class="deleted-count">%s</span>)', 'Deleted (<span class="deleted-count">%s</span>)')
73        );
74 $link = 'edit-comments.php';
75 if ( !empty($comment_type) && 'all' != $comment_type )
76@@ -246,13 +247,17 @@
77 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
78 <option value="unapprove"><?php _e('Unapprove'); ?></option>
79 <?php endif; ?>
80-<?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
81+<?php if ( 'approved' != $comment_status ): ?>
82 <option value="approve"><?php _e('Approve'); ?></option>
83 <?php endif; ?>
84 <?php if ( 'spam' != $comment_status ): ?>
85 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
86 <?php endif; ?>
87+<?php if ( 'deleted' == $comment_status ): ?>
88+<option value="delete"><?php _e('Delete Permanently'); ?></option>
89+<?php else: ?>
90 <option value="delete"><?php _e('Delete'); ?></option>
91+<?php endif; ?>
92 </select>
93 <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
94 <?php wp_nonce_field('bulk-comments'); ?>
95@@ -333,13 +338,17 @@
96 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
97 <option value="unapprove"><?php _e('Unapprove'); ?></option>
98 <?php endif; ?>
99-<?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
100+<?php if ( 'approved' != $comment_status ): ?>
101 <option value="approve"><?php _e('Approve'); ?></option>
102 <?php endif; ?>
103 <?php if ( 'spam' != $comment_status ): ?>
104 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
105 <?php endif; ?>
106+<?php if ( 'deleted' == $comment_status ): ?>
107+<option value="delete"><?php _e('Delete Permanently'); ?></option>
108+<?php else: ?>
109 <option value="delete"><?php _e('Delete'); ?></option>
110+<?php endif; ?>
111 </select>
112 <input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
113 
114Index: wp-admin/admin-ajax.php
115===================================================================
116--- wp-admin/admin-ajax.php     (revision 11707)
117+++ wp-admin/admin-ajax.php     (working copy)
118@@ -192,7 +192,7 @@
119                        die( (string) time() );
120                $r = wp_set_comment_status( $comment->comment_ID, 'spam' );
121        } else {
122-               $r = wp_delete_comment( $comment->comment_ID );
123+               $r = wp_set_comment_status( $comment->comment_ID, 'delete' );
124        }
125        if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
126                _wp_ajax_delete_comment_response( $comment->comment_ID );
127@@ -336,7 +336,7 @@
128                die( (string) time() );
129 
130        $r = 0;
131-       if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
132+       if ( in_array( $current, array( 'unapproved', 'spam', 'deleted' ) ) ) {
133                check_ajax_referer( "approve-comment_$id" );
134                $result = wp_set_comment_status( $comment->comment_ID, 'approve', true );
135        } else {
136Index: wp-admin/wp-admin.css
137===================================================================
138--- wp-admin/wp-admin.css       (revision 11707)
139+++ wp-admin/wp-admin.css       (working copy)
140@@ -444,7 +444,7 @@
141        display: none;
142 }
143 
144-.unapproved .approve, .spam .approve {
145+.unapproved .approve, .spam .approve, .deleted .approve {
146        display: inline;
147 }
148 
149Index: wp-admin/includes/template.php
150===================================================================
151--- wp-admin/includes/template.php      (revision 11707)
152+++ wp-admin/includes/template.php      (working copy)
153@@ -2012,6 +2012,9 @@
154        } elseif ( 'spam' == $status ) {
155                $approved = "comment_approved = 'spam'";
156                $total = $count->spam;
157+       } elseif ( 'deleted' == $status ) {
158+               $approved = "comment_approved = 'deleted'";
159+               $total = $count->deleted;
160        } else {
161                $approved = "( comment_approved = '0' OR comment_approved = '1' )";
162                $total = $count->moderated + $count->approved;
163@@ -2151,10 +2154,13 @@
164                                        }
165                                        if ( 'spam' != $the_comment_status )
166                                                $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . __( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
167-                                       $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>';
168+                                       if ( 'deleted' == $the_comment_status )
169+                                               $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::deleted=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
170+                                       else
171+                                               $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>';
172                                        $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
173                                        $actions['quickedit'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\');return false;" class="vim-q" title="'.__('Quick Edit').'" href="#">' . __('Quick&nbsp;Edit') . '</a>';
174-                                       if ( 'spam' != $the_comment_status )
175+                                       if ( 'spam' != $the_comment_status && 'deleted' != $the_comment_status )
176                                                $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\');return false;" class="vim-r" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
177 
178                                        $actions = apply_filters( 'comment_row_actions', $actions, $comment );
179Index: wp-admin/js/edit-comments.dev.js
180===================================================================
181--- wp-admin/js/edit-comments.dev.js    (revision 11707)
182+++ wp-admin/js/edit-comments.dev.js    (working copy)
183@@ -38,7 +38,7 @@
184                settings.data._page = pageInput.val();
185                settings.data._url = document.location.href;
186 
187-               if ( 'undefined' != showNotice && settings.data.action && settings.data.action == 'delete-comment' && !settings.data.spam )
188+               if ( 'undefined' != showNotice && settings.data.action && settings.data.action == 'delete-comment' && settings.data.deleted)
189                        return showNotice.warn() ? settings : false;
190 
191                return settings;
192@@ -101,7 +101,26 @@
193                        a.html(n);
194                });
195 
196+               $('span.deleted-count').each( function() {
197+                       var a = $(this), n;
198+                       n = a.html().replace(/[ ,.]+/g, '');
199+                       n = parseInt(n,10);
200+                       if ( isNaN(n) ) return;
201+                       if ( $(settings.target).parents( 'span.delete' ).size() && $('#' + settings.element).is('.deleted') ) { // we destroyed a deleted comment
202+                               n--;
203+                       } else if ( $(settings.target).parents( 'span.delete' ).size() ) { // we deleted a comment
204+                               n++;
205+                       } else if ( $('#' + settings.element).is('.deleted') ) { // we approved or spammed a deleted comment
206+                               n--;
207+                       }
208+                       if ( n < 0 ) { n = 0; }
209+                       n = n.toString();
210+                       if ( n.length > 3 )
211+                               n = n.substr(0, n.length-3)+' '+n.substr(-3);
212+                       a.html(n);
213+               });
214 
215+
216                // XML response
217                if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
218                        // Set the total to the known good value (even if this value is a little old, newer values should only be a few less, and so shouldn't mess up the page links)
219Index: wp-admin/edit-form-comment.php
220===================================================================
221--- wp-admin/edit-form-comment.php      (revision 11707)
222+++ wp-admin/edit-form-comment.php      (working copy)
223@@ -38,19 +38,24 @@
224 <div class="submitbox" id="submitcomment">
225 <div id="minor-publishing">
226 
227+<?php if ($comment->comment_approved == '1') { ?>
228 <div id="minor-publishing-actions">
229 <div id="preview-action">
230 <a class="preview button" href="<?php echo get_comment_link(); ?>" target="_blank"><?php _e('View Comment'); ?></a>
231 </div>
232 <div class="clear"></div>
233 </div>
234+<?php } ?>
235 
236 <div id="misc-publishing-actions">
237 
238 <div class="misc-pub-section" id="comment-status-radio">
239 <label class="approved"><input type="radio"<?php checked( $comment->comment_approved, '1' ); ?> name="comment_status" value="1" /><?php /* translators: comment type radio button */ echo _x('Approved', 'adjective') ?></label><br />
240 <label class="waiting"><input type="radio"<?php checked( $comment->comment_approved, '0' ); ?> name="comment_status" value="0" /><?php /* translators: comment type radio button */ echo _x('Pending', 'adjective') ?></label><br />
241-<label class="spam"><input type="radio"<?php checked( $comment->comment_approved, 'spam' ); ?> name="comment_status" value="spam" /><?php /* translators: comment type radio button */ echo _x('Spam', 'adjective'); ?></label>
242+<label class="spam"><input type="radio"<?php checked( $comment->comment_approved, 'spam' ); ?> name="comment_status" value="spam" /><?php /* translators: comment type radio button */ echo _x('Spam', 'adjective'); ?></label><br />
243+<?php if ($comment->comment_approved == 'deleted') { ?>
244+<label class="deleted"><input type="radio"<?php checked( $comment->comment_approved, 'deleted' ); ?> name="comment_status" value="deleted" /><?php /* translators: comment type radio button */ echo _x('Deleted', 'adjective'); ?></label>
245+<?php } ?>
246 </div>
247 
248 <div class="misc-pub-section curtime misc-pub-section-last">
249@@ -69,7 +74,12 @@
250 
251 <div id="major-publishing-actions">
252 <div id="delete-action">
253-<?php echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=deletecomment&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'delete-comment_' . $comment->comment_ID) . "' onclick=\"if ( confirm('" . esc_js(__("You are about to delete this comment. \n  'Cancel' to stop, 'OK' to delete.")) . "') ){return true;}return false;\">" . __('Delete') . "</a>\n"; ?>
254+<?php
255+if ($comment->comment_approved == 'deleted')
256+       echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=deletecomment&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'delete-comment_' . $comment->comment_ID) . "' onclick=\"if ( confirm('" . esc_js(__("You are about to delete this comment. \n  'Cancel' to stop, 'OK' to delete.")) . "') ){return true;}return false;\">" . __('Delete Permanently') . "</a>\n";
257+else
258+       echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=deletecomment&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'delete-comment_' . $comment->comment_ID) . "'>" . __('Delete') . "</a>\n";
259+?>
260 </div>
261 <div id="publishing-action">
262 <input type="submit" name="save" value="<?php esc_attr_e('Update Comment'); ?>" tabindex="4" class="button-primary" />
263Index: wp-admin/css/colors-fresh.css
264===================================================================
265--- wp-admin/css/colors-fresh.css       (revision 11707)
266+++ wp-admin/css/colors-fresh.css       (working copy)
267@@ -58,7 +58,8 @@
268        border-color: #ccc;
269 }
270 
271-#poststuff .inside label.spam {
272+#poststuff .inside label.spam,
273+#poststuff .inside label.deleted {
274        color: red;
275 }
276 
277Index: wp-admin/css/colors-classic.css
278===================================================================
279--- wp-admin/css/colors-classic.css     (revision 11707)
280+++ wp-admin/css/colors-classic.css     (working copy)
281@@ -58,7 +58,8 @@
282        border-color: #ccc;
283 }
284 
285-#poststuff .inside label.spam {
286+#poststuff .inside label.spam,
287+#poststuff .inside label.deleted {
288        color: red;
289 }
290