<!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" />
<title>[31349] trunk: WPDB: If a site is using the `utf8` charset, and their version of MySQL supports `utf8mb4`, auto-upgrade them to `utf8mb4`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/31349">31349</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/31349","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>pento</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-02-06 04:50:19 +0000 (Fri, 06 Feb 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>WPDB: If a site is using the `utf8` charset, and their version of MySQL supports `utf8mb4`, auto-upgrade them to `utf8mb4`.
This patch also resizes some indexes, to allow for the 767 byte index size limit in standard MySQL installs.
See <a href="https://core.trac.wordpress.org/ticket/21212">#21212</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesschemaphp">trunk/src/wp-admin/includes/schema.php</a></li>
<li><a href="#trunksrcwpadminincludesupgradephp">trunk/src/wp-admin/includes/upgrade.php</a></li>
<li><a href="#trunksrcwpadminsetupconfigphp">trunk/src/wp-admin/setup-config.php</a></li>
<li><a href="#trunksrcwpincludesversionphp">trunk/src/wp-includes/version.php</a></li>
<li><a href="#trunksrcwpincludeswpdbphp">trunk/src/wp-includes/wp-db.php</a></li>
<li><a href="#trunktestsphpunittestsdbcharsetphp">trunk/tests/phpunit/tests/db/charset.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesschemaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/schema.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/schema.php 2015-02-06 03:25:32 UTC (rev 31348)
+++ trunk/src/wp-admin/includes/schema.php 2015-02-06 04:50:19 UTC (rev 31349)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -44,6 +44,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Engage multisite if in the middle of turning it on from network.php.
</span><span class="cx" style="display: block; padding: 0 10px"> $is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
+ * As of 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which
+ * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
+ */
+ $max_index_length = 191;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Blog specific tables.
</span><span class="cx" style="display: block; padding: 0 10px"> $blog_tables = "CREATE TABLE $wpdb->terms (
</span><span class="cx" style="display: block; padding: 0 10px"> term_id bigint(20) unsigned NOT NULL auto_increment,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -51,8 +58,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> slug varchar(200) NOT NULL default '',
</span><span class="cx" style="display: block; padding: 0 10px"> term_group bigint(10) NOT NULL default 0,
</span><span class="cx" style="display: block; padding: 0 10px"> PRIMARY KEY (term_id),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- KEY slug (slug),
- KEY name (name)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ KEY slug (slug($max_index_length)),
+ KEY name (name($max_index_length))
</ins><span class="cx" style="display: block; padding: 0 10px"> ) $charset_collate;
</span><span class="cx" style="display: block; padding: 0 10px"> CREATE TABLE $wpdb->term_taxonomy (
</span><span class="cx" style="display: block; padding: 0 10px"> term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -79,7 +86,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> meta_value longtext,
</span><span class="cx" style="display: block; padding: 0 10px"> PRIMARY KEY (meta_id),
</span><span class="cx" style="display: block; padding: 0 10px"> KEY comment_id (comment_id),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- KEY meta_key (meta_key)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ KEY meta_key (meta_key($max_index_length))
</ins><span class="cx" style="display: block; padding: 0 10px"> ) $charset_collate;
</span><span class="cx" style="display: block; padding: 0 10px"> CREATE TABLE $wpdb->comments (
</span><span class="cx" style="display: block; padding: 0 10px"> comment_ID bigint(20) unsigned NOT NULL auto_increment,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -136,7 +143,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> meta_value longtext,
</span><span class="cx" style="display: block; padding: 0 10px"> PRIMARY KEY (meta_id),
</span><span class="cx" style="display: block; padding: 0 10px"> KEY post_id (post_id),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- KEY meta_key (meta_key)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ KEY meta_key (meta_key($max_index_length))
</ins><span class="cx" style="display: block; padding: 0 10px"> ) $charset_collate;
</span><span class="cx" style="display: block; padding: 0 10px"> CREATE TABLE $wpdb->posts (
</span><span class="cx" style="display: block; padding: 0 10px"> ID bigint(20) unsigned NOT NULL auto_increment,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -163,7 +170,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> post_mime_type varchar(100) NOT NULL default '',
</span><span class="cx" style="display: block; padding: 0 10px"> comment_count bigint(20) NOT NULL default '0',
</span><span class="cx" style="display: block; padding: 0 10px"> PRIMARY KEY (ID),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- KEY post_name (post_name),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ KEY post_name (post_name($max_index_length)),
</ins><span class="cx" style="display: block; padding: 0 10px"> KEY type_status_date (post_type,post_status,post_date,ID),
</span><span class="cx" style="display: block; padding: 0 10px"> KEY post_parent (post_parent),
</span><span class="cx" style="display: block; padding: 0 10px"> KEY post_author (post_author)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -213,7 +220,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> meta_value longtext,
</span><span class="cx" style="display: block; padding: 0 10px"> PRIMARY KEY (umeta_id),
</span><span class="cx" style="display: block; padding: 0 10px"> KEY user_id (user_id),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- KEY meta_key (meta_key)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ KEY meta_key (meta_key($max_index_length))
</ins><span class="cx" style="display: block; padding: 0 10px"> ) $charset_collate;\n";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Global tables
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -261,7 +268,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> domain varchar(200) NOT NULL default '',
</span><span class="cx" style="display: block; padding: 0 10px"> path varchar(100) NOT NULL default '',
</span><span class="cx" style="display: block; padding: 0 10px"> PRIMARY KEY (id),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- KEY domain (domain,path)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ KEY domain (domain(140),path(51))
</ins><span class="cx" style="display: block; padding: 0 10px"> ) $charset_collate;
</span><span class="cx" style="display: block; padding: 0 10px"> CREATE TABLE $wpdb->sitemeta (
</span><span class="cx" style="display: block; padding: 0 10px"> meta_id bigint(20) NOT NULL auto_increment,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -269,7 +276,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> meta_key varchar(255) default NULL,
</span><span class="cx" style="display: block; padding: 0 10px"> meta_value longtext,
</span><span class="cx" style="display: block; padding: 0 10px"> PRIMARY KEY (meta_id),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- KEY meta_key (meta_key),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ KEY meta_key (meta_key($max_index_length)),
</ins><span class="cx" style="display: block; padding: 0 10px"> KEY site_id (site_id)
</span><span class="cx" style="display: block; padding: 0 10px"> ) $charset_collate;
</span><span class="cx" style="display: block; padding: 0 10px"> CREATE TABLE $wpdb->signups (
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -288,7 +295,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> KEY activation_key (activation_key),
</span><span class="cx" style="display: block; padding: 0 10px"> KEY user_email (user_email),
</span><span class="cx" style="display: block; padding: 0 10px"> KEY user_login_email (user_login,user_email),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- KEY domain_path (domain,path)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ KEY domain_path (domain(140),path(51))
</ins><span class="cx" style="display: block; padding: 0 10px"> ) $charset_collate;";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> switch ( $scope ) {
</span></span></pre></div>
<a id="trunksrcwpadminincludesupgradephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/upgrade.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/upgrade.php 2015-02-06 03:25:32 UTC (rev 31348)
+++ trunk/src/wp-admin/includes/upgrade.php 2015-02-06 04:50:19 UTC (rev 31349)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -519,6 +519,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $wp_current_db_version < 29630 )
</span><span class="cx" style="display: block; padding: 0 10px"> upgrade_400();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $wp_current_db_version < 31349 )
+ upgrade_420();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> maybe_disable_link_manager();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> maybe_disable_automattic_widgets();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1407,6 +1410,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Execute changes made in WordPress 4.2.0.
+ *
+ * @since 4.2.0
+ */
+function upgrade_420() {
+ global $wp_current_db_version, $wpdb;
+
+ if ( $wp_current_db_version < 31349 && $wpdb->charset === 'utf8mb4' ) {
+ if ( is_multisite() ) {
+ $tables = $wpdb->tables( 'blog' );
+ } else {
+ $tables = $wpdb->tables( 'all' );
+ }
+
+ foreach ( $tables as $table ) {
+ maybe_convert_table_to_utf8mb4( $table );
+ }
+ }
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Executes network-level upgrade routines.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1502,6 +1526,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> update_site_option( 'illegal_names', $illegal_names );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // 4.2
+ if ( $wp_current_db_version < 31349 && $wpdb->charset === 'utf8mb4' ) {
+ if ( ! ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES ) ) {
+ $wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );
+ $wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
+ $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );
+
+ $tables = $wpdb->tables( 'global' );
+
+ foreach ( $tables as $table ) {
+ maybe_convert_table_to_utf8mb4( $table );
+ }
+ }
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> //
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1608,6 +1647,42 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * If a table only contains utf8 or utf8mb4 columns, convert it to utf8mb4.
+ *
+ * @since 4.2.0
+ *
+ * @param string $table The table to convert.
+ * @return bool true if the table was converted, false if it wasn't.
+ */
+function maybe_convert_table_to_utf8mb4( $table ) {
+ global $wpdb;
+
+ $results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" );
+ if ( ! $results ) {
+ return false;
+ }
+
+ $has_utf8 = false;
+ foreach ( $results as $column ) {
+ if ( $column->Collation ) {
+ if ( 'utf8' === $column->Collation ) {
+ $has_utf8 = true;
+ } elseif ( 'utf8mb4' !== $column->Collation ) {
+ // Don't upgrade tables that have non-utf8 columns.
+ return false;
+ }
+ }
+ }
+
+ if ( ! $has_utf8 ) {
+ // Don't bother upgrading tables that don't have utf8 columns.
+ return false;
+ }
+
+ return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" );
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Retrieve all options as it was for 1.2.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.2.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2284,6 +2359,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // dbDelta() can recreate but can't drop the index.
</span><span class="cx" style="display: block; padding: 0 10px"> $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug" );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Upgrade versions prior to 4.2.
+ if ( $wp_current_db_version < 31349 ) {
+ // So that we can change tables to utf8mb4, we need to shorten the index lengths to less than 767 bytes
+ $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
+ $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" );
+ $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" );
+ $wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
+ $wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
+ $wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpadminsetupconfigphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/setup-config.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/setup-config.php 2015-02-06 03:25:32 UTC (rev 31348)
+++ trunk/src/wp-admin/setup-config.php 2015-02-06 04:50:19 UTC (rev 31349)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -280,6 +280,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> case 'DB_HOST' :
</span><span class="cx" style="display: block; padding: 0 10px"> $config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'" . addcslashes( constant( $constant ), "\\'" ) . "');\r\n";
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'DB_CHARSET' :
+ if ( 'utf8mb4' === $wpdb->charset || ( ! $wpdb->charset && $wpdb->has_cap( 'utf8mb4' ) ) ) {
+ $config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'utf8mb4');\r\n";
+ }
+ break;
</ins><span class="cx" style="display: block; padding: 0 10px"> case 'AUTH_KEY' :
</span><span class="cx" style="display: block; padding: 0 10px"> case 'SECURE_AUTH_KEY' :
</span><span class="cx" style="display: block; padding: 0 10px"> case 'LOGGED_IN_KEY' :
</span></span></pre></div>
<a id="trunksrcwpincludesversionphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/version.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/version.php 2015-02-06 03:25:32 UTC (rev 31348)
+++ trunk/src/wp-includes/version.php 2015-02-06 04:50:19 UTC (rev 31349)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,7 +11,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global int $wp_db_version
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-$wp_db_version = 30133;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+$wp_db_version = 31349;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Holds the TinyMCE version
</span></span></pre></div>
<a id="trunksrcwpincludeswpdbphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/wp-db.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/wp-db.php 2015-02-06 03:25:32 UTC (rev 31348)
+++ trunk/src/wp-includes/wp-db.php 2015-02-06 04:50:19 UTC (rev 31349)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -624,8 +624,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->init_charset();
-
</del><span class="cx" style="display: block; padding: 0 10px"> $this->dbuser = $dbuser;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->dbpassword = $dbpassword;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->dbname = $dbname;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -717,16 +715,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function init_charset() {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( function_exists('is_multisite') && is_multisite() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->charset = 'utf8';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( defined( 'DB_COLLATE' ) && DB_COLLATE )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->collate = DB_COLLATE;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- else
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } else {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->collate = 'utf8_general_ci';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> } elseif ( defined( 'DB_COLLATE' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->collate = DB_COLLATE;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( defined( 'DB_CHARSET' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( defined( 'DB_CHARSET' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->charset = DB_CHARSET;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+
+ if ( ( $this->use_mysqli && ! ( $this->dbh instanceof mysqli ) )
+ || ( empty( $this->dbh ) || ! ( $this->dbh instanceof mysqli ) ) ) {
+ return;
+ }
+
+ if ( 'utf8' === $this->charset && $this->has_cap( 'utf8mb4' ) ) {
+ $this->charset = 'utf8mb4';
+ }
+
+ if ( 'utf8mb4' === $this->charset && ( ! $this->collate || stripos( $this->collate, 'utf8_' ) === 0 ) ) {
+ $this->collate = 'utf8mb4_unicode_ci';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1476,8 +1489,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( $this->dbh ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $this->has_connected ) {
+ $this->init_charset();
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->has_connected = true;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->set_charset( $this->dbh );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->ready = true;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->set_sql_mode();
</span><span class="cx" style="display: block; padding: 0 10px"> $this->select( $this->dbname, $this->dbh );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2249,14 +2268,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Retrieves the character set for the given column.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.2.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @access protected
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @access public
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $table Table name.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $column Column name.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return mixed Column character set as a string. False if the column has no
</span><span class="cx" style="display: block; padding: 0 10px"> * character set. {@see WP_Error} object if there was an error.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected function get_col_charset( $table, $column ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function get_col_charset( $table, $column ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $tablekey = strtolower( $table );
</span><span class="cx" style="display: block; padding: 0 10px"> $columnkey = strtolower( $column );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2356,7 +2375,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'gb2312' => 'EUC-CN',
</span><span class="cx" style="display: block; padding: 0 10px"> 'ujis' => 'EUC-JP',
</span><span class="cx" style="display: block; padding: 0 10px"> 'utf32' => 'UTF-32',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'utf8mb4' => 'UTF-8',
</del><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $supported_charsets = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2391,8 +2409,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // utf8(mb3) can be handled by regex, which is a bunch faster than a DB lookup.
- if ( 'utf8' === $charset || 'utf8mb3' === $charset ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // utf8 can be handled by regex, which is a bunch faster than a DB lookup.
+ if ( 'utf8' === $charset || 'utf8mb3' === $charset || 'utf8mb4' === $charset ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $regex = '/
</span><span class="cx" style="display: block; padding: 0 10px"> (
</span><span class="cx" style="display: block; padding: 0 10px"> (?: [\x00-\x7F] # single-byte sequences 0xxxxxxx
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2400,8 +2418,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> | \xE0[\xA0-\xBF][\x80-\xBF] # triple-byte sequences 1110xxxx 10xxxxxx * 2
</span><span class="cx" style="display: block; padding: 0 10px"> | [\xE1-\xEC][\x80-\xBF]{2}
</span><span class="cx" style="display: block; padding: 0 10px"> | \xED[\x80-\x9F][\x80-\xBF]
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- | [\xEE-\xEF][\x80-\xBF]{2}
- ){1,50} # ...one or more times
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ | [\xEE-\xEF][\x80-\xBF]{2}';
+
+ if ( 'utf8mb4' === $charset) {
+ $regex .= '
+ | \xF0[\x90-\xBF][\x80-\xBF]{2} # four-byte sequences 11110xxx 10xxxxxx * 3
+ | [\xF1-\xF3][\x80-\xBF]{3}
+ | \xF4[\x80-\x8F][\x80-\xBF]{2}
+ ';
+ }
+
+ $regex .= '){1,50} # ...one or more times
</ins><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> | . # anything else
</span><span class="cx" style="display: block; padding: 0 10px"> /x';
</span></span></pre></div>
<a id="trunktestsphpunittestsdbcharsetphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/db/charset.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/db/charset.php 2015-02-06 03:25:32 UTC (rev 31348)
+++ trunk/tests/phpunit/tests/db/charset.php 2015-02-06 04:50:19 UTC (rev 31349)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -130,11 +130,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @ ticket 21212
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 21212
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_process_fields_failure() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $data = array( 'post_content' => "H€llo\xf0\x9f\x98\x88World¢" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // \xf0\xff\xff\xff is invalid in utf8 and utf8mb4.
+ $data = array( 'post_content' => "H€llo\xf0\xff\xff\xffWorld¢" );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertFalse( self::$_wpdb->process_fields( $wpdb->posts, $data, null ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -436,6 +437,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_invalid_characters_in_query() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertFalse( $wpdb->query( "INSERT INTO {$wpdb->posts} (post_content) VALUES ('foo\xf0\x9f\x98\x88bar')" ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertFalse( $wpdb->query( "INSERT INTO {$wpdb->posts} (post_content) VALUES ('foo\xf0\xff\xff\xffbar')" ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>