Make WordPress Core


Ignore:
Timestamp:
10/01/2015 03:10:13 AM (9 years ago)
Author:
boonebgorges
Message:

Simplify pagination logic in comments_template().

[34561] "fixed" the problem of newest-first comments showing fewer than
'per_page' comments on the post permalink when the total number of comments
was not divisible by 'per_page'. See #29462. But this fix caused numerous
other problems. First, comment pages reported by get_page_of_comment()
(which expects comment pages to be filled oldest-first) were no longer correct.
Second, and more seriously, the new logic caused comments to be shifted
between pages, making their permalinks non-permanent.

The current changeset reverts the changed behavior. In order to preserve the
performance improvements introduced in [34561], an additional query must be
performed when 'default_comments_page=newest' and 'cpage=0' (ie, you're viewing
the post permalink). A nice side effect of this revert is that we no longer
need the hacks required to determine proper comment pagination, introduced in
[34561].

See #8071. See #34073.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/commentsTemplate.php

    r34713 r34729  
    326326        $this->assertSame( array( $comment_1, $comment_2 ), $found_cids );
    327327    }
     328
     329    /**
     330     * @ticket 8071
     331     * @ticket 34073
     332     * @ticket 29462
     333     */
     334    public function test_last_page_of_comments_should_be_full_when_default_comment_page_is_newest() {
     335        $now = time();
     336        $p = $this->factory->post->create();
     337        $comment_1 = $this->factory->comment->create( array(
     338            'comment_post_ID' => $p,
     339            'comment_content' => '1',
     340            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     341        ) );
     342        $comment_2 = $this->factory->comment->create( array(
     343            'comment_post_ID' => $p,
     344            'comment_content' => '2',
     345            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     346        ) );
     347        $comment_3 = $this->factory->comment->create( array(
     348            'comment_post_ID' => $p,
     349            'comment_content' => '3',
     350            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     351        ) );
     352
     353        update_option( 'default_comments_page', 'newest' );
     354        update_option( 'comment_order', 'desc' );
     355
     356        $link = add_query_arg( array(
     357            'cpage' => 1,
     358            'comments_per_page' => 2,
     359        ), get_permalink( $p ) );
     360
     361        $this->go_to( $link );
     362        $found = get_echo( 'comments_template' );
     363
     364        $comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
     365
     366        $found_cids = array_map( 'intval', $matches[1] );
     367
     368        $this->assertSame( array( $comment_2, $comment_3 ), $found_cids );
     369    }
     370
     371    /**
     372     * @ticket 8071
     373     * @ticket 34073
     374     * @ticket 29462
     375     */
     376    public function test_first_page_of_comments_should_have_remainder_when_default_comments_page_is_newest() {
     377        $now = time();
     378        $p = $this->factory->post->create();
     379        $comment_1 = $this->factory->comment->create( array(
     380            'comment_post_ID' => $p,
     381            'comment_content' => '1',
     382            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     383        ) );
     384        $comment_2 = $this->factory->comment->create( array(
     385            'comment_post_ID' => $p,
     386            'comment_content' => '2',
     387            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     388        ) );
     389        $comment_3 = $this->factory->comment->create( array(
     390            'comment_post_ID' => $p,
     391            'comment_content' => '3',
     392            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     393        ) );
     394
     395        update_option( 'default_comments_page', 'newest' );
     396        update_option( 'comment_order', 'desc' );
     397
     398        $link = add_query_arg( array(
     399            'cpage' => 2,
     400            'comments_per_page' => 2,
     401        ), get_permalink( $p ) );
     402
     403        $this->go_to( $link );
     404        $found = get_echo( 'comments_template' );
     405
     406        $comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
     407
     408        $found_cids = array_map( 'intval', $matches[1] );
     409
     410        $this->assertSame( array( $comment_1 ), $found_cids );
     411    }
    328412}
Note: See TracChangeset for help on using the changeset viewer.