Ticket #15459: 15459.5.diff
File 15459.5.diff, 7.1 KB (added by , 10 years ago) |
---|
-
src/wp-admin/includes/class-wp-posts-list-table.php
diff --git src/wp-admin/includes/class-wp-posts-list-table.php src/wp-admin/includes/class-wp-posts-list-table.php index 076ee7d..f1d83a8 100644
class WP_Posts_List_Table extends WP_List_Table { 450 450 $count = 0; 451 451 $start = ( $pagenum - 1 ) * $per_page; 452 452 $end = $start + $per_page; 453 $to_display = array(); 453 454 454 455 foreach ( $pages as $page ) { 455 456 if ( $count >= $end ) 456 457 break; 457 458 458 459 if ( $count >= $start ) { 459 echo "\t"; 460 $this->single_row( $page, $level ); 460 $to_display[$page->ID] = $level; 461 461 } 462 462 463 463 $count++; 464 464 465 465 if ( isset( $children_pages ) ) 466 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );466 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); 467 467 } 468 468 469 469 // If it is the last pagenum and there are orphaned pages, display them with paging as well. … … class WP_Posts_List_Table extends WP_List_Table { 474 474 break; 475 475 476 476 if ( $count >= $start ) { 477 echo "\t"; 478 $this->single_row( $op, 0 ); 477 $to_display[$op->ID] = 0; 479 478 } 480 479 481 480 $count++; 482 481 } 483 482 } 484 483 } 484 485 $ids = array_keys( $to_display ); 486 _prime_post_caches( $ids ); 487 488 if ( ! isset( $GLOBALS['post'] ) ) { 489 // touch_time() requires a global post set 490 $GLOBALS['post'] = array_shift( $ids ); 491 } 492 493 foreach ( $to_display as $page_id => $level ) { 494 echo "\t"; 495 $this->single_row( $page_id, $level ); 496 } 485 497 } 486 498 487 499 /** … … class WP_Posts_List_Table extends WP_List_Table { 496 508 * @param int $level 497 509 * @param int $pagenum 498 510 * @param int $per_page 511 * @param array $to_display list of pages to be displayed 499 512 */ 500 private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) {513 private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) { 501 514 502 515 if ( ! isset( $children_pages[$parent] ) ) 503 516 return; … … class WP_Posts_List_Table extends WP_List_Table { 515 528 $my_parents = array(); 516 529 $my_parent = $page->post_parent; 517 530 while ( $my_parent ) { 518 $my_parent = get_post( $my_parent ); 531 // Get the ID from the list or the attribute if my_parent is an object 532 $parent_id = $my_parent; 533 if ( is_object( $my_parent ) ) { 534 $parent_id = $my_parent->ID; 535 } 536 537 $my_parent = get_post( $parent_id ); 519 538 $my_parents[] = $my_parent; 520 539 if ( !$my_parent->post_parent ) 521 540 break; … … class WP_Posts_List_Table extends WP_List_Table { 523 542 } 524 543 $num_parents = count( $my_parents ); 525 544 while ( $my_parent = array_pop( $my_parents ) ) { 526 echo "\t"; 527 $this->single_row( $my_parent, $level - $num_parents ); 545 $to_display[$my_parent->ID] = $level - $num_parents; 528 546 $num_parents--; 529 547 } 530 548 } 531 549 532 550 if ( $count >= $start ) { 533 echo "\t"; 534 $this->single_row( $page, $level ); 551 $to_display[$page->ID] = $level; 535 552 } 536 553 537 554 $count++; 538 555 539 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );556 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); 540 557 } 541 558 542 559 unset( $children_pages[$parent] ); //required in order to keep track of orphans … … class WP_Posts_List_Table extends WP_List_Table { 547 564 static $alternate; 548 565 549 566 $global_post = get_post(); 567 568 if ( is_integer( $post ) ) { 569 $post = get_post( $post ); 570 } 571 550 572 $GLOBALS['post'] = $post; 551 573 setup_postdata( $post ); 552 574 -
src/wp-admin/includes/post.php
diff --git src/wp-admin/includes/post.php src/wp-admin/includes/post.php index d230667..f30ddc6 100644
function wp_edit_posts_query( $q = false ) { 985 985 $query['order'] = 'asc'; 986 986 $query['posts_per_page'] = -1; 987 987 $query['posts_per_archive_page'] = -1; 988 $query['fields'] = 'id=>parent'; 988 989 } 989 990 990 991 if ( ! empty( $q['show_sticky'] ) ) -
src/wp-includes/class-wp.php
diff --git src/wp-includes/class-wp.php src/wp-includes/class-wp.php index 4edcaf7..98a140c 100644
class WP { 25 25 * @since 2.0.0 26 26 * @var array 27 27 */ 28 public $private_query_vars = array( 'offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent', 'post_parent__in', 'post_parent__not_in' );28 public $private_query_vars = array( 'offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent', 'post_parent__in', 'post_parent__not_in', 'fields' ); 29 29 30 30 /** 31 31 * Extra query variables set by the user. -
tests/phpunit/tests/admin/includesListTable.php
diff --git tests/phpunit/tests/admin/includesListTable.php tests/phpunit/tests/admin/includesListTable.php index e69de29..e88f777 100644
1 <?php 2 3 /** 4 * @group admin 5 */ 6 class Tests_Admin_includesListTable extends WP_UnitTestCase { 7 function setUp() { 8 set_current_screen( 'edit-page' ); 9 $GLOBALS['hook_suffix'] = ''; 10 $this->table = _get_list_table( 'WP_Posts_List_Table' ); 11 12 parent::setUp(); 13 14 // create top level pages 15 $num_posts = 5; 16 foreach ( range( 1, $num_posts ) as $i ) { 17 $this->pages[] = $this->factory->post->create_and_get( array( 18 'post_type' => 'page', 19 ) ); 20 } 21 22 // create child pages 23 $num_posts = 3; 24 foreach ( $this->pages as $page ) { 25 foreach ( range( 1, $num_posts ) as $i ) { 26 $this->pages[] = $this->factory->post->create_and_get( 27 array( 28 'post_type' => 'page', 29 'post_parent' => $page->ID, 30 ) 31 ); 32 } 33 } 34 } 35 36 /** 37 * @ticket 15459 38 */ 39 function test_list_hierarchical_pages_first_page() { 40 $this->_test_list_hierarchical_page( 1, array( 'post-3', 'post-8' ), 2 ); 41 } 42 43 /** 44 * @ticket 15459 45 */ 46 function test_list_hierarchical_pages_second_page() { 47 $this->_test_list_hierarchical_page( 2, array( 'post-23', 'post-29', 'post-30' ), 3 ); 48 } 49 50 /** 51 * Helper function to test the output of a 52 * WP_Posts_List_Table page 53 * 54 * @param $page_num 55 * @param $expected_ids 56 * @param $expected_count 57 */ 58 protected function _test_list_hierarchical_page( $page_num, $expected_ids, $expected_count ) { 59 global $per_page; 60 61 $matches = array(); 62 $per_page = 2; 63 $_REQUEST['paged'] = $page_num; 64 $this->table->hierarchical_display = true; 65 66 ob_start(); 67 $this->table->display_rows( $this->pages ); 68 $output = ob_get_clean(); 69 preg_match_all( '|<tr[^>]*>|', $output, $matches ); 70 71 $this->assertCount( $expected_count, array_keys( $matches[0] ) ); 72 73 foreach ( $expected_ids as $id ) { 74 $this->assertContains( $id, $output ); 75 } 76 } 77 }