<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12757] trunk: options network page, db variable change, See #11644</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12757">12757</a></dd>
<dt>Author</dt> <dd>wpmuguru</dd>
<dt>Date</dt> <dd>2010-01-19 00:18:52 +0000 (Tue, 19 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>options network page, db variable change, See <a href="http://trac.wordpress.org/ticket/11644">#11644</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminmenuphp">trunk/wp-admin/menu.php</a></li>
<li><a href="#trunkwpincludeswpdbphp">trunk/wp-includes/wp-db.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkwpadminoptionsnetworkphp">trunk/wp-admin/options-network.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminmenuphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/menu.php (12756 => 12757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/menu.php        2010-01-19 00:04:25 UTC (rev 12756)
+++ trunk/wp-admin/menu.php        2010-01-19 00:18:52 UTC (rev 12757)
</span><span class="lines">@@ -158,6 +158,9 @@
</span><span class="cx">         $submenu['options-general.php'][40] = array(__('Permalinks'), 'manage_options', 'options-permalink.php');
</span><span class="cx">         if ( is_super_admin() )
</span><span class="cx">                 $submenu['options-general.php'][45] = array(__('Miscellaneous'), 'manage_options', 'options-misc.php');
</span><ins>+        if ( !is_multisite() && is_super_admin() ) {
+                $submenu['options-general.php'][50] = array(__('Network'), 'manage_options', 'options-network.php');
+        }
</ins><span class="cx">
</span><span class="cx"> $_wp_last_utility_menu = 80; // The index of the last top-level menu in the utility menu group
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpadminoptionsnetworkphp"></a>
<div class="addfile"><h4>Added: trunk/wp-admin/options-network.php (0 => 12757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/options-network.php         (rev 0)
+++ trunk/wp-admin/options-network.php        2010-01-19 00:18:52 UTC (rev 12757)
</span><span class="lines">@@ -0,0 +1,333 @@
</span><ins>+<?php
+/**
+ * Network settings administration panel.
+ *
+ * @since 3.0
+ *
+ * @package WordPress
+ * @subpackage Administration
+ */
+
+/** WordPress Administration Bootstrap */
+require_once('./admin.php');
+
+if ( ! is_super_admin() )
+        wp_die(__('You do not have sufficient permissions to manage options for this blog.'));
+
+$title = __('Network Settings');
+$parent_file = 'options-network.php';
+
+add_contextual_help($current_screen, __('<a href="http://codex.wordpress.org/Settings_Network_SubPanel" target="_blank">Network Settings</a>'));
+
+include('./admin-header.php');
+/*
+This option panel does not save data to the options table.
+It contains a multi-step process allowing the user to enable a network of WordPress sites.
+*/
+
+$dirs = array( substr( ABSPATH, 0, -1), ABSPATH . "wp-content" );
+?>
+<div class="wrap">
+<?php screen_icon(); ?>
+<h2><?php echo esc_html( $title ); ?></h2>
+
+<form method="post" action="options-network.php">
+<?php
+function filestats( $err ) {
+        print "<h2>Server Summary</h2>";
+        print "<p>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>";
+
+        print "<blockquote style='background: #eee; border: 1px solid #333; padding: 5px;'>";
+        print "<br /><strong>ERROR: $err</strong><br />";
+        clearstatcache();
+        $files = array( "htaccess.dist", ".htaccess" );
+        
+        foreach ( (array) $files as $val ) {
+                $stats = @stat( $val );
+                if( $stats ) {
+                        print "<h2>$val</h2>";
+                        print "&nbsp;&nbsp;&nbsp;&nbsp;uid/gid: " . $stats[ 'uid' ] . "/" . $stats[ 'gid' ] . "<br />\n";
+                        print "&nbsp;&nbsp;&nbsp;&nbsp;size: " . $stats[ 'size' ] . "<br />";
+                        print "&nbsp;&nbsp;&nbsp;&nbsp;perms: " . substr( sprintf('%o', fileperms( $val ) ), -4 ) . "<br />";
+                        print "&nbsp;&nbsp;&nbsp;&nbsp;readable: ";
+                        print is_readable( $val ) == true ? "yes" : "no";
+                        print "<br />";
+                        print "&nbsp;&nbsp;&nbsp;&nbsp;writeable: ";
+                        print is_writeable( $val ) == true ? "yes" : "no";
+                        print "<br />";
+                } elseif( file_exists( $val ) == false ) {
+                        print "<h2>$val</h2>";
+                        print "&nbsp;&nbsp;&nbsp;&nbsp;FILE NOT FOUND: $val<br />";
+                }
+        }
+        print "</blockquote>";
+}
+
+function step2_htaccess() {
+        global $base;
+
+        // remove ending slash from $base and $url
+        $htaccess = '';
+        if( substr($base, -1 ) == '/') {
+                $base = substr($base, 0, -1);
+        }
+        $htaccess_sample = ABSPATH . 'wp-admin/includes/htaccess.ms';
+        if ( !file_exists( $htaccess_sample ) )
+                wp_die("Sorry, I need a {$htaccess_sample} to work from. Please re-upload this file to your WordPress installation.");
+
+        $htaccess_file = file( $htaccess_sample );
+        $fp = @fopen( $htaccess_sample, "r" );
+        if( $fp ) {
+                while( !feof( $fp ) ) {
+                        $htaccess .= fgets( $fp, 4096 );
+                }
+                fclose( $fp );
+                $htaccess_file = str_replace( "BASE", $base, $htaccess );
+        } else {
+                wp_die("Sorry, I need to be able to read {$htaccess_sample}. Please check the permissions on this file.");
+        }
+
+        //@todo: check for super-cache in use
+?>
+                        <li><p>Replace the contents of your <code>.htaccess</code> with the following:</p>
+                                <textarea name="htaccess" cols="120" rows="20">
+<?php echo $htaccess_file; ?>
+                                </textarea>
+                        </li>
+<?php
+}
+
+function step1() {
+        $rewrite_enabled = false;
+        ?>
+        <h2>Installing Network of WordPress Sites</h2>
+        <p>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>
+        
+        <h2>What do I need?</h2>
+        <ul>
+                <li>Access to your server to change directory permissions. This can be done through ssh or ftp for example.</li>
+                <li>A valid email where your password and administrative emails will be sent.</li>
+                <li> 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>
+        </ul>
+        <?php
+        $mod_rewrite_msg = "<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>";
+        
+        if( function_exists( "apache_get_modules" ) ) {
+                $modules = apache_get_modules();
+                if( in_array( "mod_rewrite", $modules ) == false ) {
+                        echo "<p><strong>Warning!</strong> It looks like mod_rewrite is not installed.</p>" . $mod_rewrite_msg;
+                } else {
+                        $rewrite_enabled = true;
+                }
+        } else {
+                ?><p>Please make sure <code>mod_rewrite</code> is installed as it will be activated at the end of this install.</p><?php
+                echo $mod_rewrite_msg;
+        }
+        return $rewrite_enabled;
+}
+
+function printstep1form( $rewrite_enabled = false ) {
+        $weblog_title = ucfirst( get_option( 'blogname' ) ) . ' Sites';
+        $email = get_option( 'admin_email' );
+        $hostname = $_SERVER[ 'HTTP_HOST' ];
+        if( substr( $_SERVER[ 'HTTP_HOST' ], 0, 4 ) == 'www.' )
+                $hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] );
+
+        wp_nonce_field( 'install-network-1' );
+        ?>
+                <input type='hidden' name='action' value='step2' />
+                <h2>Site Addresses</h2>
+                <p>Please choose whether you would like sites in your WordPress install to use sub-domains or sub-directories. You can not change this later.</p>
+                <?php if ( !$rewrite_enabled ) { ?>
+                <p><strong>Note</strong> It looks like <code>mod_rewrite</code> is not installed.</p>
+                <?php } ?>
+                <p class="blog-address">
+                        <label><input type='radio' name='vhost' value='yes' <?php if( $rewrite_enabled ) echo 'checked="checked"'; ?> /> Sub-domains (like <code>blog1.example.com</code>)</label><br />
+                        <label><input type='radio' name='vhost' value='no' <?php if( !$rewrite_enabled ) echo 'checked="checked"'; ?> /> Sub-directories (like <code>example.com/blog1</code>)</label>
+                </p>
+
+                <h2>Server Address</h2>
+                <table class="form-table">
+                        <tr>
+                                <th scope='row'>Server Address</th>
+                                <td>
+                                        <p>What is the Internet address of your site? You should enter the shortest address possible. For example, use <em>example.com</em> instead of <em>www.example.com</em> but if you are going to use an address like <em>blogs.example.com</em> then enter that unaltered in the box below.</p>
+                                        <input type='text' name='basedomain' value='<?php echo $hostname ?>' />
+                                        <p>Do not use an IP address (like 127.0.0.1) or a single word hostname like <q>localhost</q> as your server address, use <q>localhost.localdomain</q> instead.</p>
+                                </td>
+                        </tr>
+                </table>
+
+                <h2>Site Details</h2>
+                <table class="form-table">
+                        <tr>
+                                <th scope='row'>Site&nbsp;Title</th>
+                                <td>
+                                        <input name='weblog_title' type='text' size='45' value='<?php echo $weblog_title ?>' />
+                                        <br />What would you like to call your site?
+                                </td>
+                        </tr>
+                        <tr>
+                                <th scope='row'>Email</th>
+                                <td>
+                                        <input name='email' type='text' size='45' value='<?php echo $email ?>' />
+                                        <br />Your email address.
+                                </td>
+                        </tr>
+                </table>
+                <p class='submit'><input class="button" name='submit' type='submit' value='Proceed' /></p>
+        <?php
+}
+
+function step2() {
+?>
+                <h2>Enabling WordPress Sites</h2>
+                <p>Complete the following steps to enable the features for creating a network of sites. <strong>Note:</strong> We recommend you make a backup copy of your existing <code>wp-config.php</code> and <code>.htaccess</code> files.</p>
+                <ol>
+                        <li>Create a <code>blogs.dir</code> directory in your <code>wp-content</code> directory. This directory is used to stored uploaded media for your additional sites and must be writeable by the web server.</li>
+<?php step2_config(); ?>
+<?php step2_htaccess(); ?>
+                </ol>
+<?php
+}
+
+function step2_config() {
+        global $base, $wpdb, $vhost;
+
+        $vhost = stripslashes($_POST['vhost' ]);
+        $prefix = $wpdb->base_prefix;
+
+        $config_sample = ABSPATH . 'wp-admin/includes/wp-config.ms';
+        if ( !file_exists( $config_sample ) )
+                wp_die("Sorry, I need a {$config_sample} to work from. Please re-upload this file to your WordPress installation.");
+
+        $wp_config_file = file( $config_sample );
+?>
+                        <li><p>Replace the contents of your <code>wp-config.php</code> with the following:</p>
+                                <textarea name="wp-config" cols="120" rows="20">
+<?php
+        foreach ($wp_config_file as $line) {
+                switch ( trim( substr($line,0,16) ) ) {
+                        case "define('DB_NAME'":
+                                $output = str_replace("wordpress", DB_NAME, $line);
+                                break;
+                        case "define('DB_USER'":
+                                $output = str_replace("username", DB_USER, $line);
+                                break;
+                        case "define('DB_PASSW":
+                                $output = str_replace("password", DB_PASSWORD, $line);
+                                break;
+                        case "define('DB_HOST'":
+                                $output = str_replace("localhost", DB_HOST, $line);
+                                break;
+                        case "define('VHOST',":
+                                $output = str_replace("VHOSTSETTING", $vhost, $line);
+                                break;
+                        case '$table_prefix =':
+                                $output = str_replace('wp_', $prefix, $line);
+                                break;
+                        case '$base = \'BASE\';':
+                                $output = str_replace('BASE', $base, $line);
+                                break;
+                        case "define('DOMAIN_C":
+                                $domain = get_clean_basedomain();
+                                $output = str_replace("current_site_domain", $domain, $line);
+                                break;
+                        case "define('PATH_CUR":
+                                $output = str_replace("current_site_path", $base, $line);
+                                break;
+                        case "define('AUTH_KEY":
+                        case "define('AUTH_SAL":
+                        case "define('LOGGED_I":
+                        case "define('SECURE_A":
+                        case "define('NONCE_KE":
+                                $constant = substr( $line, 8, strpos( $line, "'", 9 ) - 8 );
+                                if ( defined( $constant ) )
+                                        $hash = constant( $constant );
+                                else
+                                        $hash = md5( mt_rand() ) . md5( mt_rand() );
+                                $output = str_replace('put your unique phrase here', $hash, $line);
+                                break;
+                        default:
+                                $output = $line;
+                                break;
+                }
+                echo $output;
+        }
+?>
+                                </textarea>
+                        </li>
+<?php
+}
+
+function get_clean_basedomain() {
+        global $wpdb;
+        $domain = $wpdb->escape( $_POST[ 'basedomain' ] );
+        $domain = str_replace( 'http://', '', $domain );
+        if( substr( $domain, 0, 4 ) == 'www.' )
+                $domain = substr( $domain, 4 );
+        if( strpos( $domain, '/' ) )
+                $domain = substr( $domain, 0, strpos( $domain, '/' ) );
+        return $domain;
+}
+
+function nowww() {
+        $nowww = str_replace( 'www.', '', $_POST[ 'basedomain' ] );
+        ?>
+        <h2>No-www</h2>
+        <p>WordPress strips the string "www" from the URLs of sites using this software. It is still possible to visit your site using the "www" prefix with an address like <em><?php echo $_POST[ 'basedomain' ] ?></em> but any links will not have the "www" prefix. They will instead point at <?php echo $nowww ?>.</p>
+        <p>The preferred method of hosting sites is without the "www" prefix as it's more compact and simple.</p>
+        <p>You can still use "<?php echo $_POST[ 'basedomain' ] ?>" and URLs like "www.blog1.<?php echo $nowww; ?>" to address your site and blogs after installation but internal links will use the <?php echo $nowww ?> format.</p>
+
+        <p><a href="http://no-www.org/">www. is depreciated</a> has a lot more information on why 'www.' isn't needed any more.</p>
+        <p>
+        <?php wp_nonce_field( 'install-network-1' ); ?>
+                <input type='hidden' name='vhost' value='<?php echo $_POST[ 'vhost' ]; ?>' />
+                <input type='hidden' name='weblog_title' value='<?php echo $_POST[ 'weblog_title' ]; ?>' />
+                <input type='hidden' name='email' value='<?php echo $_POST[ 'email' ]; ?>' />
+                <input type='hidden' name='action' value='step2' />
+                <input type='hidden' name='basedomain' value='<?echo $nowww ?>' />
+                <input class="button" type='submit' value='Continue' />
+        </p>
+        <?php
+}
+
+$action = isset($_POST[ 'action' ]) ? $_POST[ 'action' ] : null;
+switch($action) {
+        case "step2":
+                check_admin_referer( 'install-network-1' );
+                if( substr( $_POST[ 'basedomain' ], 0, 4 ) == 'www.' ) {
+                        nowww();
+                        continue;
+                }
+                
+                // Install!
+                $base = stripslashes( dirname( dirname($_SERVER["SCRIPT_NAME"]) ) );
+                if( $base != "/")
+                        $base .= "/";
+
+                require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
+                // create network tables
+                $_SERVER[ 'HTTP_HOST' ] = str_replace( 'www.', '', $_SERVER[ 'HTTP_HOST' ] ); // normalise hostname - no www.
+                install_network();
+                populate_network( 1, $_SERVER[ 'HTTP_HOST' ], sanitize_email( $_POST[ 'email' ] ), $_POST[ 'weblog_title' ], $base, $_POST[ 'vhost' ] );
+                // create wp-config.php / htaccess
+                step2();
+//continue;
+                
+//                step3();
+        break;
+        default:
+                //@todo: give an informative screen instead
+                if ( is_multisite() ) {
+                        wp_die('Network already enabled');
+                }
+                $rewrite_enabled = step1();
+                printstep1form($rewrite_enabled);
+        break;
+}
+?>
+</form>
+</div>
+
+<?php include('./admin-footer.php'); ?>
</ins></span></pre></div>
<a id="trunkwpincludeswpdbphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/wp-db.php (12756 => 12757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/wp-db.php        2010-01-19 00:04:25 UTC (rev 12756)
+++ trunk/wp-includes/wp-db.php        2010-01-19 00:18:52 UTC (rev 12757)
</span><span class="lines">@@ -491,7 +491,7 @@
</span><span class="cx">         function get_blog_prefix( $blog_id = '' ) {
</span><span class="cx">                 if ( $blog_id ) {
</span><span class="cx"> if( defined('MULTISITE') && ( $blog_id == 0 || $blog_id == 1) ) {
</span><del>-                         return $this->prefix;
</del><ins>+                         return $this->base_prefix;
</ins><span class="cx"> } else {
</span><span class="cx">                         return $this->base_prefix . $blog_id . '_';
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>