Ticket #11248: 11248.patch
| File 11248.patch, 6.6 KB (added by , 11 years ago) |
|---|
-
wp-includes/comment-template.php
2060 2060 if ( empty($wp_query->comments) ) 2061 2061 return; 2062 2062 if ( 'all' != $r['type'] ) { 2063 if ( empty( $wp_query->comments_by_type) )2064 $wp_query->comments_by_type = separate_comments( $wp_query->comments);2065 if ( empty( $wp_query->comments_by_type[$r['type']]) )2063 if ( empty( $wp_query->comments_by_type ) ) 2064 $wp_query->comments_by_type = separate_comments( $wp_query->comments ); 2065 if ( empty( $wp_query->comments_by_type[$r['type']] ) ) 2066 2066 return; 2067 2067 $_comments = $wp_query->comments_by_type[$r['type']]; 2068 2068 } else { … … 2070 2070 } 2071 2071 } 2072 2072 2073 if ( '' === $r['per_page'] && get_option( 'page_comments') )2074 $r['per_page'] = get_query_var( 'comments_per_page');2073 if ( '' === $r['per_page'] && get_option( 'page_comments' ) ) 2074 $r['per_page'] = get_query_var( 'comments_per_page' ); 2075 2075 2076 if ( empty( $r['per_page']) ) {2076 if ( empty( $r['per_page'] ) ) { 2077 2077 $r['per_page'] = 0; 2078 2078 $r['page'] = 0; 2079 2079 } 2080 2080 2081 2081 if ( '' === $r['max_depth'] ) { 2082 if ( get_option( 'thread_comments') )2083 $r['max_depth'] = get_option( 'thread_comments_depth');2082 if ( get_option( 'thread_comments' ) ) 2083 $r['max_depth'] = get_option( 'thread_comments_depth' ); 2084 2084 else 2085 2085 $r['max_depth'] = -1; 2086 2086 } 2087 2087 2088 2088 if ( '' === $r['page'] ) { 2089 if ( empty( $overridden_cpage) ) {2090 $r['page'] = get_query_var( 'cpage');2089 if ( empty( $overridden_cpage ) ) { 2090 $r['page'] = get_query_var( 'cpage' ); 2091 2091 } else { 2092 2092 $threaded = ( -1 != $r['max_depth'] ); 2093 $r['page'] = ( 'newest' == get_option( 'default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;2093 $r['page'] = ( 'newest' == get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $r['per_page'], $threaded ) : 1; 2094 2094 set_query_var( 'cpage', $r['page'] ); 2095 2095 } 2096 2096 } 2097 2097 // Validation check 2098 $r['page'] = intval( $r['page']);2098 $r['page'] = intval( $r['page'] ); 2099 2099 if ( 0 == $r['page'] && 0 != $r['per_page'] ) 2100 2100 $r['page'] = 1; 2101 2101 2102 2102 if ( null === $r['reverse_top_level'] ) 2103 $r['reverse_top_level'] = ( 'desc' == get_option( 'comment_order') );2103 $r['reverse_top_level'] = ( 'desc' == get_option( 'comment_order' ) ); 2104 2104 2105 2105 if ( empty( $r['walker'] ) ) { 2106 2106 $walker = new Walker_Comment; … … 2109 2109 } 2110 2110 2111 2111 $output = $walker->paged_walk( $_comments, $r['max_depth'], $r['page'], $r['per_page'], $r ); 2112 $wp_query->max_num_comment_pages = $walker->max_pages;2113 2112 2113 // When requested comment page does not exist, display last page of comments. 2114 if ( $r['page'] > intval( $walker->max_pages ) ) { 2115 $r['page'] = intval( $walker->max_pages ); 2116 set_query_var( 'cpage', $r['page'] ); 2117 $output = $walker->paged_walk( $_comments, $r['max_depth'], $r['page'], $r['per_page'], $r ); 2118 } 2119 2120 $wp_query->max_num_comment_pages = intval( $walker->max_pages ); 2121 2114 2122 $in_comment_loop = false; 2115 2123 2116 2124 if ( $r['echo'] ) { -
wp-includes/link-template.php
2431 2431 function get_next_comments_link( $label = '', $max_page = 0 ) { 2432 2432 global $wp_query; 2433 2433 2434 if ( !is_singular() || !get_option( 'page_comments') )2434 if ( !is_singular() || !get_option( 'page_comments' ) ) 2435 2435 return; 2436 2436 2437 $page = get_query_var( 'cpage');2437 $page = get_query_var( 'cpage' ); 2438 2438 2439 $nextpage = intval( $page) + 1;2439 $nextpage = intval( $page ) + 1; 2440 2440 2441 if ( empty( $max_page) )2441 if ( empty( $max_page ) ) 2442 2442 $max_page = $wp_query->max_num_comment_pages; 2443 2443 2444 if ( empty( $max_page) )2444 if ( empty( $max_page ) ) 2445 2445 $max_page = get_comment_pages_count(); 2446 2446 2447 2447 if ( $nextpage > $max_page ) 2448 2448 return; 2449 2449 2450 if ( empty( $label) )2450 if ( empty( $label ) ) 2451 2451 $label = __('Newer Comments »'); 2452 2452 2453 2453 /** … … 2478 2478 * @since 2.7.1 2479 2479 * 2480 2480 * @param string $label Optional. Label for comments link text. 2481 * @param int $max_page Optional. Max page. 2481 2482 * @return string|null HTML-formatted link for the previous page of comments. 2482 2483 */ 2483 function get_previous_comments_link( $label = '' ) { 2484 if ( !is_singular() || !get_option('page_comments') ) 2484 function get_previous_comments_link( $label = '', $max_page = 0 ) { 2485 global $wp_query; 2486 2487 if ( !is_singular() || !get_option( 'page_comments' ) ) 2485 2488 return; 2486 2489 2487 $page = get_query_var( 'cpage');2490 $page = get_query_var( 'cpage' ); 2488 2491 2489 if ( intval($page) <= 1 ) 2492 if ( empty( $max_page ) ) 2493 $max_page = $wp_query->max_num_comment_pages; 2494 2495 if ( empty( $max_page ) ) 2496 $max_page = get_comment_pages_count(); 2497 2498 if ( intval( $page ) <= 1 ) 2490 2499 return; 2491 2500 2492 $prevpage = intval($page) - 1; 2501 if ( intval( $page ) > $max_page ) 2502 $page = $max_page; 2493 2503 2494 if ( empty($label) ) 2495 $label = __('« Older Comments'); 2504 $prevpage = intval( $page ) - 1; 2496 2505 2506 if ( empty( $label ) ) 2507 $label = __( '« Older Comments' ); 2508 2497 2509 /** 2498 2510 * Filter the anchor tag attributes for the previous comments page link. 2499 2511 * … … 2510 2522 * @since 2.7.0 2511 2523 * 2512 2524 * @param string $label Optional. Label for comments link text. 2525 * @param int $max_page Optional. Max page. 2513 2526 */ 2514 function previous_comments_link( $label = '' ) {2515 echo get_previous_comments_link( $label );2527 function previous_comments_link( $label = '', $max_page = 0 ) { 2528 echo get_previous_comments_link( $label, $max_page ); 2516 2529 } 2517 2530 2518 2531 /** … … 2524 2537 * @param string|array $args Optional args. See paginate_links(). 2525 2538 * @return string Markup for pagination links. 2526 2539 */ 2527 function paginate_comments_links( $args = array()) {2540 function paginate_comments_links( $args = array() ) { 2528 2541 global $wp_rewrite; 2529 2542 2530 if ( !is_singular() || !get_option( 'page_comments') )2543 if ( !is_singular() || !get_option( 'page_comments' ) ) 2531 2544 return; 2532 2545 2533 $page = get_query_var('cpage'); 2534 if ( !$page ) 2546 $page = get_query_var( 'cpage' ); 2547 2548 if ( !$page ) { 2535 2549 $page = 1; 2550 } 2551 2536 2552 $max_page = get_comment_pages_count(); 2553 2537 2554 $defaults = array( 2538 2555 'base' => add_query_arg( 'cpage', '%#%' ), 2539 2556 'format' => '', … … 2542 2559 'echo' => true, 2543 2560 'add_fragment' => '#comments' 2544 2561 ); 2545 if ( $wp_rewrite->using_permalinks() ) 2546 $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged'); 2562 if ( $wp_rewrite->using_permalinks() ) { 2563 $defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . 'comment-page-%#%', 'commentpaged' ); 2564 } 2547 2565 2548 2566 $args = wp_parse_args( $args, $defaults ); 2549 2567 $page_links = paginate_links( $args ); 2550 2568 2551 if ( $args['echo'] ) 2569 if ( $args['echo'] ) { 2552 2570 echo $page_links; 2553 else2571 } else { 2554 2572 return $page_links; 2573 } 2574 2555 2575 } 2556 2576 2557 2577 /**