Index: wp-admin/maint/repair.php
===================================================================
--- wp-admin/maint/repair.php	(revision 13228)
+++ wp-admin/maint/repair.php	(working copy)
@@ -31,40 +31,33 @@
 
 	$okay = true;
 
-	$tables = array_merge( $wpdb->tables, is_multisite() ? $wpdb->global_tables : array( 'users', 'usermeta' ) );
-	$prefix = $wpdb->prefix;
-	if ( is_multisite() && ! defined('MULTISITE') ) // _1 to get MU-era main blog
-		$prefix .= '_1';
-
+	$tables = $wpdb->tables( 'all', true );
 	// Loop over the WP tables, checking and repairing as needed.
 	foreach ( $tables as $table ) {
-		if ( in_array( $table, $wpdb->old_tables ) )
-			continue;
-
-		$check = $wpdb->get_row("CHECK TABLE {$prefix}$table");
+		$check = $wpdb->get_row("CHECK TABLE $table");
 		if ( 'OK' == $check->Msg_text ) {
-			echo "<p>The {$prefix}$table table is okay.";
+			echo "<p>The $table table is okay.";
 		} else {
-			echo "<p>The {$prefix}$table table is not okay. It is reporting the following error: <code>$check->Msg_text</code>.  WordPress will attempt to repair this table&hellip;";
-			$repair = $wpdb->get_row("REPAIR TABLE {$prefix}$table");
+			echo "<p>The $table table is not okay. It is reporting the following error: <code>$check->Msg_text</code>.  WordPress will attempt to repair this table&hellip;";
+			$repair = $wpdb->get_row("REPAIR TABLE $table");
 			if ( 'OK' == $check->Msg_text ) {
-				echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Successfully repaired the {$prefix}$table table.";
+				echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Successfully repaired the $table table.";
 			} else {
-				echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Failed to repair the {prefix}$table table. Error: $check->Msg_text<br />";
-				$problems["{$prefix}$table"] = $check->Msg_text;
+				echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Failed to repair the $table table. Error: $check->Msg_text<br />";
+				$problems["$table"] = $check->Msg_text;
 				$okay = false;
 			}
 		}
 		if ( $okay && $optimize ) {
-			$check = $wpdb->get_row("ANALYZE TABLE {$prefix}$table");
+			$check = $wpdb->get_row("ANALYZE TABLE $table");
 			if ( 'Table is already up to date' == $check->Msg_text )  {
-				echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;The {$prefix}$table table is already optimized.";
+				echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;The $table table is already optimized.";
 			} else {
-				$check = $wpdb->get_row("OPTIMIZE TABLE {$prefix}$table");
+				$check = $wpdb->get_row("OPTIMIZE TABLE $table");
 				if ( 'OK' == $check->Msg_text || 'Table is already up to date' == $check->Msg_text )
-					echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Successfully optimized the {$prefix}$table table.";
+					echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Successfully optimized the $table table.";
 				else
-					echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Failed to optimize the {$prefix}$table table. Error: $check->Msg_text";
+					echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;Failed to optimize the $table table. Error: $check->Msg_text";
 			}
 		}
 		echo '</p>';
Index: wp-includes/deprecated.php
===================================================================
--- wp-includes/deprecated.php	(revision 13228)
+++ wp-includes/deprecated.php	(working copy)
@@ -1,80 +1,14 @@
 <?php
 /**
  * Deprecated functions from past WordPress versions. You shouldn't use these
- * globals and functions and look for the alternatives instead. The functions
- * and globals will be removed in a later version.
+ * functions and look for the alternatives instead. The functions will be
+ * removed in a later version.
  *
  * @package WordPress
  * @subpackage Deprecated
  */
 
 /*
- * Deprecated global variables.
- */
-
-/**
- * The name of the Posts table
- * @global string $tableposts
- * @deprecated Use $wpdb->posts
- */
-$tableposts = $wpdb->posts;
-
-/**
- * The name of the Users table
- * @global string $tableusers
- * @deprecated Use $wpdb->users
- */
-$tableusers = $wpdb->users;
-
-/**
- * The name of the Categories table
- * @global string $tablecategories
- * @deprecated Use $wpdb->categories
- */
-$tablecategories = $wpdb->categories;
-
-/**
- * The name of the post to category table
- * @global string $tablepost2cat
- * @deprecated Use $wpdb->post2cat;
- */
-$tablepost2cat = $wpdb->post2cat;
-
-/**
- * The name of the comments table
- * @global string $tablecomments
- * @deprecated Use $wpdb->comments;
- */
-$tablecomments = $wpdb->comments;
-
-/**
- * The name of the links table
- * @global string $tablelinks
- * @deprecated Use $wpdb->links;
- */
-$tablelinks = $wpdb->links;
-
-/**
- * @global string $tablelinkcategories
- * @deprecated Not used anymore;
- */
-$tablelinkcategories = 'linkcategories_is_gone';
-
-/**
- * The name of the options table
- * @global string $tableoptions
- * @deprecated Use $wpdb->options;
- */
-$tableoptions = $wpdb->options;
-
-/**
- * The name of the postmeta table
- * @global string $tablepostmeta
- * @deprecated Use $wpdb->postmeta;
- */
-$tablepostmeta = $wpdb->postmeta;
-
-/*
  * Deprecated functions come here to die.
  */
 
Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 13228)
+++ wp-includes/functions.php	(working copy)
@@ -1827,12 +1827,13 @@
 	$tables = $wpdb->get_col('SHOW TABLES');
 	$wpdb->suppress_errors( $suppress );
 
