Ticket #10425: 10425.patch
File 10425.patch, 6.3 KB (added by , 16 years ago) |
---|
-
wp-admin/includes/misc.php
154 154 // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP 155 155 if ( ( ! file_exists($web_config_file) && win_is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable($web_config_file) ) { 156 156 if ( iis7_supports_permalinks() ) { 157 $rule = $wp_rewrite->iis7_url_rewrite_rules();158 if ( ! empty($rule ) ) {159 return iis7_add_rewrite_rule ($web_config_file, $rule);157 $rules = $wp_rewrite->iis7_url_rewrite_rules(); 158 if ( ! empty($rules) ) { 159 return iis7_add_rewrite_rules($web_config_file, $rules); 160 160 } else { 161 return iis7_delete_rewrite_rule ($web_config_file);161 return iis7_delete_rewrite_rules($web_config_file); 162 162 } 163 163 } 164 164 } … … 457 457 } 458 458 459 459 /** 460 * Check if rewrite rule for WordPress already exists in the IIS 7 configuration file460 * Delete WordPress rewrite rules from web.config file if it exists there 461 461 * 462 462 * @since 2.8.0 463 463 * 464 * @return bool465 * @param string $filename The file path to the configuration file466 */467 function iis7_rewrite_rule_exists($filename) {468 if ( ! file_exists($filename) )469 return false;470 if ( ! class_exists('DOMDocument') )471 return false;472 473 $doc = new DOMDocument();474 if ( $doc->load($filename) === false )475 return false;476 $xpath = new DOMXPath($doc);477 $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[@name=\'wordpress\']');478 if ( $rules->length == 0 )479 return false;480 else481 return true;482 }483 484 /**485 * Delete WordPress rewrite rule from web.config file if it exists there486 *487 * @since 2.8.0488 *489 464 * @param string $filename Name of the configuration file 490 465 * @return bool 491 466 */ 492 function iis7_delete_rewrite_rule ($filename) {467 function iis7_delete_rewrite_rules( $filename ) { 493 468 // If configuration file does not exist then rules also do not exist so there is nothing to delete 494 469 if ( ! file_exists($filename) ) 495 470 return true; … … 503 478 if ( $doc -> load($filename) === false ) 504 479 return false; 505 480 $xpath = new DOMXPath($doc); 506 $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[ @name=\'wordpress\']');481 $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[contains(@name,\'wordpress\')]'); 507 482 if ( $rules->length > 0 ) { 508 $child = $rules->item(0); 509 $parent = $child->parentNode; 510 $parent->removeChild($child); 483 foreach ( $rules as $child ) { 484 $parent = $child->parentNode; 485 $parent->removeChild($child); 486 } 511 487 $doc->formatOutput = true; 512 488 saveDomDocument($doc, $filename); 513 489 } … … 515 491 } 516 492 517 493 /** 518 * Add WordPress rewrite rule to the IIS 7 configuration file.494 * Add WordPress rewrite rules to the IIS 7 configuration file. 519 495 * 520 496 * @since 2.8.0 521 497 * 522 498 * @param string $filename The file path to the configuration file 523 * @param string $rewrite_rule The XML fragment with URL Rewrite rule499 * @param string $rewrite_rules The XML fragment with URL Rewrite rule 524 500 * @return bool 525 501 */ 526 function iis7_add_rewrite_rule ($filename, $rewrite_rule) {502 function iis7_add_rewrite_rules($filename, $rewrite_rules) { 527 503 if ( ! class_exists('DOMDocument') ) 528 504 return false; 529 505 … … 542 518 543 519 $xpath = new DOMXPath($doc); 544 520 545 // First check if the rule already exists as in that case there is no need to re-add it 546 $wordpress_rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[@name=\'wordpress\']'); 547 if ( $wordpress_rules->length > 0 ) 548 return true; 521 // First check if the rules already exist as in that case we need to remove them before writing the updated ones. 522 $wordpress_rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[contains(@name,\'wordpress\')]'); 523 if ( $wordpress_rules->length > 0 ) { 524 foreach ( $wordpress_rules as $child ) { 525 $parent = $child->parentNode; 526 $parent->removeChild($child); 527 } 528 } 549 529 550 530 // Check the XPath to the rewrite rule and create XML nodes if they do not exist 551 531 $xmlnodes = $xpath->query('/configuration/system.webServer/rewrite/rules'); … … 584 564 } 585 565 586 566 $rule_fragment = $doc->createDocumentFragment(); 587 $rule_fragment->appendXML($rewrite_rule );567 $rule_fragment->appendXML($rewrite_rules); 588 568 $rules_node->appendChild($rule_fragment); 589 569 590 570 $doc->formatOutput = true; -
wp-includes/rewrite.php
1720 1720 if ( ! $this->using_permalinks()) { 1721 1721 return ''; 1722 1722 } 1723 $rules = "<rule name=\"wordpress\" patternSyntax=\"Wildcard\">\n";1724 $rules .= " <match url=\"*\" />\n";1725 $rules .= " <conditions>\n";1726 $rules .= " <add input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" negate=\"true\" />\n";1727 $rules .= " <add input=\"{REQUEST_FILENAME}\" matchType=\"IsDirectory\" negate=\"true\" />\n";1728 $rules .= " </conditions>\n";1729 $rules .= " <action type=\"Rewrite\" url=\"index.php\" />\n";1730 $rules .= "</rule>";1731 1723 1724 $rules = "\n"; 1725 $counter = 0; 1726 //add in the rules that don't rewrite to WP's index.php (and thus shouldn't be handled by WP at all) 1727 foreach ( (array) $this->non_wp_rules as $match => $query ) { 1728 $rules .= '<rule name="non_wordpress_rule_' . $counter++ . '" stopProcessing="true">' . "\n"; 1729 $rules .= ' <match url="' . $match . '" />' . "\n"; 1730 // Apache uses $N (N=0,..,9) for back-references. IIS URL rewrite uses {R:N} (N=0,...,9) 1731 // We need to replaces all the back-referenses 1732 $query = preg_replace('/\$(\d)/i', '{R:$1}', $query); 1733 $rules .= ' <action type="Rewrite" url="' . $query . '" />' . "\n"; 1734 $rules .= '</rule>' . "\n"; 1735 } 1736 1737 $rules .= '<rule name="wordpress" patternSyntax="Wildcard">'."\n"; 1738 $rules .= ' <match url="*" />'."\n"; 1739 $rules .= ' <conditions>'."\n"; 1740 $rules .= ' <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />'."\n"; 1741 $rules .= ' <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />'."\n"; 1742 $rules .= ' </conditions>'."\n"; 1743 $rules .= ' <action type="Rewrite" url="index.php" />'."\n"; 1744 $rules .= '</rule>'; 1745 1732 1746 $rules = apply_filters('iis7_url_rewrite_rules', $rules); 1733 1747 1734 1748 return $rules;