Make WordPress Core

Ticket #3614: manage pages diff.patch

File manage pages diff.patch, 5.9 KB (added by pirom, 18 years ago)

Solves the freezing, crashing or extreme sluggishness of Page Management view for WP 2.3 (Trunk) [Patch Version 5772]

  • edit-pages.php

     
    1111                        'publish' => array(__('Published'), __('Published pages'))
    1212                );
    1313
    14 
    1514$post_status_label = _c('Pages|manage pages header');
    1615$post_status_q = '';
    1716if ( isset($_GET['post_status']) && in_array( $_GET['post_status'], array_keys($post_stati) ) ) {
     
    2120
    2221?>
    2322
     23<?php
     24//Added functions to speed up Page Management page load
     25function &lp_get_pages($_pages) {
     26
     27    // permalink stuff
     28    global $wp_rewrite;
     29    $pagestruct = $wp_rewrite->get_page_permastruct();
     30    $home = get_settings('home');
     31
     32    $pages = array();
     33    $deferred = array();
     34
     35    foreach ($_pages as $k=>$page) {
     36
     37        $id = $page['id'];
     38        $parent = $page['post_parent'];
     39
     40        $_pages[$k]['root_page'] = empty($parent);
     41        $_pages[$k]['children'] = array();
     42
     43        if (!empty($parent) && $parent != $id) {
     44            if (isset($pages[$parent]))
     45                $pages[$parent]['children'][$page['menu_order'] . $page['post_title']] =& $_pages[$k];
     46            else
     47                $deferred[$id] = array($page['menu_order'] . $page['post_title'], $parent);
     48        }
     49        $pages[$id] =& $_pages[$k];
     50
     51    }
     52
     53    foreach ($deferred as $id=>$details) {
     54        list($title, $parent) = $details;
     55        if (isset($pages[$parent]))
     56            $pages[$parent]['children'][$title] =& $pages[$id];
     57        else
     58            $pages[$id]['parent'] = '';
     59    }
     60
     61    /*
     62    Add unpublished pages to the begining of the page list
     63    */
     64    $temp_pages_list = $pages;
     65    $unpublished_pages = array();
     66    $array_offset = 0;
     67    foreach ($temp_pages_list as $id => $page)
     68    {
     69        if ($page['post_date'] == '0000-00-00 00:00:00')
     70        {
     71            $slice = array_splice($pages, $array_offset, 1);
     72            $unpublished_pages[] = $slice[0];
     73        }
     74
     75        $array_offset++;
     76    }
     77    $unpublished_pages = array_reverse($unpublished_pages);
     78    foreach ($unpublished_pages as $unpublished_page)
     79          array_unshift($pages, $unpublished_page);
     80   
     81
     82    foreach ($pages as $id=>$page) {
     83
     84        $parent = $page['post_parent'];
     85
     86        if (empty($pagestruct)) {
     87            $link = "$home/?page_id=$id";
     88        } else {
     89            $uri = urldecode($page['post_name']);
     90            if ($parent != $id) {
     91                while (!empty($parent) && isset($pages[$parent])) {
     92                    $uri = urldecode($pages[$parent]['post_name']) . "/$uri";
     93                    $parent = $pages[$parent]['post_parent'];
     94                }
     95            }
     96            $link = $home . '/' . str_replace('%pagename%', $uri, $pagestruct) . '/';
     97        }
     98        $pages[$id]['permalink'] = apply_filters('page_link', $link, $id);
     99    }
     100
     101    return $pages;
     102}
     103
     104function recurse(&$tree, $padding='', $index=0) {
     105
     106    foreach ($tree as $post) {
     107        if (empty($padding) && !empty($post['post_parent']))
     108            continue;
     109        $index++;
     110        $title = wp_specialchars($post['post_title']);
     111        $id = $post['id'];
     112        $class = (($index%2)==1) ? '' : 'alternate';
     113
     114        ?>
     115        <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
     116            <th scope="row" style="text-align: center"><?php echo $id; ?></th>
     117            <td>
     118              <?php echo $padding; ?><?php echo $title; ?>
     119            </td>
     120            <td><?php echo $post['display_name']; ?></td>
     121            <td><?php if ( '0000-00-00 00:00:00' ==$post['post_date'] ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post['post_modified'] ); ?></td>
     122            <td><a href="<?php if ('0000-00-00 00:00:00' ==$post['post_date']) echo "/?page_id=$id"; else echo $post['permalink']; ?>" rel="permalink" class="edit"><?php _e( 'View' ); ?></a></td>
     123            <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td>
     124            <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&amp;post=$id", 'delete-page_' . $id ) .  "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), $title ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td>
     125        </tr>
     126        <?php
     127
     128        ksort($post['children']);
     129        $index = recurse($post['children'], $padding . '&#8212; ', $index);
     130    }
     131    return $index;
     132}
     133
     134?>           
     135
    24136<div class="wrap">
    25137
    26138<h2><?php
     
    64176
    65177<br style="clear:both;" />
    66178
    67 <?php
    68 wp("post_type=page&orderby=menu_order&what_to_show=posts$post_status_q&posts_per_page=-1&posts_per_archive_page=-1&order=asc");
     179<?php       
    69180
    70 $all = !( $h2_search || $post_status_q );
     181$all = !( $h2_search || $post_status_q );       
     182 
     183if ($_GET['s']) {
     184    wp("post_type=page&orderby=menu_order&what_to_show=posts$post_status_q&posts_per_page=-1&posts_per_archive_page=-1&order=asc");
     185}
     186else {
     187    $q = "SELECT p.id, p.post_name, p.post_title, p.post_parent, p.menu_order, p.post_modified, p.post_date, " .
     188                "u.display_name " .
     189                "FROM $wpdb->posts p " .
     190                "INNER JOIN $wpdb->users u ON p.post_author = u.id " .
     191                "WHERE p.post_type='page' " .
     192                "ORDER BY p.menu_order ASC , p.post_date DESC";
    71193
     194    $posts =& lp_get_pages($wpdb->get_results($q,  ARRAY_A));
     195
     196
    72197if ($posts) {
    73198?>
    74199<table class="widefat">
     
    82207  </tr>
    83208  </thead>
    84209  <tbody id="the-list">
    85 <?php page_rows(0, 0, $posts, $all); ?>
     210<?php
     211    if ( $all == false )
     212    {
     213        page_rows(0, 0, $posts, $all);
     214    }
     215    else
     216    {
     217        //page_rows();
     218
     219        //Added to speed up Page Management page load
     220        recurse($posts);
     221    }
     222?>
    86223  </tbody>
    87224</table>
    88225