Ticket #19897: 19897.diff
| File 19897.diff, 13.0 KB (added by , 14 years ago) |
|---|
-
wp-includes/rewrite.php
372 372 */ 373 373 class WP_Rewrite { 374 374 /** 375 * Default permalink structure for WordPress.375 * Permalink structure for posts. 376 376 * 377 377 * @since 1.5.0 378 378 * @access private … … 390 390 var $use_trailing_slashes; 391 391 392 392 /** 393 * Permalink author request base ( example.com/author/authorname).393 * Base for the author permalink structure (example.com/$author_base/authorname). 394 394 * 395 395 * @since 1.5.0 396 396 * @access private … … 399 399 var $author_base = 'author'; 400 400 401 401 /** 402 * Permalink request structure for author pages.402 * Permalink structure for author archives. 403 403 * 404 404 * @since 1.5.0 405 405 * @access private … … 408 408 var $author_structure; 409 409 410 410 /** 411 * Permalink request structure for dates.411 * Permalink structure for date archives. 412 412 * 413 413 * @since 1.5.0 414 414 * @access private … … 417 417 var $date_structure; 418 418 419 419 /** 420 * Permalink requeststructure for pages.420 * Permalink structure for pages. 421 421 * 422 422 * @since 1.5.0 423 423 * @access private … … 426 426 var $page_structure; 427 427 428 428 /** 429 * Search permalink base ( example.com/search/query).429 * Base of the search permalink structure (example.com/$search_base/query). 430 430 * 431 431 * @since 1.5.0 432 432 * @access private … … 435 435 var $search_base = 'search'; 436 436 437 437 /** 438 * Permalink requeststructure for searches.438 * Permalink structure for searches. 439 439 * 440 440 * @since 1.5.0 441 441 * @access private … … 471 471 var $feed_base = 'feed'; 472 472 473 473 /** 474 * Comments feed request structure permalink.474 * Comments feed permalink structure. 475 475 * 476 476 * @since 1.5.0 477 477 * @access private … … 480 480 var $comments_feed_structure; 481 481 482 482 /** 483 * Feed request structure permalink.483 * Feed request permalink structure. 484 484 * 485 485 * @since 1.5.0 486 486 * @access private … … 489 489 var $feed_structure; 490 490 491 491 /** 492 * Front URL path.492 * The static portion of the post permalink structure. 493 493 * 494 * The difference between the root property is that WordPress might be 495 * located at example/WordPress/index.php, if permalinks are turned off. The 496 * WordPress/index.php will be the front portion. If permalinks are turned 497 * on, this will most likely be empty or not set. 494 * If the permalink structure is "/archive/%post_id%" then the front 495 * is "/archive/". If the permalink structure is "/%year%/%postname%/" 496 * then the front is "/". 498 497 * 498 * @see WP_Rewrite::init() 499 499 * @since 1.5.0 500 500 * @access private 501 501 * @var string … … 503 503 var $front; 504 504 505 505 /** 506 * Root URL path to WordPress (without domain).506 * The prefix for all permalink structures. 507 507 * 508 * The difference between front property is that WordPress might be located 509 * at example.com/WordPress/. The root is the 'WordPress/' portion. 508 * If PATHINFO/index permalinks are in use then the root is the value of 509 * {@link WP_Rewrite::$index} with a trailing slash appended. Otherwise 510 * the root will be empty. 510 511 * 512 * @see WP_Rewrite::init() 513 * @see WP_Rewrite::using_index_permalinks() 511 514 * @since 1.5.0 512 515 * @access private 513 516 * @var string … … 515 518 var $root = ''; 516 519 517 520 /** 518 * Permalink to the home page.521 * The name of the index file which is the entry point to all requests. 519 522 * 520 523 * @since 1.5.0 521 524 * @access public … … 524 527 var $index = 'index.php'; 525 528 526 529 /** 527 * Request match string.530 * Variable name to use for regex matches in the rewritten query. 528 531 * 529 532 * @since 1.5.0 530 533 * @access private … … 550 553 * @access private 551 554 * @var array 552 555 */ 553 var $extra_rules = array(); //556 var $extra_rules = array(); 554 557 555 558 /** 556 559 * Additional rules that belong at the beginning to match first. … … 561 564 * @access private 562 565 * @var array 563 566 */ 564 var $extra_rules_top = array(); //567 var $extra_rules_top = array(); 565 568 566 569 /** 567 * Rules that don't redirect to W P'sindex.php.570 * Rules that don't redirect to WordPress' index.php. 568 571 * 569 * These rules are written to the mod_rewrite portion of the .htaccess. 572 * These rules are written to the mod_rewrite portion of the .htaccess, 573 * and are added by {@link add_external_rule()}. 570 574 * 571 575 * @since 2.1.0 572 576 * @access private 573 577 * @var array 574 578 */ 575 var $non_wp_rules = array(); //579 var $non_wp_rules = array(); 576 580 577 581 /** 578 * Extra permalink structures .582 * Extra permalink structures, e.g. categories, added by {@link add_permastruct()}. 579 583 * 580 584 * @since 2.1.0 581 585 * @access private … … 584 588 var $extra_permastructs = array(); 585 589 586 590 /** 587 * Endpoints permalinks591 * Endpoints (like /trackback/) added by {@link add_rewrite_endpoint()}. 588 592 * 589 593 * @since 2.1.0 590 594 * @access private … … 593 597 var $endpoints; 594 598 595 599 /** 596 * Whether to write every mod_rewrite rule for WordPress .600 * Whether to write every mod_rewrite rule for WordPress into the .htaccess file. 597 601 * 598 602 * This is off by default, turning it on might print a lot of rewrite rules 599 603 * to the .htaccess file. 600 604 * 605 * @see WP_Rewrite::mod_rewrite_rules() 601 606 * @since 2.0.0 602 607 * @access public 603 608 * @var bool … … 605 610 var $use_verbose_rules = false; 606 611 607 612 /** 608 * Whether to write every mod_rewrite rule for WordPress pages.613 * Could post permalinks be confused with those of pages? 609 614 * 615 * If the first rewrite tag in the post permalink structure is one that could 616 * also match a page name (e.g. %postname% or %author%) then this flag is 617 * set to true. Prior to WordPress 3.3 this flag indicated that every page 618 * would have a set of rules added to the top of the rewrite rules array. 619 * Now it tells {@link WP::parse_request()} to check if a URL matching the 620 * page permastruct is actually a page before accepting it. 621 * 622 * @link http://core.trac.wordpress.org/ticket/16687 623 * @see WP_Rewrite::init() 610 624 * @since 2.5.0 611 625 * @access public 612 626 * @var bool … … 614 628 var $use_verbose_page_rules = true; 615 629 616 630 /** 617 * Permalink structure search for preg_replace.631 * Rewrite tags that can be used in permalink structures. 618 632 * 633 * These are translated into the regular expressions stored in 634 * {@link WP_Rewrite::$rewritereplace} and are rewritten to the 635 * query variables listed in {@link WP_Rewrite::$queryreplace}. 636 * 637 * Additional tags can be added with {@link add_rewrite_tag()}. 638 * 619 639 * @since 1.5.0 620 640 * @access private 621 641 * @var array 622 642 */ 623 var $rewritecode = 624 array( 625 '%year%', 626 '%monthnum%', 627 '%day%', 628 '%hour%', 629 '%minute%', 630 '%second%', 631 '%postname%', 632 '%post_id%', 633 '%author%', 634 '%pagename%', 635 '%search%' 636 ); 643 var $rewritecode = array( 644 '%year%', 645 '%monthnum%', 646 '%day%', 647 '%hour%', 648 '%minute%', 649 '%second%', 650 '%postname%', 651 '%post_id%', 652 '%author%', 653 '%pagename%', 654 '%search%' 655 ); 637 656 638 657 /** 639 * Preg_replace values for the search, see {@link WP_Rewrite::$rewritecode}. 658 * Regular expressions to be substituted into rewrite rules in place 659 * of rewrite tags, see {@link WP_Rewrite::$rewritecode}. 640 660 * 641 661 * @since 1.5.0 642 662 * @access private 643 663 * @var array 644 664 */ 645 var $rewritereplace = 646 array( 647 '([0-9]{4})', 648 '([0-9]{1,2})', 649 '([0-9]{1,2})', 650 '([0-9]{1,2})', 651 '([0-9]{1,2})', 652 '([0-9]{1,2})', 653 '([^/]+)', 654 '([0-9]+)', 655 '([^/]+)', 656 '([^/]+?)', 657 '(.+)' 658 ); 665 var $rewritereplace = array( 666 '([0-9]{4})', 667 '([0-9]{1,2})', 668 '([0-9]{1,2})', 669 '([0-9]{1,2})', 670 '([0-9]{1,2})', 671 '([0-9]{1,2})', 672 '([^/]+)', 673 '([0-9]+)', 674 '([^/]+)', 675 '([^/]+?)', 676 '(.+)' 677 ); 659 678 660 679 /** 661 * Search for the query to look for replacing.680 * Query variables that rewrite tags map to, see {@link WP_Rewrite::$rewritecode}. 662 681 * 663 682 * @since 1.5.0 664 683 * @access private 665 684 * @var array 666 685 */ 667 var $queryreplace = 668 array ( 669 'year=', 670 'monthnum=', 671 'day=', 672 'hour=', 673 'minute=', 674 'second=', 675 'name=', 676 'p=', 677 'author_name=', 678 'pagename=', 679 's=' 680 ); 686 var $queryreplace = array( 687 'year=', 688 'monthnum=', 689 'day=', 690 'hour=', 691 'minute=', 692 'second=', 693 'name=', 694 'p=', 695 'author_name=', 696 'pagename=', 697 's=' 698 ); 681 699 682 700 /** 683 701 * Supported default feeds. … … 686 704 * @access private 687 705 * @var array 688 706 */ 689 var $feeds = array ( 'feed', 'rdf', 'rss', 'rss2', 'atom' );707 var $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); 690 708 691 709 /** 692 710 * Whether permalinks are being used. … … 902 920 * @return bool|string False on failure. Year structure on success. 903 921 */ 904 922 function get_year_permastruct() { 905 $structure = $this->get_date_permastruct( $this->permalink_structure);923 $structure = $this->get_date_permastruct(); 906 924 907 925 if ( empty($structure) ) 908 926 return false; … … 927 945 * @return bool|string False on failure. Year/Month structure on success. 928 946 */ 929 947 function get_month_permastruct() { 930 $structure = $this->get_date_permastruct( $this->permalink_structure);948 $structure = $this->get_date_permastruct(); 931 949 932 950 if ( empty($structure) ) 933 951 return false; … … 950 968 * @return bool|string False on failure. Year/Month/Day structure on success. 951 969 */ 952 970 function get_day_permastruct() { 953 return $this->get_date_permastruct( $this->permalink_structure);971 return $this->get_date_permastruct(); 954 972 } 955 973 956 974 /** … … 1166 1184 } 1167 1185 1168 1186 /** 1169 * Generate the rules frompermalink structure.1187 * Generate rewrite rules from a permalink structure. 1170 1188 * 1171 1189 * The main WP_Rewrite function for building the rewrite rule list. The 1172 1190 * contents of the function is a mix of black magic and regular expressions, … … 1176 1194 * @access public 1177 1195 * 1178 1196 * @param string $permalink_structure The permalink structure. 1179 * @param int $ep_mask Optional, default is EP_NONE. Endpoint constant, see EP_* constants. 1180 * @param bool $paged Optional, default is true. Whether permalink request is paged. 1181 * @param bool $feed Optional, default is true. Whether for feed. 1182 * @param bool $forcomments Optional, default is false. Whether for comments. 1183 * @param bool $walk_dirs Optional, default is true. Whether to create list of directories to walk over. 1184 * @param bool $endpoints Optional, default is true. Whether endpoints are enabled. 1197 * @param int $ep_mask Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE. 1198 * @param bool $paged Should archive pagination rules be added for the structure? Default is true. 1199 * @param bool $feed Should feed rewrite rules be added for the structure? Default is true. 1200 * @param bool $forcomments Should the feed rules be a query for a comments feed? Default is false. 1201 * @param bool $walk_dirs Should the 'directories' making up the structure be walked over and rewrite rules 1202 * built for each in turn? Default is true. 1203 * @param bool $endpoints Should endpoints be applied to the generated rewrite rules? Default is true. 1185 1204 * @return array Rewrite rule list. 1186 1205 */ 1187 1206 function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) { … … 1240 1259 $structure = str_replace($front, '', $structure); 1241 1260 1242 1261 //create a list of dirs to walk over, making rewrite rules for each level 1243 //so for example, a $structure of /%year%/%month %/%postname% would create1244 //rewrite rules for /%year%/, /%year%/%month %/ and /%year%/%month%/%postname%1262 //so for example, a $structure of /%year%/%monthnum%/%postname% would create 1263 //rewrite rules for /%year%/, /%year%/%monthnum%/ and /%year%/%monthnum%/%postname% 1245 1264 $structure = trim($structure, '/'); 1246 1265 $dirs = $walk_dirs ? explode('/', $structure) : array( $structure ); 1247 1266 $num_dirs = count($dirs); … … 1377 1396 $sub1feed = $sub1 . $feedregex; //and <permalink>/feed/(atom|...) 1378 1397 $sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...) 1379 1398 $sub1comment = $sub1 . $commentregex; //and <permalink>/comment-page-xx 1380 //add an ? as we don't have to match that last slash, and finally a $ so we1381 //match to the end of the URL1382 1399 1383 1400 //add another rule to match attachments in the explicit form: 1384 1401 //<permalink>/attachment/some-text … … 1405 1422 } 1406 1423 1407 1424 //now we've finished with endpoints, finish off the $sub1 and $sub2 matches 1425 //add an ? as we don't have to match that last slash, and finally a $ so we 1426 //match to the end of the URL 1408 1427 $sub1 .= '?$'; 1409 1428 $sub2 .= '?$'; 1410 1429 1411 // allow URLs like <permalink>/2 for <permalink>/page/21430 //post pagination, e.g. <permalink>/2/ 1412 1431 $match = $match . '(/[0-9]+)?/?$'; 1413 1432 $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1); 1414 1433 } else { //not matching a permalink so this is a lot simpler … … 1586 1605 * Does not actually write to the .htaccess file, but creates the rules for 1587 1606 * the process that will. 1588 1607 * 1589 * Will add the non_wp_rules property rules to the .htaccess file before1608 * Will add the non_wp_rules property rules to the .htaccess file before 1590 1609 * the WordPress rewrite rules one. 1591 1610 * 1592 1611 * @since 1.5.0