Make WordPress Core

Ticket #33154: 33154.3.diff

File 33154.3.diff, 10.5 KB (added by dd32, 10 years ago)
  • src/wp-admin/includes/class-wp-comments-list-table.php

    class WP_Comments_List_Table extends WP_ 
    429429         * @global WP_Post $post
    430430         * @global object  $comment
    431431         *
    432432         * @param object $a_comment
    433433         */
    434434        public function single_row( $a_comment ) {
    435435                global $post, $comment;
    436436
    437437                $comment = $a_comment;
    438438                $the_comment_class = wp_get_comment_status( $comment->comment_ID );
    439439                if ( ! $the_comment_class ) {
    440440                        $the_comment_class = '';
    441441                }
    442442                $the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment->comment_ID, $comment->comment_post_ID ) );
    443443
    444                 $post = get_post( $comment->comment_post_ID );
    445 
    446444                $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
    447445
    448446                echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
    449447                $this->single_row_columns( $comment );
    450448                echo "</tr>\n";
    451449        }
    452450
    453451        /**
    454452         * Generate and display row actions links.
    455453         *
    456454         * @since 4.3.0
    457455         * @access protected
    458456         *
    459457         * @param object $comment     Comment being acted upon.
    460458         * @param string $column_name Current column name.
    461459         * @param string $primary     Primary column name.
    462460         * @return string|void Comment row actions output.
    463461         */
    464462        protected function handle_row_actions( $comment, $column_name, $primary ) {
    465463                global $comment_status;
    466464
    467465                if ( $primary !== $column_name ) {
    468466                        return '';
    469467                }
    470468
    471469                if ( ! $this->user_can ) {
    472470                        return;
    473471                }
    474472
    475                 $post = get_post();
    476 
    477473                $the_comment_status = wp_get_comment_status( $comment->comment_ID );
    478474
    479475                $out = '';
    480476
    481477                $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
    482478                $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
    483479
    484480                $url = "comment.php?c=$comment->comment_ID";
    485481
    486482                $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
    487483                $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
    488484                $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
    489485                $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
    490486                $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
    491487                $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
    class WP_Comments_List_Table extends WP_ 
    522518                if ( 'trash' == $the_comment_status ) {
    523519                        $actions['untrash'] = "<a href='$untrash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1' class='vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
    524520                }
    525521
    526522                if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
    527523                        $actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::delete=1' class='delete vim-d vim-destructive'>" . __( 'Delete Permanently' ) . '</a>';
    528524                } else {
    529525                        $actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
    530526                }
    531527
    532528                if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
    533529                        $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>';
    534530
    535531                        $format = '<a data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s" title="%s" href="#">%s</a>';
    536532
    537                         $actions['quickedit'] = sprintf( $format, $comment->comment_ID, $post->ID, 'edit', 'vim-q comment-inline',esc_attr__( 'Edit this item inline' ), __( 'Quick&nbsp;Edit' ) );
     533                        $actions['quickedit'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'edit', 'vim-q comment-inline',esc_attr__( 'Edit this item inline' ), __( 'Quick&nbsp;Edit' ) );
    538534
    539                         $actions['reply'] = sprintf( $format, $comment->comment_ID, $post->ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) );
     535                        $actions['reply'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) );
    540536                }
    541537
    542538                /** This filter is documented in wp-admin/includes/dashboard.php */
    543539                $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
    544540
    545541                $i = 0;
    546542                $out .= '<div class="row-actions">';
    547543                foreach ( $actions as $action => $link ) {
    548544                        ++$i;
    549545                        ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
    550546
    551547                        // Reply and quickedit need a hide-if-no-js span when not added with ajax
    552548                        if ( ( 'reply' == $action || 'quickedit' == $action ) && ! defined('DOING_AJAX') )
    553549                                $action .= ' hide-if-no-js';
    554550                        elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) {
    class WP_Comments_List_Table extends WP_ 
    660656
    661657        /**
    662658         *
    663659         * @return string
    664660         */
    665661        public function column_date() {
    666662                return get_comment_date( __( 'Y/m/d \a\t g:i a' ) );
    667663        }
    668664
    669665        /**
    670666         * @access public
    671667         */
    672668        public function column_response() {
    673669                $post = get_post();
    674670
     671                if ( ! $post ) {
     672                        return;
     673                }
     674
    675675                if ( isset( $this->pending_count[$post->ID] ) ) {
    676676                        $pending_comments = $this->pending_count[$post->ID];
    677677                } else {
    678678                        $_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
    679679                        $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID];
    680680                }
    681681
    682682                if ( current_user_can( 'edit_post', $post->ID ) ) {
    683683                        $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>";
    684684                        $post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>';
    685685                } else {
    686686                        $post_link = esc_html( get_the_title( $post->ID ) );
    687687                }
    688688
    689689                echo '<div class="response-links">';
  • src/wp-includes/capabilities.php

    function map_meta_cap( $cap, $user_id )  
    12931293                         * @param string $cap      Capability name.
    12941294                         * @param array  $caps     User capabilities.
    12951295                         */
    12961296                        $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps );
    12971297                        if ( ! $allowed )
    12981298                                $caps[] = $cap;
    12991299                } elseif ( $meta_key && is_protected_meta( $meta_key, 'post' ) ) {
    13001300                        $caps[] = $cap;
    13011301                }
    13021302                break;
    13031303        case 'edit_comment':
    13041304                $comment = get_comment( $args[0] );
    13051305                if ( empty( $comment ) )
    13061306                        break;
    13071307                $post = get_post( $comment->comment_post_ID );
    1308                 $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
     1308
     1309                /*
     1310                 * If the post doesn't exist, we have an orphaned comment.
     1311                 * Fall back to the edit_posts capability, instead.
     1312                 */
     1313                if ( $post ) {
     1314                        $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
     1315                } else {
     1316                        $caps = map_meta_cap( 'edit_posts', $user_id );
     1317                }
    13091318                break;
    13101319        case 'unfiltered_upload':
    13111320                if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) )  )
    13121321                        $caps[] = $cap;
    13131322                else
    13141323                        $caps[] = 'do_not_allow';
    13151324                break;
    13161325        case 'unfiltered_html' :
    13171326                // Disallow unfiltered_html for all users, even admins and super admins.
    13181327                if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML )
    13191328                        $caps[] = 'do_not_allow';
    13201329                elseif ( is_multisite() && ! is_super_admin( $user_id ) )
    13211330                        $caps[] = 'do_not_allow';
    13221331                else
    13231332                        $caps[] = $cap;
  • tests/phpunit/tests/ajax/EditComment.php

    class Tests_Ajax_EditComment extends WP_ 
    6363                $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
    6464
    6565                // Check the meta data
    6666                $this->assertEquals( -1, (string) $xml->response[0]->edit_comment['position'] );
    6767                $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->edit_comment['id'] );
    6868                $this->assertEquals( 'edit-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
    6969
    7070                // Check the payload
    7171                $this->assertNotEmpty( (string) $xml->response[0]->edit_comment[0]->response_data );
    7272
    7373                // And supplemental is empty
    7474                $this->assertEmpty( (string) $xml->response[0]->edit_comment[0]->supplemental );
    7575        }
    7676
    7777        /**
     78         * @ticket 33154
     79         */
     80        function test_editor_can_edit_orphan_comments() {
     81                global $wpdb;
     82
     83                // Become an editor
     84                $this->_setRole( 'editor' );
     85
     86                // Get a comment
     87                $comments = get_comments( array(
     88                        'post_id' => $this->_comment_post->ID
     89                ) );
     90                $comment = array_pop( $comments );
     91
     92                // Manually update the comment_post_ID, because wp_update_comment() will prevent it.
     93                $wpdb->query( "UPDATE {$wpdb->comments} SET comment_post_ID=0 WHERE comment_ID={$comment->comment_ID}" );
     94                clean_comment_cache( $comment->comment_ID );
     95
     96                // Set up a default request
     97                $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
     98                $_POST['comment_ID']                  = $comment->comment_ID;
     99                $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     100
     101                // Make the request
     102                try {
     103                        $this->_handleAjax( 'edit-comment' );
     104                } catch ( WPAjaxDieContinueException $e ) {
     105                        unset( $e );
     106                }
     107
     108                // Get the response
     109                $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
     110
     111                // Check the meta data
     112                $this->assertEquals( -1, (string) $xml->response[0]->edit_comment['position'] );
     113                $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->edit_comment['id'] );
     114                $this->assertEquals( 'edit-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
     115
     116                // Check the payload
     117                $this->assertNotEmpty( (string) $xml->response[0]->edit_comment[0]->response_data );
     118
     119                // And supplemental is empty
     120                $this->assertEmpty( (string) $xml->response[0]->edit_comment[0]->supplemental );
     121        }
     122
     123        /**
    78124         * Get comments as a non-privileged user (subscriber)
    79125         * Expects test to fail
    80126         * @return void
    81127         */
    82128        public function test_as_subscriber() {
    83129
    84130                // Become an administrator
    85131                $this->_setRole( 'subscriber' );
    86132
    87133                // Get a comment
    88134                $comments = get_comments( array(
    89135                        'post_id' => $this->_comment_post->ID
    90136                ) );
    91137                $comment = array_pop( $comments );
    92138