Make WordPress Core

Changeset 35331


Ignore:
Timestamp:
10/21/2015 04:25:31 PM (9 years ago)
Author:
boonebgorges
Message:

Don't force comment pagination.

[34561] instituted the policy of forcing pagination for comments. This strategy
was intended to avert problems when 'page_comments' is set to 0 - as it is by
default - and the number of comments on a given post rises into the hundreds or
thousands. By forcing pagination in all cases, we ensured that WordPress would
not time out by processing unwieldy numbers of comments on a given pageload.

The strategy proves problematic, however, because comment permalinks are
generated using the page of the comment. Forcing pagination for posts that
were not previously paginated would change the URL of all comments that do not
appear on the default comment page.

This changeset reintroduces the 'page_comments' setting and its corresponding
checkbox on Settings > Discussion. A number of tests, which were written after
[34561], are modified to work now that 'page_comments' will, once again, be
disabled by default.

See #8071.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/schema.php

    r35312 r35331  
    483483    'thread_comments' => 1,
    484484    'thread_comments_depth' => 5,
     485    'page_comments' => 0,
    485486    'comments_per_page' => 50,
    486487    'default_comments_page' => 'newest',
     
    568569        'random_seed', 'rss_excerpt_length', 'secret', 'use_linksupdate', 'default_comment_status_page',
    569570        'wporg_popular_tags', 'what_to_show', 'rss_language', 'language', 'enable_xmlrpc', 'enable_app',
    570         'embed_autourls', 'default_post_edit_rows', 'page_comments',
     571        'embed_autourls', 'default_post_edit_rows',
    571572    );
    572573    foreach ( $unusedoptions as $option )
  • trunk/src/wp-admin/options-discussion.php

    r34726 r35331  
    9999?></label>
    100100<br />
     101<label for="page_comments">
     102<input name="page_comments" type="checkbox" id="page_comments" value="1" <?php checked( '1', get_option( 'page_comments' ) ); ?> />
    101103<?php
    102104$default_comments_page = '</label><label for="default_comments_page"><select name="default_comments_page" id="default_comments_page"><option value="newest"';
     
    106108$default_comments_page .= '>' . __('first') . '</option></select>';
    107109
    108 printf( __('Break comments into pages with %1$s top level comments per page and the %2$s page displayed by default'), '<label for="comments_per_page"><input name="comments_per_page" type="number" step="1" min="0" id="comments_per_page" value="' . esc_attr(get_option('comments_per_page')) . '" class="small-text" />', $default_comments_page );
     110printf( __('Break comments into pages with %1$s top level comments per page and the %2$s page displayed by default'), '</label><label for="comments_per_page"><input name="comments_per_page" type="number" step="1" min="0" id="comments_per_page" value="' . esc_attr(get_option('comments_per_page')) . '" class="small-text" />', $default_comments_page );
    109111
    110112?></label>
  • trunk/src/wp-admin/options.php

    r34912 r35331  
    8484$whitelist_options = array(
    8585    'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ),
    86     'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ),
     86    'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ),
    8787    'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
    8888    'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
  • trunk/src/wp-includes/canonical.php

    r35170 r35331  
    319319            }
    320320
    321             if ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) {
     321            if ( get_option( 'page_comments' ) && (
     322                ( 'newest' == get_option( 'default_comments_page' ) && get_query_var( 'cpage' ) > 0 ) ||
     323                ( 'newest' != get_option( 'default_comments_page' ) && get_query_var( 'cpage' ) > 1 )
     324            ) ) {
    322325                $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . get_query_var('cpage'), 'commentpaged' );
    323326                $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
  • trunk/src/wp-includes/comment-functions.php

    r35170 r35331  
    808808        return 0;
    809809
     810    if ( ! get_option( 'page_comments' ) ) {
     811        return 1;
     812    }
     813
    810814    if ( !isset($per_page) )
    811815        $per_page = (int) get_query_var('comments_per_page');
     
    861865
    862866    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    863     if ( '' === $args['per_page'] ) {
    864         $args['per_page'] = get_query_var( 'comments_per_page' );
    865     }
    866 
    867     if ( '' === $args['per_page'] ) {
    868         $args['per_page'] = get_option( 'comments_per_page' );
     867    if ( get_option( 'page_comments' ) ) {
     868        if ( '' === $args['per_page'] ) {
     869            $args['per_page'] = get_query_var( 'comments_per_page' );
     870        }
     871
     872        if ( '' === $args['per_page'] ) {
     873            $args['per_page'] = get_option( 'comments_per_page' );
     874        }
    869875    }
    870876
  • trunk/src/wp-includes/comment-template.php

    r35013 r35331  
    707707    // No 'cpage' is provided, so we calculate one.
    708708    } else {
    709         if ( '' === $args['per_page'] ) {
     709        if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) {
    710710            $args['per_page'] = get_option('comments_per_page');
    711711        }
     
    12691269    $comment_args = array(
    12701270        'orderby' => 'comment_date_gmt',
     1271        'order' => 'ASC',
    12711272        'status'  => 'approve',
    12721273        'post_id' => $post->ID,
     
    12821283    }
    12831284
    1284     $per_page = (int) get_query_var( 'comments_per_page' );
    1285     if ( 0 === $per_page ) {
    1286         $per_page = (int) get_option( 'comments_per_page' );
    1287     }
    1288 
    1289     $comment_args['order']  = 'ASC';
    1290     $comment_args['number'] = $per_page;
    1291     $page = (int) get_query_var( 'cpage' );
    1292 
    1293     if ( $page ) {
    1294         $comment_args['offset'] = ( $page - 1 ) * $per_page;
    1295     } elseif ( 'oldest' === get_option( 'default_comments_page' ) ) {
    1296         $comment_args['offset'] = 0;
    1297     } else {
    1298         // If fetching the first page of 'newest', we need a top-level comment count.
    1299         $top_level_query = new WP_Comment_Query();
    1300         $top_level_count = $top_level_query->query( array(
    1301             'count'   => true,
    1302             'orderby' => false,
    1303             'post_id' => $post->ID,
    1304             'parent'  => 0,
    1305         ) );
    1306 
    1307         $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
     1285    $per_page = 0;
     1286    if ( get_option( 'page_comments' ) ) {
     1287        $per_page = (int) get_query_var( 'comments_per_page' );
     1288        if ( 0 === $per_page ) {
     1289            $per_page = (int) get_option( 'comments_per_page' );
     1290        }
     1291
     1292        $comment_args['number'] = $per_page;
     1293        $page = (int) get_query_var( 'cpage' );
     1294
     1295        if ( $page ) {
     1296            $comment_args['offset'] = ( $page - 1 ) * $per_page;
     1297        } elseif ( 'oldest' === get_option( 'default_comments_page' ) ) {
     1298            $comment_args['offset'] = 0;
     1299        } else {
     1300            // If fetching the first page of 'newest', we need a top-level comment count.
     1301            $top_level_query = new WP_Comment_Query();
     1302            $top_level_count = $top_level_query->query( array(
     1303                'count'   => true,
     1304                'orderby' => false,
     1305                'post_id' => $post->ID,
     1306                'parent'  => 0,
     1307            ) );
     1308
     1309            $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
     1310        }
    13081311    }
    13091312
     
    13461349
    13471350    $overridden_cpage = false;
    1348     if ( '' == get_query_var('cpage') ) {
     1351    if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) {
    13491352        set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
    13501353        $overridden_cpage = true;
     
    19421945    }
    19431946
    1944     if ( '' === $r['per_page'] )
     1947    if ( '' === $r['per_page'] && get_option( 'page_comments' ) ) {
    19451948        $r['per_page'] = get_query_var('comments_per_page');
     1949    }
    19461950
    19471951    if ( empty($r['per_page']) ) {
  • trunk/src/wp-includes/default-filters.php

    r35253 r35331  
    330330add_filter( 'default_option_embed_autourls', '__return_true' );
    331331
    332 // This option no longer exists; tell plugins we want comment pagination.
    333 add_filter( 'pre_option_page_comments', '__return_true' );
    334 
    335332// Default settings for heartbeat
    336333add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' );
  • trunk/src/wp-includes/version.php

    r35306 r35331  
    1212 * @global int $wp_db_version
    1313 */
    14 $wp_db_version = 34978;
     14$wp_db_version = 35329;
    1515
    1616/**
  • trunk/tests/phpunit/tests/comment/commentsTemplate.php

    r35242 r35331  
    167167        update_option( 'comment_order', 'asc' );
    168168        update_option( 'default_comments_page', 'newest' );
     169        update_option( 'page_comments', '1' );
    169170
    170171        $link = add_query_arg( array(
     
    222223        update_option( 'comment_order', 'desc' );
    223224        update_option( 'default_comments_page', 'newest' );
     225        update_option( 'page_comments', '1' );
    224226
    225227        $link = add_query_arg( array(
     
    267269        update_option( 'comment_order', 'asc' );
    268270        update_option( 'default_comments_page', 'oldest' );
     271        update_option( 'page_comments', '1' );
    269272
    270273        $link = add_query_arg( array(
     
    312315        update_option( 'comment_order', 'desc' );
    313316        update_option( 'default_comments_page', 'oldest' );
     317        update_option( 'page_comments', '1' );
    314318
    315319        $link = add_query_arg( array(
     
    354358        update_option( 'default_comments_page', 'newest' );
    355359        update_option( 'comment_order', 'desc' );
     360        update_option( 'page_comments', '1' );
    356361
    357362        $link = add_query_arg( array(
     
    396401        update_option( 'default_comments_page', 'newest' );
    397402        update_option( 'comment_order', 'desc' );
     403        update_option( 'page_comments', '1' );
    398404
    399405        $link = add_query_arg( array(
     
    441447        update_option( 'comment_order', 'desc' );
    442448        update_option( 'default_comments_page', 'oldest' );
     449        update_option( 'page_comments', '1' );
    443450
    444451        $link_p1 = add_query_arg( array(
     
    515522        update_option( 'comment_order', 'desc' );
    516523        update_option( 'default_comments_page', 'newest' );
     524        update_option( 'page_comments', '1' );
    517525
    518526        $link_p0 = add_query_arg( array(
  • trunk/tests/phpunit/tests/comment/getCommentLink.php

    r35242 r35331  
    4949     */
    5050    public function test_default_comments_page_newest_default_page_should_have_cpage() {
     51        update_option( 'page_comments', 1 );
    5152        update_option( 'default_comments_page', 'newest' );
    5253        update_option( 'comments_per_page', 2 );
     
    6162     */
    6263    public function test_default_comments_page_newest_middle_page_should_have_cpage() {
     64        update_option( 'page_comments', 1 );
    6365        update_option( 'default_comments_page', 'newest' );
    6466        update_option( 'comments_per_page', 2 );
     
    7375     */
    7476    public function test_default_comments_page_newest_last_page_should_have_cpage() {
     77        update_option( 'page_comments', 1 );
    7578        update_option( 'default_comments_page', 'newest' );
    7679        update_option( 'comments_per_page', 2 );
     
    97100     */
    98101    public function test_default_comments_page_oldest_middle_page_should_have_cpage() {
     102        update_option( 'page_comments', 1 );
    99103        update_option( 'default_comments_page', 'oldest' );
    100104        update_option( 'comments_per_page', 2 );
     
    109113     */
    110114    public function test_default_comments_page_oldest_last_page_should_have_cpage() {
     115        update_option( 'page_comments', 1 );
    111116        update_option( 'default_comments_page', 'oldest' );
    112117        update_option( 'comments_per_page', 2 );
  • trunk/tests/phpunit/tests/comment/getPageOfComment.php

    r35242 r35331  
    234234        $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) );
    235235
     236        update_option( 'page_comments', 1 );
    236237        update_option( 'comments_per_page', 2 );
    237238
Note: See TracChangeset for help on using the changeset viewer.