Make WordPress Core

Ticket #11260: 11260-first-run.diff

File 11260-first-run.diff, 7.4 KB (added by caesarsgrunt, 14 years ago)

First attempt at implementing undo for spam.

  • wp-admin/admin-ajax.php

     
    220220                if ( 'spam' == $status )
    221221                        die( (string) time() );
    222222                $r = wp_set_comment_status( $comment->comment_ID, 'spam' );
     223        } elseif ( isset($_POST['unspam']) && ( 0 == $_POST['unspam'] || 1 == $_POST['unspam'] ) ) {
     224                if ( 'spam' != $status )
     225                        die( (string) time() );
     226                $r = wp_set_comment_status( $comment->comment_ID, $_POST['unspam'] );
    223227        } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
    224228                $r = wp_delete_comment( $comment->comment_ID );
    225229        } else {
  • wp-admin/includes/template.php

     
    23712371 */
    23722372function wp_comment_trashnotice() {
    23732373?>
    2374 <div class="hidden" id="undo-holder">
    2375 <div class="trash-undo-inside"><?php _e('Comment by'); ?> <strong></strong> <?php _e('moved to the trash.'); ?> <span class="untrash"><a class="undo-trash" href="#"><?php _e('Undo'); ?></a></span></div>
     2374<div class="hidden" id="trash-undo-holder">
     2375        <div class="trash-undo-inside"><?php printf(__('Comment by %s moved to the trash.'), '<strong></strong>'); ?> <span class="undo untrash"><a href="#"><?php _e('Undo'); ?></a></span></div>
    23762376</div>
     2377<div class="hidden" id="spam-undo-holder">
     2378        <div class="spam-undo-inside"><?php printf(__('Comment by %s marked as spam.'), '<strong></strong>'); ?> <span class="undo unspam"><a href="#"><?php _e('Undo'); ?></a></span></div>
     2379</div>
    23772380<?php
    23782381}
    23792382
  • wp-admin/js/edit-comments.dev.js

     
    3838                settings.data._per_page = perPageInput.val() || 0;
    3939                settings.data._page = pageInput.val() || 0;
    4040                settings.data._url = document.location.href;
     41               
     42                var action;
     43                if ( cl.indexOf(':trash=1') != -1 )
     44                        action = 'trash';
     45                else if ( cl.indexOf(':spam=1') != -1 )
     46                        action = 'spam';
    4147
    42                 if ( cl.indexOf(':trash=1') != -1 ) {
     48                if ( action == 'trash' || action == 'spam' ) {
    4349                        id = cl.replace(/.*?comment-([0-9]+).*/, '$1');
    4450                        el = $('#comment-' + id);
    45                         note = $('#undo-holder').html();
     51                        note = $('#'+action+'-undo-holder').html();
    4652
    4753                        if ( el.siblings('#replyrow').length && commentReply.cid == id )
    4854                                commentReply.close();
     
    5056                        if ( el.is('tr') ) {
    5157                                n = el.children(':visible').length;
    5258                                author = $('.author strong', el).text();
    53                                 h = $('<tr id="trashundo-' + id + '" class="trash-undo" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
     59                                h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
    5460                        } else {
    5561                                author = $('.comment-author', el).text();
    56                                 h = $('<div id="trashundo-' + id + '" style="display:none;" class="trash-undo">' + note + '</div>');
     62                                h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
    5763                        }
    5864
    5965                        el.before(h);
    6066
    61                         $('strong', '#trashundo-' + id).text(author + ' ');
    62                         a = $('a.undo-trash', '#trashundo-' + id);
    63                         a.attr('href', 'comment.php?action=untrashcomment&c=' + id + '&_ajax_nonce=' + settings.data._ajax_nonce);
    64                         a.attr('className', 'delete:the-comment-list:comment-' + id + '::untrash=1 vim-z vim-destructive');
    65                         $('.avatar', el).clone().prependTo('#trashundo-' + id + ' .trash-undo-inside');
     67                        $('strong', '#undo-' + id).text(author + ' ');
     68                        a = $('.undo a', '#undo-' + id);
     69                        if ( action == 'trash' ) {
     70                                a.attr('href', 'comment.php?action=untrashcomment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
     71                                a.attr('className', 'delete:the-comment-list:comment-' + id + '::untrash=1 vim-z vim-destructive');
     72                        }
     73                        else if ( action == 'spam' ) {
     74                                a.attr('href', 'comment.php?action=deletecomment&dt=unspam&s=' + ($(el).is('.approved') ? '1' : '0') + '&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
     75                                a.attr('className', 'delete:the-comment-list:comment-' + id + '::unspam=' + ($(el).is('.approved') ? '1' : '0') + ' vim-z vim-destructive');
     76/*
     77                                if ( $(el).is('.approved') ) {
     78                                        a.attr('href', $('.approve a', el).attr('href'));
     79                                        a.attr('className', $('.approve a', el).attr('className'));
     80                                }
     81                                else {
     82                                        a.attr('href', $('.unapprove a', el).attr('href'));
     83                                        a.attr('className', $('.unapprove a', el).attr('className'));
     84                                }
     85*/
     86                        }
     87                        $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
    6688
    6789                        a.click(function(){
    6890                                list.wpList.del(this);
    69                                 $('#trashundo-' + id).fadeOut(300, function(){
     91                                $('#undo-' + id).fadeOut(300, function(){
    7092                                        $(this).remove();
    7193                                        $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() });
    7294                                });
     
    135157
    136158        // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
    137159        delAfter = function( r, settings ) {
    138                 var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), spam, trash;
     160                var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), spam, trash;
    139161
    140162                function getUpdate(s) {
    141163                        if ( $(settings.target).parent().is('span.' + s) )
     
    150172
    151173                if ( untrash )
    152174                        trash = -1;
     175                if ( unspam )
     176                        spam = -1;
    153177
    154178                $('span.pending-count').each( function() {
    155179                        var a = $(this), n = getCount(a), unapproved = $('#' + settings.element).is('.unapproved');
    156180
    157                         if ( $(settings.target).parent().is('span.unapprove') || ( untrash && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
     181                        if ( $(settings.target).parent().is('span.unapprove') || ( (untrash||unspam) && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
    158182                                n = n + 1;
    159183                        } else if ( unapproved ) { // we deleted a formerly unapproved comment
    160184                                n = n - 1;
     
    212236                .bind('wpListDelEnd', function(e, s){
    213237                        var id = s.element.replace(/[^0-9]+/g, '');
    214238
    215                         if ( s.target.className.indexOf(':trash=1') != -1 )
    216                                 $('#trashundo-' + id).fadeIn(300, function(){ $(this).show() });
     239                        if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 )
     240                                $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
    217241                });
    218242};
    219243
  • wp-admin/comment.php

     
    153153
    154154        if ( 'spam' == $_REQUEST['dt'] )
    155155                wp_set_comment_status( $comment->comment_ID, 'spam' );
     156        elseif ( 'unspam' == $_REQUEST['dt'] && isset($_REQUEST['s']) )
     157                wp_set_comment_status( $comment->comment_ID, $_REQUEST['s'] );
    156158        else
    157159                wp_delete_comment( $comment->comment_ID );
    158160
  • wp-admin/wp-admin.dev.css

     
    35243524        font-size: 11px;
    35253525}
    35263526
    3527 .trash-undo-inside {
     3527.trash-undo-inside,
     3528.spam-undo-inside {
    35283529        margin: 1px 8px 1px 0;
    35293530        line-height: 16px;
    35303531}
    35313532
     3533.spam-undo-inside .avatar,
    35323534.trash-undo-inside .avatar {
    35333535        height: 20px;
    35343536        width: 20px;