Index: includes/tablesort.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/tablesort.inc,v
retrieving revision 1.19
diff -u -r1.19 tablesort.inc
--- includes/tablesort.inc	29 May 2004 17:38:53 -0000	1.19
+++ includes/tablesort.inc	2 Jun 2004 02:17:16 -0000
@@ -2,13 +2,9 @@
 // $Id: tablesort.inc,v 1.19 2004/05/29 17:38:53 dries Exp $
 
 function tablesort_init($header) {
-  static $ts;
-
-  if (empty($ts)) {
-    $ts = tablesort_get_order($header);
-    $ts['sort'] = tablesort_get_sort($header);
-    $ts['query_string'] = tablesort_get_querystring();
-  }
+  $ts = tablesort_get_order($header);
+  $ts['sort'] = tablesort_get_sort($header);
+  $ts['query_string'] = tablesort_get_querystring();
   return $ts;
 }
 
@@ -20,30 +16,43 @@
 
 function tablesort_sql($header) {
   $ts = tablesort_init($header);
-  $sql = check_query($ts['sql']);
-  $sort = strtoupper(check_query($ts['sort']));
-  return " ORDER BY $sql $sort";
+  if ($ts['field']) {
+    $sql = check_query($ts['sql']);
+    $sort = strtoupper(check_query($ts['sort']));
+    return " ORDER BY $sql $sort";
+  }
 }
 
-function tablesort($cell, $header) {
-  $ts = tablesort_init($header);
-  $title = t("sort by %s", array("%s" => $cell['data']));
-
+function tablesort_header($cell, $header, $ts) {
   // special formatting for the currently sorted column header
-  if ($cell['data'] == $ts['name']) {
-    $ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc');
-    $cell['class'] = 'active';
-    $image = '&nbsp;<img src="' . theme('image', 'arrow-' . $ts['sort'] . '.gif') . '" alt="'. t('sort icon') .'" />';
-    $title = ($ts['sort'] == 'asc' ? t("sort ascending") : t("sort descending"));
-  }
-  else {
-    // If the user clicks a different header, we want to sort ascending initially.
-    $ts['sort'] = "asc";
+  if (is_array($cell) && $cell['field']) {
+    if ($cell['data'] == $ts['name']) {
+      $ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc');
+      $cell['class'] = 'active';
+      $image = '&nbsp;<img src="' . theme('image', 'arrow-' . $ts['sort'] . '.gif') . '" alt="'. t('sort icon') .'" />';
+      $title = ($ts['sort'] == 'asc' ? t("sort ascending") : t("sort descending"));
+    }
+    else {
+      // If the user clicks a different header, we want to sort ascending initially.
+      $ts['sort'] = "asc";
+    }
+    $title = t("sort by %s", array("%s" => $cell['data']));
+    $cell['data'] = l($cell['data'] . $image, $_GET['q'], array("title" => $title), "sort=". $ts['sort']. "&amp;order=". urlencode($cell['data']). $ts['query_string']);
+  
+    unset($cell['field'], $cell['sort']);
   }
+  return $cell;
+}
 
-  $cell['data'] = l($cell['data'] . $image, $_GET['q'], array("title" => $title), "sort=". $ts['sort']. "&amp;order=". urlencode($cell['data']). $ts['query_string']);
-
-  unset($cell['field'], $cell['sort']);
+function tablesort_cell($cell, $header, $ts, $i) {
+  if ($header[$i]['data'] == $ts['name'] && $header[$i]['field']) {
+    if (is_array($cell)) {
+      $cell['class'] .= ' active';
+    }
+    else {
+      $cell = array('data' => $cell, 'class' => 'active');
+    }
+  }
   return $cell;
 }
 
@@ -67,6 +76,7 @@
     if ($header['sort'] == 'asc' || $header['sort'] == 'desc') {
       $default = array('name' => $header['data'], 'sql' => $header['field']);
     }
+    $i++;
   }
 
   if ($default) {
@@ -75,7 +85,7 @@
   else {
     // The first column specified is initial 'order by' field unless otherwise specified
     if (is_array($headers[0])) {
-      return array('name' => $headers[0]['name'], 'sql' => $headers[0]['field']);
+      return array('name' => $headers[0]['data'], 'sql' => $headers[0]['field']);
     }
     else {
       return array('name' => $headers[0]);
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.195
diff -u -r1.195 theme.inc
--- includes/theme.inc	31 May 2004 09:40:55 -0000	1.195
+++ includes/theme.inc	2 Jun 2004 02:16:52 -0000
@@ -322,9 +322,7 @@
     $ts = tablesort_init($header);
     $output .= " <tr>";
     foreach ($header as $cell) {
-      if (is_array($cell) && $cell['field']) {
-        $cell = tablesort($cell, $header);
-      }
+      $cell = tablesort_header($cell, $header, $ts);
       $output .= _theme_table_cell($cell, 1);
     }
     $output .= " </tr>\n";
@@ -345,14 +343,7 @@
       }
 
       foreach ($row as $cell) {
-        if  ($header[$i]['data'] == $ts['name'] && $header[$i]['field']) {
-          if (is_array($cell)) {
-            $cell['class'] .= ' active';
-          }
-          else {
-            $cell = array('data' => $cell, 'class' => 'active');
-          }
-        }
+        $cell = tablesort_cell($cell, $header, $ts, $i);
         $output .= _theme_table_cell($cell, 0);
         $i++;
       }
Index: modules/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment.module,v
retrieving revision 1.246
diff -u -r1.246 comment.module
--- modules/comment.module	31 May 2004 19:14:43 -0000	1.246
+++ modules/comment.module	1 Jun 2004 22:37:40 -0000
@@ -1017,7 +1017,14 @@
 
   while ($comment = db_fetch_object($result)) {
     $comment->name = $comment->registered_name ? $comment->registered_name : $comment->name;
-    $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid", array("title" => htmlspecialchars(truncate_utf8($comment->comment, 128))), NULL, "comment-$comment->cid") ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme("mark") : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". format_date($comment->timestamp, "small") ."</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid"));
+    $rows[] = array(
+        l($comment->subject, "node/view/$comment->nid/$comment->cid", array("title" => htmlspecialchars(truncate_utf8($comment->comment, 128))), NULL, "comment-$comment->cid") ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme("mark") : ""),
+        format_name($comment),
+        ($comment->status == 0 ? t("published") : t("not published")),
+        format_date($comment->timestamp, "small"),
+        l(t("edit comment"), "admin/comment/edit/$comment->cid"),
+        l(t("delete comment"), "admin/comment/delete/$comment->cid")
+      );
   }
 
   if ($pager = theme("pager", NULL, 50, 0, tablesort_pager())) {
