<!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>[12896] trunk/wp-includes/ms-settings.php: ms-settings cleanup.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12896">12896</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-01-29 16:26:46 +0000 (Fri, 29 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>ms-settings cleanup. Props nacin. see <a href="http://trac.wordpress.org/ticket/11644">#11644</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesmssettingsphp">trunk/wp-includes/ms-settings.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesmssettingsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/ms-settings.php (12895 => 12896)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/ms-settings.php        2010-01-29 08:11:20 UTC (rev 12895)
+++ trunk/wp-includes/ms-settings.php        2010-01-29 16:26:46 UTC (rev 12896)
</span><span class="lines">@@ -20,7 +20,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx"> $domain = addslashes( $_SERVER['HTTP_HOST'] );
</span><del>-if ( strpos( $domain, ':' ) ) {
</del><ins>+if ( false !== strpos( $domain, ':' ) ) {
</ins><span class="cx">         if ( substr( $domain, -3 ) == ':80' ) {
</span><span class="cx">                 $domain = substr( $domain, 0, -3 );
</span><span class="cx">                 $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
</span><span class="lines">@@ -28,133 +28,104 @@
</span><span class="cx">                 $domain = substr( $domain, 0, -4 );
</span><span class="cx">                 $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
</span><span class="cx">         } else {
</span><del>-                die( 'WPMU only works without the port number in the URL.' );
</del><ins>+                wp_die( 'Multisite only works without the port number in the URL.' );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><del>-$domain = preg_replace('/:.*$/', '', $domain); // Strip ports
-if ( substr( $domain, -1 ) == '.' )
-        $domain = substr( $domain, 0, -1 );
</del><span class="cx"> 
</span><del>-if ( substr( $domain, 0, 4 ) == 'www.' )
-        $cookie_domain = substr( $domain, 4 );
-else
-        $cookie_domain = $domain;
</del><ins>+$domain = rtrim( $domain, '.' );
+$cookie_domain = $domain;
+if ( substr( $cookie_domain, 0, 4 ) == 'www.' )
+        $cookie_domain = substr( $cookie_domain, 4 );
</ins><span class="cx"> 
</span><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="cx"> 
</span><span class="cx"> $current_site = wpmu_current_site();
</span><del>-if ( !isset( $current_site-&gt;blog_id ) )
-        $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; );
</del><ins>+if ( ! isset( $current_site-&gt;blog_id ) )
+        $current_site-&gt;blog_id = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT blog_id FROM $wpdb-&gt;blogs WHERE domain = %s AND path = %s&quot;, $current_site-&gt;domain, $current_site-&gt;path ) );
</ins><span class="cx"> 
</span><span class="cx"> if ( is_subdomain_install() ) {
</span><span class="cx">         $current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
</span><span class="cx">         if ( !$current_blog ) {
</span><del>-                $current_blog = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;blogs WHERE domain = %s&quot;, $domain) );
</del><ins>+                $current_blog = $wpdb-&gt;get_row( $wpdb-&gt;prepare( &quot;SELECT * FROM $wpdb-&gt;blogs WHERE domain = %s&quot;, $domain ) );
</ins><span class="cx">                 if ( $current_blog )
</span><span class="cx">                         wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
</span><span class="cx">         }
</span><del>-        if ( $current_blog != null &amp;&amp; $current_blog-&gt;site_id != $current_site-&gt;id )
-                $current_site = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;site WHERE id = %d&quot;, $current_blog-&gt;site_id) );
</del><ins>+        if ( $current_blog &amp;&amp; $current_blog-&gt;site_id != $current_site-&gt;id )
+                $current_site = $wpdb-&gt;get_row( $wpdb-&gt;prepare( &quot;SELECT * FROM $wpdb-&gt;site WHERE id = %d&quot;, $current_blog-&gt;site_id ) );
</ins><span class="cx">         else
</span><span class="cx">                 $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
</span><span class="cx"> } else {
</span><span class="cx">         $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
</span><del>-        if ( strpos( $blogname, '/' ) )
</del><ins>+        if ( false !== strpos( $blogname, '/' ) )
</ins><span class="cx">                 $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
</span><del>-        if ( strpos( &quot; &quot;.$blogname, '?' ) )
</del><ins>+        if ( false !== strpos( $blogname, '?' ) )
</ins><span class="cx">                 $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
</span><span class="cx">         $reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
</span><del>-        if ( $blogname != '' &amp;&amp; !in_array( $blogname, $reserved_blognames ) &amp;&amp; !is_file( $blogname ) )
</del><ins>+        if ( $blogname != '' &amp;&amp; ! in_array( $blogname, $reserved_blognames ) &amp;&amp; ! is_file( $blogname ) )
</ins><span class="cx">                 $path = $path . $blogname . '/';
</span><span class="cx">         $current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
</span><del>-        if ( !$current_blog ) {
-                $current_blog = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;blogs WHERE domain = %s AND path = %s&quot;, $domain, $path) );
</del><ins>+        if ( ! $current_blog ) {
+                $current_blog = $wpdb-&gt;get_row( $wpdb-&gt;prepare( &quot;SELECT * FROM $wpdb-&gt;blogs WHERE domain = %s AND path = %s&quot;, $domain, $path ) );
</ins><span class="cx">                 if ( $current_blog )
</span><span class="cx">                         wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-if ( ! defined( 'WP_INSTALLING' ) &amp;&amp; is_subdomain_install() &amp;&amp; !is_object( $current_blog ) ) {
-
</del><ins>+if ( ! defined( 'WP_INSTALLING' ) &amp;&amp; is_subdomain_install() &amp;&amp; ! is_object( $current_blog ) ) {
</ins><span class="cx">         if ( defined( 'NOBLOGREDIRECT' ) ) {
</span><del>-                $destination = constant( 'NOBLOGREDIRECT' );
-                if ( $destination == '%siteurl%' )
</del><ins>+                $destination = NOBLOGREDIRECT;
+                if ( '%siteurl%' == $destination )
</ins><span class="cx">                         $destination = &quot;http://&quot; . $current_site-&gt;domain . $current_site-&gt;path;
</span><del>-                header( &quot;Location: &quot; .  $destination);
-                die();
</del><span class="cx">         } else {
</span><del>-                header( &quot;Location: http://&quot; . $current_site-&gt;domain . $current_site-&gt;path . &quot;wp-signup.php?new=&quot; . str_replace( '.' . $current_site-&gt;domain, '', $domain ) );
-                die();
</del><ins>+                $destination = 'http://' . $current_site-&gt;domain . $current_site-&gt;path . 'wp-signup.php?new=' . str_replace( '.' . $current_site-&gt;domain, '', $domain );
</ins><span class="cx">         }
</span><del>-
</del><ins>+        wp_redirect( $destination );
+        die();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> if ( ! defined( 'WP_INSTALLING' ) ) {
</span><del>-        if ( $current_site &amp;&amp; $current_blog == null ) {
</del><ins>+        if ( $current_site &amp;&amp; ! $current_blog ) {
</ins><span class="cx">                 if ( $current_site-&gt;domain != $_SERVER[ 'HTTP_HOST' ] ) {
</span><del>-                        header( &quot;Location: http://&quot; . $current_site-&gt;domain . $current_site-&gt;path );
</del><ins>+                        wp_redirect( 'http://' . $current_site-&gt;domain . $current_site-&gt;path );
</ins><span class="cx">                         exit;
</span><span class="cx">                 }
</span><del>-                $current_blog = $wpdb-&gt;get_row( $wpdb-&gt;prepare(&quot;SELECT * FROM $wpdb-&gt;blogs WHERE domain = %s AND path = %s&quot;, $current_site-&gt;domain, $current_site-&gt;path) );
</del><ins>+                $current_blog = $wpdb-&gt;get_row( $wpdb-&gt;prepare( &quot;SELECT * FROM $wpdb-&gt;blogs WHERE domain = %s AND path = %s&quot;, $current_site-&gt;domain, $current_site-&gt;path ) );
</ins><span class="cx">         }
</span><del>-        if ( $current_blog == false || $current_site == false )
</del><ins>+        if ( ! $current_blog || ! $current_site )
</ins><span class="cx">                 is_installed();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> $blog_id = $current_blog-&gt;blog_id;
</span><span class="cx"> $public  = $current_blog-&gt;public;
</span><span class="cx"> 
</span><del>-if ( $current_blog-&gt;site_id == 0 || $current_blog-&gt;site_id == '' )
</del><ins>+if ( empty( $current_blog-&gt;site_id ) )
</ins><span class="cx">         $current_blog-&gt;site_id = 1;
</span><span class="cx"> $site_id = $current_blog-&gt;site_id;
</span><span class="cx"> 
</span><span class="cx"> $current_site = get_current_site_name( $current_site );
</span><span class="cx"> 
</span><del>-if ( $blog_id == false ) {
-    // no blog found, are we installing? Check if the table exists.
-    if ( defined('WP_INSTALLING') ) {
-                $blog_id = $wpdb-&gt;get_var( &quot;SELECT blog_id FROM $wpdb-&gt;blogs LIMIT 0,1&quot; );
-                if ( $blog_id == false ) {
-                    // table doesn't exist. This is the first blog
-                    $blog_id = 1;
-                } else {
-                    // table exists
-                    // don't create record at this stage. we're obviously installing so it doesn't matter what the table vars below are like.
-                    // default to using the &quot;main&quot; blog.
-                    $blog_id = 1;
-                }
-                $current_blog-&gt;blog_id = $blog_id;
</del><ins>+if ( ! $blog_id ) {
+        if ( defined('WP_INSTALLING') ) {
+                $current_blog-&gt;blog_id = $blog_id = 1;
</ins><span class="cx">     } else {
</span><del>-                $check = $wpdb-&gt;get_results( &quot;SELECT * FROM $wpdb-&gt;site&quot; );
-                if ( $check == false )
-                    $msg = ': DB Tables Missing';
-                else
-                    $msg = '';
-                die( &quot;No Blog by that name on this system.&quot; . $msg );
</del><ins>+                $msg = ! $wpdb-&gt;get_var( &quot;SHOW TABLES LIKE '$wpdb-&gt;site'&quot; ) ? __( 'Database tables are missing.' ) : '';
+                wp_die( __( 'No blog by that name on this system.' ) . $msg );
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> $wpdb-&gt;suppress_errors( false );
</span><span class="cx"> 
</span><del>-if ( '0' == $current_blog-&gt;public ) {
-        // This just means the blog shouldn't show up in google, etc. Only to registered members
-}
-
</del><span class="cx"> $wpdb-&gt;blogid = $current_blog-&gt;blog_id;
</span><span class="cx"> $wpdb-&gt;siteid = $current_blog-&gt;site_id;
</span><del>-$wpdb-&gt;set_prefix($table_prefix); // set up blog tables
</del><ins>+$wpdb-&gt;set_prefix( $table_prefix ); // set up blog tables
</ins><span class="cx"> $table_prefix = $wpdb-&gt;get_blog_prefix();
</span><span class="cx"> 
</span><del>-// Fix empty PHP_SELF
-$PHP_SELF = $_SERVER['PHP_SELF'];
-if ( empty($PHP_SELF) || ( empty($PHP_SELF) &amp;&amp; !is_subdomain_install() &amp;&amp; $current_blog-&gt;path != '/' ) )
-        $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace(&quot;/(\?.*)?$/&quot;,'',$_SERVER[&quot;REQUEST_URI&quot;]);
-
</del><span class="cx"> // need to init cache again after blog_id is set
</span><span class="cx"> wp_start_object_cache();
</span><span class="cx"> 
</span><ins>+// Define upload directory constants
</ins><span class="cx"> ms_default_constants( 'uploads' );
</span><span class="cx"> 
</span><span class="cx"> ?&gt;
</span></span></pre>
</div>
</div>

</body>
</html>