? fix.patch
? sites/default/files
? sites/default/private
? sites/default/settings.php
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.984
diff -u -p -r1.984 common.inc
--- includes/common.inc	5 Sep 2009 15:05:01 -0000	1.984
+++ includes/common.inc	9 Sep 2009 21:23:29 -0000
@@ -4013,10 +4013,17 @@ function drupal_alter($type, &$data) {
  */
 function drupal_set_page_content($content = NULL) {
   $content_block = &drupal_static(__FUNCTION__, NULL);
+  $main_content_display = &drupal_static('system_main_content_added', FALSE);
+
   if (!empty($content)) {
     $content_block = (is_array($content) ? $content : array('main' => array('#markup' => $content)));
   }
   else {
+    // Indicate that the main content has been requested. We assume that
+    // the module requesting the content will be adding it to the page.
+    // A module can indicate that it does not handle the content by setting
+    // the static variable back to FALSE after calling this function.
+    $main_content_display = TRUE;
     return $content_block;
   }
 }
@@ -4034,6 +4041,8 @@ function drupal_set_page_content($conten
  * @see element_info('page')
  */
 function drupal_render_page($page) {
+  $main_content_display = &drupal_static('system_main_content_added', FALSE);
+
   // Allow menu callbacks to return strings or arbitrary arrays to render.
   // If the array returned is not of #type page directly, we need to fill
   // in the page with defaults.
@@ -4051,6 +4060,13 @@ function drupal_render_page($page) {
   // 'sidebar_first', 'footer', etc.
   drupal_alter('page', $page);
 
+  // If no module has taken care of the main content, add it to the page now.
+  // This allows the site to still be usable even if no modules that
+  // control page regions (for example, the Block module) are enabled.
+  if(!$main_content_display) {
+    $page['content']['system_main'] = drupal_set_page_content();
+  }
+
   return drupal_render($page);
 }
 
Index: modules/simpletest/tests/system_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/system_test.module,v
retrieving revision 1.15
diff -u -p -r1.15 system_test.module
--- modules/simpletest/tests/system_test.module	17 Aug 2009 20:32:30 -0000	1.15
+++ modules/simpletest/tests/system_test.module	9 Sep 2009 21:23:30 -0000
@@ -73,6 +73,27 @@ function system_test_menu() {
     'type' => MENU_CALLBACK,
   );
 
+  $items['system-test/main-content-handling'] = array(
+    'title' => 'Test main content handling',
+    'page callback' => 'system_test_main_content_fallback',
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
+
+  $items['system-test/main-content-fallback'] = array(
+    'title' => 'Test main content fallback',
+    'page callback' => 'system_test_main_content_fallback',
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
+
+  $items['system-test/main-content-duplication'] = array(
+    'title' => 'Test main content duplication',
+    'page callback' => 'system_test_main_content_fallback',
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
+
   return $items;
 }
 
@@ -225,3 +246,31 @@ function system_test_lock_exit() {
     return 'FALSE: Lock not acquired in system_test_lock_exit()';
   }
 }
+
+/**
+ * Implement hook_page_build().
+ */
+function system_test_page_build(&$page) {
+  $menu_item = menu_get_item();
+  $main_content_display = &drupal_static('system_main_content_added', FALSE);
+
+  if ($menu_item['path'] == 'system-test/main-content-handling') {
+    $page['footer'] = drupal_set_page_content();
+    $page['footer']['main']['#markup'] = '<div id="system-test-content">' . $page['footer']['main']['#markup'] . '</div>';
+  }
+  else if ($menu_item['path'] == 'system-test/main-content-fallback') {
+    drupal_set_page_content();
+    $main_content_display = FALSE;
+  }
+  else if ($menu_item['path'] == 'system-test/main-content-duplication') {
+    drupal_set_page_content();
+  }
+}
+
+/**
+ * Menu callback to test main content fallback().
+ */
+function system_test_main_content_fallback() {
+  return t('Content to test main content fallback');
+}
+
Index: modules/system/system.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.test,v
retrieving revision 1.75
diff -u -p -r1.75 system.test
--- modules/system/system.test	1 Sep 2009 16:50:12 -0000	1.75
+++ modules/system/system.test	9 Sep 2009 21:23:32 -0000
@@ -927,7 +927,84 @@ class SystemBlockTestCase extends Drupal
     $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
     $this->drupalPost('admin/structure/block/configure/system/powered-by', array('title' => '', 'color' => 'powered-blue', 'size' => '80x15'), t('Save block'));
   }
+}
+
+/**
+ * Test main content rendering fallback provided by system module.
+ */
+class SystemMainContentFallback extends DrupalWebTestCase {
+  protected $admin_user;
+  protected $web_user;
 
+  public static function getInfo() {
+    return array(
+      'name' => 'Main content rendering fallback',
+      'description' => ' Test system module main content rendering fallback.',
+      'group' => 'System',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('system_test');
+
+    // Create and login admin user
+    $this->admin_user = $this->drupalCreateUser(array(
+      'access administration pages',
+      'administer site configuration',
+      'administer blocks',
+      'administer nodes',
+    ));
+    $this->drupalLogin($this->admin_user);
+
+    // Create a web user.
+    $this->web_user = $this->drupalCreateUser(array('access user profiles', 'access content'));
+  }
+
+  /**
+   * Test availability of main content.
+   */
+  function testMainContentFallback() {
+    $edit = array();
+    $edit['modules[Core][block][enable]'] = FALSE;
+    $this->drupalPost('admin/config/modules', $edit, t('Save configuration'));
+    $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
+    module_list(TRUE);
+    $this->assertFalse(module_exists('block'), t('block.module disabled.'));
+
+    // At this point, no region is filled and fallback should be triggered.
+    $this->drupalGet('admin/config/system/site-information');
+    $this->assertField('site_name', t('Admin interface still availble.'));
+
+    // Fallback should not trigger when another module is handling content.
+    $this->drupalGet('system-test/main-content-handling');
+    $this->assertRaw('id="system-test-content"', t('Content handled by another module'));
+    $this->assertText(t('Content to test main content fallback'), t("Main content still displayed."));
+
+    // Fallback should trigger when another module
+    // indicates that it is not handling the content.
+    $this->drupalGet('system-test/main-content-fallback');
+    $this->assertText(t('Content to test main content fallback'), t('Main content fallback properly triggers.'));
+
+    // Fallback should not trigger when another module is handling content.
+    // Note that this test ensures that no duplicate
+    // content gets created by the fallback.
+    $this->drupalGet('system-test/main-content-duplication');
+    $this->assertNoText(t('Content to test main content fallback'), t('Main content not duplicated'));
+
+    // Request a user* page and see if it is displayed
+    $this->drupalLogin($this->web_user);
+    $this->drupalGet('user/' . $this->web_user->uid . '/edit');
+    $this->assertField('mail', t('User interface still availble'));
+
+    // Enable block.module again.
+    $this->drupalLogin($this->admin_user);
+    $edit = array();
+    $edit['modules[Core][block][enable]'] = 'block';
+    $this->drupalPost('admin/config/modules', $edit, t('Save configuration'));
+    $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
+    module_list(TRUE);
+    $this->assertTrue(module_exists('block'), t('block.module re-enabled.'));
+  }
 }
 
 class SystemSettingsForm extends DrupalWebTestCase {
