<!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>[12880] trunk: Improvements to queries in populate_network(), also gettext,
props nacin, see #11816</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12880">12880</a></dd>
<dt>Author</dt> <dd>wpmuguru</dd>
<dt>Date</dt> <dd>2010-01-27 19:13:00 +0000 (Wed, 27 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Improvements to queries in populate_network(), also gettext, props nacin, see <a href="http://trac.wordpress.org/ticket/11816">#11816</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesschemaphp">trunk/wp-admin/includes/schema.php</a></li>
<li><a href="#trunkwpincludesloadphp">trunk/wp-includes/load.php</a></li>
<li><a href="#trunkwpincludesmsfunctionsphp">trunk/wp-includes/ms-functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesschemaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/schema.php (12879 => 12880)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/schema.php        2010-01-27 18:11:17 UTC (rev 12879)
+++ trunk/wp-admin/includes/schema.php        2010-01-27 19:13:00 UTC (rev 12880)
</span><span class="lines">@@ -630,7 +630,7 @@
</span><span class="cx">                 die( 'You must provide a site name!' );
</span><span class="cx">
</span><span class="cx">         // check for network collision
</span><del>-        $existing_network = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$wpdb->site} WHERE id = %d", $network_id ) );
</del><ins>+        $existing_network = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) );
</ins><span class="cx">         if ( $existing_network == $network_id )
</span><span class="cx">                 die( 'That network already exists!' );
</span><span class="cx">
</span><span class="lines">@@ -645,25 +645,25 @@
</span><span class="cx">         else
</span><span class="cx">                 $allowed_themes = array( $stylesheet => true );
</span><span class="cx">
</span><del>-        if ( $network_id == 1 )
-                $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->site." ( id, domain, path ) VALUES ( NULL, %s, %s )", $domain, $path ) );
-        else
-                $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->site." ( id, domain, path ) VALUES ( %d, %s, %s )", $network_id, $domain, $path ) );
</del><ins>+        if ( 1 == $network_id ) {
+                $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) );
+                $network_id = $wpdb->insert_id;
+        } else {
+                $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path, 'network_id' => $network_id ) );
+        }
</ins><span class="cx">
</span><del>-        $network_id = $wpdb->insert_id;
</del><ins>+        if ( !is_multisite() ) {
</ins><span class="cx">
</span><del>-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'site_name', %s)", $network_id, $site_name ) );
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'admin_email', %s)", $network_id, $site_user->user_email ) );
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'admin_user_id', %d)", $network_id, $site_user->ID ) );
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'registration', 'none')", $network_id ) );
-        if ( !is_multisite() ) {
-                $wpdb->query( "INSERT INTO " . $wpdb->sitecategories . " ( cat_ID, cat_name, category_nicename, last_updated ) VALUES (1, 'Uncategorized', 'uncategorized', NOW())" );
-                $wpdb->query( "INSERT INTO " . $wpdb->sitecategories . " ( cat_ID, cat_name, category_nicename, last_updated ) VALUES (2, 'Blogroll', 'blogroll', NOW())" );
-        }
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'upload_filetypes', 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf' )", $network_id ) );
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'blog_upload_space', '10' )", $network_id ) );
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'fileupload_maxk', '1500' )", $network_id ) );
-        if ( !is_multisite() ) {
</del><ins>+                /* translators: Default category slug */
+                $cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) );
+
+                $wpdb->insert( $wpdb->sitecategories, array( 'site_id' => $network_id, 'cat_ID' => 1, 'cat_name' => __('Uncategorized'), 'category_nicename' => $cat_slug, 'last_updated' => current_time( 'mysql', true ) ) );
+
+                /* translators: Default link category slug */
+                $cat_slug = sanitize_title( _x( 'Blogroll', 'Default link category slug' ) );
+
+                $wpdb->insert( $wpdb->sitecategories, array( 'site_id' => $network_id, 'cat_ID' => 2, 'cat_name' => __('Blogroll'), 'category_nicename' => $cat_slug, 'last_updated' => current_time( 'mysql', true ) ) );
+
</ins><span class="cx">                 $site_admins = array( $site_user->user_login );
</span><span class="cx">                 $users = get_users_of_blog();
</span><span class="cx">                 if ( $users ) {
</span><span class="lines">@@ -675,12 +675,9 @@
</span><span class="cx">         } else {
</span><span class="cx">                 $site_admins = get_site_option( 'site_admins' );
</span><span class="cx">         }
</span><del>-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'site_admins', '" . serialize( $site_admins ) . "' )", $network_id ) );
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'allowedthemes', '" . serialize( $allowed_themes ) . "' )", $network_id ) );
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'illegal_names', '" . serialize( array( "www", "web", "root", "admin", "main", "invite", "administrator" ) ) . "' )", $network_id ) );
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'wpmu_upgrade_site', '{$wp_db_version}')", $network_id ) );
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'welcome_email', 'Dear User,
</del><span class="cx">
</span><ins>+        $welcome_email = __( 'Dear User,
+
</ins><span class="cx"> Your new SITE_NAME blog has been successfully set up at:
</span><span class="cx"> BLOG_URL
</span><span class="cx">
</span><span class="lines">@@ -692,17 +689,45 @@
</span><span class="cx"> We hope you enjoy your new blog.
</span><span class="cx"> Thanks!
</span><span class="cx">
</span><del>---The Team @ SITE_NAME')", $network_id ) );
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'first_post', 'Welcome to <a href=\"SITE_URL\">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' )", $network_id ) );
-        //@todo - network admins should have a method of editing the network siteurl (used for cookie hash)
-        $wpdb->query( $wpdb->prepare( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, %d, 'siteurl', %s)", $network_id, get_option( 'siteurl' ) ) );
</del><ins>+--The Team @ SITE_NAME' );
</ins><span class="cx">
</span><ins>+        $sitemeta = array(
+                'site_name' => $site_name,
+                'admin_email' => $site_user->user_email,
+                'admin_user_id' => $site_user->ID,
+                'registration' => 'none',
+                'upload_filetypes' => 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf',
+                'blog_upload_space' => 10,
+                'fileupload_maxk' => 1500,
+                'site_admins' => $site_admins,
+                'allowedthemes' => $allowed_themes,
+                'illegal_names' => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ),
+                'wpmu_upgrade_site' => $wp_db_version,
+                'welcome_email' => $welcome_email,
+                'first_post' => __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ),
+                // @todo - network admins should have a method of editing the network siteurl (used for cookie hash)
+                'siteurl' => get_option( 'siteurl' )
+        );
+
+        $insert = '';
+        foreach ( $sitemeta as $meta_key => $meta_value ) {
+                $meta_key = $wpdb->escape( $meta_key );
+                if ( is_array( $meta_value ) )
+                        $meta_value = serialize( $meta_value );
+                $meta_value = $wpdb->escape( $meta_value );
+                if ( !empty( $insert ) )
+                        $insert .= ', ';
+                $insert .= "( $network_id, '$meta_key', '$meta_value')";
+        }
+        $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert );
+
</ins><span class="cx">         $current_site->domain = $domain;
</span><span class="cx">         $current_site->path = $base;
</span><span class="cx">         $current_site->site_name = ucfirst( $domain );
</span><span class="cx">
</span><span class="cx">         if ( !is_multisite() ) {
</span><del>-                $wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->blogs} (site_id, domain, path) VALUES (%s, %s, %s)", $network_id, $domain, $path ) );
</del><ins>+                $wpdb->insert( $wpdb->blogs, array( 'site_id' => $network_id, 'domain' => $domain, 'path' => $path ) );
+
</ins><span class="cx">                 update_usermeta( $site_user->ID, 'source_domain', $domain );
</span><span class="cx">                 update_usermeta( $site_user->ID, 'primary_blog', 1 );
</span><span class="cx">         }
</span><span class="lines">@@ -726,11 +751,13 @@
</span><span class="cx">                                 $vhost_ok = true;
</span><span class="cx">                 }
</span><span class="cx">                 if ( !$vhost_ok ) {
</span><del>-                        $msg = "<h2>Warning! Wildcard DNS may not be configured correctly!</h2>";
-                        $msg .= "<p>To use the subdomain feature of WordPress MU you must have a wildcard entry in your dns. The installer attempted to contact a random hostname ($hostname) on your domain but failed. It returned this error message:<br /> <strong>$errstr</strong></p><p>From the README.txt:</p>";
-                        $msg .= "<p><blockquote> If you want to host blogs of the form http://blog.domain.tld/ where domain.tld is the domain name of your machine then you must add a wildcard record to your DNS records.<br />
-This usually means adding a '*' hostname record pointing at your webserver in your DNS configuration tool. Matt has a more detailed <a href='http://ma.tt/2003/10/10/wildcard-dns-and-sub-domains/'>explanation</a> on his blog. If you still have problems, these <a href='http://mu.wordpress.org/forums/tags/wildcard'>forum messages</a> may help.</blockquote></p>";
-                        $msg .= "<p>You can still use your site but any subdomain you create may not be accessible. This check is not foolproof so ignore if you know your dns is correct.</p>";
</del><ins>+                        // @todo Update this to reflect the merge. Also: Multisite readme file, or remove the <blockquote> tags.
+                        $msg = '<h2>' . esc_html__( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</h2>';
+                        $msg .= '<p>' . __( 'To use the subdomain feature of WordPress MU you must have a wildcard entry in your dns. The installer attempted to contact a random hostname ($hostname) on your domain but failed. It returned this error message:' ) . '<br />';
+                        $msg .= '<br/><strong>' . $errstr . '</strong></p>';
+                        $msg .= '<p>' . __( 'From the README.txt:' ) . '</p>';
+                        $msg .= '<blockquote><p>' . __( "If you want to host blogs of the form http://blog.domain.tld/ where domain.tld is the domain name of your machine then you must add a wildcard record to your DNS records. This usually means adding a '*' hostname record pointing at your webserver in your DNS configuration tool. Matt has a more detailed <a href='http://ma.tt/2003/10/10/wildcard-dns-and-sub-domains/'>explanation</a> on his blog. If you still have problems, these <a href='http://mu.wordpress.org/forums/tags/wildcard'>forum messages</a> may help." ) . '</p></blockquote>';
+                        $msg .= '<p>' . __( 'You can still use your site but any subdomain you create may not be accessible. This check is not foolproof so ignore if you know your dns is correct.' ) . '</p>';
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">         return $msg;
</span></span></pre></div>
<a id="trunkwpincludesloadphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/load.php (12879 => 12880)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/load.php        2010-01-27 18:11:17 UTC (rev 12879)
+++ trunk/wp-includes/load.php        2010-01-27 19:13:00 UTC (rev 12880)
</span><span class="lines">@@ -298,7 +298,10 @@
</span><span class="cx">         $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
</span><span class="cx">                 'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'commment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
</span><span class="cx">                 'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
</span><del>-                'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d' );
</del><ins>+                'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d',
+                // multisite:
+                'active' => '%d', 'cat_id' => '%d', 'deleted' => '%d', 'lang_id' => '%d', 'mature' => '%d', 'public' => '%d', 'site_id' => '%d', 'spam' => '%d',
+        );
</ins><span class="cx">
</span><span class="cx">         $prefix = $wpdb->set_prefix( $table_prefix );
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesmsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/ms-functions.php (12879 => 12880)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/ms-functions.php        2010-01-27 18:11:17 UTC (rev 12879)
+++ trunk/wp-includes/ms-functions.php        2010-01-27 19:13:00 UTC (rev 12880)
</span><span class="lines">@@ -1466,7 +1466,7 @@
</span><span class="cx">
</span><span class="cx">         $welcome_email = stripslashes( get_site_option( 'welcome_email' ) );
</span><span class="cx">         if ( $welcome_email == false )
</span><del>-                $welcome_email = stripslashes( __( "Dear User,
</del><ins>+                $welcome_email = stripslashes( __( 'Dear User,
</ins><span class="cx">
</span><span class="cx"> Your new SITE_NAME blog has been successfully set up at:
</span><span class="cx"> BLOG_URL
</span><span class="lines">@@ -1476,11 +1476,10 @@
</span><span class="cx"> Password: PASSWORD
</span><span class="cx"> Login Here: BLOG_URLwp-login.php
</span><span class="cx">
</span><del>-We hope you enjoy your new weblog.
</del><ins>+We hope you enjoy your new blog.
</ins><span class="cx"> Thanks!
</span><span class="cx">
</span><del>---The WordPress Team
-SITE_NAME" ) );
</del><ins>+--The Team @ SITE_NAME' ) );
</ins><span class="cx">
</span><span class="cx">         $url = get_blogaddress_by_id($blog_id);
</span><span class="cx">         $user = new WP_User($user_id);
</span></span></pre>
</div>
</div>
</body>
</html>