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.
Built from https://develop.svn.wordpress.org/trunk@35331


git-svn-id: http://core.svn.wordpress.org/trunk@35297 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-10-21 16:26:42 +00:00
parent 3df1d2abde
commit 3eab09a694
8 changed files with 51 additions and 38 deletions

View File

@ -482,6 +482,7 @@ function populate_options() {
'close_comments_days_old' => 14,
'thread_comments' => 1,
'thread_comments_depth' => 5,
'page_comments' => 0,
'comments_per_page' => 50,
'default_comments_page' => 'newest',
'comment_order' => 'asc',
@ -567,7 +568,7 @@ function populate_options() {
'can_compress_scripts', 'page_uris', 'update_core', 'update_plugins', 'update_themes', 'doing_cron',
'random_seed', 'rss_excerpt_length', 'secret', 'use_linksupdate', 'default_comment_status_page',
'wporg_popular_tags', 'what_to_show', 'rss_language', 'language', 'enable_xmlrpc', 'enable_app',
'embed_autourls', 'default_post_edit_rows', 'page_comments',
'embed_autourls', 'default_post_edit_rows',
);
foreach ( $unusedoptions as $option )
delete_option($option);

View File

@ -98,6 +98,8 @@ printf( __('Enable threaded (nested) comments %s levels deep'), $thread_comments
?></label>
<br />
<label for="page_comments">
<input name="page_comments" type="checkbox" id="page_comments" value="1" <?php checked( '1', get_option( 'page_comments' ) ); ?> />
<?php
$default_comments_page = '</label><label for="default_comments_page"><select name="default_comments_page" id="default_comments_page"><option value="newest"';
if ( 'newest' == get_option('default_comments_page') ) $default_comments_page .= ' selected="selected"';
@ -105,7 +107,7 @@ $default_comments_page .= '>' . __('last') . '</option><option value="oldest"';
if ( 'oldest' == get_option('default_comments_page') ) $default_comments_page .= ' selected="selected"';
$default_comments_page .= '>' . __('first') . '</option></select>';
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 );
printf( __('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 );
?></label>
<br />

View File

@ -83,7 +83,7 @@ if ( is_multisite() && ! is_super_admin() && 'update' != $action ) {
$whitelist_options = array(
'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ),
'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' ),
'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' ),
'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' ),
'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ),
'writing' => array( 'default_category', 'default_email_category', 'default_link_category', 'default_post_format' )

View File

@ -318,7 +318,10 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
}
}
if ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) {
if ( get_option( 'page_comments' ) && (
( 'newest' == get_option( 'default_comments_page' ) && get_query_var( 'cpage' ) > 0 ) ||
( 'newest' != get_option( 'default_comments_page' ) && get_query_var( 'cpage' ) > 1 )
) ) {
$addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . get_query_var('cpage'), 'commentpaged' );
$redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
}

View File

@ -807,6 +807,10 @@ function get_comment_pages_count( $comments = null, $per_page = null, $threaded
if ( empty($comments) )
return 0;
if ( ! get_option( 'page_comments' ) ) {
return 1;
}
if ( !isset($per_page) )
$per_page = (int) get_query_var('comments_per_page');
if ( 0 === $per_page )
@ -860,12 +864,14 @@ function get_page_of_comment( $comment_ID, $args = array() ) {
$original_args = $args;
// Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
if ( '' === $args['per_page'] ) {
$args['per_page'] = get_query_var( 'comments_per_page' );
}
if ( get_option( 'page_comments' ) ) {
if ( '' === $args['per_page'] ) {
$args['per_page'] = get_query_var( 'comments_per_page' );
}
if ( '' === $args['per_page'] ) {
$args['per_page'] = get_option( 'comments_per_page' );
if ( '' === $args['per_page'] ) {
$args['per_page'] = get_option( 'comments_per_page' );
}
}
if ( empty($args['per_page']) ) {

View File

@ -706,7 +706,7 @@ function get_comment_link( $comment = null, $args = array() ) {
// No 'cpage' is provided, so we calculate one.
} else {
if ( '' === $args['per_page'] ) {
if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) {
$args['per_page'] = get_option('comments_per_page');
}
@ -1268,6 +1268,7 @@ function comments_template( $file = '/comments.php', $separate_comments = false
$comment_args = array(
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'approve',
'post_id' => $post->ID,
'hierarchical' => 'threaded',
@ -1281,30 +1282,32 @@ function comments_template( $file = '/comments.php', $separate_comments = false
$comment_args['include_unapproved'] = array( $comment_author_email );
}
$per_page = (int) get_query_var( 'comments_per_page' );
if ( 0 === $per_page ) {
$per_page = (int) get_option( 'comments_per_page' );
}
$per_page = 0;
if ( get_option( 'page_comments' ) ) {
$per_page = (int) get_query_var( 'comments_per_page' );
if ( 0 === $per_page ) {
$per_page = (int) get_option( 'comments_per_page' );
}
$comment_args['order'] = 'ASC';
$comment_args['number'] = $per_page;
$page = (int) get_query_var( 'cpage' );
$comment_args['number'] = $per_page;
$page = (int) get_query_var( 'cpage' );
if ( $page ) {
$comment_args['offset'] = ( $page - 1 ) * $per_page;
} elseif ( 'oldest' === get_option( 'default_comments_page' ) ) {
$comment_args['offset'] = 0;
} else {
// If fetching the first page of 'newest', we need a top-level comment count.
$top_level_query = new WP_Comment_Query();
$top_level_count = $top_level_query->query( array(
'count' => true,
'orderby' => false,
'post_id' => $post->ID,
'parent' => 0,
) );
if ( $page ) {
$comment_args['offset'] = ( $page - 1 ) * $per_page;
} elseif ( 'oldest' === get_option( 'default_comments_page' ) ) {
$comment_args['offset'] = 0;
} else {
// If fetching the first page of 'newest', we need a top-level comment count.
$top_level_query = new WP_Comment_Query();
$top_level_count = $top_level_query->query( array(
'count' => true,
'orderby' => false,
'post_id' => $post->ID,
'parent' => 0,
) );
$comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
$comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
}
}
$comment_query = new WP_Comment_Query( $comment_args );
@ -1345,7 +1348,7 @@ function comments_template( $file = '/comments.php', $separate_comments = false
}
$overridden_cpage = false;
if ( '' == get_query_var('cpage') ) {
if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) {
set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
$overridden_cpage = true;
}
@ -1941,8 +1944,9 @@ function wp_list_comments( $args = array(), $comments = null ) {
}
}
if ( '' === $r['per_page'] )
if ( '' === $r['per_page'] && get_option( 'page_comments' ) ) {
$r['per_page'] = get_query_var('comments_per_page');
}
if ( empty($r['per_page']) ) {
$r['per_page'] = 0;

View File

@ -329,9 +329,6 @@ add_filter( 'default_option_link_manager_enabled', '__return_true' );
// This option no longer exists; tell plugins we always support auto-embedding.
add_filter( 'default_option_embed_autourls', '__return_true' );
// This option no longer exists; tell plugins we want comment pagination.
add_filter( 'pre_option_page_comments', '__return_true' );
// Default settings for heartbeat
add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' );

View File

@ -4,14 +4,14 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-35330';
$wp_version = '4.4-alpha-35331';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
*
* @global int $wp_db_version
*/
$wp_db_version = 34978;
$wp_db_version = 35329;
/**
* Holds the TinyMCE version