X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/8d3bb1a5dcfdea9857d3c88c3751f09593e34dc8..ef91a7f4f3c6468973e192335a27ec0e0faca0b5:/wp-includes/wp-db.php?ds=sidebyside diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 8057bcc0..74dedd51 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -1189,18 +1189,19 @@ class wpdb { * * @uses wpdb::_real_escape() * @since 2.8.0 - * @access private + * @access public * * @param string|array $data * @return string|array escaped */ - function _escape( $data ) { + public function _escape( $data ) { if ( is_array( $data ) ) { foreach ( $data as $k => $v ) { - if ( is_array($v) ) + if ( is_array( $v ) ) { $data[$k] = $this->_escape( $v ); - else + } else { $data[$k] = $this->_real_escape( $v ); + } } } else { $data = $this->_real_escape( $data ); @@ -1273,8 +1274,8 @@ class wpdb { * * Both %d and %s should be left unquoted in the query string. * - * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", 'foo', 1337 ) - * wpdb::prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' ); + * $wpdb->prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", 'foo', 1337 ); + * $wpdb->prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' ); * * @link https://secure.php.net/sprintf Description of syntax. * @since 2.3.0 @@ -1363,10 +1364,13 @@ class wpdb { wp_load_translations_early(); - if ( $caller = $this->get_caller() ) + if ( $caller = $this->get_caller() ) { + /* translators: 1: Database error message, 2: SQL query, 3: Name of the calling function */ $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s' ), $str, $this->last_query, $caller ); - else + } else { + /* translators: 1: Database error message, 2: SQL query */ $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s' ), $str, $this->last_query ); + } error_log( $error_str ); @@ -2293,10 +2297,8 @@ class wpdb { * @since 0.71 * * @param string|null $query SQL query. - * @param string $output Optional. one of ARRAY_A | ARRAY_N | OBJECT constants. - * Return an associative array (column => value, ...), - * a numerically indexed array (0 => value, ...) or - * an object ( ->column = value ), respectively. + * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to + * an stdClass object, an associative array, or a numeric array, respectively. Default OBJECT. * @param int $y Optional. Row to return. Indexed from 0. * @return array|object|null|void Database query result in format specified by $output or null on failure */ @@ -3033,17 +3035,23 @@ class wpdb { . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?' . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?' . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?' - . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?' + . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:.+?FROM)?' . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) { return str_replace( '`', '', $maybe[1] ); } - // SHOW TABLE STATUS and SHOW TABLES - if ( preg_match( '/^\s*(?:' - . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' - . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' - . ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) { - return str_replace( '`', '', $maybe[1] ); + // SHOW TABLE STATUS and SHOW TABLES WHERE Name = 'wp_posts' + if ( preg_match( '/^\s*SHOW\s+(?:TABLE\s+STATUS|(?:FULL\s+)?TABLES).+WHERE\s+Name\s*=\s*("|\')((?:[0-9a-zA-Z$_.-]|[\xC2-\xDF][\x80-\xBF])+)\\1/is', $query, $maybe ) ) { + return $maybe[2]; + } + + // SHOW TABLE STATUS LIKE and SHOW TABLES LIKE 'wp\_123\_%' + // This quoted LIKE operand seldom holds a full table name. + // It is usually a pattern for matching a prefix so we just + // strip the trailing % and unescape the _ to get 'wp_123_' + // which drop-ins can use for routing these SQL statements. + if ( preg_match( '/^\s*SHOW\s+(?:TABLE\s+STATUS|(?:FULL\s+)?TABLES)\s+(?:WHERE\s+Name\s+)?LIKE\s*("|\')((?:[\\\\0-9a-zA-Z$_.-]|[\xC2-\xDF][\x80-\xBF])+)%?\\1/is', $query, $maybe ) ) { + return str_replace( '\\_', '_', $maybe[2] ); } // Big pattern for the rest of the table-related queries. @@ -3208,8 +3216,10 @@ class wpdb { public function check_database_version() { global $wp_version, $required_mysql_version; // Make sure the server has the required MySQL version - if ( version_compare($this->db_version(), $required_mysql_version, '<') ) + if ( version_compare($this->db_version(), $required_mysql_version, '<') ) { + /* translators: 1: WordPress version number, 2: Minimum required MySQL version number */ return new WP_Error('database_version', sprintf( __( 'ERROR: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version )); + } } /**