WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/27/2010 01:48:37 PM (12 years ago)
Author:
ryan
Message:

Whitespace cleanup and inline docs. Props nacin. see #12027

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/network.php

    r12859 r12865  
    33 * Network settings administration panel.
    44 *
    5  * @since 3.0
     5 * A multi-step process allowing the user to enable a network of WordPress sites.
     6 *
     7 * @since 3.0.0
    68 *
    79 * @package WordPress
     
    1012
    1113/** WordPress Administration Bootstrap */
    12 require_once('./admin.php');
     14require_once( './admin.php' );
    1315
    1416if ( ! is_super_admin() )
    15     wp_die(__('You do not have sufficient permissions to manage options for this blog.'));
    16 
    17 $title = __('Network Settings');
     17    wp_die( __( 'You do not have sufficient permissions to manage options for this blog.' ) );
     18
     19$title = __( 'Network Settings' );
    1820$parent_file = 'tools.php';
    1921
    20 add_contextual_help($current_screen, __('<a href="http://codex.wordpress.org/Settings_Network_SubPanel" target="_blank">Network Settings</a>'));
    21 
    22 include('./admin-header.php');
    23 /*
    24 This option panel does not save data to the options table.
    25 It contains a multi-step process allowing the user to enable a network of WordPress sites.
    26 */
    27 
    28 $dirs = array( substr( ABSPATH, 0, -1), ABSPATH . "wp-content" );
     22add_contextual_help( $current_screen, __( '<a href="http://codex.wordpress.org/Settings_Network_SubPanel" target="_blank">Network Settings</a>') );
     23
     24include( './admin-header.php' );
     25
     26$dirs = array( substr( ABSPATH, 0, -1 ), ABSPATH . 'wp-content' );
    2927?>
    3028<div class="wrap">
     
    3432<form method="post" action="network.php">
    3533<?php
     34/**
     35 * Prints summary of server statistics in preparation for setting up a network.
     36 *
     37 * @since 3.0.0
     38 */
    3639function filestats( $err ) {
    3740?>
    38     <h2><?php esc_html_e('Server Summary'); ?></h2>
    39     <p><?php _e('If you post a message to the WordPress support forum at <a target="_blank" href="http://wordpress.org/support/">http://wordpress.org/support/</a> then copy and paste the following information into your message:'); ?></p>
     41    <h2><?php esc_html_e( 'Server Summary' ); ?></h2>
     42    <p><?php _e( 'If you post a message to the WordPress support forum at <a target="_blank" href="http://wordpress.org/support/">http://wordpress.org/support/</a> then copy and paste the following information into your message:' ); ?></p>
    4043    <blockquote style="background: #eee; border: 1px solid #333; padding: 5px;">
    41     <br /><strong><?php echo __('ERROR:') . " $err"; ?></strong><br />
     44    <br /><strong><?php printf( __( 'ERROR: %s' ), $err ); ?></strong><br />
    4245<?php
    4346    clearstatcache();
    44     $files = array( "htaccess.dist", ".htaccess" );
     47    $files = array( 'htaccess.dist', '.htaccess' );
    4548
    4649    $indent = '&nbsp;&nbsp;&nbsp;&nbsp;';
    4750    foreach ( (array) $files as $val ) {
    4851        $stats = @stat( $val );
    49         if( $stats ) {
     52        if ( $stats ) {
    5053?>
    5154            <h2><?php echo esc_html( $val ); ?></h2>
    52             <?php echo $indent . sprintf( __('uid/gid: %1$s/%2$s'), $stats[ 'uid' ], $stats[ 'gid' ] ); ?><br />
    53             <?php echo $indent . sprintf( __('size: %s'), $stats['size'] ); ?><br/>
    54             <?php echo $indent . sprintf( __('perms: %s'), substr( sprintf('%o', fileperms( $val ) ), -4 ) ); ?><br/>
    55             <?php echo $indent . sprintf( __('readable: %s'), is_readable( $val ) ? __('yes') : __('no') ); ?><br/>
    56             <?php echo $indent . sprintf( __('writeable: %s'), is_writeable( $val ) ? __('yes') : __('no') ); ?><br/>
    57 <?php
    58         } elseif( ! file_exists( $val ) ) {
     55            <?php echo $indent . sprintf( __( 'uid/gid: %1$s/%2$s' ), $stats['uid'], $stats['gid'] ); ?><br />
     56            <?php echo $indent . sprintf( __( 'size: %s' ), $stats['size'] ); ?><br/>
     57            <?php echo $indent . sprintf( __( 'perms: %s' ), substr( sprintf( '%o', fileperms( $val ) ), -4 ) ); ?><br/>
     58            <?php echo $indent . sprintf( __( 'readable: %s' ), is_readable( $val ) ? __( 'yes' ) : __( 'no' ) ); ?><br/>
     59            <?php echo $indent . sprintf( __( 'writeable: %s' ), is_writeable( $val ) ? __( 'yes' ) : __( 'no' ) ); ?><br/>
     60<?php
     61        } elseif ( ! file_exists( $val ) ) {
    5962?>
    6063            <h2><?php echo esc_html( $val ); ?></h2>
    61             <?php echo $indent . sprintf( __('FILE NOT FOUND: %s'), $val ); ?><br/>
     64            <?php echo $indent . sprintf( __( 'FILE NOT FOUND: %s' ), $val ); ?><br/>
    6265<?php
    6366        }
     
    6669}
    6770
     71/**
     72 * Prints .htaccess component of step 2 for network settings.
     73 *
     74 * @since 3.0.0
     75 */
    6876function step2_htaccess() {
    6977    global $base;
     
    7179    // remove ending slash from $base and $url
    7280    $htaccess = '';
    73     if( substr($base, -1 ) == '/') {
    74         $base = substr($base, 0, -1);
    75     }
     81    if ( substr( $base, -1 ) == '/' )
     82        $base = substr( $base, 0, -1 );
     83
    7684    $htaccess_sample = ABSPATH . 'wp-admin/includes/htaccess.ms';
    77     if ( !file_exists( $htaccess_sample ) )
    78         wp_die( sprintf( __('Sorry, I need a %s to work from. Please re-upload this file to your WordPress installation.'), $htaccess_sample ) );
     85    if ( ! file_exists( $htaccess_sample ) )
     86        wp_die( sprintf( __( 'Sorry, I need a %s to work from. Please re-upload this file to your WordPress installation.' ), $htaccess_sample ) );
    7987
    8088    $htaccess_file = file( $htaccess_sample );
    8189    $fp = @fopen( $htaccess_sample, "r" );
    82     if( $fp ) {
    83         while( !feof( $fp ) ) {
     90    if ( $fp ) {
     91        while ( ! feof( $fp ) ) {
    8492            $htaccess .= fgets( $fp, 4096 );
    8593        }
     
    8795        $htaccess_file = str_replace( "BASE", $base, $htaccess );
    8896    } else {
    89         wp_die( sprintf( __('Sorry, I need to be able to read %s. Please check the permissions on this file.'), $htaccess_sample ) );
     97        wp_die( sprintf( __( 'Sorry, I need to be able to read %s. Please check the permissions on this file.' ), $htaccess_sample ) );
    9098    }
    9199
    92100    //@todo: check for super-cache in use
    93101?>
    94             <li><p><?php _e('Replace the contents of your <code>.htaccess</code> with the following:'); ?></p>
     102            <li><p><?php _e( 'Replace the contents of your <code>.htaccess</code> with the following:' ); ?></p>
    95103                <textarea name="htaccess" cols="120" rows="20">
    96 <?php echo $htaccess_file; ?>
     104<?php echo wp_htmledit_pre( $htaccess_file ); ?>
    97105                </textarea>
    98106            </li>
     
    100108}
    101109
     110/**
     111 * Prints part of step 1 for network settings and checks for mod_rewrite.
     112 *
     113 * @since 3.0.0
     114 * @return bool Whether mod_rewrite is enabled.
     115 */
    102116function step1() {
    103117    $rewrite_enabled = false;
    104118    ?>
    105     <h2><?php esc_html_e('Installing Network of WordPress Sites'); ?></h2>
    106     <p><?php _e('I will help you enable the features for creating a network of sites by asking you a few questions so that you can create configuration files and make a directory to store all your uploaded files.'); ?></p>
    107 
    108     <h2><?php esc_html_e('What do I need?'); ?></h2>
     119    <h2><?php esc_html_e( 'Installing Network of WordPress Sites' ); ?></h2>
     120    <p><?php _e( 'I will help you enable the features for creating a network of sites by asking you a few questions so that you can create configuration files and make a directory to store all your uploaded files.' ); ?></p>
     121
     122    <h2><?php esc_html_e( 'What do I need?' ); ?></h2>
    109123    <ul>
    110124        <li><?php _e( 'Access to your server to change directory permissions. This can be done through ssh or ftp for example.' ); ?></li>
    111125        <li><?php _e( 'A valid email where your password and administrative emails will be sent.' ); ?></li>
    112         <li><?php _e( "Wildcard dns records if you're going to use the virtual host (sub-domain) functionality. Check the <a href='http://trac.mu.wordpress.org/browser/trunk/README.txt'>README</a> for further details."); ?></li>
     126        <li><?php _e( "Wildcard dns records if you're going to use the virtual host (sub-domain) functionality. Check the <a href='http://trac.mu.wordpress.org/browser/trunk/README.txt'>README</a> for further details." ); ?></li>
    113127    </ul>
    114128    <?php
    115     $mod_rewrite_msg = "\n<p>" . __( "If the <code>mod_rewrite</code> module is disabled ask your administrator to enable that module, or look at the <a href='http://httpd.apache.org/docs/mod/mod_rewrite.html'>Apache documentation</a> or <a href='http://www.google.com/search?q=apache+mod_rewrite'>elsewhere</a> for help setting it up." ) . '</p>';
     129    $mod_rewrite_msg = "\n<p>" . __( 'If the <code>mod_rewrite</code> module is disabled ask your administrator to enable that module, or look at the <a href="http://httpd.apache.org/docs/mod/mod_rewrite.html">Apache documentation</a> or <a href="http://www.google.com/search?q=apache+mod_rewrite">elsewhere</a> for help setting it up.' ) . '</p>';
    116130
    117131    if ( function_exists( 'apache_get_modules' ) ) {
    118132        $modules = apache_get_modules();
    119133        if ( ! in_array( 'mod_rewrite', $modules ) )
    120             echo '<p>' . __('<strong>Warning!</strong> It looks like mod_rewrite is not installed.') . '</p>' . $mod_rewrite_msg;
     134            echo '<p>' . __( '<strong>Warning!</strong> It looks like mod_rewrite is not installed.' ) . '</p>' . $mod_rewrite_msg;
    121135        else
    122136            $rewrite_enabled = true;
     
    127141}
    128142
     143/**
     144 * Prints most of step 1 for network settings.
     145 *
     146 * @since 3.0.0
     147 * @param bool $rewrite_enabled Whether mod_rewrite is enabled. Default false.
     148 */
    129149function printstep1form( $rewrite_enabled = false ) {
    130     $weblog_title = sprintf( __('%s Sites'), ucfirst( get_option( 'blogname' ) ) );
     150    $weblog_title = sprintf( __( '%s Sites' ), ucfirst( get_option( 'blogname' ) ) );
    131151    $email = get_option( 'admin_email' );
    132152    $hostname = get_clean_basedomain();
    133     if( substr( $hostname, 0, 4 ) == 'www.' )
     153    if ( substr( $hostname, 0, 4 ) == 'www.' )
    134154        $nowww = substr( $hostname, 4 );
    135155
     
    139159        <h2><?php esc_html_e( 'Site Addresses' ); ?></h2>
    140160        <p><?php _e( 'Please choose whether you would like sites in your WordPress install to use sub-domains or sub-directories. You cannot change this later.' ); ?></p>
    141         <?php if ( !$rewrite_enabled ) { ?>
    142         <p><?php _e( '<strong>Note</strong> It looks like <code>mod_rewrite</code> is not installed.'); ?></p>
     161        <?php if ( ! $rewrite_enabled ) { ?>
     162        <p><?php _e( '<strong>Note</strong> It looks like <code>mod_rewrite</code> is not installed.' ); ?></p>
    143163        <?php } ?>
    144164        <p class="blog-address">
    145             <label><input type='radio' name='vhost' value='yes'<?php if( $rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-domains (like <code>blog1.example.com</code>)' ); ?></label><br />
    146             <label><input type='radio' name='vhost' value='no'<?php if( !$rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-directories (like <code>example.com/blog1</code>) '); ?></label>
     165            <label><input type='radio' name='vhost' value='yes'<?php if ( $rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-domains (like <code>blog1.example.com</code>)' ); ?></label><br />
     166            <label><input type='radio' name='vhost' value='no'<?php if ( ! $rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-directories (like <code>example.com/blog1</code>)' ); ?></label>
    147167        </p>
    148168
     
    183203}
    184204
     205/**
     206 * Prints step 2 for network settings.
     207 *
     208 * @since 3.0.0
     209 */
    185210function step2() {
    186211?>
     
    195220}
    196221
     222/**
     223 * Prints configuration file component of step 2 for network settings.
     224 *
     225 * @since 3.0.0
     226 */
    197227function step2_config() {
    198228    global $base, $wpdb, $vhost;
    199229
    200     $vhost   = stripslashes($_POST['vhost' ]);
     230    $vhost   = stripslashes( $_POST['vhost' ] );
    201231    $prefix  = $wpdb->base_prefix;
    202232
    203233    $config_sample = ABSPATH . 'wp-admin/includes/wp-config.ms';
    204     if ( !file_exists( $config_sample ) )
     234    if ( ! file_exists( $config_sample ) )
    205235        wp_die( sprintf( __( 'Sorry, I need a <code>%s</code> to work from. Please re-upload this file to your WordPress installation.' ), $config_sample ) );
    206236
     
    210240                <textarea name="wp-config" cols="120" rows="20">
    211241<?php
    212     foreach ($wp_config_file as $line) {
    213         switch ( trim( substr($line,0,16) ) ) {
     242    foreach ( $wp_config_file as $line ) {
     243        switch ( trim( substr( $line, 0, 16 ) ) ) {
    214244            case "define('DB_NAME'":
    215                 $output = str_replace("wordpress", DB_NAME, $line);
     245                $output = str_replace( "wordpress", DB_NAME, $line );
    216246                break;
    217247            case "define('DB_USER'":
    218                 $output = str_replace("username", DB_USER, $line);
     248                $output = str_replace( "username", DB_USER, $line );
    219249                break;
    220250            case "define('DB_PASSW":
    221                 $output = str_replace("password", DB_PASSWORD, $line);
     251                $output = str_replace( "password", DB_PASSWORD, $line );
    222252                break;
    223253            case "define('DB_HOST'":
    224                 $output = str_replace("localhost", DB_HOST, $line);
     254                $output = str_replace( "localhost", DB_HOST, $line );
    225255                break;
    226256            case "define('VHOST',":
    227                 $output = str_replace("VHOSTSETTING", $vhost, $line);
     257                $output = str_replace( "VHOSTSETTING", $vhost, $line );
    228258                break;
    229259            case '$table_prefix  =':
    230                 $output = str_replace('wp_', $prefix, $line);
     260                $output = str_replace( 'wp_', $prefix, $line );
    231261                break;
    232262            case '$base = \'BASE\';':
    233                 $output = str_replace('BASE', $base, $line);
     263                $output = str_replace( 'BASE', $base, $line );
    234264                break;
    235265            case "define('DOMAIN_C":
    236266                $domain = get_clean_basedomain();
    237                 $output = str_replace("current_site_domain", $domain, $line);
     267                $output = str_replace( "current_site_domain", $domain, $line );
    238268                break;
    239269            case "define('PATH_CUR":
    240                 $output = str_replace("current_site_path", $base, $line);
     270                $output = str_replace( "current_site_path", $base, $line );
    241271                break;
    242272            case "define('AUTH_KEY":
     
    250280                else
    251281                    $hash = md5( mt_rand() ) . md5( mt_rand() );
    252                 $output = str_replace('put your unique phrase here', $hash, $line);
     282                $output = str_replace( 'put your unique phrase here', $hash, $line );
    253283                break;
    254284            default:
     
    264294}
    265295
     296/**
     297 * Gets base domain of network.
     298 *
     299 * @since 3.0.0
     300 */
    266301function get_clean_basedomain() {
    267302    global $wpdb;
    268     $domain = preg_replace( '|https?://|', '', get_option( 'siteurl') );
    269     if( strpos( $domain, '/' ) )
     303    $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
     304    if ( strpos( $domain, '/' ) )
    270305        $domain = substr( $domain, 0, strpos( $domain, '/' ) );
    271306    return $domain;
    272307}
    273308
    274 $action = isset($_POST[ 'action' ]) ? $_POST[ 'action' ] : null;
    275 switch($action) {
    276     case "step2":
     309$action = isset( $_POST[ 'action' ] ) ? $_POST[ 'action' ] : null;
     310
     311switch( $action ) {
     312    case 'step2':
    277313        check_admin_referer( 'install-network-1' );
    278314
    279315        // Install!
    280         $base = stripslashes( dirname( dirname($_SERVER["SCRIPT_NAME"]) ) );
    281         if( $base != "/")
    282             $base .= "/";
     316        $base = stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) );
     317        if ( $base != '/' )
     318            $base .= '/';
    283319
    284320        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     
    286322        $domain = get_clean_basedomain();
    287323        install_network();
    288         populate_network( 1, $domain, sanitize_email( $_POST[ 'email' ] ), $_POST[ 'weblog_title' ], $base, $_POST[ 'vhost' ] );
     324        populate_network( 1, $domain, sanitize_email( $_POST['email'] ), $_POST['weblog_title'], $base, $_POST['vhost'] );
    289325        // create wp-config.php / htaccess
    290326        step2();
     
    293329        //@todo: give an informative screen instead
    294330        if ( is_multisite() ) {
    295             _e('Network already enabled');
     331            _e( 'Network already enabled.' );
    296332        } else {
    297333            $rewrite_enabled = step1();
    298             printstep1form($rewrite_enabled);
     334            printstep1form( $rewrite_enabled );
    299335        }
    300336    break;
     
    304340</div>
    305341
    306 <?php include('./admin-footer.php'); ?>
     342<?php include( './admin-footer.php' ); ?>
Note: See TracChangeset for help on using the changeset viewer.