diff --git a/wp-admin/edit-pages.php b/wp-admin/edit-pages.php
index 0f93d977a7..6a9c5f733d 100644
--- a/wp-admin/edit-pages.php
+++ b/wp-admin/edit-pages.php
@@ -118,6 +118,25 @@ endif;
+ add_query_arg( 'pagenum', '%#%' ),
+ 'format' => '',
+ 'total' => $num_pages,
+ 'current' => $pagenum
+));
+
+if ( $page_links )
+ echo "
$page_links
";
+?>
+
@@ -151,7 +170,7 @@ if ($posts) {
-
+
@@ -169,6 +188,10 @@ if ($posts) {
?>
+$page_links
";
+?>
diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php
index 1e807596a9..87ba776e3a 100644
--- a/wp-admin/includes/template.php
+++ b/wp-admin/includes/template.php
@@ -398,7 +398,7 @@ function wp_manage_pages_columns() {
* display one row if the page doesn't have any children
* otherwise, display the row and its children in subsequent rows
*/
-function display_page_row( $page, &$children_pages, $level = 0 ) {
+function display_page_row( $page, $level = 0 ) {
global $post;
static $class;
@@ -522,66 +522,104 @@ foreach ($posts_columns as $column_name=>$column_display_name) {
post_parent == $id ) {
- array_splice($children_pages, $i, 1);
- display_page_row($child, $children_pages, $level+1);
- $i = -1; //as numeric keys in $children_pages are not preserved after splice
- }
- }
}
/*
* displays pages in hierarchical order
*/
-function page_rows( $pages ) {
- if ( ! $pages )
+
+function page_rows($pages, $pagenum = 1, $per_page = 20) {
+ $level = 0;
+
+ if ( ! $pages ) {
$pages = get_pages( array('sort_column' => 'menu_order') );
- if ( ! $pages )
- return false;
+ if ( ! $pages )
+ return false;
+ }
// splice pages into two parts: those without parent and those with parent
-
$top_level_pages = array();
$children_pages = array();
- foreach ( $pages as $page ) {
-
- // catch and repair bad pages
- if ( $page->post_parent == $page->ID ) {
- $page->post_parent = 0;
- $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) );
- clean_page_cache( $page->ID );
+ // If searching, ignore hierarchy and treat everything as top level, otherwise split
+ // into top level and children
+ if ( empty($_GET['s']) ) {
+ foreach ( $pages as $page ) {
+ // catch and repair bad pages
+ if ( $page->post_parent == $page->ID ) {
+ $page->post_parent = 0;
+ $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) );
+ clean_page_cache( $page->ID );
+ }
+
+ if ( 0 == $page->post_parent )
+ $top_level_pages[] = $page;
+ else
+ $children_pages[] = $page;
}
- if ( 0 == $page->post_parent )
- $top_level_pages[] = $page;
- else
- $children_pages[] = $page;
+ $pages = &$top_level_pages;
}
- foreach ( $top_level_pages as $page )
- display_page_row($page, $children_pages, 0);
+ $count = 0;
+ $start = ($pagenum - 1) * $per_page;
+ $end = $start + $per_page;
+ foreach ( $pages as $page ) {
+ if ( $count >= $end )
+ break;
- /*
- * display the remaining children_pages which are orphans
- * having orphan requires parental attention
- */
- if ( count($children_pages) > 0 ) {
- $empty_array = array();
- foreach ( $children_pages as $orphan_page ) {
- clean_page_cache( $orphan_page->ID);
- display_page_row( $orphan_page, $empty_array, 0 );
+ $i++;
+
+ if ( $count >= $start )
+ echo "\t" . display_page_row( $page, $level );
+
+ $count++;
+
+ if ( isset($children_pages) )
+ _page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
+ }
+}
+
+function _page_rows( $pages, &$count, $parent, $level, $pagenum, $per_page ) {
+ $start = ($pagenum - 1) * $per_page;
+ $end = $start + $per_page;
+ $i = -1;
+ foreach ( $pages as $page ) {
+ if ( $count >= $end )
+ break;
+
+ $i++;
+
+ if ( $page->post_parent != $parent )
+ continue;
+
+ // If the page starts in a subtree, print the parents.
+ if ( $count == $start && $page->post_parent > 0 ) {
+ $my_parents = array();
+ $my_parent = $page->post_parent;
+ while ( $my_parent) {
+ $my_parent = get_post($my_parent);
+ $my_parents[] = $my_parent;
+ if ( !$my_parent->post_parent )
+ break;
+ $my_parent = $my_parent->post_parent;
+ }
+ $num_parents = count($my_parents);
+ while( $my_parent = array_pop($my_parents) ) {
+ echo "\t" . display_page_row( $my_parent, $level - $num_parents );
+ $num_parents--;
+ }
}
- }
+
+ if ( $count >= $start )
+ echo "\t" . display_page_row( $page, $level );
+
+ unset($pages[$i]); // Prune the working set
+ $count++;
+
+ _page_rows( $pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
+ }
}
function user_row( $user_object, $style = '', $role = '' ) {