Changeset 34561
- Timestamp:
- 09/25/2015 08:39:18 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/schema.php
r34529 r34561 483 483 'thread_comments' => 1, 484 484 'thread_comments_depth' => 5, 485 'page_comments' => 0,485 'page_comments' => 1, 486 486 'comments_per_page' => 50, 487 487 'default_comments_page' => 'newest', -
trunk/src/wp-admin/options-discussion.php
r34022 r34561 99 99 ?></label> 100 100 <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')); ?> /> 103 <?php 104 101 <?php 105 102 $default_comments_page = '</label><label for="default_comments_page"><select name="default_comments_page" id="default_comments_page"><option value="newest"'; 106 103 if ( 'newest' == get_option('default_comments_page') ) $default_comments_page .= ' selected="selected"'; … … 109 106 $default_comments_page .= '>' . __('first') . '</option></select>'; 110 107 111 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 );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 ); 112 109 113 110 ?></label> -
trunk/src/wp-admin/options.php
r34315 r34561 84 84 $whitelist_options = array( 85 85 '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', ' page_comments', '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', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ), 87 87 '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' ), 88 88 '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
r34492 r34561 322 322 } 323 323 324 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 )) ) {324 if ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) { 325 325 $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . get_query_var('cpage'), 'commentpaged' ); 326 326 $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); -
trunk/src/wp-includes/class-wp-comment-query.php
r34549 r34561 866 866 do { 867 867 $parent_ids = $levels[ $level ]; 868 if ( ! $parent_ids ) { 869 break; 870 } 871 868 872 $where = 'WHERE ' . implode( ' AND ', $where_clauses ) . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $parent_ids ) ) . ')'; 869 873 $comment_ids = $wpdb->get_col( "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']}" ); -
trunk/src/wp-includes/class-wp-comment.php
r34546 r34561 228 228 * @access public 229 229 * 230 * @param string $format Return value format. 'tree' for a hierarchical tree, 'flat' for a flattened array. 231 * Default 'tree'. 230 232 * @return array Array of `WP_Comment` objects. 231 233 */ 232 public function get_children( ) {234 public function get_children( $format = 'tree' ) { 233 235 if ( is_null( $this->children ) ) { 234 236 $this->children = get_comments( array( … … 238 240 } 239 241 240 return $this->children; 242 if ( 'flat' === $format ) { 243 $children = array(); 244 foreach ( $this->children as $child ) { 245 $children = array_merge( $children, array( $child ), $child->get_children( 'flat' ) ); 246 } 247 } else { 248 $children = $this->children; 249 } 250 251 return $children; 241 252 } 242 253 -
trunk/src/wp-includes/comment-functions.php
r34545 r34561 808 808 return 0; 809 809 810 if ( ! get_option( 'page_comments' ) )811 return 1;812 813 810 if ( !isset($per_page) ) 814 811 $per_page = (int) get_query_var('comments_per_page'); … … 859 856 $args = wp_parse_args( $args, $defaults ); 860 857 861 if ( '' === $args['per_page'] && get_option('page_comments'))858 if ( '' === $args['per_page'] ) 862 859 $args['per_page'] = get_query_var('comments_per_page'); 863 860 if ( empty($args['per_page']) ) { -
trunk/src/wp-includes/comment-template.php
r34525 r34561 684 684 $args = wp_parse_args( $args, $defaults ); 685 685 686 if ( '' === $args['per_page'] && get_option('page_comments'))686 if ( '' === $args['per_page'] ) 687 687 $args['per_page'] = get_option('comments_per_page'); 688 688 … … 1215 1215 1216 1216 $comment_args = array( 1217 'order' => 'ASC',1218 1217 'orderby' => 'comment_date_gmt', 1219 1218 'status' => 'approve', 1220 1219 'post_id' => $post->ID, 1220 'hierarchical' => 'threaded', 1221 'no_found_rows' => false, 1221 1222 'update_comment_meta_cache' => false, // We lazy-load comment meta for performance. 1222 1223 ); … … 1228 1229 } 1229 1230 1230 $comments = get_comments( $comment_args ); 1231 $per_page = (int) get_query_var( 'comments_per_page' ); 1232 if ( 0 === $per_page ) { 1233 $per_page = (int) get_option( 'comments_per_page' ); 1234 } 1235 1236 $flip_comment_order = $trim_comments_on_page = false; 1237 if ( $post->comment_count > $per_page ) { 1238 $comment_args['number'] = $per_page; 1239 1240 /* 1241 * For legacy reasons, higher page numbers always mean more recent comments, regardless of sort order. 1242 * Since we don't have full pagination info until after the query, we use some tricks to get the 1243 * right comments for the current page. 1244 * 1245 * Abandon all hope, ye who enter here! 1246 */ 1247 $page = (int) get_query_var( 'cpage' ); 1248 if ( 'newest' === get_option( 'default_comments_page' ) ) { 1249 if ( $page ) { 1250 $comment_args['order'] = 'ASC'; 1251 1252 /* 1253 * We don't have enough data (namely, the total number of comments) to calculate an 1254 * exact offset. We'll fetch too many comments, and trim them as needed 1255 * after the query. 1256 */ 1257 $offset = ( $page - 2 ) * $per_page; 1258 if ( 0 > $offset ) { 1259 // `WP_Comment_Query` doesn't support negative offsets. 1260 $comment_args['offset'] = 0; 1261 } else { 1262 $comment_args['offset'] = $offset; 1263 } 1264 1265 // Fetch double the number of comments we need. 1266 $comment_args['number'] += $per_page; 1267 $trim_comments_on_page = true; 1268 } else { 1269 $comment_args['order'] = 'DESC'; 1270 $comment_args['offset'] = 0; 1271 $flip_comment_order = true; 1272 } 1273 } else { 1274 $comment_args['order'] = 'ASC'; 1275 if ( $page ) { 1276 $comment_args['offset'] = ( $page - 1 ) * $per_page; 1277 } else { 1278 $comment_args['offset'] = 0; 1279 } 1280 } 1281 } 1282 1283 $comment_query = new WP_Comment_Query( $comment_args ); 1284 $_comments = $comment_query->comments; 1285 1286 // Delightful pagination quirk #1: first page of results sometimes needs reordering. 1287 if ( $flip_comment_order ) { 1288 $_comments = array_reverse( $_comments ); 1289 } 1290 1291 // Delightful pagination quirk #2: reverse chronological order requires page shifting. 1292 if ( $trim_comments_on_page ) { 1293 // Correct the value of max_num_pages, which is wrong because we manipulated the per_page 'number'. 1294 $comment_query->max_num_pages = ceil( $comment_query->found_comments / $per_page ); 1295 1296 // Identify the number of comments that should appear on page 1. 1297 $page_1_count = $comment_query->found_comments - ( ( $comment_query->max_num_pages - 1 ) * $per_page ); 1298 1299 // Use that value to shift the matched comments. 1300 if ( 1 === $page ) { 1301 $_comments = array_slice( $_comments, 0, $page_1_count ); 1302 } else { 1303 $_comments = array_slice( $_comments, $page_1_count, $per_page ); 1304 } 1305 } 1306 1307 // Trees must be flattened before they're passed to the walker. 1308 $comments_flat = array(); 1309 foreach ( $_comments as $_comment ) { 1310 $comments_flat = array_merge( $comments_flat, array( $_comment ), $_comment->get_children( 'flat' ) ); 1311 } 1231 1312 1232 1313 /** … … 1238 1319 * @param int $post_ID Post ID. 1239 1320 */ 1240 $wp_query->comments = apply_filters( 'comments_array', $comments , $post->ID );1321 $wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID ); 1241 1322 $comments = &$wp_query->comments; 1242 1323 $wp_query->comment_count = count($wp_query->comments); 1324 $wp_query->max_num_comment_pages = $comment_query->max_num_pages; 1243 1325 1244 1326 if ( $separate_comments ) { … … 1250 1332 1251 1333 $overridden_cpage = false; 1252 if ( '' == get_query_var('cpage') && get_option('page_comments')) {1334 if ( '' == get_query_var('cpage') ) { 1253 1335 set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 ); 1254 1336 $overridden_cpage = true; … … 1826 1908 $_comments = $wp_query->comments; 1827 1909 } 1828 } 1829 1830 if ( '' === $r['per_page'] && get_option('page_comments') ) 1910 1911 // Pagination is already handled by `WP_Comment_Query`, so we tell Walker not to bother. 1912 if ( 1 < $wp_query->max_num_comment_pages ) { 1913 $r['page'] = 1; 1914 } 1915 } 1916 1917 if ( '' === $r['per_page'] ) 1831 1918 $r['per_page'] = get_query_var('comments_per_page'); 1832 1919 … … 1867 1954 1868 1955 $output = $walker->paged_walk( $_comments, $r['max_depth'], $r['page'], $r['per_page'], $r ); 1869 $wp_query->max_num_comment_pages = $walker->max_pages;1870 1956 1871 1957 $in_comment_loop = false; -
trunk/src/wp-includes/default-filters.php
r34529 r34561 317 317 add_filter( 'default_option_embed_autourls', '__return_true' ); 318 318 319 // This option no longer exists; tell plugins we want comment pagination. 320 add_filter( 'pre_option_page_comments', '__return_true' ); 321 319 322 // Default settings for heartbeat 320 323 add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' ); -
trunk/src/wp-includes/link-template.php
r34528 r34561 2591 2591 global $wp_query; 2592 2592 2593 if ( ! is_singular() || !get_option('page_comments') )2593 if ( ! is_singular() ) 2594 2594 return; 2595 2595 … … 2645 2645 */ 2646 2646 function get_previous_comments_link( $label = '' ) { 2647 if ( ! is_singular() || !get_option('page_comments') )2647 if ( ! is_singular() ) 2648 2648 return; 2649 2649 … … 2693 2693 global $wp_rewrite; 2694 2694 2695 if ( ! is_singular() || !get_option('page_comments') )2695 if ( ! is_singular() ) 2696 2696 return; 2697 2697 … … 2738 2738 2739 2739 // Are there comments to navigate through? 2740 if ( get_comment_pages_count() > 1 && get_option( 'page_comments' )) {2740 if ( get_comment_pages_count() > 1 ) { 2741 2741 $args = wp_parse_args( $args, array( 2742 2742 'prev_text' => __( 'Older comments' ), -
trunk/tests/phpunit/tests/comment/getCommentsPagesCount.php
r31623 r34561 69 69 $this->assertEquals( 2, get_comment_pages_count( $comments, 10, true ) ); 70 70 $this->assertEquals( 4, get_comment_pages_count( $comments, 4, true ) ); 71 }72 73 /**74 * Validate get_comments_pages_count for option page_comments75 */76 function test_option_page_comments() {77 //setup post and comments78 $post = $this->factory->post->create_and_get( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );79 $comments = $this->factory->comment->create_post_comments( $post->ID, 15 );80 81 // comment paging disabled82 update_option( 'page_comments', false );83 84 $this->assertEquals( 1, get_comment_pages_count( $comments, 10, false ) );85 $this->assertEquals( 1, get_comment_pages_count( $comments, 0, true ) );86 $this->assertEquals( 1, get_comment_pages_count( $comments, 2, true ) );87 88 // comment paging enabled89 update_option( 'page_comments', true );90 91 $this->assertEquals( 2, get_comment_pages_count( $comments, 10, false ) );92 $this->assertEquals( 3, get_comment_pages_count( $comments, 5, false ) );93 71 } 94 72 -
trunk/tests/phpunit/tests/link/getNextCommentsLink.php
r31617 r34561 17 17 18 18 public function test_page_should_respect_value_of_cpage_query_var() { 19 update_option( 'page_comments', '1' );20 19 $p = $this->factory->post->create(); 21 20 $this->go_to( get_permalink( $p ) ); … … 35 34 */ 36 35 public function test_page_should_default_to_1_when_no_cpage_query_var_is_found() { 37 update_option( 'page_comments', '1' );38 36 $p = $this->factory->post->create(); 39 37 $this->go_to( get_permalink( $p ) ); -
trunk/tests/phpunit/tests/link/getPreviousCommentsLink.php
r31617 r34561 17 17 18 18 public function test_page_should_respect_value_of_cpage_query_var() { 19 update_option( 'page_comments', '1' );20 19 $p = $this->factory->post->create(); 21 20 $this->go_to( get_permalink( $p ) ); … … 32 31 33 32 public function test_page_should_default_to_1_when_no_cpage_query_var_is_found() { 34 update_option( 'page_comments', '1' );35 33 $p = $this->factory->post->create(); 36 34 $this->go_to( get_permalink( $p ) );
Note: See TracChangeset
for help on using the changeset viewer.