+	$wp_tables = $wpdb->tables( 'all', true );
 	// Loop over the WP tables.  If none exist, then scratch install is allowed.
 	// If one or more exist, suggest table repair since we got here because the options
 	// table could not be accessed.
-	foreach ($wpdb->tables as $table) {
+	foreach ( $wp_tables as $table ) {
 		// If one of the WP tables exist, then we are in an insane state.
-		if ( in_array($wpdb->prefix . $table, $tables) ) {
+		if ( in_array( $table, $tables ) ) {
 			// If visiting repair.php, return true and let it take over.
 			if ( defined('WP_REPAIRING') )
 				return true;
Index: wp-includes/wp-db.php
===================================================================
--- wp-includes/wp-db.php	(revision 13228)
+++ wp-includes/wp-db.php	(working copy)
@@ -137,12 +137,6 @@
 	var $ready = false;
 	var $blogid = 0;
 	var $siteid = 0;
-	var $blogs;
-	var $signups;
-	var $site;
-	var $sitemeta;
-	var $sitecategories;
-	var $global_tables = array('blogs', 'signups', 'site', 'sitemeta', 'users', 'usermeta', 'sitecategories', 'registration_log', 'blog_versions');
 
 	/**
 	 * WordPress Posts table
@@ -163,24 +157,6 @@
 	var $users;
 
 	/**
-	 * WordPress Categories table
-	 *
-	 * @since 1.5.0
-	 * @access public
-	 * @var string
-	 */
-	var $categories;
-
-	/**
-	 * WordPress Post to Category table
-	 *
-	 * @since 1.5.0
-	 * @access public
-	 * @var string
-	 */
-	var $post2cat;
-
-	/**
 	 * WordPress Comments table
 	 *
 	 * @since 1.5.0
@@ -262,34 +238,120 @@
 	var $term_relationships;
 
 	/**
-	 * List of WordPress tables
+	 * List of WordPress per-blog tables
 	 *
 	 * @since {@internal Version Unknown}}
 	 * @access private
+	 * @see wpdb::tables()
 	 * @var array
 	 */
-	var $tables = array('posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options',
-			'postmeta', 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta');
+	var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta',
+		'terms', 'term_taxonomy', 'term_relationships', 'commentmeta' );
 
 	/**
 	 * List of deprecated WordPress tables
 	 *
 	 * @since 2.9.0
 	 * @access private
+	 * @see wpdb::tables()
 	 * @var array
 	 */
-	var $old_tables = array('categories', 'post2cat', 'link2cat');
+	var $old_tables = array( 'categories', 'post2cat', 'link2cat' );
 
+	/**
+	 * Multisite Blogs table
+	 *
+	 * @since 3.0.0
+	 * @access public
+	 * @var string
+	 */
+	var $blogs;
 
 	/**
-	 * Format specifiers for DB columns. Columns not listed here default to %s.  Initialized in wp-settings.php.
+	 * Multisite Signups table
 	 *
+	 * @since 3.0.0
+	 * @access public
+	 * @var string
+	 */
+	var $signups;
+
+	/**
+	 * Multisite Sites table
+	 *
+	 * @since 3.0.0
+	 * @access public
+	 * @var string
+	 */
+	var $site;
+
+	/**
+	 * Multisite Site Metadata table
+	 *
+	 * @since 3.0.0
+	 * @access public
+	 * @var string
+	 */
+	var $sitemeta;
+
+	/**
+	 * Multisite Sitewide Terms table
+	 *
+	 * @since 3.0.0
+	 * @access public
+	 * @var string
+	 */
+	var $sitecategories;
+
+	/**
+	 * Multisite Registration Log table
+	 *
+	 * @since 3.0.0
+	 * @access public
+	 * @var string
+	 */
+	var $registration_log;
+
+	/**
+	 * Multisite Blog Versions table
+	 *
+	 * @since 3.0.0
+	 * @access public
+	 * @var string
+	 */
+	var $blog_versions;
+
+	/**
+	 * List of Multisite global tables
+	 *
+	 * @since 3.0.0
+	 * @access private
+	 * @see wpdb::tables()
+	 * @var array
+	 */
+	var $ms_tables = array( 'blogs', 'signups', 'site', 'sitemeta',
+		'sitecategories', 'registration_log', 'blog_versions' );
+
+	/**
+	 * List of WordPress global tables
+	 *
+	 * @since 3.0.0
+	 * @access private
+	 * @see wpdb::tables()
+	 * @var array
+	 */
+	var $global_tables = array( 'users', 'usermeta' );
+
+	/**
+	 * Format specifiers for DB columns. Columns not listed here default to %s. Initialized in wp-settings.php.
+	 *
 	 * Keys are colmn names, values are format types: 'ID' => '%d'
 	 *
 	 * @since 2.8.0
 	 * @see wpdb:prepare()
 	 * @see wpdb:insert()
 	 * @see wpdb:update()
+	 * @see wp_set_wpdb_vars()
 	 * @access public
 	 * @var array
 	 */
@@ -439,7 +501,7 @@
 	 * @param string $prefix Alphanumeric name for the new prefix.
 	 * @return string|WP_Error Old prefix or WP_Error on error
 	 */
-	function set_prefix($prefix) {
+	function set_prefix( $prefix ) {
 
 		if ( preg_match('|[^a-z0-9_]|i', $prefix) )
 			return new WP_Error('invalid_db_prefix', /*WP_I18N_DB_BAD_PREFIX*/'Invalid database prefix'/*/WP_I18N_DB_BAD_PREFIX*/);
@@ -452,17 +514,20 @@
 		if ( isset( $this->base_prefix ) )
 			$old_prefix = $this->base_prefix;
 		$this->base_prefix = $prefix;
-		foreach ( $this->global_tables as $table )
+		foreach ( $this->tables( 'global' ) as $table )
 			$this->$table = $prefix . $table;
 
-		if ( defined('VHOST') && empty($this->blogid) )
+		if ( defined('VHOST') && empty( $this->blogid ) )
 			return $old_prefix;
 
 		$this->prefix = $this->get_blog_prefix( $this->blogid );
 
-		foreach ( (array) $this->tables as $table )
+		foreach ( (array) $this->tables( 'blog' ) as $table )
 			$this->$table = $this->prefix . $table;
 
+		foreach ( (array) $this->tables( 'old' ) as $table )
+			$this->$table = $this->prefix . $table;
+
 		if ( defined('CUSTOM_USER_TABLE') )
 			$this->users = CUSTOM_USER_TABLE;
 
@@ -481,9 +546,12 @@
 
 		$this->prefix = $this->get_blog_prefix( $this->blogid );
 
-		foreach ( $this->tables as $table )
+		foreach ( $this->tables( 'blog' ) as $table )
 			$this->$table = $this->prefix . $table;
 
+		foreach ( $this->tables( 'old' ) as $table )
+			$this->$table = $this->prefix . $table;
+
 		return $old_blog_id;
 	}
 
@@ -499,6 +567,49 @@
 	}
 
 	/**
+	 * Returns an array of WordPress tables.
+	 *
+	 * @since 3.0.0
+	 * @uses wpdb::tables
+	 * @uses wpdb::old_tables
+	 * @uses wpdb::global_tables
+	 * @uses is_multisite()
+	 *
+	 * @param string $scope Can be all, global, blog, or old tables. Default all.
+	 * 	All returns all global tables and the blog tables for the queried blog.
+	 * @param bool $prefix Whether to include the blog prefix. Default false.
+	 * @param int $blog_id The blog_id to prefix. Defaults to main blog.
+	 * @return array Table names.
+	 */
+	function tables( $scope = 'all', $prefix = false, $blog_id = 0 ) {
+		switch ( $scope ) {
+			case 'old' :
+				$tables = $this->old_tables;
+				break;
+			case 'blog' :
+				$tables = $this->tables;
+				break;
+			case 'global' :
+				$tables = array_merge( $this->global_tables, $this->ms_tables );
+				break;
+			case 'all' :
+				$tables = array_merge( $this->global_tables, $this->tables );
+				if ( is_multisite() )
+					$tables = array_merge( $tables, $this->ms_tables );
+				break;
+		}
+
+		if ( $prefix ) {
+			$prefix = $this->get_blog_prefix( $blog_id );
+			foreach ( $tables as &$table ) {
+				$table = $prefix . $table;
+			}
+		}
+
+		return $tables;
+	}
+
+	/**
 	 * Selects a database using the current database connection.
 	 *
 	 * The database name will be changed based on the current database
