From 8cd2ad7b10d83d9e460fd0fa83e701fa00e8a770 Mon Sep 17 00:00:00 2001 From: discomrade Date: Sat, 29 Jan 2022 22:32:08 -0100 Subject: [PATCH] Drop remaining MySQL <5.5.3 support (utf8 without multibyte) It's over 10 years out-of-date and EOL and the version code isn't failsafe which causes issues with some MariaDB versions, resulting in broken multibyte character behaviors. --- inc/database.php | 16 +--------------- inc/functions.php | 3 --- inc/mod/pages.php | 3 --- install.php | 8 +------- post.php | 17 +---------------- 5 files changed, 3 insertions(+), 44 deletions(-) diff --git a/inc/database.php b/inc/database.php index 84a050f2..a69273f9 100644 --- a/inc/database.php +++ b/inc/database.php @@ -78,10 +78,7 @@ function sql_open() { if ($config['debug']) $debug['time']['db_connect'] = '~' . round((microtime(true) - $start) * 1000, 2) . 'ms'; - if (mysql_version() >= 50503) - query('SET NAMES utf8mb4') or error(db_error()); - else - query('SET NAMES utf8') or error(db_error()); + query('SET NAMES utf8mb4') or error(db_error()); return $pdo; } catch(PDOException $e) { $message = $e->getMessage(); @@ -95,17 +92,6 @@ function sql_open() { } } -// 5.6.10 becomes 50610 -function mysql_version() { - global $pdo; - - $version = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION); - $v = explode('.', $version); - if (count($v) != 3) - return false; - return (int) sprintf("%02d%02d%02d", $v[0], $v[1], $v[2]); -} - function prepare($query) { global $pdo, $debug, $config; diff --git a/inc/functions.php b/inc/functions.php index 1935b145..33f937a2 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -2445,9 +2445,6 @@ function markup(&$body, $track_cites = false, $op = false) { $body = str_replace("\r", '', $body); $body = utf8tohtml($body); - if (mysql_version() < 50503) - $body = mb_encode_numericentity($body, array(0x010000, 0xffffff, 0, 0xffffff), 'UTF-8'); - if ($config['markup_code']) { $code_markup = array(); $body = preg_replace_callback($config['markup_code'], function($matches) use (&$code_markup) { diff --git a/inc/mod/pages.php b/inc/mod/pages.php index fe1def9b..bc7f6eb4 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -502,9 +502,6 @@ function mod_new_board() { $query = Element('posts.sql', array('board' => $board['uri'])); - if (mysql_version() < 50503) - $query = preg_replace('/(CHARSET=|CHARACTER SET )utf8mb4/', '$1utf8', $query); - query($query) or error(db_error()); // Create shadow copy table diff --git a/install.php b/install.php index 21288c8a..455f7ae9 100644 --- a/install.php +++ b/install.php @@ -68,10 +68,7 @@ if (file_exists($config['has_installed'])) { function __query($sql) { sql_open(); - if (mysql_version() >= 50503) - return query($sql); - else - return query(str_replace('utf8mb4', 'utf8', $sql)); + return query($sql); } $boards = listBoards(); @@ -1118,7 +1115,6 @@ if ($step == 0) { $sql = @file_get_contents('install.sql') or error("Couldn't load install.sql."); sql_open(); - $mysql_version = mysql_version(); // This code is probably horrible, but what I'm trying // to do is find all of the SQL queires and put them @@ -1130,8 +1126,6 @@ if ($step == 0) { $sql_errors = ''; foreach ($queries as $query) { - if ($mysql_version < 50503) - $query = preg_replace('/(CHARSET=|CHARACTER SET )utf8mb4/', '$1utf8', $query); $query = preg_replace('/^([\w\s]*)`([0-9a-zA-Z$_\x{0080}-\x{FFFF}]+)`/u', '$1``$2``', $query); if (!query($query)) $sql_errors .= '
  • ' . db_error() . '
  • '; diff --git a/post.php b/post.php index 25335f76..b1374eac 100644 --- a/post.php +++ b/post.php @@ -834,22 +834,7 @@ if (isset($_POST['delete'])) { $post['body'] .= "\n".$proxy.""; } - if (mysql_version() >= 50503) { - $post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset - } else { - // MySQL's `utf8` charset only supports up to 3-byte symbols - // Remove anything >= 0x010000 - - $chars = preg_split('//u', $post['body'], -1, PREG_SPLIT_NO_EMPTY); - $post['body_nomarkup'] = ''; - foreach ($chars as $char) { - $o = 0; - $ord = ordutf8($char, $o); - if ($ord >= 0x010000) - continue; - $post['body_nomarkup'] .= $char; - } - } + $post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset $post['tracked_cites'] = markup($post['body'], true);