Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.534
diff -u -F^f -r1.534 common.inc
--- includes/common.inc	12 Apr 2006 08:42:47 -0000	1.534
+++ includes/common.inc	12 Apr 2006 20:23:00 -0000
@@ -156,6 +156,46 @@ function drupal_get_headers() {
  */
 
 /**
+ * Parse an array into a valid urlencoded query string.
+ *
+ * @param $query
+ *   The array to be processed e.g. $_GET
+ * @param $exclude
+ *   The array filled with keys to be excluded. Use parent[child] to exclude nested items.
+ * @param $urlencode
+ *   If TRUE, the keys and values are both urlencoded.
+ * @param $parent
+ *   Should not be passed, only used in recursive calls
+ * @return
+ *   urlencoded string which can be appended to/as the URL query string
+ */
+function drupal_query_string_encode($query, $exclude = array(), $parent = '') {
+  $params = array();
+
+  foreach ($query as $key => $value) {
+    if ($parent) {
+      $key = $parent .'['. urlencode($key) .']';
+    }
+    else {
+      $key = urlencode($key);
+    }
+
+    if (in_array(urldecode($key), $exclude)) {
+      continue;
+    }
+
+    if (is_array($value)) {
+      $params[] = drupal_query_string_encode($value, $exclude, $key);
+    }
+    else {
+      $params[] = $key .'='. urlencode($value);
+    }
+  }
+
+  return implode('&', $params);
+}
+
+/**
  * 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. By default the current URL is returned.
@@ -171,17 +211,11 @@ function drupal_get_destination() {
   }
   else {
     $path = $_GET['q'];
-    $params = array();
-    foreach ($_GET as $key => $value) {
-      if ($key == 'q') {
-        continue;
-      }
-      $params[] = urlencode($key) .'='. urlencode($value);
-    }
-    if (count($params)) {
-      $path .= '?';
+    $query = drupal_query_string_encode($_GET, array('q'));
+    if ($query != '') {
+      $path .= '?'. $query;
     }
-    return 'destination='. urlencode($path . implode('&', $params));
+    return 'destination='. urlencode($path);
   }
 }
 
Index: includes/pager.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/pager.inc,v
retrieving revision 1.53
diff -u -F^f -r1.53 pager.inc
--- includes/pager.inc	15 Jan 2006 16:55:35 -0000	1.53
+++ includes/pager.inc	12 Apr 2006 20:23:00 -0000
@@ -84,6 +84,21 @@ function pager_query($query, $limit = 10
 }
 
 /**
+ * Compose a query string to append to pager requests.
+ *
+ * @return
+ *   A query string that consists of all components of the current page request
+ *   except for those pertaining to paging.
+ */
+function pager_get_querystring() {
+  static $string = NULL;
+  if (!isset($string)) {
+    $string = drupal_query_string_encode($_REQUEST, array('q', 'page'));
+  }
+  return $string;
+}
+
+/**
  * Format a query pager.
  *
  * Menu callbacks that display paged query results should call theme('pager') to
@@ -179,6 +194,7 @@ function theme_pager_previous($text, $li
   // If we are anywhere but the first page
   if ($pager_page_array[$element] > 0) {
     $page_new = pager_load_array($pager_page_array[$element] - $interval, $element, $pager_page_array);
+
     // If the previous page is the first page, mark the link as such.
     if ($page_new[$element] == 0) {
       $output = theme('pager_first', $text, $limit, $element, $parameters);
@@ -357,8 +373,12 @@ function theme_pager_link($text, $page_n
   }
 
   $query = array();
-  foreach ($parameters as $key => $value) {
-    $query[] = $key .'='. $value;
+  if (count($parameters)) {
+    $query[] = drupal_query_string_encode($parameters, array());
+  }
+  $querystring = pager_get_querystring();
+  if ($querystring != '') {
+    $query[] = $querystring;
   }
 
   // Set each pager link title
Index: includes/tablesort.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/tablesort.inc,v
retrieving revision 1.37
diff -u -F^f -r1.37 tablesort.inc
--- includes/tablesort.inc	10 Dec 2005 19:26:47 -0000	1.37
+++ includes/tablesort.inc	12 Apr 2006 20:23:01 -0000
@@ -86,7 +86,7 @@ function tablesort_header($cell, $header
       $ts['sort'] = 'asc';
       $image = '';
     }
-    $cell['data'] = l($cell['data'] . $image, $_GET['q'], array('title' => $title), 'sort='. $ts['sort'] .'&order='. urlencode($cell['data']). $ts['query_string'], NULL, FALSE, TRUE);
+    $cell['data'] = l($cell['data'] . $image, $_GET['q'], array('title' => $title), 'sort='. $ts['sort'] .'&order='. urlencode($cell['data']) . $ts['query_string'], NULL, FALSE, TRUE);
 
     unset($cell['field'], $cell['sort']);
   }
@@ -134,14 +134,7 @@ function tablesort_cell($cell, $header, 
  *   except for those pertaining to table sorting.
  */
 function tablesort_get_querystring() {
-  $cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST;
-  $query_string = '';
-  foreach ($cgi as $key => $val) {
-    if ($key != 'order' && $key != 'sort' && $key != 'q') {
-      $query_string .= '&'. $key .'='. $val;
-    }
-  }
-  return $query_string;
+  return drupal_query_string_encode($_REQUEST, array('q', 'order', 'sort'));
 }
 
 /**
Index: modules/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment.module,v
retrieving revision 1.449
diff -u -F^f -r1.449 comment.module
--- modules/comment.module	11 Apr 2006 11:33:15 -0000	1.449
+++ modules/comment.module	12 Apr 2006 20:23:05 -0000
@@ -980,7 +980,7 @@ function comment_admin_overview($type = 
     $form['operations'][$comment->cid] = array('#value' => l(t('edit'), 'comment/edit/'. $comment->cid, array(), $destination));
   }
   $form['comments'] = array('#type' => 'checkboxes', '#options' => $comments);
-  $form['pager'] = array('#value' => theme('pager', NULL, 50, 0, tablesort_pager()));
+  $form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
   return drupal_get_form('comment_admin_overview', $form);
 }
 
Index: modules/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum.module,v
retrieving revision 1.327
diff -u -F^f -r1.327 forum.module
--- modules/forum.module	7 Apr 2006 15:32:17 -0000	1.327
+++ modules/forum.module	12 Apr 2006 20:23:57 -0000
@@ -1002,7 +1002,7 @@ function theme_forum_topic_list($tid, $t
   }
 
   $output .= theme('table', $forum_topic_list_header, $rows);
-  $output .= theme('pager', NULL, $forum_per_page, 0, tablesort_pager());
+  $output .= theme('pager', NULL, $forum_per_page, 0);
 
   return $output;
 }
Index: modules/path.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/path.module,v
retrieving revision 1.82
diff -u -F^f -r1.82 path.module
--- modules/path.module	9 Apr 2006 22:17:40 -0000	1.82
+++ modules/path.module	12 Apr 2006 20:23:57 -0000
@@ -307,7 +307,7 @@ function path_overview() {
   }
 
   $output = theme('table', $header, $rows);
-  $output .= theme('pager', NULL, 50, 0, tablesort_pager());
+  $output .= theme('pager', NULL, 50, 0);
   return $output;
 }
 
Index: modules/statistics.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics.module,v
retrieving revision 1.224
diff -u -F^f -r1.224 statistics.module
--- modules/statistics.module	11 Apr 2006 11:33:15 -0000	1.224
+++ modules/statistics.module	12 Apr 2006 20:23:57 -0000
@@ -192,7 +192,7 @@ function statistics_node_tracker() {
 
     drupal_set_title(check_plain($node->title));
     $output = theme('table', $header, $rows);
-    $output .= theme('pager', NULL, 30, 0, tablesort_pager());
+    $output .= theme('pager', NULL, 30, 0);
     return $output;
   }
   else {
@@ -218,7 +218,7 @@ function statistics_user_tracker() {
 
     drupal_set_title($account->name);
     $output = theme('table', $header, $rows);
-    $output .= theme('pager', NULL, 30, 0, tablesort_pager());
+    $output .= theme('pager', NULL, 30, 0);
     return $output;
   }
   else {
@@ -249,7 +249,7 @@ function statistics_recent_hits() {
   }
 
   $output = theme('table', $header, $rows);
-  $output .= theme('pager', NULL, 30, 0, tablesort_pager());
+  $output .= theme('pager', NULL, 30, 0);
   return $output;
 }
 
@@ -275,7 +275,7 @@ function statistics_top_pages() {
 
   drupal_set_title(t('Top pages in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
   $output = theme('table', $header, $rows);
-  $output .= theme('pager', NULL, 30, 0, tablesort_pager());
+  $output .= theme('pager', NULL, 30, 0);
   return $output;
 }
 
@@ -303,7 +303,7 @@ function statistics_top_visitors() {
 
   drupal_set_title(t('Top visitors in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
   $output = theme('table', $header, $rows);
-  $output .= theme('pager', NULL, 30, 0, tablesort_pager());
+  $output .= theme('pager', NULL, 30, 0);
   return $output;
 }
 
@@ -329,7 +329,7 @@ function statistics_top_referrers() {
   }
 
   $output = theme('table', $header, $rows);
-  $output .= theme('pager', NULL, 30, 0, tablesort_pager());
+  $output .= theme('pager', NULL, 30, 0);
   return $output;
 }
 
Index: modules/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user.module,v
retrieving revision 1.605
diff -u -F^f -r1.605 user.module
--- modules/user.module	10 Apr 2006 19:11:25 -0000	1.605
+++ modules/user.module	12 Apr 2006 20:24:04 -0000
@@ -1907,7 +1907,7 @@ function user_admin_account() {
   }
 
   $output = theme('table', $header, $rows);
-  $output .= theme('pager', NULL, 50, 0, tablesort_pager());
+  $output .= theme('pager', NULL, 50, 0);
   return $output;
 }
 
Index: modules/watchdog.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/watchdog.module,v
retrieving revision 1.142
diff -u -F^f -r1.142 watchdog.module
--- modules/watchdog.module	27 Mar 2006 07:29:34 -0000	1.142
+++ modules/watchdog.module	12 Apr 2006 20:24:04 -0000
@@ -139,7 +139,7 @@ function watchdog_overview() {
   }
 
   $output .= theme('table', $header, $rows);
-  $output .= theme('pager', NULL, 50, 0, tablesort_pager());
+  $output .= theme('pager', NULL, 50, 0);
 
   return $output;
 }
