WordPress.org

Make WordPress Core

Changeset 6351


Ignore:
Timestamp:
12/04/07 00:19:10 (6 years ago)
Author:
ryan
Message:

Don't save page and attachemtn uris to page_uris and page_attachment_uris. This is not needed. Add an option to use wildcard page rewrite rules instead of per-page rules. see #3614

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r6337 r6351  
    11691169} 
    11701170 
    1171 function generate_page_uri_index() { 
    1172     global $wpdb; 
    1173  
    1174     //get pages in order of hierarchy, i.e. children after parents 
    1175     $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page'")); 
    1176     //now reverse it, because we need parents after children for rewrite rules to work properly 
    1177     $posts = array_reverse($posts, true); 
    1178  
    1179     $page_uris = array(); 
    1180     $page_attachment_uris = array(); 
    1181  
    1182     if ($posts) { 
    1183  
    1184         foreach ($posts as $id => $post) { 
    1185  
    1186             // URL => page name 
    1187             $uri = get_page_uri($id); 
    1188             $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id )); 
    1189             if ( $attachments ) { 
    1190                 foreach ( $attachments as $attachment ) { 
    1191                     $attach_uri = get_page_uri($attachment->ID); 
    1192                     $page_attachment_uris[$attach_uri] = $attachment->ID; 
    1193                 } 
    1194             } 
    1195  
    1196             $page_uris[$uri] = $id; 
    1197         } 
    1198  
    1199         delete_option('page_uris'); 
    1200         update_option('page_uris', $page_uris); 
    1201  
    1202         if ( $page_attachment_uris ) { 
    1203             delete_option('page_attachment_uris'); 
    1204             update_option('page_attachment_uris', $page_attachment_uris); 
    1205         } 
    1206     } 
    1207 } 
    1208  
    12091171// 
    12101172// Attachment functions 
  • trunk/wp-includes/rewrite.php

    r5959 r6351  
    186186    var $endpoints; 
    187187    var $use_verbose_rules = false; 
     188    var $use_verbose_page_rules = true; 
    188189    var $rewritecode = 
    189190        array( 
     
    278279    } 
    279280 
     281    function page_uri_index() { 
     282        global $wpdb; 
     283 
     284        //get pages in order of hierarchy, i.e. children after parents 
     285        $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page'")); 
     286        //now reverse it, because we need parents after children for rewrite rules to work properly 
     287        $posts = array_reverse($posts, true); 
     288 
     289        $page_uris = array(); 
     290        $page_attachment_uris = array(); 
     291 
     292        if ( !$posts ) 
     293            return array( array(), array() ); 
     294     
     295 
     296        foreach ($posts as $id => $post) { 
     297            // URL => page name 
     298            $uri = get_page_uri($id); 
     299            $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id )); 
     300            if ( $attachments ) { 
     301                foreach ( $attachments as $attachment ) { 
     302                    $attach_uri = get_page_uri($attachment->ID); 
     303                    $page_attachment_uris[$attach_uri] = $attachment->ID; 
     304                } 
     305            } 
     306 
     307            $page_uris[$uri] = $id; 
     308        } 
     309 
     310        return array( $page_uris, $page_attachment_uris ); 
     311    } 
     312 
    280313    function page_rewrite_rules() { 
    281         $uris = get_option('page_uris'); 
    282         $attachment_uris = get_option('page_attachment_uris'); 
     314        global $wpdb; 
    283315 
    284316        $rewrite_rules = array(); 
    285317        $page_structure = $this->get_page_permastruct(); 
     318 
     319        if ( ! $this->use_verbose_page_rules ) { 
     320            $this->add_rewrite_tag('%pagename%', "(.+)", 'pagename='); 
     321            $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES)); 
     322            return $rewrite_rules; 
     323        } 
     324 
     325        $page_uris = $this->page_uri_index(); 
     326        $uris = $page_uris[0]; 
     327        $attachment_uris = $page_uris[1]; 
     328 
     329 
    286330        if( is_array( $attachment_uris ) ) { 
    287331            foreach ($attachment_uris as $uri => $pagename) { 
     
    786830 
    787831        // Put them together. 
    788         $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules); 
     832        if ( $this->use_verbose_page_rules ) 
     833            $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules); 
     834        else 
     835            $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules); 
    789836 
    790837        do_action_ref_array('generate_rewrite_rules', array(&$this)); 
     
    901948 
    902949    function flush_rules() { 
    903         generate_page_uri_index(); 
    904950        delete_option('rewrite_rules'); 
    905951        $this->wp_rewrite_rules(); 
Note: See TracChangeset for help on using the changeset viewer.