Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.383
diff -u -9 -p -r1.383 menu.inc
--- includes/menu.inc	26 Mar 2010 17:14:45 -0000	1.383
+++ includes/menu.inc	7 Apr 2010 09:44:15 -0000
@@ -1064,39 +1064,42 @@ function menu_tree_all_data($menu_name, 
 }
 
 /**
  * Get the data structure representing a named menu tree, based on the current page.
  *
  * The tree order is maintained by storing each parent in an individual
  * field, see http://drupal.org/node/141866 for more.
  *
  * @param $menu_name
- *   The named menu links to return
+ *   The named menu links to return.
  * @param $max_depth
  *   Optional maximum depth of links to retrieve.
+ * @param $only_active_trail
+ *   Only return the items in the active trail instead of all items on every
+ *   level of the trail.
  *
  * @return
  *   An array of menu links, in the order they should be rendered. The array
  *   is a list of associative arrays -- these have two keys, link and below.
  *   link is a menu item, ready for theming as a link. Below represents the
  *   submenu below the link if there is one, and it is a subtree that has the
  *   same structure described for the top-level array.
  */
-function menu_tree_page_data($menu_name, $max_depth = NULL) {
+function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail = FALSE) {
   $tree = &drupal_static(__FUNCTION__, array());
 
   // Load the menu item corresponding to the current page.
   if ($item = menu_get_item()) {
     if (isset($max_depth)) {
       $max_depth = min($max_depth, MENU_MAX_DEPTH);
     }
     // Generate a cache ID (cid) specific for this page.
-    $cid = 'links:' . $menu_name . ':page-cid:' . $item['href'] . ':' . $GLOBALS['language']->language . ':' . (int)$item['access'] . ':' . (int)$max_depth;
+    $cid = 'links:' . $menu_name . ':page-cid:' . $item['href'] . ':' . $GLOBALS['language']->language . ':' . (int)$item['access'] . ':' . (int)$max_depth . ':' . (int)$only_active_trail;
 
     if (!isset($tree[$cid])) {
       // If the static variable doesn't have the data, check {cache_menu}.
       $cache = cache_get($cid, 'cache_menu');
       if ($cache && isset($cache->data)) {
         // If the cache entry exists, it will just be the cid for the actual data.
         // This avoids duplication of large amounts of data.
         $cache = cache_get($cache->data, 'cache_menu');
         if ($cache && isset($cache->data)) {
@@ -1146,19 +1149,19 @@ function menu_tree_page_data($menu_name,
               ->execute()->fetchAssoc();
           }
           // We always want all the top-level links with plid == 0.
           $parents[] = '0';
 
           // Use array_values() so that the indices are numeric for array_merge().
           $args = $parents = array_unique(array_values($parents));
           $expanded = variable_get('menu_expanded', array());
           // Check whether the current menu has any links set to be expanded.
-          if (in_array($menu_name, $expanded)) {
+          if (in_array($menu_name, $expanded) && !$only_active_trail) {
             // Collect all the links set to be expanded, and then add all of
             // their children to the list as well.
             do {
               $result = db_select('menu_links', NULL, array('fetch' => PDO::FETCH_ASSOC))
                 ->fields('menu_links', array('mlid'))
                 ->condition('menu_name', $menu_name)
                 ->condition('expanded', 1)
                 ->condition('has_children', 1)
                 ->condition('plid', $args, 'IN')
@@ -1198,19 +1201,19 @@ function menu_tree_page_data($menu_name,
           'theme_callback',
           'theme_arguments',
           'type',
           'description',
         ));
         for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
           $query->orderBy('p' . $i, 'ASC');
         }
         $query->condition('ml.menu_name', $menu_name);
-        $query->condition('ml.plid', $args, 'IN');
+        $query->condition($only_active_trail ? 'ml.mlid' : 'ml.plid', $args, 'IN');
         if (isset($max_depth)) {
           $query->condition('ml.depth', $max_depth, '<=');
         }
         // Build an ordered array of links using the query result object.
         $links = array();
         foreach ($query->execute() as $item) {
           $links[] = $item;
         }
         $data['tree'] = menu_tree_data($links, $parents);
@@ -2105,19 +2108,19 @@ function menu_set_active_trail($new_trai
       $query->condition('ml.menu_name', $menu_names, 'IN');
       $result = $query->execute();
       $found = array();
       foreach ($result as $menu) {
         $found[] = $menu->menu_name;
       }
       // The $menu_names array is ordered, so take the first one that matches.
       $name = current(array_intersect($menu_names, $found));
       if ($name !== FALSE) {
-        $tree = menu_tree_page_data($name);
+        $tree = menu_tree_page_data($name, NULL, TRUE);
         list($key, $curr) = each($tree);
       }
     }
 
     while ($curr) {
       // Terminate the loop when we find the current path in the active trail.
       if ($curr['link']['href'] == $item['href']) {
         $trail[] = $curr['link'];
         $curr = FALSE;
