Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.457
diff -u -F^f -r1.457 common.inc
--- includes/common.inc	6 Jul 2005 14:20:11 -0000	1.457
+++ includes/common.inc	6 Jul 2005 19:09:50 -0000
@@ -133,20 +133,26 @@ function drupal_get_headers() {
 
 /**
  * Prepare a destination query string for use in combination with
- * drupal_goto().  Used to direct the user back to the referring page
- * after completing a form.
+ * drupal_goto(). Used to direct the user back to the referring page after
+ * completing a form. By default the current url is returned. If a destination
+ * exists in the previous request, that destination is returned.
  *
  * @see drupal_goto()
  */
 function drupal_get_destination() {
-  $destination[] = $_GET['q'];
-  $params = array('page', 'sort', 'order');
-  foreach ($params as $param) {
-    if (isset($_GET[$param])) {
-      $destination[] = "$param=". $_GET[$param];
+  if ($_REQUEST['destination']) {
+    return 'destination='. urlencode($_REQUEST['destination']);
+  }
+  else {
+    $destination[] = $_GET['q'];
+    $params = array('page', 'sort', 'order');
+    foreach ($params as $param) {
+      if (isset($_GET[$param])) {
+        $destination[] = "$param=". $_GET[$param];
+      }
     }
+    return 'destination='. urlencode(implode('&', $destination));
   }
-  return 'destination='. urlencode(implode('&', $destination));
 }
 
 /**
