<!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( &quot;www.&quot;, &quot;&quot;, $_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">         ?&gt;
</span><span class="lines">@@ -147,6 +147,9 @@
</span><span class="cx">                 &lt;/p&gt;
</span><span class="cx"> 
</span><span class="cx">                 &lt;h2&gt;Server Address&lt;/h2&gt;
</span><ins>+                &lt;?php if ( isset( $nowww ) ) { ?&gt;
+                &lt;h3&gt;We recommend you change your siteurl to &lt;code&gt;&lt;?php echo $nowww; ?&gt;&lt;/code&gt; before enabling the network feature. It will still be possible to visit your site using the &quot;www&quot; prefix with an address like &lt;code&gt;&lt;?php echo $hostname; ?&gt;&lt;/code&gt; but any links will not have the &quot;www&quot; prefix. &lt;/h3&gt;
+                &lt;?php } ?&gt;
</ins><span class="cx">                 &lt;table class=&quot;form-table&quot;&gt;  
</span><span class="cx">                         &lt;tr&gt; 
</span><span class="cx">                                 &lt;th scope='row'&gt;Server Address&lt;/th&gt; 
</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' ] );
-        ?&gt;
-        &lt;h2&gt;No-www&lt;/h2&gt;
-        &lt;p&gt;WordPress strips the string &quot;www&quot; from the URLs of sites using this software. It is still possible to visit your site using the &quot;www&quot; prefix with an address like &lt;em&gt;&lt;?php echo $_POST[ 'basedomain' ] ?&gt;&lt;/em&gt; but any links will not have the &quot;www&quot; prefix. They will instead point at &lt;?php echo $nowww ?&gt;.&lt;/p&gt;
-        &lt;p&gt;The preferred method of hosting sites is without the &quot;www&quot; prefix as it's more compact and simple.&lt;/p&gt;
-        &lt;p&gt;You can still use &quot;&lt;?php echo $_POST[ 'basedomain' ] ?&gt;&quot; and URLs like &quot;www.blog1.&lt;?php echo $nowww; ?&gt;&quot; to address your site and blogs after installation but internal links will use the &lt;?php echo $nowww ?&gt; format.&lt;/p&gt;
-
-        &lt;p&gt;&lt;a href=&quot;http://no-www.org/&quot;&gt;www. is depreciated&lt;/a&gt; has a lot more information on why 'www.' isn't needed any more.&lt;/p&gt;
-        &lt;p&gt;
-        &lt;?php wp_nonce_field( 'install-network-1' ); ?&gt;
-                &lt;input type='hidden' name='vhost' value='&lt;?php echo $_POST[ 'vhost' ]; ?&gt;' /&gt;
-                &lt;input type='hidden' name='weblog_title' value='&lt;?php echo $_POST[ 'weblog_title' ]; ?&gt;' /&gt;
-                &lt;input type='hidden' name='email' value='&lt;?php echo $_POST[ 'email' ]; ?&gt;' /&gt;
-                &lt;input type='hidden' name='action' value='step2' /&gt;
-                &lt;input type='hidden' name='basedomain' value='&lt;?echo $nowww ?&gt;' /&gt;
-                &lt;input class=&quot;button&quot; type='submit' value='Continue' /&gt;
-        &lt;/p&gt;
-        &lt;?php
-}
-
</del><span class="cx"> $action = isset($_POST[ 'action' ]) ? $_POST[ 'action' ] : null; 
</span><span class="cx"> switch($action) {
</span><span class="cx">         case &quot;step2&quot;:
</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[&quot;SCRIPT_NAME&quot;]) ) );
</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-&gt;domain);
</del><ins>+                        define('COOKIE_DOMAIN', '.' . $current_site-&gt;cookie_domain);
</ins><span class="cx"> }
</span><span class="cx"> ?&gt;
</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' ) &amp;&amp; defined( 'PATH_CURRENT_SITE' ) ) {
</span><span class="cx">                 $current_site-&gt;id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1);
</span><span class="cx">                 $current_site-&gt;domain = DOMAIN_CURRENT_SITE;
</span><span class="cx">                 $current_site-&gt;path   = $path = PATH_CURRENT_SITE;
</span><span class="cx">                 if ( defined( 'BLOGID_CURRENT_SITE' ) )
</span><span class="cx">                         $current_site-&gt;blog_id = BLOGID_CURRENT_SITE;
</span><ins>+                if ( DOMAIN_CURRENT_SITE == $domain ) 
+                        $current_site-&gt;cookie_domain = $cookie_domain;
+                elseif ( substr( $current_site-&gt;domain, 0, 4 ) == 'www.' )
+                        $current_site-&gt;cookie_domain = substr( $current_site-&gt;domain, 4 );
+                else
+                        $current_site-&gt;cookie_domain = $current_site-&gt;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-&gt;path;
</span><span class="cx">                 $current_site-&gt;blog_id = $wpdb-&gt;get_var( &quot;SELECT blog_id FROM {$wpdb-&gt;blogs} WHERE domain='{$current_site-&gt;domain}' AND path='{$current_site-&gt;path}'&quot; );
</span><span class="cx">                 $current_site = get_current_site_name( $current_site );
</span><ins>+                if ( substr( $current_site-&gt;domain, 0, 4 ) == 'www.' )
+                        $current_site-&gt;cookie_domain = substr( $current_site-&gt;domain, 4 );
</ins><span class="cx">                 wp_cache_set( &quot;current_site&quot;, $current_site, &quot;site-options&quot; );
</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-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE domain = %s AND path = %s&quot;, $domain, $path) );
-                if ( $current_site != null )
-                        return $current_site;
-                $current_site = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE domain = %s AND path='/'&quot;, $domain) );
-                if ( $current_site != null ) {
-                        $path = '/';
-                        return $current_site;
-                }
</del><span class="cx"> 
</span><ins>+        if ( $domain == $cookie_domain )
+                $current_site = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE domain = %s AND path = %s&quot;, $domain, $path ) );
+        else
+                $current_site = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1&quot;, $domain, $cookie_domain, $path ) );
+        if ( $current_site == null ) {
+                if ( $domain == $cookie_domain )
+                        $current_site = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE domain = %s AND path='/'&quot;, $domain ) );
+                else
+                        $current_site = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1&quot;, $domain, $cookie_domain, $path ) );
+        }
+        if ( $current_site != null ) {
+                $path = $current_site-&gt;path;
+                $current_site-&gt;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-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE domain = %s AND path = %s&quot;, $sitedomain, $path) );
</span><del>-                if ( $current_site != null )
</del><ins>+                if ( $current_site != null ) {
+                        $current_site-&gt;cookie_domain = $current_site-&gt;domain;
</ins><span class="cx">                         return $current_site;
</span><ins>+                }
</ins><span class="cx">                 $current_site = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE domain = %s AND path='/'&quot;, $sitedomain) );
</span><span class="cx">                 if ( $current_site == null &amp;&amp; defined( &quot;WP_INSTALLING&quot; ) == 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-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE domain = %s AND path = %s&quot;, $domain, $path) );
-                if ( $current_site != null )
-                        return $current_site;
-                $current_site = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE domain = %s AND path='/'&quot;, $domain) );
-                if ( $current_site == null &amp;&amp; defined( &quot;WP_INSTALLING&quot; ) == false ) {
-                        if ( count( $sites ) == 1 ) {
-                                $current_site = $sites[0];
-                                die( &quot;That blog does not exist. Please try &lt;a href='http://{$current_site-&gt;domain}{$current_site-&gt;path}'&gt;http://{$current_site-&gt;domain}{$current_site-&gt;path}&lt;/a&gt;&quot; );
-                        } else {
-                                die( &quot;No WPMU site defined on this host. If you are the owner of this site, please check &lt;a href='http://codex.wordpress.org/Debugging_WPMU'&gt;Debugging WPMU&lt;/a&gt; for further assistance.&quot; );
-                        }
</del><ins>+        } elseif ( defined( &quot;WP_INSTALLING&quot; ) == false ) {
+                if ( count( $sites ) == 1 ) {
+                        $current_site = $sites[0];
+                        die( &quot;That blog does not exist. Please try &lt;a href='http://{$current_site-&gt;domain}{$current_site-&gt;path}'&gt;http://{$current_site-&gt;domain}{$current_site-&gt;path}&lt;/a&gt;&quot; );
</ins><span class="cx">                 } else {
</span><del>-                        $path = '/';
</del><ins>+                        die( &quot;No WPMU site defined on this host. If you are the owner of this site, please check &lt;a href='http://codex.wordpress.org/Debugging_WPMU'&gt;Debugging WPMU&lt;/a&gt; for further assistance.&quot; );
</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>