Make WordPress Core

Ticket #49236: 49236.2.patch

File 49236.2.patch, 10.3 KB (added by imath, 5 years ago)
  • src/wp-admin/includes/ajax-actions.php

    diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php
    index ea33d9d792..180335a005 100644
    function wp_ajax_replyto_comment( $action ) { 
    12831283                $comment_author_email = wp_slash( $user->user_email );
    12841284                $comment_author_url   = wp_slash( $user->user_url );
    12851285                $comment_content      = trim( $_POST['content'] );
    1286                 $comment_type         = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : '';
     1286                $comment_type         = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : 'comment';
    12871287
    12881288                if ( current_user_can( 'unfiltered_html' ) ) {
    12891289                        if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) {
  • src/wp-admin/includes/schema.php

    diff --git src/wp-admin/includes/schema.php src/wp-admin/includes/schema.php
    index bb993f2617..b191cd6476 100644
    CREATE TABLE $wpdb->comments ( 
    111111        comment_karma int(11) NOT NULL default '0',
    112112        comment_approved varchar(20) NOT NULL default '1',
    113113        comment_agent varchar(255) NOT NULL default '',
    114         comment_type varchar(20) NOT NULL default '',
     114        comment_type varchar(20) NOT NULL default 'comment',
    115115        comment_parent bigint(20) unsigned NOT NULL default '0',
    116116        user_id bigint(20) unsigned NOT NULL default '0',
    117117        PRIMARY KEY  (comment_ID),
  • src/wp-admin/includes/upgrade.php

    diff --git src/wp-admin/includes/upgrade.php src/wp-admin/includes/upgrade.php
    index 26614c9634..c38cd6d4f8 100644
    Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.' 
    283283                                'comment_date'         => $now,
    284284                                'comment_date_gmt'     => $now_gmt,
    285285                                'comment_content'      => $first_comment,
     286                                'comment_type'         => 'comment',
    286287                        )
    287288                );
    288289
    function upgrade_all() { 
    834835                upgrade_530();
    835836        }
    836837
     838        if ( $wp_current_db_version < 47426 ) {
     839                wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_types_batch' );
     840        }
     841
    837842        maybe_disable_link_manager();
    838843
    839844        maybe_disable_automattic_widgets();
  • src/wp-content/themes/twentyten/functions.php

    diff --git src/wp-content/themes/twentyten/functions.php src/wp-content/themes/twentyten/functions.php
    index 96629d1074..6c092f1074 100644
    if ( ! function_exists( 'twentyten_comment' ) ) : 
    418418                $GLOBALS['comment'] = $comment;
    419419                switch ( $comment->comment_type ) :
    420420                        case '':
     421                        case 'comment':
    421422                                ?>
    422423                <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    423424                <div id="comment-<?php comment_ID(); ?>">
  • src/wp-includes/class-wp-comment-query.php

    diff --git src/wp-includes/class-wp-comment-query.php src/wp-includes/class-wp-comment-query.php
    index 8d788a3ec3..4b9d80e3e3 100644
    class WP_Comment_Query { 
    741741
    742742                                        case 'comment':
    743743                                        case 'comments':
    744                                                 $comment_types[ $operator ][] = "''";
     744                                                $comment_types[ $operator ][] = "'comment'";
    745745                                                break;
    746746
    747747                                        case 'pings':
  • src/wp-includes/class-wp-comment.php

    diff --git src/wp-includes/class-wp-comment.php src/wp-includes/class-wp-comment.php
    index 70d7db2bd8..9b3b57e206 100644
    final class WP_Comment { 
    116116         * @since 4.4.0
    117117         * @var string
    118118         */
    119         public $comment_type = '';
     119        public $comment_type = 'comment';
    120120
    121121        /**
    122122         * Parent comment ID.
  • src/wp-includes/comment.php

    diff --git src/wp-includes/comment.php src/wp-includes/comment.php
    index 15cb44bcc3..768bc53c76 100644
    function wp_insert_comment( $commentdata ) { 
    19011901        $comment_karma    = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma'];
    19021902        $comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved'];
    19031903        $comment_agent    = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent'];
    1904         $comment_type     = ! isset( $data['comment_type'] ) ? '' : $data['comment_type'];
     1904        $comment_type     = ! isset( $data['comment_type'] ) ? 'comment' : $data['comment_type'];
    19051905        $comment_parent   = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent'];
    19061906
    19071907        $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id'];
    function wp_throttle_comment_flood( $block, $time_lastcomment, $time_newcomment 
    20572057 *     @type string $comment_author_email The comment author email address.
    20582058 *     @type string $comment_author_url   The comment author URL.
    20592059 *     @type string $comment_content      The content of the comment.
     2060 *     @type string $comment_type         The name of the comment type.
    20602061 *     @type string $comment_date         The date the comment was submitted. Default is the current time.
    20612062 *     @type string $comment_date_gmt     The date the comment was submitted in the GMT timezone.
    20622063 *                                        Default is `$comment_date` in the GMT timezone.
    function wp_new_comment( $commentdata, $avoid_die = false ) { 
    21222123                $commentdata['comment_date_gmt'] = current_time( 'mysql', 1 );
    21232124        }
    21242125
     2126        if ( empty( $commentdata['comment_type'] ) ) {
     2127                $commentdata['comment_type'] = 'comment';
     2128        }
     2129
    21252130        $commentdata = wp_filter_comment( $commentdata );
    21262131
    21272132        $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $avoid_die );
    function wp_handle_comment_submission( $comment_data ) { 
    33483353                }
    33493354        }
    33503355
    3351         $comment_type = '';
     3356        $comment_type = 'comment';
    33523357
    33533358        if ( get_option( 'require_name_email' ) && ! $user->exists() ) {
    33543359                if ( '' == $comment_author_email || '' == $comment_author ) {
    function wp_comments_personal_data_eraser( $email_address, $page = 1 ) { 
    36363641function wp_cache_set_comments_last_changed() {
    36373642        wp_cache_set( 'last_changed', microtime(), 'comment' );
    36383643}
     3644
     3645/**
     3646 * Updates the comment type of a batch of comments.
     3647 *
     3648 * @since 5.5.0
     3649 *
     3650 * @global wpdb $wpdb WordPress database abstraction object.
     3651 */
     3652function _wp_batch_update_comment_types() {
     3653        global $wpdb;
     3654
     3655        $lock_name = 'update_comment_types.lock';
     3656
     3657        // Try to lock.
     3658        $lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_name, time() ) );
     3659
     3660        if ( ! $lock_result ) {
     3661                $lock_result = get_option( $lock_name );
     3662
     3663                // Bail if we were unable to create a lock, or if the existing lock is still valid.
     3664                if ( ! $lock_result || ( $lock_result > ( time() - HOUR_IN_SECONDS ) ) ) {
     3665                        wp_schedule_single_event( time() + ( 5 * MINUTE_IN_SECONDS ), 'wp_update_comment_types_batch' );
     3666                        return;
     3667                }
     3668        }
     3669
     3670        // Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
     3671        update_option( $lock_name, time() );
     3672
     3673        // Check if there's still empty comment types.
     3674        $empty_comment_types = $wpdb->get_var(
     3675                "SELECT comment_ID FROM $wpdb->comments
     3676                WHERE comment_type = ''
     3677                LIMIT 1"
     3678        );
     3679
     3680        // No empty comment types, we're done here.
     3681        if ( ! $empty_comment_types ) {
     3682                update_option( 'finished_updating_comments_type', true );
     3683                delete_option( $lock_name );
     3684                return;
     3685        }
     3686
     3687        // Empty comment types found? We'll need to run this script again.
     3688        wp_schedule_single_event( time() + ( 2 * MINUTE_IN_SECONDS ), 'wp_update_comment_types_batch' );
     3689
     3690        // Update the `comment_type` field value to be `comment` for the next 100 rows about comments.
     3691        $wpdb->query(
     3692                "UPDATE {$wpdb->comments}
     3693                SET comment_type = 'comment'
     3694                WHERE comment_type = ''
     3695                ORDER BY comment_ID DESC
     3696                LIMIT 100"
     3697        );
     3698
     3699        delete_option( $lock_name );
     3700}
     3701
     3702/**
     3703 * In order to avoid the _wp_batch_update_comment_types() job being accidentally removed,
     3704 * check that it's still scheduled while we haven't finished updating comment types.
     3705 *
     3706 * @ignore
     3707 * @since 5.5.0
     3708 */
     3709function _wp_check_for_scheduled_update_comment_types() {
     3710        if ( ! get_option( 'finished_updating_comments_type' ) && ! wp_next_scheduled( 'wp_update_comment_types_batch' ) ) {
     3711                wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'wp_update_comment_types_batch' );
     3712        }
     3713}
  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index 9a46d7e2f7..9a8636760c 100644
    add_action( 'rest_api_init', 'register_initial_settings', 10 ); 
    450450add_action( 'rest_api_init', 'create_initial_rest_routes', 99 );
    451451add_action( 'parse_request', 'rest_api_loaded' );
    452452
     453// Comments comment type updates.
     454add_action( 'admin_init', '_wp_check_for_scheduled_update_comment_types' );
     455add_action( 'wp_update_comment_types_batch', '_wp_batch_update_comment_types' );
     456
    453457/**
    454458 * Filters formerly mixed into wp-includes.
    455459 */
  • src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
    index 8d241d7c63..f12082c3c0 100644
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    585585                        return $prepared_comment;
    586586                }
    587587
    588                 $prepared_comment['comment_type'] = '';
     588                $prepared_comment['comment_type'] = 'comment';
    589589
    590590                /*
    591591                 * Do not allow a comment to be created with missing or empty
  • src/wp-includes/version.php

    diff --git src/wp-includes/version.php src/wp-includes/version.php
    index 3cb65cb0cd..344c43186d 100644
    $wp_version = '5.5-alpha-47426-src'; 
    2020 *
    2121 * @global int $wp_db_version
    2222 */
    23 $wp_db_version = 47018;
     23$wp_db_version = 47426;
    2424
    2525/**
    2626 * Holds the TinyMCE version.
  • tests/phpunit/tests/comment-submission.php

    diff --git tests/phpunit/tests/comment-submission.php tests/phpunit/tests/comment-submission.php
    index 70d9bb1185..6a5b845bb0 100644
    class Tests_Comment_Submission extends WP_UnitTestCase { 
    742742                                'comment_author_email' => $user->user_email,
    743743                                'comment_author_url'   => $user->user_url,
    744744                                'comment_content'      => $data['comment'],
    745                                 'comment_type'         => '',
     745                                'comment_type'         => 'comment',
    746746                                'comment_parent'       => '0',
    747747                                'user_ID'              => $user->ID,
    748748                                'user_id'              => $user->ID,