Make WordPress Core

Changeset 6380


Ignore:
Timestamp:
12/14/2007 06:20:42 AM (19 years ago)
Author:
ryan
Message:

Faster page_rows() from hailin. see #5303

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-pages.php

    r6213 r6380  
    6969
    7070<?php
    71 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");
     71$query_str = "post_type=page&orderby=menu_order title&what_to_show=posts$post_status_q&posts_per_page=-1&posts_per_archive_page=-1&order=asc";
     72$query_str = apply_filters('manage_pages_query', $query_str);
     73wp($query_str);
    7274
    7375$all = !( $h2_search || $post_status_q );
    … …  
    8688  </thead>
    8789  <tbody id="the-list" class="list:page">
    88 <?php page_rows(0, 0, $posts, $all); ?>
     90  <?php page_rows($posts); ?> 
    8991  </tbody>
    9092</table>
  • trunk/wp-admin/includes/template.php

    r6363 r6380  
    226226}
    227227
    228 function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) {
    229         global $class, $post;
    230 
    231         if (!$pages )
    232                 $pages = get_pages( 'sort_column=menu_order' );
    233 
    234         if (! $pages )
    235                 return false;
    236 
    237         foreach ( $pages as $post) {
    238                 setup_postdata( $post);
    239                 if ( $hierarchy && ($post->post_parent != $parent) )
    240                         continue;
    241 
    242                 $post->post_title = wp_specialchars( $post->post_title );
    243                 $pad = str_repeat( '&#8212; ', $level );
    244                 $id = (int) $post->ID;
    245                 $class = ('alternate' == $class ) ? '' : 'alternate';
     228/*
     229 * display one row if the page doesn't have any children
     230 * otherwise, display the row and its children in subsequent rows
     231 */
     232function display_page_row( $page, &$children_pages, $level = 0 ) {
     233        global $post;
     234        static $class;
     235       
     236        $post = $page;
     237        setup_postdata($page);
     238
     239        $page->post_title = wp_specialchars( $page->post_title );
     240        $pad = str_repeat( '&#8212; ', $level );
     241        $id = (int) $page->ID;
     242        $class = ('alternate' == $class ) ? '' : 'alternate';
     243
    246244?>
    247245  <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
    248     <th scope="row" style="text-align: center"><?php echo $post->ID; ?></th>
     246    <th scope="row" style="text-align: center"><?php echo $page->ID; ?></th>
    249247    <td>
    250       <?php echo $pad; ?><?php the_title() ?>
     248      <?php echo $pad; ?><?php the_title(); ?>
    251249    </td>
    252250    <td><?php the_author() ?></td>
    253     <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?></td>
     251    <td><?php if ( '0000-00-00 00:00:00' ==$page->post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $page->post_modified ); ?></td>
    254252    <td><a href="<?php the_permalink(); ?>" rel="permalink" class="view"><?php _e( 'View' ); ?></a></td>
    255253    <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td>
    … …  
    258256
    259257<?php
    260                 if ( $hierarchy )
    261                         page_rows( $id, $level + 1, $pages );
    262         }
     258
     259        if ( ! $children_pages )
     260                return true;
     261
     262        for ( $i=0; $i < count($children_pages); $i++ ) {
     263
     264                $child = $children_pages[$i];
     265                       
     266                if ( $child->post_parent == $id ) {
     267                array_splice($children_pages, $i, 1);
     268                        display_page_row($child, $children_pages, $level+1);
     269                        $i--;
     270                }
     271        }
     272}
     273
     274/*
     275 * displays pages in hierarchical order
     276 */
     277function page_rows( $pages ) {
     278        if ( ! $pages )
     279                $pages = get_pages( 'sort_column=menu_order' );
     280
     281        if ( ! $pages )
     282                return false;
     283
     284        // splice pages into two parts: those without parent and those with parent
     285
     286        $top_level_pages = array();
     287        $children_pages  = array();
     288
     289        foreach ( $pages as $page ) {
     290                if ( 0 == $page->post_parent )
     291                        $top_level_pages[] = $page;
     292                else
     293                        $children_pages[] = $page;
     294        }
     295
     296        foreach ( $top_level_pages as $page )
     297                display_page_row($page, $children_pages, 0);
     298       
     299        /*
     300         * display the remaining children_pages which are orphans
     301         * having orphan requires parental attention
     302         */
     303         if ( count($children_pages) > 0 ) {
     304                $empty_array = array();
     305                foreach ($children_pages as $orphan_page)
     306                        display_page_row($orphan_page, $empty_array, 0);
     307         }
    263308}
    264309
    265310function user_row( $user_object, $style = '' ) {
    266         if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
     311        if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
    267312                $user_object = new WP_User( (int) $user_object );
    268313        $email = $user_object->user_email;
  • trunk/wp-includes/query.php

    r6377 r6380  
    11141114                } else {
    11151115                        // Used to filter values
    1116                         $allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order');
     1116                        $allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order', 'parent', 'ID');
    11171117                        $q['orderby'] = urldecode($q['orderby']);
    11181118                        $q['orderby'] = addslashes_gpc($q['orderby']);
    … …  
    11241124                                // Only allow certain values for safety
    11251125                                $orderby = $orderby_array[$i];
    1126                                 if ( 'menu_order' != $orderby )
     1126                                if ( !('menu_order' == $orderby || 'ID' == $orderby ))
    11271127                                        $orderby = 'post_' . $orderby;
    11281128                                if ( in_array($orderby_array[$i], $allowed_keys) )
    1129                                         $q['orderby'] .= (($i == 0) ? '' : ',') . "$orderby {$q['order']}";
    1130                         }
     1129                                        $q['orderby'] .= (($i == 0) ? '' : ',') . $orderby;
     1130                        }
     1131                        /* append ASC or DESC at the end */
     1132                        if ( !empty($q['orderby'])){
     1133                                $q['orderby'] .= " {$q['order']}";
     1134                        }
     1135                       
    11311136                        if ( empty($q['orderby']) )
    11321137                                $q['orderby'] = 'post_date '.$q['order'];
Note: See TracChangeset for help on using the changeset viewer.