Index: modules/block/block.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v
retrieving revision 1.58
diff -u -p -r1.58 block.admin.inc
--- modules/block/block.admin.inc	30 Sep 2009 13:09:29 -0000	1.58
+++ modules/block/block.admin.inc	10 Oct 2009 03:25:03 -0000
@@ -11,7 +11,9 @@
  */
 function block_admin_display($theme = NULL) {
   // Fetch and sort blocks.
-  $blocks = _block_rehash();
+  $blocks = block_rehash($custom_theme);
+  // Pass information about the theme to _block_compare().
+  _block_compare(NULL, NULL, $custom_theme);
   usort($blocks, '_block_compare');
 
   return drupal_get_form('block_admin_display_form', $blocks, $theme);
@@ -110,12 +112,28 @@ function block_admin_display_form_submit
 /**
  * Helper function for sorting blocks on admin/structure/block.
  *
- * Active blocks are sorted by region, then by weight.
- * Disabled blocks are sorted by name.
+ * Active blocks are sorted by region, then by weight. Disabled blocks are
+ * sorted by name.
+ *
+ * @param $a
+ *   First sorting element.
+ * @param $b
+ *   Second sorting element.
+ * @param $theme
+ *   (optional) If set, the theme name will be setup for a subsequent invocation
+ *   of this function, region data will be reset, and the function will
+ *   immediately return.
+ *
+ * @see block_admin_display()
  */
-function _block_compare($a, $b) {
-  global $theme_key;
-  $regions = &drupal_static(__FUNCTION__);
+function _block_compare($a = NULL, $b = NULL, $theme = NULL) {
+  static $theme_key, $regions;
+  // If $theme is set, memorize it for future calls and reset region data.
+  if (isset($theme)) {
+    $theme_key = $theme;
+    $regions = NULL;
+    return;
+  }
 
   // We need the region list to correctly order by region.
   if (!isset($regions)) {
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.384
diff -u -p -r1.384 block.module
--- modules/block/block.module	9 Oct 2009 08:02:24 -0000	1.384
+++ modules/block/block.module	10 Oct 2009 03:13:47 -0000
@@ -261,16 +261,22 @@ function block_get_blocks_by_region($reg
 }
 
 /**
- * Update the 'block' DB table with the blocks currently exported by modules.
+ * Update the {block} table with the blocks currently exported by modules for all themes.
+ */
+function block_rehash_all() {
+  $themes = db_query("SELECT name FROM {system} WHERE type = :type AND status = :status", array(':type' => 'theme', ':status' => 1));
+  foreach ($themes as $theme) {
+    block_rehash($theme->name);
+  }
+}
+
+/**
+ * Update the {block} table with the blocks currently exported by modules.
  *
  * @return
  *   Blocks currently exported by modules.
  */
-function _block_rehash() {
-  global $theme_key;
-
-  drupal_theme_initialize();
-
+function block_rehash($theme_key) {
   $old_blocks = array();
   $result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $theme_key));
   foreach ($result as $old_block) {
@@ -513,7 +519,7 @@ function block_theme_initialize($theme) 
     $result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC));
     foreach ($result as $block) {
       // If the region isn't supported by the theme, assign the block to the theme's default region.
-      if (!array_key_exists($block['region'], $regions)) {
+      if (!empty($block['region']) && !array_key_exists($block['region'], $regions)) {
         $block['region'] = system_default_region($theme);
       }
       $block['theme'] = $theme;
@@ -831,6 +837,14 @@ function template_preprocess_block(&$var
 }
 
 /**
+ * Implement hook_modules_enabled().
+ */
+function block_modules_enabled() {
+  // Rehash the blocks.
+  block_rehash_all();
+}
+
+/**
  * Implement hook_user_role_delete().
  *
  * Remove deleted role from blocks that use it. 
Index: modules/block/block.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.test,v
retrieving revision 1.28
diff -u -p -r1.28 block.test
--- modules/block/block.test	5 Oct 2009 02:43:01 -0000	1.28
+++ modules/block/block.test	10 Oct 2009 03:14:52 -0000
@@ -271,10 +271,10 @@ class NewDefaultThemeBlocks extends Drup
     // Turn on the Stark theme and ensure that it contains all of the blocks
     // that Garland did.
     $this->drupalPost('admin/appearance', array('theme_default' => 'stark'), t('Save configuration'));
-    $result = db_query("SELECT * FROM {block} WHERE theme='stark'");
+    $result = db_query("SELECT * FROM {block} WHERE theme = 'stark'");
     foreach ($result as $block) {
       unset($block->theme, $block->bid);
-      $this->assertEqual($blocks[$block->module][$block->delta], $block, t('Block %name matched', array('%name' => $block->module . '-' . $block->delta)));
+      $this->assertEqual($blocks[$block->module][$block->delta], $block, t('Block matched: @module-@delta', array('@module' => $block->module, '@delta' => $block->delta)));
     }
   }
 }
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.803
diff -u -p -r1.803 system.module
--- modules/system/system.module	9 Oct 2009 07:48:06 -0000	1.803
+++ modules/system/system.module	10 Oct 2009 03:16:05 -0000
@@ -1553,15 +1553,21 @@ function system_block_info() {
     'info' => t('Main page content'),
      // Cached elsewhere.
     'cache' => DRUPAL_NO_CACHE,
+    'status' => 1,
+    'region' => 'content',
   );
   $blocks['powered-by'] = array(
     'info' => t('Powered by Drupal'),
     'weight' => '10',
     'cache' => DRUPAL_NO_CACHE,
+    'status' => 1,
+    'region' => 'footer',
   );
   $blocks['help'] = array(
     'info' => t('System help'),
     'weight' => '5',
+    'status' => 1,
+    'region' => 'help',
   );
   // System-defined menu blocks.
   foreach (menu_list_system_menus() as $menu_name => $title) {
@@ -1569,6 +1575,12 @@ function system_block_info() {
     // Menu blocks can't be cached because each menu item can have
     // a custom access callback. menu.inc manages its own caching.
     $blocks[$menu_name]['cache'] = DRUPAL_NO_CACHE;
+
+    // Enable the 'navigation' and 'management' blocks by default.
+    if (in_array($menu_name, array('navigation', 'management'))) {
+      $blocks[$menu_name]['status'] = 1;
+      $blocks[$menu_name]['region'] = 'left';
+    }
   }
   return $blocks;
 }
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.1059
diff -u -p -r1.1059 user.module
--- modules/user/user.module	9 Oct 2009 15:39:12 -0000	1.1059
+++ modules/user/user.module	10 Oct 2009 03:17:30 -0000
@@ -962,17 +962,20 @@ function user_login_block($form) {
  * Implement hook_block_info().
  */
 function user_block_info() {
-  global $user;
-
-  $blocks['login']['info'] = t('User login');
-  // Not worth caching.
-  $blocks['login']['cache'] = DRUPAL_NO_CACHE;
-
-  $blocks['new']['info'] = t('Who\'s new');
-
-  // Too dynamic to cache.
-  $blocks['online']['info'] = t('Who\'s online');
-  $blocks['online']['cache'] = DRUPAL_NO_CACHE;
+  $blocks['login'] = array(
+    'info' => t('User login'),
+    // Not worth caching.
+    'cache' => BLOCK_NO_CACHE,
+    'status' => 1,
+    'region' => 'left',
+  );
+  $blocks['new'] = array(
+    'info' => t("Who's new"),
+  );
+  $blocks['online'] = array(
+    'info' => t("Who's online"),
+    'cache' => BLOCK_NO_CACHE,
+  );
   return $blocks;
 }
 
Index: profiles/default/default.install
===================================================================
RCS file: /cvs/drupal/drupal/profiles/default/default.install,v
retrieving revision 1.9
diff -u -p -r1.9 default.install
--- profiles/default/default.install	8 Oct 2009 07:58:47 -0000	1.9
+++ profiles/default/default.install	10 Oct 2009 03:18:56 -0000
@@ -7,116 +7,6 @@
  * Perform actions to set up the site for this profile.
  */
 function default_install() {
-
-  // Enable some standard blocks.
-  $values = array(
-    array(
-      'module' => 'system',
-      'delta' => 'main',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 0,
-      'region' => 'content',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'search',
-      'delta' => 'form',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => -1,
-      'region' => 'sidebar_first',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'user',
-      'delta' => 'login',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 0,
-      'region' => 'sidebar_first',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'system',
-      'delta' => 'navigation',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 0,
-      'region' => 'sidebar_first',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'system',
-      'delta' => 'management',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 1,
-      'region' => 'sidebar_first',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'system',
-      'delta' => 'powered-by',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 10,
-      'region' => 'footer',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'system',
-      'delta' => 'help',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 0,
-      'region' => 'help',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'system',
-      'delta' => 'main',
-      'theme' => 'seven',
-      'status' => 1,
-      'weight' => 0,
-      'region' => 'content',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'system',
-      'delta' => 'help',
-      'theme' => 'seven',
-      'status' => 1,
-      'weight' => 0,
-      'region' => 'help',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'user',
-      'delta' => 'login',
-      'theme' => 'seven',
-      'status' => 1,
-      'weight' => 10,
-      'region' => 'content',
-      'pages' => '',
-      'cache' => -1,
-    ),
-  );
-  $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
-  foreach ($values as $record) {
-    $query->values($record);
-  }
-  $query->execute();
-
   // Insert default user-defined node types into the database. For a complete
   // list of available node type attributes, refer to the node type API
   // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info.
Index: profiles/expert/expert.install
===================================================================
RCS file: /cvs/drupal/drupal/profiles/expert/expert.install,v
retrieving revision 1.4
diff -u -p -r1.4 expert.install
--- profiles/expert/expert.install	20 Sep 2009 07:32:19 -0000	1.4
+++ profiles/expert/expert.install	10 Oct 2009 03:19:21 -0000
@@ -7,66 +7,6 @@
  * Perform actions to set up the site for this profile.
  */
 function expert_install() {
-
-  // Enable some standard blocks.
-  $values = array(
-    array(
-      'module' => 'system',
-      'delta' => 'main',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 0,
-      'region' => 'content',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'user',
-      'delta' => 'login',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 0,
-      'region' => 'sidebar_first',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'system',
-      'delta' => 'navigation',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 0,
-      'region' => 'sidebar_first',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'system',
-      'delta' => 'management',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 1,
-      'region' => 'sidebar_first',
-      'pages' => '',
-      'cache' => -1,
-    ),
-    array(
-      'module' => 'system',
-      'delta' => 'help',
-      'theme' => 'garland',
-      'status' => 1,
-      'weight' => 0,
-      'region' => 'help',
-      'pages' => '',
-      'cache' => -1,
-    ),
-  );
-  $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
-  foreach ($values as $record) {
-    $query->values($record);
-  }
-  $query->execute();  
-
   // Enable default permissions for system roles.
   user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'use text format 1'));
   user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content', 'access comments', 'post comments', 'post comments without approval', 'use text format 1'));
