Changeset 57926
- Timestamp:
- 04/04/2024 03:11:37 PM (6 months ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-site-health.php
r57793 r57926 1285 1285 1286 1286 /** 1287 * Tests if the database server is capable of using utf8mb4.1288 *1289 * @since 5.2.01290 *1291 * @return array The test results.1292 */1293 public function get_test_utf8mb4_support() {1294 if ( ! $this->mysql_server_version ) {1295 $this->prepare_sql_data();1296 }1297 1298 $result = array(1299 'label' => __( 'UTF8MB4 is supported' ),1300 'status' => 'good',1301 'badge' => array(1302 'label' => __( 'Performance' ),1303 'color' => 'blue',1304 ),1305 'description' => sprintf(1306 '<p>%s</p>',1307 __( 'UTF8MB4 is the character set WordPress prefers for database storage because it safely supports the widest set of characters and encodings, including Emoji, enabling better support for non-English languages.' )1308 ),1309 'actions' => '',1310 'test' => 'utf8mb4_support',1311 );1312 1313 if ( ! $this->is_mariadb ) {1314 if ( version_compare( $this->mysql_server_version, '5.5.3', '<' ) ) {1315 $result['status'] = 'recommended';1316 1317 $result['label'] = __( 'utf8mb4 requires a MySQL update' );1318 1319 $result['description'] .= sprintf(1320 '<p>%s</p>',1321 sprintf(1322 /* translators: %s: Version number. */1323 __( 'WordPress’ utf8mb4 support requires MySQL version %s or greater. Please contact your server administrator.' ),1324 '5.5.3'1325 )1326 );1327 } else {1328 $result['description'] .= sprintf(1329 '<p>%s</p>',1330 __( 'Your MySQL version supports utf8mb4.' )1331 );1332 }1333 } else { // MariaDB introduced utf8mb4 support in 5.5.0.1334 if ( version_compare( $this->mysql_server_version, '5.5.0', '<' ) ) {1335 $result['status'] = 'recommended';1336 1337 $result['label'] = __( 'utf8mb4 requires a MariaDB update' );1338 1339 $result['description'] .= sprintf(1340 '<p>%s</p>',1341 sprintf(1342 /* translators: %s: Version number. */1343 __( 'WordPress’ utf8mb4 support requires MariaDB version %s or greater. Please contact your server administrator.' ),1344 '5.5.0'1345 )1346 );1347 } else {1348 $result['description'] .= sprintf(1349 '<p>%s</p>',1350 __( 'Your MariaDB version supports utf8mb4.' )1351 );1352 }1353 }1354 1355 // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_client_info1356 $mysql_client_version = mysqli_get_client_info();1357 1358 /*1359 * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server.1360 * mysqlnd has supported utf8mb4 since 5.0.9.1361 */1362 if ( str_contains( $mysql_client_version, 'mysqlnd' ) ) {1363 $mysql_client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $mysql_client_version );1364 if ( version_compare( $mysql_client_version, '5.0.9', '<' ) ) {1365 $result['status'] = 'recommended';1366 1367 $result['label'] = __( 'utf8mb4 requires a newer client library' );1368 1369 $result['description'] .= sprintf(1370 '<p>%s</p>',1371 sprintf(1372 /* translators: 1: Name of the library, 2: Number of version. */1373 __( 'WordPress’ utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ),1374 'mysqlnd',1375 '5.0.9'1376 )1377 );1378 }1379 } else {1380 if ( version_compare( $mysql_client_version, '5.5.3', '<' ) ) {1381 $result['status'] = 'recommended';1382 1383 $result['label'] = __( 'utf8mb4 requires a newer client library' );1384 1385 $result['description'] .= sprintf(1386 '<p>%s</p>',1387 sprintf(1388 /* translators: 1: Name of the library, 2: Number of version. */1389 __( 'WordPress’ utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ),1390 'libmysql',1391 '5.5.3'1392 )1393 );1394 }1395 }1396 1397 return $result;1398 }1399 1400 /**1401 1287 * Tests if the site can communicate with WordPress.org. 1402 1288 * … … 2740 2626 'test' => 'sql_server', 2741 2627 ), 2742 'utf8mb4_support' => array(2743 'label' => __( 'MySQL utf8mb4 support' ),2744 'test' => 'utf8mb4_support',2745 ),2746 2628 'ssl_support' => array( 2747 2629 'label' => __( 'Secure communication' ), -
trunk/src/wp-admin/setup-config.php
r57793 r57926 397 397 break; 398 398 case 'DB_CHARSET': 399 if ( 'utf8mb4' === $wpdb->charset || ( ! $wpdb->charset && $wpdb->has_cap( 'utf8mb4' )) ) {399 if ( 'utf8mb4' === $wpdb->charset || ( ! $wpdb->charset ) ) { 400 400 $config_file[ $line_num ] = "define( '" . $constant . "'," . $padding . "'utf8mb4' );\r\n"; 401 401 } -
trunk/src/wp-includes/class-wpdb.php
r57239 r57926 879 879 } 880 880 881 if ( 'utf8' === $charset && $this->has_cap( 'utf8mb4' )) {881 if ( 'utf8' === $charset ) { 882 882 $charset = 'utf8mb4'; 883 }884 885 if ( 'utf8mb4' === $charset && ! $this->has_cap( 'utf8mb4' ) ) {886 $charset = 'utf8';887 $collate = str_replace( 'utf8mb4_', 'utf8_', $collate );888 883 } 889 884 … … 3243 3238 list( $charset ) = explode( '_', $column->Collation ); 3244 3239 3245 // If the current connection can't support utf8mb4 characters, let's only send 3-byte utf8 characters.3246 if ( 'utf8mb4' === $charset && ! $this->has_cap( 'utf8mb4' ) ) {3247 $charset = 'utf8';3248 }3249 3250 3240 $charsets[ strtolower( $charset ) ] = true; 3251 3241 } … … 4058 4048 * @since 4.6.0 Added support for the 'utf8mb4_520' feature. 4059 4049 * @since 6.2.0 Added support for the 'identifier_placeholders' feature. 4050 * @since 6.6.0 The `utf8mb4` feature now always returns true. 4060 4051 * 4061 4052 * @see wpdb::db_version() … … 4093 4084 return version_compare( $db_version, '5.0.7', '>=' ); 4094 4085 case 'utf8mb4': // @since 4.1.0 4095 if ( version_compare( $db_version, '5.5.3', '<' ) ) { 4096 return false; 4097 } 4098 4099 $client_version = mysqli_get_client_info(); 4100 4101 /* 4102 * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server. 4103 * mysqlnd has supported utf8mb4 since 5.0.9. 4104 * 4105 * Note: str_contains() is not used here, as this file can be included 4106 * directly outside of WordPress core, e.g. by HyperDB, in which case 4107 * the polyfills from wp-includes/compat.php are not loaded. 4108 */ 4109 if ( false !== strpos( $client_version, 'mysqlnd' ) ) { 4110 $client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $client_version ); 4111 return version_compare( $client_version, '5.0.9', '>=' ); 4112 } else { 4113 return version_compare( $client_version, '5.5.3', '>=' ); 4114 } 4086 return true; 4115 4087 case 'utf8mb4_520': // @since 4.6.0 4116 4088 return version_compare( $db_version, '5.6', '>=' ); -
trunk/tests/phpunit/tests/db.php
r57089 r57926 1440 1440 global $wpdb; 1441 1441 1442 if ( ! $wpdb->has_cap( 'utf8mb4' ) ) {1443 $this->markTestSkipped( 'This test requires utf8mb4 support.' );1444 }1445 1446 1442 $charset = 'utf8'; 1447 1443 $collate = 'utf8_general_ci'; … … 1478 1474 global $wpdb; 1479 1475 1480 if ( ! $wpdb->has_cap( 'utf8mb4' ) ) {1481 $this->markTestSkipped( 'This test requires utf8mb4 support.' );1482 }1483 1484 1476 $charset = 'utf8'; 1485 1477 $collate = 'utf8_swedish_ci'; … … 1488 1480 1489 1481 $this->assertSame( 'utf8mb4_swedish_ci', $result['collate'] ); 1490 }1491 1492 /**1493 * @ticket 379821494 */1495 public function test_charset_switched_to_utf8() {1496 global $wpdb;1497 1498 if ( $wpdb->has_cap( 'utf8mb4' ) ) {1499 $this->markTestSkipped( 'This test requires utf8mb4 to not be supported.' );1500 }1501 1502 $charset = 'utf8mb4';1503 $collate = 'utf8mb4_general_ci';1504 1505 $result = $wpdb->determine_charset( $charset, $collate );1506 1507 $this->assertSame( 'utf8', $result['charset'] );1508 $this->assertSame( 'utf8_general_ci', $result['collate'] );1509 1482 } 1510 1483 -
trunk/tests/phpunit/tests/db/charset.php
r57239 r57926 521 521 } else { 522 522 $new_charset = $data[0]['charset']; 523 }524 525 if ( 'utf8mb4' === $new_charset && ! self::$_wpdb->has_cap( 'utf8mb4' ) ) {526 $this->markTestSkipped( "The current MySQL server doesn't support the utf8mb4 character set." );527 523 } 528 524 … … 796 792 public function test_get_table_charset( $drop, $create, $table, $expected_charset ) { 797 793 self::$_wpdb->query( $drop ); 798 799 if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) {800 $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." );801 }802 803 794 self::$_wpdb->query( $create ); 804 795 … … 837 828 public function test_get_column_charset( $drop, $create, $table, $expected_charset ) { 838 829 self::$_wpdb->query( $drop ); 839 840 if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) {841 $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." );842 }843 844 830 self::$_wpdb->query( $create ); 845 831 … … 865 851 self::$_wpdb->query( $drop ); 866 852 867 if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) {868 $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." );869 }870 871 853 self::$_wpdb->is_mysql = false; 872 854 … … 891 873 public function test_get_column_charset_is_mysql_undefined( $drop, $create, $table, $columns ) { 892 874 self::$_wpdb->query( $drop ); 893 894 if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) {895 $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." );896 }897 875 898 876 unset( self::$_wpdb->is_mysql ); … … 953 931 public function test_strip_invalid_text_from_query( $create, $query, $expected, $drop ) { 954 932 self::$_wpdb->query( $drop ); 955 956 if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) {957 $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." );958 }959 960 933 self::$_wpdb->query( $create ); 961 934 -
trunk/tests/phpunit/tests/db/dbDelta.php
r56971 r57926 427 427 global $wpdb; 428 428 429 if ( ! $wpdb->has_cap( 'utf8mb4' ) ) {430 $this->markTestSkipped( 'This test requires utf8mb4 support in MySQL.' );431 }432 433 429 // This table needs to be actually created. 434 430 remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
Note: See TracChangeset
for help on using the changeset viewer.