Ticket #8071: 8071.7.diff
File 8071.7.diff, 8.5 KB (added by , 9 years ago) |
---|
-
src/wp-includes/canonical.php
diff --git src/wp-includes/canonical.php src/wp-includes/canonical.php index a88b3a8..52850b4 100644
function redirect_canonical( $requested_url = null, $do_redirect = true ) { 321 321 } 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'] ); 327 327 } -
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 2e978c4..4050e48 100644
class WP_Comment_Query { 865 865 $level = 0; 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']}" ); 870 874 -
src/wp-includes/class-wp-comment.php
diff --git src/wp-includes/class-wp-comment.php src/wp-includes/class-wp-comment.php index 955925b..7225539 100644
final class WP_Comment { 227 227 * @since 4.4.0 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( 235 237 'parent' => $this->comment_ID, … … final class WP_Comment { 237 239 ) ); 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 243 254 /** -
src/wp-includes/comment-template.php
diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php index d8c16a9..8495cf3 100644
function comments_template( $file = '/comments.php', $separate_comments = false 1214 1214 $comment_author_url = esc_url($commenter['comment_author_url']); 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 ); 1223 1224 … … function comments_template( $file = '/comments.php', $separate_comments = false 1227 1228 $comment_args['include_unapproved'] = array( $comment_author_email ); 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 $paging_threshold = $per_page ? $per_page * 2 : 100; 1237 1238 /** 1239 * Filter the threshold at which comment pagination is forced. 1240 * 1241 * Pages with large numbers of comments perform extremely poorly, so we force pagination when the comment 1242 * count exceeds a certain threshold. Use this filter to change that threshold. 1243 * 1244 * @since 4.4.0 1245 * 1246 * @param int $paging_threshold Number of comments a post must have before pagination is forced. 1247 * @param WP_Post $post The WP_Post instance. 1248 */ 1249 $paging_threshold = apply_filters( 'force_comment_paging_threshold', $paging_threshold, $post ); 1250 1251 $flip_comment_order = $trim_comments_on_page = false; 1252 if ( (int) get_option( 'page_comments' ) || $post->comment_count > $paging_threshold ) { 1253 // Force pagination to be turned on in theme comment navigation functions. 1254 add_filter( 'pre_option_page_comments', '__return_true' ); 1255 1256 if ( ! $per_page ) { 1257 $comment_args['number'] = $paging_threshold / 2; 1258 } 1259 $comment_args['number'] = $per_page; 1260 1261 /* 1262 * For legacy reasons, higher page numbers always mean more recent comments, regardless of sort order. 1263 * Since we don't have full pagination info until after the query, we use some tricks to get the 1264 * right comments for the current page. 1265 * 1266 * Abandon all hope, ye who enter here! 1267 */ 1268 $page = (int) get_query_var( 'cpage' ); 1269 if ( 'newest' === get_option( 'default_comments_page' ) ) { 1270 if ( $page ) { 1271 $comment_args['order'] = 'ASC'; 1272 1273 /* 1274 * We don't have enough data (namely, the total number of comments) to calculate an 1275 * exact offset. We'll fetch too many comments, and trim them as needed 1276 * after the query. 1277 */ 1278 $offset = ( $page - 2 ) * $per_page; 1279 if ( 0 > $offset ) { 1280 // `WP_Comment_Query` doesn't support negative offsets. 1281 $comment_args['offset'] = 0; 1282 } else { 1283 $comment_args['offset'] = $offset; 1284 } 1285 1286 // Fetch double the number of comments we need. 1287 $comment_args['number'] += $per_page; 1288 $trim_comments_on_page = true; 1289 } else { 1290 $comment_args['order'] = 'DESC'; 1291 $comment_args['offset'] = 0; 1292 $flip_comment_order = true; 1293 } 1294 } else { 1295 $comment_args['order'] = 'ASC'; 1296 if ( $page ) { 1297 $comment_args['offset'] = ( $page - 1 ) * $per_page; 1298 } else { 1299 $comment_args['offset'] = 0; 1300 } 1301 } 1302 } 1303 1304 $comment_query = new WP_Comment_Query( $comment_args ); 1305 $_comments = $comment_query->comments; 1306 1307 // Delightful pagination quirk #1: first page of results sometimes needs reordering. 1308 if ( $flip_comment_order ) { 1309 $_comments = array_reverse( $_comments ); 1310 } 1311 1312 // Delightful pagination quirk #2: reverse chronological order requires page shifting. 1313 if ( $trim_comments_on_page ) { 1314 // Correct the value of max_num_pages, which is wrong because we manipulated the per_page 'number'. 1315 $comment_query->max_num_pages = ceil( $comment_query->found_comments / $per_page ); 1316 1317 // Identify the number of comments that should appear on page 1. 1318 $page_1_count = $comment_query->found_comments - ( ( $comment_query->max_num_pages - 1 ) * $per_page ); 1319 1320 // Use that value to shift the matched comments. 1321 if ( 1 === $page ) { 1322 $_comments = array_slice( $_comments, 0, $page_1_count ); 1323 } else { 1324 $_comments = array_slice( $_comments, $page_1_count, $per_page ); 1325 } 1326 } 1327 1328 // Trees must be flattened before they're passed to the walker. 1329 $comments_flat = array(); 1330 foreach ( $_comments as $_comment ) { 1331 $comments_flat = array_merge( $comments_flat, array( $_comment ), $_comment->get_children( 'flat' ) ); 1332 } 1231 1333 1232 1334 /** 1233 1335 * Filter the comments array. … … function comments_template( $file = '/comments.php', $separate_comments = false 1237 1339 * @param array $comments Array of comments supplied to the comments template. 1238 1340 * @param int $post_ID Post ID. 1239 1341 */ 1240 $wp_query->comments = apply_filters( 'comments_array', $comments , $post->ID );1342 $wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID ); 1241 1343 $comments = &$wp_query->comments; 1242 1344 $wp_query->comment_count = count($wp_query->comments); 1345 $wp_query->max_num_comment_pages = $comment_query->max_num_pages; 1243 1346 1244 1347 if ( $separate_comments ) { 1245 1348 $wp_query->comments_by_type = separate_comments($comments); … … function wp_list_comments( $args = array(), $comments = null ) { 1825 1928 } else { 1826 1929 $_comments = $wp_query->comments; 1827 1930 } 1931 1932 // Pagination is already handled by `WP_Comment_Query`, so we tell Walker not to bother. 1933 if ( 1 < $wp_query->max_num_comment_pages ) { 1934 $r['page'] = 1; 1935 } 1828 1936 } 1829 1937 1830 1938 if ( '' === $r['per_page'] && get_option('page_comments') ) … … function wp_list_comments( $args = array(), $comments = null ) { 1866 1974 } 1867 1975 1868 1976 $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 1977 1871 1978 $in_comment_loop = false; 1872 1979