Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.1211
diff -u -p -r1.1211 user.module
--- modules/user/user.module	20 Oct 2010 05:32:31 -0000	1.1211
+++ modules/user/user.module	23 Oct 2010 02:49:07 -0000
@@ -1789,6 +1789,14 @@ function user_menu_site_status_alter(&$m
  * Implements hook_menu_link_alter().
  */
 function user_menu_link_alter(&$link) {
+  // The path 'user' must be accessible for anonymous users, but only visible
+  // for authenticated users. Authenticated users should see "My account", but
+  // anonymous users should not see it at all. Therefore, invoke
+  // user_translated_menu_link_alter() to conditionally hide the link.
+  if ($link['link_path'] == 'user' && $link['module'] == 'system') {
+    $link['options']['alter'] = TRUE;
+  }
+
   // Force the Logout link to appear on the top-level of 'user-menu' menu by
   // default (i.e., unless it has been customized).
   if ($link['link_path'] == 'user/logout' && $link['module'] == 'system' && empty($link['customized'])) {
@@ -1797,6 +1805,16 @@ function user_menu_link_alter(&$link) {
 }
 
 /**
+ * Implements hook_translated_menu_link_alter().
+ */
+function user_translated_menu_link_alter(&$link) {
+  // Hide the "User account" link for anonymous users.
+  if ($link['link_path'] == 'user' && $link['module'] == 'system' && user_is_anonymous()) {
+    $link['hidden'] = 1;
+  }
+}
+
+/**
  * Implements hook_admin_paths().
  */
 function user_admin_paths() {
@@ -1809,6 +1827,17 @@ function user_admin_paths() {
 }
 
 /**
+ * Returns $arg or the user ID of the current user if $arg is '%' or empty.
+ *
+ * Deprecated. Use %user_uid_optional instead.
+ *
+ * @todo D8: Remove.
+ */
+function user_uid_only_optional_to_arg($arg) {
+  return user_uid_optional_to_arg($arg);
+}
+
+/**
  * Load either a specified or the current user account.
  *
  * @param $uid
Index: modules/user/user.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.test,v
retrieving revision 1.103
diff -u -p -r1.103 user.test
--- modules/user/user.test	11 Oct 2010 19:43:23 -0000	1.103
+++ modules/user/user.test	23 Oct 2010 02:44:55 -0000
@@ -1227,6 +1227,56 @@ class UserAutocompleteTestCase extends D
   }
 }
 
+
+/**
+ * Test user-links in secondary menu.
+ */
+class UserAccountLinksUnitTests extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'User account links',
+      'description' => 'Test user-account links.',
+      'group' => 'User'
+    );
+  }
+
+  /**
+   * Test the user login block.
+   */
+  function testSecondaryMenu() {
+    // Create a regular user.
+    $user = $this->drupalCreateUser(array());
+
+    // Log in and get the homepage.
+    $this->drupalLogin($user);
+    $this->drupalGet('<front>');
+
+    // For a logged-in user, expect the secondary menu to have links for "My
+    // account" and "Log out".
+    $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
+      ':menu_id' => 'secondary-menu-links',
+      ':href' => 'user',
+      ':text' => 'My account',
+    ));
+    $this->assertEqual(count($link), 1, 'My account link is in secondary menu.');
+
+    $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
+      ':menu_id' => 'secondary-menu-links',
+      ':href' => 'user/logout',
+      ':text' => 'Log out',
+    ));
+    $this->assertEqual(count($link), 1, 'Log out link is in secondary menu.');
+
+    // Log out and get the homepage.
+    $this->drupalLogout();
+    $this->drupalGet('<front>');
+
+    // For a logged-out user, expect no secondary links.
+    $element = $this->xpath('//ul[@id=:menu_id]', array(':menu_id' => 'secondary-menu-links'));
+    $this->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.');
+  }
+}
+
 /**
  * Test user blocks.
  */
