WordPress.org

Make WordPress Core

Ticket #15083: 15083.refactoring-first.2.patch

File 15083.refactoring-first.2.patch, 2.9 KB (added by hakre, 10 years ago)

First Patch had some bugs, fixed. Changed Regexes according to description now.

  • wp-admin/network.php

     
    2626        $wpdb->$table = $prefixed_table;
    2727
    2828/**
     29 * @param string $base configuration
     30 * @param bool $subdomain_install configuration
     31 * @return string;
     32 */
     33function network_admin_generate_htaccess_file_content($base, $subdomain_install ) {
     34
     35        $uploaded_files = sprintf(
     36                '^%sfiles/(.+) wp-includes/ms-files.php?file=$1',
     37                $subdomain_install ? '' : '[_0-9a-zA-Z-]+/'
     38        );
     39       
     40        // $htaccess_comment_if_a_subdomain_install
     41        $comment_if = $subdomain_install ? '# ' : '';
     42       
     43        $content =
     44'RewriteEngine On
     45RewriteBase ' . $base . '
     46RewriteRule ^index\.php$ - [L]
     47
     48# uploaded files
     49RewriteRule ' . $uploaded_files . ' [L]
     50
     51# add a trailing slash to /wp-admin (commented if a subdomain install)
     52' . $comment_if . 'RewriteRule ^([_0-9a-zA-Z-]+/)wp-admin$ $1wp-admin/ [R=301,L]
     53
     54RewriteCond %{REQUEST_FILENAME} -f [OR]
     55RewriteCond %{REQUEST_FILENAME} -d
     56RewriteRule ^ - [L]
     57
     58# serach for non-existent files (commented if a subdomain install)
     59' . $comment_if . 'RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
     60' . $comment_if . 'RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
     61
     62RewriteRule . index.php [L]
     63';
     64       
     65        return $content;
     66}
     67       
     68/**
    2969 * Check for an existing network.
    3070 *
    3171 * @since 3.0.0
     
    455495
    456496        <?php else : // end iis7_supports_permalinks(). construct an htaccess file instead:
    457497
    458                 $htaccess_file = 'RewriteEngine On
    459 RewriteBase ' . $base . '
    460 RewriteRule ^index\.php$ - [L]
    461 
    462 # uploaded files
    463 RewriteRule ^' . ( $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $subdomain_install ? 1 : 2 ) . ' [L]' . "\n";
    464 
    465                 if ( ! $subdomain_install )
    466                         $htaccess_file .= "\n# add a trailing slash to /wp-admin\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]' . "\n";
    467 
    468                 $htaccess_file .= "\n" . 'RewriteCond %{REQUEST_FILENAME} -f [OR]
    469 RewriteCond %{REQUEST_FILENAME} -d
    470 RewriteRule ^ - [L]';
    471 
    472                 // @todo custom content dir.
    473                 if ( ! $subdomain_install )
    474                         $htaccess_file .= "\nRewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]\nRewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]";
    475 
    476                 $htaccess_file .= "\nRewriteRule . index.php [L]";
    477 
     498                $file_content = network_admin_generate_htaccess_file_content( $base, $subdomain_install );
    478499                ?>
    479500                <li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p>
    480501                <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $subdomain_install ? 11 : 16; ?>">
    481 <?php echo wp_htmledit_pre( $htaccess_file ); ?></textarea></li>
     502<?php echo wp_htmledit_pre( $file_content ); ?></textarea></li>
    482503                </ol>
    483504
    484505        <?php endif; // end IIS/Apache code branches.