WordPress.org

Make WordPress Core

Ticket #10384: 10384.patch

File 10384.patch, 8.8 KB (added by ruslany, 9 years ago)

Patch to remove dependency on IIS version

  • wp-admin/includes/misc.php

     
    145145 *
    146146 * @return bool True if web.config was updated successfully
    147147 */
    148 function iis7_save_url_rewrite_rules(){
     148function iis_save_url_rewrite_rules(){
    149149        global $wp_rewrite;
    150150
    151151        $home_path = get_home_path();
     
    153153
    154154        // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP
    155155        if ( ( ! file_exists($web_config_file) && win_is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable($web_config_file) ) {
    156                 if ( iis7_supports_permalinks() ) {
    157                         $rule = $wp_rewrite->iis7_url_rewrite_rules();
     156                if ( iis_supports_permalinks() ) {
     157                        $rule = $wp_rewrite->iis_url_rewrite_rules();
    158158                        if ( ! empty($rule) ) {
    159                                 return iis7_add_rewrite_rule($web_config_file, $rule);
     159                                return iis_add_rewrite_rule($web_config_file, $rule);
    160160                        } else {
    161                                 return iis7_delete_rewrite_rule($web_config_file);
     161                                return iis_delete_rewrite_rule($web_config_file);
    162162                        }
    163163                }
    164164        }
     
    429429}
    430430
    431431/**
    432  * Check if IIS 7 supports pretty permalinks
     432 * Check if IIS supports pretty permalinks via URL Rewrite Module
    433433 *
    434434 * @since 2.8.0
    435435 *
    436436 * @return bool
    437437 */
    438 function iis7_supports_permalinks() {
    439         global $is_iis7;
     438function iis_supports_permalinks() {
     439        global $is_IIS;
    440440
    441441        $supports_permalinks = false;
    442         if ( $is_iis7 ) {
     442        if ( $is_IIS ) {
    443443                /* First we check if the DOMDocument class exists. If it does not exist,
    444444                 * which is the case for PHP 4.X, then we cannot easily update the xml configuration file,
    445445                 * hence we just bail out and tell user that pretty permalinks cannot be used.
     
    453453                $supports_permalinks = class_exists('DOMDocument') && isset($_SERVER['IIS_UrlRewriteModule']) && ( php_sapi_name() == 'cgi-fcgi' );
    454454        }
    455455
    456         return apply_filters('iis7_supports_permalinks', $supports_permalinks);
     456        return apply_filters('iis_supports_permalinks', $supports_permalinks);
    457457}
    458458
    459459/**
    460  * Check if rewrite rule for WordPress already exists in the IIS 7 configuration file
     460 * Check if rewrite rule for WordPress already exists in the IIS configuration file
    461461 *
    462462 * @since 2.8.0
    463463 *
    464464 * @return bool
    465465 * @param string $filename The file path to the configuration file
    466466 */
    467 function iis7_rewrite_rule_exists($filename) {
     467function iis_rewrite_rule_exists($filename) {
    468468        if ( ! file_exists($filename) )
    469469                return false;
    470470        if ( ! class_exists('DOMDocument') )
     
    489489 * @param string $filename Name of the configuration file
    490490 * @return bool
    491491 */
    492 function iis7_delete_rewrite_rule($filename) {
     492function iis_delete_rewrite_rule($filename) {
    493493        // If configuration file does not exist then rules also do not exist so there is nothing to delete
    494494        if ( ! file_exists($filename) )
    495495                return true;
     
    515515}
    516516
    517517/**
    518  * Add WordPress rewrite rule to the IIS 7 configuration file.
     518 * Add WordPress rewrite rule to the IIS configuration file.
    519519 *
    520520 * @since 2.8.0
    521521 *
     
    523523 * @param string $rewrite_rule The XML fragment with URL Rewrite rule
    524524 * @return bool
    525525 */
    526 function iis7_add_rewrite_rule($filename, $rewrite_rule) {
     526function iis_add_rewrite_rule($filename, $rewrite_rule) {
    527527        if ( ! class_exists('DOMDocument') )
    528528                return false;
    529529
  • wp-admin/options-permalink.php

     
    7070include('admin-header.php');
    7171
    7272$home_path = get_home_path();
    73 $iis7_permalinks = iis7_supports_permalinks();
     73$iis_permalinks = iis_supports_permalinks();
    7474
    7575if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
    7676        check_admin_referer('update-permalink');
     
    101101$category_base = get_option('category_base');
    102102$tag_base = get_option( 'tag_base' );
    103103
    104 if ( $iis7_permalinks ) {
     104if ( $iis_permalinks ) {
    105105        if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )
    106106                $writable = true;
    107107        else
     
    123123
    124124<?php if (isset($_POST['submit'])) : ?>
    125125<div id="message" class="updated fade"><p><?php
    126 if ( $iis7_permalinks ) {
     126if ( $iis_permalinks ) {
    127127        if ( $permalink_structure && ! $usingpi && ! $writable )
    128128                _e('You should update your web.config now');
    129129        else if ( $permalink_structure && ! $usingpi && $writable)
     
    152152<?php
    153153$prefix = '';
    154154
    155 if ( ! got_mod_rewrite() && ! $iis7_permalinks )
     155if ( ! got_mod_rewrite() && ! $iis_permalinks )
    156156        $prefix = '/index.php';
    157157
    158158$structures = array(
     
    197197</table>
    198198
    199199<h3><?php _e('Optional'); ?></h3>
    200 <?php if ( $is_apache || $iis7_permalinks ) : ?>
     200<?php if ( $is_apache || $iis_permalinks ) : ?>
    201201        <p><?php _e('If you like, you may enter custom structures for your category and tag <abbr title="Universal Resource Locator">URL</abbr>s here. For example, using <kbd>topics</kbd> as your category base would make your category links like <code>http://example.org/topics/uncategorized/</code>. If you leave these blank the defaults will be used.') ?></p>
    202202<?php else : ?>
    203203        <p><?php _e('If you like, you may enter custom structures for your category and tag <abbr title="Universal Resource Locator">URL</abbr>s here. For example, using <code>topics</code> as your category base would make your category links like <code>http://example.org/index.php/topics/uncategorized/</code>. If you leave these blank the defaults will be used.') ?></p>
     
    221221        <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
    222222</p>
    223223  </form>
    224 <?php if ($iis7_permalinks) :
     224<?php if ($iis_permalinks) :
    225225        if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) : ?>
    226226<p><?php _e('If your <code>web.config</code> file were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so this is the url rewrite rule you should have in your <code>web.config</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all. Then insert this rule inside of the <code>/&lt;configuration&gt;/&lt;system.webServer&gt;/&lt;rewrite&gt;/&lt;rules&gt;</code> element in <code>web.config</code> file.') ?></p>
    227227<form action="options-permalink.php" method="post">
    228228<?php wp_nonce_field('update-permalink') ?>
    229         <p><textarea rows="10" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->iis7_url_rewrite_rules()); ?></textarea></p>
     229        <p><textarea rows="10" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->iis_url_rewrite_rules()); ?></textarea></p>
    230230</form>
    231231<p><?php _e('If you temporarily make your <code>web.config</code> file writable for us to generate rewrite rules automatically, do not forget to revert the permissions after rule has been saved.')  ?></p>
    232232        <?php endif; ?>
  • wp-includes/rewrite.php

     
    17051705        }
    17061706
    17071707        /**
    1708          * Retrieve IIS7 URL Rewrite formatted rewrite rules to write to web.config file.
     1708         * Retrieve IIS URL Rewrite formatted rewrite rules to write to web.config file.
    17091709         *
    17101710         * Does not actually write to the web.config file, but creates the rules for
    17111711         * the process that will.
     
    17151715         *
    17161716         * @return string
    17171717         */
    1718         function iis7_url_rewrite_rules(){
     1718        function iis_url_rewrite_rules(){
    17191719
    17201720                if ( ! $this->using_permalinks()) {
    17211721                        return '';
     
    17291729                $rules .= "     <action type=\"Rewrite\" url=\"index.php\" />\n";
    17301730                $rules .= "</rule>";
    17311731
    1732                 $rules = apply_filters('iis7_url_rewrite_rules', $rules);
     1732                $rules = apply_filters('iis_url_rewrite_rules', $rules);
    17331733
    17341734                return $rules;
    17351735        }
     
    18291829                $this->wp_rewrite_rules();
    18301830                if ( $hard && function_exists('save_mod_rewrite_rules') )
    18311831                        save_mod_rewrite_rules();
    1832                 if ( $hard && function_exists('iis7_save_url_rewrite_rules') )
    1833                         iis7_save_url_rewrite_rules();
     1832                if ( $hard && function_exists('iis_save_url_rewrite_rules') )
     1833                        iis_save_url_rewrite_rules();
    18341834        }
    18351835
    18361836        /**
  • wp-includes/vars.php

     
    7373 */
    7474$is_IIS = (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
    7575
    76 /**
    77  * Whether the server software is IIS 7.X
    78  * @global bool $is_iis7
    79  */
    80 $is_iis7 = (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7.') !== false);
    81 
    82 
    8376?>
    84  No newline at end of file