<!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>[12787] trunk: allow www installs to enable multisite, see #11945</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12787">12787</a></dd>
<dt>Author</dt> <dd>wpmuguru</dd>
<dt>Date</dt> <dd>2010-01-21 17:20:23 +0000 (Thu, 21 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>allow www installs to enable multisite, see <a href="http://trac.wordpress.org/ticket/11945">#11945</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminoptionsnetworkphp">trunk/wp-admin/options-network.php</a></li>
<li><a href="#trunkwpincludesmsloadphp">trunk/wp-includes/ms-load.php</a></li>
<li><a href="#trunkwpincludesmssettingsphp">trunk/wp-includes/ms-settings.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminoptionsnetworkphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/options-network.php (12786 => 12787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/options-network.php        2010-01-21 16:03:29 UTC (rev 12786)
+++ trunk/wp-admin/options-network.php        2010-01-21 17:20:23 UTC (rev 12787)
</span><span class="lines">@@ -129,9 +129,9 @@
</span><span class="cx"> function printstep1form( $rewrite_enabled = false ) {
</span><span class="cx">         $weblog_title = ucfirst( get_option( 'blogname' ) ) . ' Sites';
</span><span class="cx">         $email = get_option( 'admin_email' );
</span><del>-        $hostname = $_SERVER[ 'HTTP_HOST' ];
-        if( substr( $_SERVER[ 'HTTP_HOST' ], 0, 4 ) == 'www.' )
-                $hostname = str_replace( "www.", "", $_SERVER[ 'HTTP_HOST' ] );
</del><ins>+        $hostname = get_clean_basedomain();
+        if( substr( $hostname, 0, 4 ) == 'www.' )
+                $nowww = substr( $hostname, 4 );
</ins><span class="cx">
</span><span class="cx">         wp_nonce_field( 'install-network-1' );
</span><span class="cx">         ?>
</span><span class="lines">@@ -147,6 +147,9 @@
</span><span class="cx">                 </p>
</span><span class="cx">
</span><span class="cx">                 <h2>Server Address</h2>
</span><ins>+                <?php if ( isset( $nowww ) ) { ?>
+                <h3>We recommend you change your siteurl to <code><?php echo $nowww; ?></code> before enabling the network feature. It will still be possible to visit your site using the "www" prefix with an address like <code><?php echo $hostname; ?></code> but any links will not have the "www" prefix. </h3>
+                <?php } ?>
</ins><span class="cx">                 <table class="form-table">
</span><span class="cx">                         <tr>
</span><span class="cx">                                 <th scope='row'>Server Address</th>
</span><span class="lines">@@ -263,43 +266,15 @@
</span><span class="cx"> function get_clean_basedomain() {
</span><span class="cx">         global $wpdb;
</span><span class="cx">         $domain = preg_replace( '|https?://|', '', get_option( 'siteurl') );
</span><del>-        //@todo: address no www in multisite code
-        if( substr( $domain, 0, 4 ) == 'www.' )
-                $domain = substr( $domain, 4 );
</del><span class="cx">         if( strpos( $domain, '/' ) )
</span><span class="cx">                 $domain = substr( $domain, 0, strpos( $domain, '/' ) );
</span><span class="cx">         return $domain;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-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
-}
-
</del><span class="cx"> $action = isset($_POST[ 'action' ]) ? $_POST[ 'action' ] : null;
</span><span class="cx"> switch($action) {
</span><span class="cx">         case "step2":
</span><span class="cx">                 check_admin_referer( 'install-network-1' );
</span><del>-                if( substr( $_POST[ 'basedomain' ], 0, 4 ) == 'www.' ) {
-                        nowww();
-                        continue;
-                }
</del><span class="cx">                 
</span><span class="cx">                 // Install!
</span><span class="cx">                 $base = stripslashes( dirname( dirname($_SERVER["SCRIPT_NAME"]) ) );
</span></span></pre></div>
<a id="trunkwpincludesmsloadphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/ms-load.php (12786 => 12787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/ms-load.php        2010-01-21 16:03:29 UTC (rev 12786)
+++ trunk/wp-includes/ms-load.php        2010-01-21 17:20:23 UTC (rev 12787)
</span><span class="lines">@@ -146,6 +146,6 @@
</span><span class="cx">          * @since 2.0.0
</span><span class="cx">          */
</span><span class="cx">         if ( !defined('COOKIE_DOMAIN') )
</span><del>-                        define('COOKIE_DOMAIN', '.' . $current_site->domain);
</del><ins>+                        define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain);
</ins><span class="cx"> }
</span><span class="cx"> ?>
</span></span></pre></div>
<a id="trunkwpincludesmssettingsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/ms-settings.php (12786 => 12787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/ms-settings.php        2010-01-21 16:03:29 UTC (rev 12786)
+++ trunk/wp-includes/ms-settings.php        2010-01-21 17:20:23 UTC (rev 12787)
</span><span class="lines">@@ -21,8 +21,6 @@
</span><span class="cx"> $wpmuBaseTablePrefix = $table_prefix;
</span><span class="cx">
</span><span class="cx"> $domain = addslashes( $_SERVER['HTTP_HOST'] );
</span><del>-if ( substr( $domain, 0, 4 ) == 'www.' )
-        $domain = substr( $domain, 4 );
</del><span class="cx"> if ( strpos( $domain, ':' ) ) {
</span><span class="cx">         if ( substr( $domain, -3 ) == ':80' ) {
</span><span class="cx">                 $domain = substr( $domain, 0, -3 );
</span><span class="lines">@@ -38,6 +36,11 @@
</span><span class="cx"> if ( substr( $domain, -1 ) == '.' )
</span><span class="cx">         $domain = substr( $domain, 0, -1 );
</span><span class="cx">
</span><ins>+if ( substr( $domain, 0, 4 ) == 'www.' )
+        $cookie_domain = substr( $domain, 4 );
+else
+        $cookie_domain = $domain;
+
</ins><span class="cx"> $path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
</span><span class="cx"> $path = str_replace ( '/wp-admin/', '/', $path );
</span><span class="cx"> $path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
</span><span class="lines">@@ -55,13 +58,20 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function wpmu_current_site() {
</span><del>-        global $wpdb, $current_site, $domain, $path, $sites;
</del><ins>+        global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;
</ins><span class="cx">         if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
</span><span class="cx">                 $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1);
</span><span class="cx">                 $current_site->domain = DOMAIN_CURRENT_SITE;
</span><span class="cx">                 $current_site->path = $path = PATH_CURRENT_SITE;
</span><span class="cx">                 if ( defined( 'BLOGID_CURRENT_SITE' ) )
</span><span class="cx">                         $current_site->blog_id = BLOGID_CURRENT_SITE;
</span><ins>+                if ( DOMAIN_CURRENT_SITE == $domain )
+                        $current_site->cookie_domain = $cookie_domain;
+                elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' )
+                        $current_site->cookie_domain = substr( $current_site->domain, 4 );
+                else
+                        $current_site->cookie_domain = $current_site->domain;
+                        
</ins><span class="cx">                 return $current_site;
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -76,24 +86,34 @@
</span><span class="cx">                 $path = $current_site->path;
</span><span class="cx">                 $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
</span><span class="cx">                 $current_site = get_current_site_name( $current_site );
</span><ins>+                if ( substr( $current_site->domain, 0, 4 ) == 'www.' )
+                        $current_site->cookie_domain = substr( $current_site->domain, 4 );
</ins><span class="cx">                 wp_cache_set( "current_site", $current_site, "site-options" );
</span><span class="cx">                 return $current_site;
</span><span class="cx">         }
</span><span class="cx">         $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
</span><del>-        if ( is_subdomain_install() ) {
-                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
-                if ( $current_site != null )
-                        return $current_site;
-                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) );
-                if ( $current_site != null ) {
-                        $path = '/';
-                        return $current_site;
-                }
</del><span class="cx">
</span><ins>+        if ( $domain == $cookie_domain )
+                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );
+        else
+                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );
+        if ( $current_site == null ) {
+                if ( $domain == $cookie_domain )
+                        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) );
+                else
+                        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );
+        }
+        if ( $current_site != null ) {
+                $path = $current_site->path;
+                $current_site->cookie_domain = $cookie_domain;
+                return $current_site;
+        } elseif ( is_subdomain_install() ) {
</ins><span class="cx">                 $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
</span><span class="cx">                 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
</span><del>-                if ( $current_site != null )
</del><ins>+                if ( $current_site != null ) {
+                        $current_site->cookie_domain = $current_site->domain;
</ins><span class="cx">                         return $current_site;
</span><ins>+                }
</ins><span class="cx">                 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
</span><span class="cx">                 if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
</span><span class="cx">                         if ( count( $sites ) == 1 ) {
</span><span class="lines">@@ -105,21 +125,15 @@
</span><span class="cx">                 } else {
</span><span class="cx">                         $path = '/';
</span><span class="cx">                 }
</span><del>-        } else {
-                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
-                if ( $current_site != null )
-                        return $current_site;
-                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) );
-                if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
-                        if ( count( $sites ) == 1 ) {
-                                $current_site = $sites[0];
-                                die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" );
-                        } else {
-                                die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." );
-                        }
</del><ins>+        } elseif ( defined( "WP_INSTALLING" ) == false ) {
+                if ( count( $sites ) == 1 ) {
+                        $current_site = $sites[0];
+                        die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" );
</ins><span class="cx">                 } else {
</span><del>-                        $path = '/';
</del><ins>+                        die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." );
</ins><span class="cx">                 }
</span><ins>+        } else {
+                $path = '/';
</ins><span class="cx">         }
</span><span class="cx">         return $current_site;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>