Index: wp-includes/user.php
===================================================================
--- wp-includes/user.php	(revision 21840)
+++ wp-includes/user.php	(working copy)
@@ -865,10 +865,14 @@
 		foreach ( $avail_roles as $this_role => $name ) {
 			$select_count[] = "COUNT(NULLIF(`meta_value` LIKE '%\"" . like_escape( $this_role ) . "\"%', false))";
 		}
-		$select_count = implode(', ', $select_count);
-
+		
+		if ( ! empty( $select_count ) )
+			$select_count = implode(', ', $select_count) . ',';
+		else
+			$select_count = '';
+		
 		// Add the meta_value index to the selection list, then run the query.
-		$row = $wpdb->get_row( "SELECT $select_count, COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N );
+		$row = $wpdb->get_row( "SELECT $select_count COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N );
 
 		// Run the previous loop again to associate results with role names.
 		$col = 0;
Index: wp-includes/capabilities.php
===================================================================
--- wp-includes/capabilities.php	(revision 21840)
+++ wp-includes/capabilities.php	(working copy)
@@ -61,7 +61,7 @@
 	 * @access public
 	 * @var string
 	 */
-	var $role_key;
+	var $role_key = 'user_roles';
 
 	/**
 	 * Whether to use the database for retrieval and storage.
@@ -84,8 +84,7 @@
 	/**
 	 * Set up the object properties.
 	 *
-	 * The role key is set to the current prefix for the $wpdb object with
-	 * 'user_roles' appended. If the $wp_user_roles global is set, then it will
+	 * If the $wp_user_roles global is set, then it will
 	 * be used and the role option will not be updated or used.
 	 *
 	 * @since 2.1.0
@@ -94,13 +93,15 @@
 	 * @global array $wp_user_roles Used to set the 'roles' property value.
 	 */
 	function _init () {
-		global $wpdb, $wp_user_roles;
-		$this->role_key = $wpdb->prefix . 'user_roles';
+		global $wp_user_roles;
+
 		if ( ! empty( $wp_user_roles ) ) {
 			$this->roles = $wp_user_roles;
 			$this->use_db = false;
 		} else {
 			$this->roles = get_option( $this->role_key );
+			if ( empty( $this->roles ) )
+				$this->roles = _WP_User_Roles::init();
 		}
 
 		if ( empty( $this->roles ) )
@@ -128,12 +129,12 @@
 		if ( ! $this->use_db )
 			return;
 
-		global $wpdb, $wp_user_roles;
-
 		// Duplicated from _init() to avoid an extra function call.
-		$this->role_key = $wpdb->prefix . 'user_roles';
 		$this->roles = get_option( $this->role_key );
 		if ( empty( $this->roles ) )
+			$this->roles = _WP_User_Roles::init();
+		
+		if ( empty( $this->roles ) )
 			return;
 
 		$this->role_objects = array();
@@ -1444,3 +1445,247 @@
 
 	return false;
 }
+
+/**
+ * WordPress Default User Roles.
+ *
+ * Allows regeneration of the required 'user_roles' option
+ * 
+ * @acccess private
+ * 
+ * @since 3.5.0
+ * @package WordPress
+ * @subpackage User
+ */
+class _WP_User_Roles {
+	static $instance;
+	private $roles = array();
+	
+	private function __construct() {
+		if ( empty( $this->roles ) )
+			$this->populate();
+	}
+	
+	static function init() {
+		if ( ! isset( self::$instance ) )
+			self::$instance = new _WP_User_Roles;
+		
+		return self::$instance->roles;
+	}
+	
+	private function populate() {
+		$roles = array();
+		
+		/**
+		 * @since 2.1.0
+		 */
+		$caps_210 = array(
+			'edit_others_pages' => 1,
+			'edit_published_pages' => 1,
+			'publish_pages' => 1,
+			'delete_pages' => 1,
+			'delete_others_pages' => 1,
+			'delete_published_pages' => 1,
+			'delete_posts' => 1,
+			'delete_others_posts' => 1,
+			'delete_published_posts' => 1,
+			'delete_private_posts' => 1,
+			'edit_private_posts' => 1,
+			'read_private_posts' => 1,
+			'delete_private_pages' => 1,
+			'edit_private_pages' => 1,
+			'read_private_pages' => 1			
+		);
+		
+		$admin_caps = array(
+			/**
+			 * @since 1.6.0
+			 */
+			'switch_themes' => 1,
+			'edit_themes' => 1,
+			'activate_plugins' => 1,
+			'edit_plugins' => 1,
+			'edit_users' => 1,
+			'edit_files' => 1,
+			'manage_options' => 1,
+			'moderate_comments' => 1,
+			'manage_categories' => 1,
+			'manage_links' => 1,
+			'upload_files' => 1,
+			'import',
+			'unfiltered_html' => 1,
+			'edit_posts' => 1,
+			'edit_others_posts' => 1,
+			'edit_published_posts' => 1,
+			'publish_posts' => 1,
+			'edit_pages' => 1,
+			'read' => 1,
+			/**
+			 * @since 2.1.0
+			 */
+			'delete_users' => 1,
+			'create_users' => 1,			
+			/**
+			 * @since 2.3.0
+			 */
+			'unfiltered_upload' => 1,
+			/**
+			 * @since 2.5.0
+			 */
+			'edit_dashboard' => 1,
+			/**
+			 * @since 2.6.0
+			 */
+			'update_plugins' => 1,
+			'delete_plugins' => 1,
+			/**
+			 * @since 2.7.0
+			 */
+			'install_plugins' => 1,
+			'update_themes' => 1,
+			/**
+			 * @since 2.8.0
+			 */
+			'install_themes' => 1,
+			/**
+			 * @since 3.0.0
+			 */
+			'update_core' => 1,
+			'list_users' => 1,
+			'remove_users' => 1,
+			'add_users' => 1,
+			'promote_users' => 1,
+			'edit_theme_options' => 1,
+			'delete_themes' => 1,
+			'export' => 1,
+		);
+		
+		/**
+		 * @since 1.6.0
+		 */
+		for ( $i = 0; $i <= 10; $i++ )
+			$admin_caps['level_' . $i] = 1;	
+		
+		/**
+		 * @since 2.1.0
+		 */
+		$admin_caps = array_merge( $admin_caps, $caps_210 );
+		
+		$roles[] = array( 
+			'administrator', 
+			/* translators: user role */ 
+			_x( 'Administrator', 'User role' ), 
+			$admin_caps
+		);
+		
+		$editor_caps = array(
+			/**
+			 * @since 1.6.0
+			 */
+			'moderate_comments' => 1,
+			'manage_categories' => 1,
+			'manage_links' => 1,
+			'upload_files' => 1,
+			'import' => 1,
+			'unfiltered_html' => 1,
+			'edit_posts' => 1,
+			'edit_others_posts' => 1,
+			'edit_published_posts' => 1,
+			'publish_posts' => 1,
+			'edit_pages' => 1,
+			'read' => 1,
+		);
+		/**
+		 * @since 1.6.0
+		 */
+		for ( $i = 0; $i <= 7; $i++ )
+			$editor_caps['level_' . $i] = 1;		
+		
+		/**
+		 * @since 2.1.0
+		 */
+		$editor_caps = array_merge( $editor_caps, $caps_210 );
+		
+		$roles[] = array( 
+			'editor', 
+			/* translators: user role */ 
+			_x( 'Editor', 'User role' ),
+			$editor_caps
+		);
+
+		$author_caps = array(
+			/**
+			 * @since 1.6.0
+			 */
+			'upload_files' => 1,
+			'edit_posts' => 1,
+			'edit_published_posts' => 1,
+			'publish_posts' => 1,
+			'read' => 1,
+			/**
+			 * @since 2.1.0
+			 */
+			'delete_posts' => 1,
+			'delete_published_posts' => 1
+		);
+		/**
+		 * @since 1.6.0
+		 */
+		for ( $i = 0; $i <= 2; $i++ )
+			$author_caps['level_' . $i] = 1;		
+		
+		$roles[] = array( 
+			'author', 
+			/* translators: user role */ 
+			_x( 'Author', 'User role' ),
+			$author_caps
+		);		
+		
+		$contributor_caps = array(
+			/**
+			 * @since 1.6.0
+			 */
+			'edit_posts' => 1,
+			'read' => 1,
+			'level_0' => 1,
+			'level_1' => 1,
+			/**
+			 * @since 2.1.0
+			 */
+			'delete_posts' => 1,
+		);
+		
+		$roles[] = array( 
+			'contributor', 
+			/* translators: user role */ 
+			_x( 'Contributor', 'User role' ),
+			$contributor_caps
+		);
+		
+		$subscriber_caps = array(
+			/**
+			 * @since 1.6.0
+			 */
+			'read' => 1,
+			'level_0' => 1
+		);
+		
+		$roles[] = array( 
+			'subscriber', 
+			/* translators: user role */ 
+			_x( 'Subscriber', 'User role' ),
+			$subscriber_caps
+		);		
+		
+		foreach ( $roles as $role ) {
+			list( $slug, $name, $caps ) = $role;
+			
+			$this->roles[$slug] = array(
+				'name'			=> $name,
+				'capabilities'	=> $caps
+			);			
+		}
+		
+		update_option( 'user_roles', $this->roles );
+	}
+}
\ No newline at end of file
Index: wp-admin/includes/schema.php
===================================================================
--- wp-admin/includes/schema.php	(revision 21840)
+++ wp-admin/includes/schema.php	(working copy)
@@ -556,256 +556,25 @@
  * @since 2.0.0
  */
 function populate_roles() {
-	populate_roles_160();
-	populate_roles_210();
-	populate_roles_230();
-	populate_roles_250();
-	populate_roles_260();
-	populate_roles_270();
-	populate_roles_280();
-	populate_roles_300();
+	/**
+	 * @since 3.5.0
+	 * 
+	 */
+	_WP_User_Roles::init();
+	
+	if ( is_multisite() ) {
+		global $wpdb;
+		$blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
+		foreach ( $blog_ids as $blog_id ) {
+			if ( 1 === (int) $blog_id )
+				delete_option( 'wp_user_roles' );
+			else 
+				delete_option( "wp_{$blog_id}_user_roles" );
+		}
+	}		
 }
 
 /**
- * Create the roles for WordPress 2.0
- *
- * @since 2.0.0
- */
-function populate_roles_160() {
-	// Add roles
-
-	// Dummy gettext calls to get strings in the catalog.
-	/* translators: user role */
-	_x('Administrator', 'User role');
-	/* translators: user role */
-	_x('Editor', 'User role');
-	/* translators: user role */
-	_x('Author', 'User role');
-	/* translators: user role */
-	_x('Contributor', 'User role');
-	/* translators: user role */
-	_x('Subscriber', 'User role');
-
-	add_role('administrator', 'Administrator');
-	add_role('editor', 'Editor');
-	add_role('author', 'Author');
-	add_role('contributor', 'Contributor');
-	add_role('subscriber', 'Subscriber');
-
-	// Add caps for Administrator role
-	$role =& get_role('administrator');
-	$role->add_cap('switch_themes');
-	$role->add_cap('edit_themes');
-	$role->add_cap('activate_plugins');
-	$role->add_cap('edit_plugins');
-	$role->add_cap('edit_users');
-	$role->add_cap('edit_files');
-	$role->add_cap('manage_options');
-	$role->add_cap('moderate_comments');
-	$role->add_cap('manage_categories');
-	$role->add_cap('manage_links');
-	$role->add_cap('upload_files');
-	$role->add_cap('import');
-	$role->add_cap('unfiltered_html');
-	$role->add_cap('edit_posts');
-	$role->add_cap('edit_others_posts');
-	$role->add_cap('edit_published_posts');
-	$role->add_cap('publish_posts');
-	$role->add_cap('edit_pages');
-	$role->add_cap('read');
-	$role->add_cap('level_10');
-	$role->add_cap('level_9');
-	$role->add_cap('level_8');
-	$role->add_cap('level_7');
-	$role->add_cap('level_6');
-	$role->add_cap('level_5');
-	$role->add_cap('level_4');
-	$role->add_cap('level_3');
-	$role->add_cap('level_2');
-	$role->add_cap('level_1');
-	$role->add_cap('level_0');
-
-	// Add caps for Editor role
-	$role =& get_role('editor');
-	$role->add_cap('moderate_comments');
-	$role->add_cap('manage_categories');
-	$role->add_cap('manage_links');
-	$role->add_cap('upload_files');
-	$role->add_cap('unfiltered_html');
-	$role->add_cap('edit_posts');
-	$role->add_cap('edit_others_posts');
-	$role->add_cap('edit_published_posts');
-	$role->add_cap('publish_posts');
-	$role->add_cap('edit_pages');
-	$role->add_cap('read');
-	$role->add_cap('level_7');
-	$role->add_cap('level_6');
-	$role->add_cap('level_5');
-	$role->add_cap('level_4');
-	$role->add_cap('level_3');
-	$role->add_cap('level_2');
-	$role->add_cap('level_1');
-	$role->add_cap('level_0');
-
-	// Add caps for Author role
-	$role =& get_role('author');
-	$role->add_cap('upload_files');
-	$role->add_cap('edit_posts');
-	$role->add_cap('edit_published_posts');
-	$role->add_cap('publish_posts');
-	$role->add_cap('read');
-	$role->add_cap('level_2');
-	$role->add_cap('level_1');
-	$role->add_cap('level_0');
-
-	// Add caps for Contributor role
-	$role =& get_role('contributor');
-	$role->add_cap('edit_posts');
-	$role->add_cap('read');
-	$role->add_cap('level_1');
-	$role->add_cap('level_0');
-
-	// Add caps for Subscriber role
-	$role =& get_role('subscriber');
-	$role->add_cap('read');
-	$role->add_cap('level_0');
-}
-
-/**
- * Create and modify WordPress roles for WordPress 2.1.
- *
- * @since 2.1.0
- */
-function populate_roles_210() {
-	$roles = array('administrator', 'editor');
-	foreach ($roles as $role) {
-		$role =& get_role($role);
-		if ( empty($role) )
-			continue;
-
-		$role->add_cap('edit_others_pages');
-		$role->add_cap('edit_published_pages');
-		$role->add_cap('publish_pages');
-		$role->add_cap('delete_pages');
-		$role->add_cap('delete_others_pages');
-		$role->add_cap('delete_published_pages');
-		$role->add_cap('delete_posts');
-		$role->add_cap('delete_others_posts');
-		$role->add_cap('delete_published_posts');
-		$role->add_cap('delete_private_posts');
-		$role->add_cap('edit_private_posts');
-		$role->add_cap('read_private_posts');
-		$role->add_cap('delete_private_pages');
-		$role->add_cap('edit_private_pages');
-		$role->add_cap('read_private_pages');
-	}
-
-	$role =& get_role('administrator');
-	if ( ! empty($role) ) {
-		$role->add_cap('delete_users');
-		$role->add_cap('create_users');
-	}
-
-	$role =& get_role('author');
-	if ( ! empty($role) ) {
-		$role->add_cap('delete_posts');
-		$role->add_cap('delete_published_posts');
-	}
-
-	$role =& get_role('contributor');
-	if ( ! empty($role) ) {
-		$role->add_cap('delete_posts');
-	}
-}
-
-/**
- * Create and modify WordPress roles for WordPress 2.3.
- *
- * @since 2.3.0
- */
-function populate_roles_230() {
-	$role =& get_role( 'administrator' );
-
-	if ( !empty( $role ) ) {
-		$role->add_cap( 'unfiltered_upload' );
-	}
-}
-
-/**
- * Create and modify WordPress roles for WordPress 2.5.
- *
- * @since 2.5.0
- */
-function populate_roles_250() {
-	$role =& get_role( 'administrator' );
-
-	if ( !empty( $role ) ) {
-		$role->add_cap( 'edit_dashboard' );
-	}
-}
-
-/**
- * Create and modify WordPress roles for WordPress 2.6.
- *
- * @since 2.6.0
- */
-function populate_roles_260() {
-	$role =& get_role( 'administrator' );
-
-	if ( !empty( $role ) ) {
-		$role->add_cap( 'update_plugins' );
-		$role->add_cap( 'delete_plugins' );
-	}
-}
-
-/**
- * Create and modify WordPress roles for WordPress 2.7.
- *
- * @since 2.7.0
- */
-function populate_roles_270() {
-	$role =& get_role( 'administrator' );
-
-	if ( !empty( $role ) ) {
-		$role->add_cap( 'install_plugins' );
-		$role->add_cap( 'update_themes' );
-	}
-}
-
-/**
- * Create and modify WordPress roles for WordPress 2.8.
- *
- * @since 2.8.0
- */
-function populate_roles_280() {
-	$role =& get_role( 'administrator' );
-
-	if ( !empty( $role ) ) {
-		$role->add_cap( 'install_themes' );
-	}
-}
-
-/**
- * Create and modify WordPress roles for WordPress 3.0.
- *
- * @since 3.0.0
- */
-function populate_roles_300() {
-	$role =& get_role( 'administrator' );
-
-	if ( !empty( $role ) ) {
-		$role->add_cap( 'update_core' );
-		$role->add_cap( 'list_users' );
-		$role->add_cap( 'remove_users' );
-		$role->add_cap( 'add_users' );
-		$role->add_cap( 'promote_users' );
-		$role->add_cap( 'edit_theme_options' );
-		$role->add_cap( 'delete_themes' );
-		$role->add_cap( 'export' );
-	}
-}
-
-/**
  * Install Network.
  *
  * @since 3.0.0
Index: wp-admin/includes/template.php
===================================================================
--- wp-admin/includes/template.php	(revision 21840)
+++ wp-admin/includes/template.php	(working copy)
@@ -759,6 +759,9 @@
 
 	$editable_roles = get_editable_roles();
 
+	if ( empty( $editable_roles ) )
+		return;
+		
 	foreach ( $editable_roles as $role => $details ) {
 		$name = translate_user_role($details['name'] );
 		if ( $selected == $role ) // preselect specified role
Index: wp-admin/network/site-settings.php
===================================================================
--- wp-admin/network/site-settings.php	(revision 21840)
+++ wp-admin/network/site-settings.php	(working copy)
@@ -113,7 +113,7 @@
 	<table class="form-table">
 		<?php
 		$blog_prefix = $wpdb->get_blog_prefix( $id );
-		$options = $wpdb->get_results( "SELECT * FROM {$blog_prefix}options WHERE option_name NOT LIKE '\_%' AND option_name NOT LIKE '%user_roles'" );
+		$options = $wpdb->get_results( "SELECT * FROM {$blog_prefix}options WHERE option_name NOT LIKE '\_%' AND option_name != 'user_roles'" );
 		foreach ( $options as $option ) {
 			if ( $option->option_name == 'default_role' )
 				$editblog_default_role = $option->option_value;
