Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.654
diff -u -r1.654 system.module
--- modules/system/system.module	28 Dec 2008 19:11:31 -0000	1.654
+++ modules/system/system.module	29 Dec 2008 21:38:36 -0000
@@ -425,7 +425,8 @@
     'position' => 'left',
     'weight' => -10,
     'page callback' => 'system_admin_menu_block_page',
-    'access arguments' => array('access administration pages'),
+    'access callback' => 'system_admin_menu_block_page_access',
+    'access arguments' => array('admin/content', 'access administration pages'),
   );
 
   // menu items that are basically just menu blocks
@@ -435,7 +436,8 @@
     'position' => 'right',
     'weight' => -5,
     'page callback' => 'system_settings_overview',
-    'access arguments' => array('access administration pages'),
+    'access callback' => 'system_admin_menu_block_page_access',
+    'access arguments' => array('admin/settings', 'access administration pages'),
   );
   $items['admin/build'] = array(
     'title' => 'Site building',
@@ -443,7 +445,8 @@
     'position' => 'right',
     'weight' => -10,
     'page callback' => 'system_admin_menu_block_page',
-    'access arguments' => array('access administration pages'),
+    'access callback' => 'system_admin_menu_block_page_access',
+    'access arguments' => array('admin/build', 'access administration pages'),
   );
   $items['admin/settings/admin'] = array(
     'title' => 'Administration theme',
@@ -667,7 +670,8 @@
     'title' => 'Reports',
     'description' => 'View reports from system logs and other status information.',
     'page callback' => 'system_admin_menu_block_page',
-    'access arguments' => array('access site reports'),
+    'access callback' => 'system_admin_menu_block_page_access',
+    'access arguments' => array('admin/reports', 'access site reports'),
     'weight' => 5,
     'position' => 'left',
   );
@@ -727,6 +731,22 @@
 }
 
 /**
+ * Menu item access callback - hides empty system settings overview pages.
+ *
+ * @param $path
+ *   The path of the menu item to check for child menu entries.
+ * @param $string
+ *   The permission, such as "administer nodes", being checked for.
+ * @return
+ *   Boolean TRUE if the current user has the requested permission and the
+ *   current menu item has children.
+ */
+function system_admin_menu_block_page_access($path, $permission) {
+  $content = system_admin_menu_block(array('path' => $path));
+  return !empty($content) && user_access($permission);
+}
+
+/**
  * Implementation of hook_init().
  */
 function system_init() {
@@ -895,10 +915,14 @@
  *   The menu item to be displayed.
  */
 function system_admin_menu_block($item) {
-  $content = array();
+  static $cache;
   if (!isset($item['mlid'])) {
     $item += db_fetch_array(db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = '%s' AND module = 'system'", $item['path']));
   }
+  else if (isset($cache[$item['mlid']])) {
+    return $cache[$item['mlid']];
+  }
+  $content = array();
   $result = db_query("
     SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
     FROM {menu_links} ml
@@ -919,6 +943,7 @@
     $content[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $item;
   }
   ksort($content);
+  $cache[$item['mlid']] = $content;
   return $content;
 }
 
@@ -1442,7 +1467,12 @@
  */
 function system_admin_compact_mode() {
   global $user;
-  return (isset($user->admin_compact_mode)) ? $user->admin_compact_mode : variable_get('admin_compact_mode', FALSE);
+  if ($user->uid) {
+    return (isset($user->admin_compact_mode)) ? $user->admin_compact_mode : variable_get('admin_compact_mode', FALSE);
+  }
+  else {
+    return (isset($_SESSION['admin_compact_mode'])) ? $_SESSION['admin_compact_mode'] : variable_get('admin_compact_mode', FALSE);
+  }
 }
 
 /**
@@ -1453,7 +1483,12 @@
  */
 function system_admin_compact_page($mode = 'off') {
   global $user;
-  user_save($user, array('admin_compact_mode' => ($mode == 'on')));
+  if ($user->uid) {
+    user_save($user, array('admin_compact_mode' => ($mode == 'on')));
+  }
+  else {
+    $_SESSION['admin_compact_mode'] = ($mode == 'on');
+  }
   drupal_goto(drupal_get_destination());
 }
 
Index: modules/system/system.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.test,v
retrieving revision 1.32
diff -u -r1.32 system.test
--- modules/system/system.test	28 Dec 2008 19:11:31 -0000	1.32
+++ modules/system/system.test	29 Dec 2008 21:38:46 -0000
@@ -379,6 +379,40 @@
   }
 }
 
+class AdminHideEmptyMenuCategoryTestCase extends DrupalWebTestCase {
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('Hide empty menu categories'),
+      'description' => t('Confirm that categories with no "visible" children using the system_admin_menu_block_page_access()
+                          access callback are not displayed.'),
+      'group' => t('System')
+    );
+  }
+
+  /**
+   * Ensure that menu items without "visible" children are hidden.
+   */
+  public function testEmptyHide() {
+    $user = $this->drupalCreateUser(array('administer nodes', 'access administration pages'));
+    $this->drupalLogin($user);
+
+    $this->drupalGet('admin');
+
+    // Make sure menu items with children display.
+    $this->assertLink(t('Administer'));
+    $this->assertLink(t('Content management'));
+
+    // Make sure menu items without children are hidden.
+    $this->assertNoLink(t('Site building'));
+    $this->assertNoLink(t('Site configuration'));
+    $this->assertNoLink(t('User management'));
+    $this->assertNoLink(t('Reports'));
+  }
+}
+
 /**
  * Tests custom access denied functionality.
  */
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.950
diff -u -r1.950 user.module
--- modules/user/user.module	29 Dec 2008 16:03:57 -0000	1.950
+++ modules/user/user.module	29 Dec 2008 21:39:12 -0000
@@ -1015,7 +1015,8 @@
     'description' => "Manage your site's users, groups and access to site features.",
     'position' => 'left',
     'page callback' => 'system_admin_menu_block_page',
-    'access arguments' => array('access administration pages'),
+    'access callback' => 'system_admin_menu_block_page_access',
+    'access arguments' => array('admin/user', 'access administration pages'),
   );
   $items['admin/user/user'] = array(
     'title' => 'Users',
