--- workspace.module.org	2009-07-13 18:17:17.000000000 +0100
+++ workspace.module	2009-04-21 17:10:45.000000000 +0100
@@ -154,16 +154,25 @@
     '#type' => 'textfield',
     '#title' => t('Number of items'),
     '#description' => t('Maximum number of items to display in your workspace.'),
-    '#default_value' => $account->workspaces ? $account->workspaces['default']['maxnodes'] : 50,
+    '#default_value' => $account->workspaces['default']['maxnodes'] ? $account->workspaces['default']['maxnodes'] : 50,
     '#size' => 4
   );
   $form['maxfilenames'] = array(
     '#type' => 'textfield',
     '#title' => t('Number of files'),
     '#description' => t('Maximum number of filenames to display in your workspace.'),
-    '#default_value' => $account->workspaces ? $account->workspaces['default']['maxfilenames'] : 50,
+    '#default_value' => $account->workspaces['default']['maxfilenames'] ? $account->workspaces['default']['maxfilenames'] : 50,
     '#size' => 4
   );
+  if ( module_exists('comment') ) {
+    $form['maxcomments'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Number of comments'),
+      '#description' => t('Maximum number of comments to display in your workspace.'),
+      '#default_value' => $account->workspaces['default']['maxcomments'] ? $account->workspaces['default']['maxcomments'] : 50,
+      '#size' => 4
+    );
+  }
   $form['uid'] = array(
     '#type' => 'value',
     '#value' => $account->uid,
@@ -187,6 +196,11 @@
   if (!is_numeric($form_state['values']['maxfilenames']) && !form_get_errors()) {
     form_set_error('maxfilenames', t('Please enter a numeric value.'));
   }
+  if ( module_exists('comment') ) {
+    if (!is_numeric($form_state['values']['maxcomments']) && !form_get_errors()) {
+      form_set_error('maxfilenames', t('Please enter a numeric value.'));
+    }
+  }
 }
 
 /**
@@ -216,7 +230,7 @@
 function workspace_list_content($account) {
   global $user;
   drupal_set_title(t('Workspace: @name', array('@name' => $account->name)));
-  $max = isset($user->workspaces) ? $user->workspaces['default']['maxnodes'] : 50;
+  $max = isset($user->workspaces['default']['maxnodes']) ? $user->workspaces['default']['maxnodes'] : 50;
   $comments_enabled = module_exists('comment');
   if ($comments_enabled) {
     // If the comment module is enabled, we need to get comment counts too.
@@ -228,6 +242,10 @@
             FROM {node} n
             LEFT JOIN {node_comment_statistics} s ON n.nid = s.nid
             WHERE n.uid = %d';
+    $check_count_sql = 'SELECT COUNT(n.nid) AS ct
+            FROM {node} n
+            LEFT JOIN {node_comment_statistics} s ON n.nid = s.nid
+            WHERE n.uid = %d';
   }
   else {
     // Otherwise we use a simpler query.
@@ -237,8 +255,16 @@
     $count_sql = 'SELECT COUNT(n.nid)
             FROM {node} n
             WHERE n.uid = %d';
+    $check_count_sql = 'SELECT COUNT(n.nid) AS ct
+            FROM {node} n
+            WHERE n.uid = %d';
   }
 
+  // check wether this user has any comments, if not skip pager to avoid div by zero error
+  $result = db_query($check_count_sql, array($account->uid));
+  $row = db_fetch_array($result);
+  $has_contents = $row['ct'];
+
   $header = array(
     array('data' => t('Type'), 'field' => 'type'),
     array('data' => t('Title'), 'field' => 'title'),
@@ -249,8 +275,13 @@
     array('data' => t('Operations'), 'colspan' => 2)
   );
   $cols = 8;
+  if ($has_contents) {
   $result = pager_query(db_rewrite_sql($sql . tablesort_sql($header)), $max, 0, db_rewrite_sql($count_sql), $account->uid);
   $rows = workspace_build_rows($result, $account);
+  }
+  else {
+    $rows = FALSE;
+  }
   $output = '';
   // Only add the content add form if the user is viewing his/her own workspace.
   if ($user->uid == 1 || user_access('view all workspaces') || $user->uid == $account->uid) {
@@ -269,13 +300,17 @@
  */
 function workspace_list_comments($account) {
   drupal_set_title(t('Workspace: @name', array('@name' => $account->name)));
-  $max = isset($account->workspaces) ? $account->workspaces['default']['maxcomments'] : 50;
+  $max = isset($account->workspaces['default']['maxcomments']) ? $account->workspaces['default']['maxcomments'] : 50;
 
   $sql =       'SELECT c.nid, c.uid, c.cid, c.subject, c.status, c.timestamp, c.pid, 0
                 FROM {comments} c
                 WHERE c.uid = %d';
 
   $count_sql = 'SELECT COUNT(cid) FROM {comments} WHERE uid = %d';
+  // check wether this user has any comments, if not skip pager to avoid div by zero error
+  $result = db_query('SELECT COUNT(cid) AS ct FROM {comments} WHERE uid = %d', array($account->uid));
+  $row = db_fetch_array($result);
+  $has_comments = $row['ct'];
 
   // Build the comment listing.
   $header = array(
@@ -286,8 +321,13 @@
     array('data' => t('Operations'), 'colspan' => 2)
   );
   $cols = 6;
-  $result = pager_query($sql . tablesort_sql($header), $max, 0, $count_sql, $account->uid);
+  if ($has_comments) {
+    $result = pager_query(db_rewrite_sql($sql . tablesort_sql($header)), $max, 0, db_rewrite_sql($count_sql), $account->uid);
   $rows = workspace_build_rows($result, $account);
+  }
+  else {
+    $rows = FALSE;
+  }
   return theme_workspace_list($header, $rows, $max, $cols);
 }
 
@@ -384,7 +425,7 @@
 function workspace_list_files($account) {
   global $user;
   drupal_set_title(t('Workspace: @name', array('@name' => $account->name)));
-  $max = isset($user->workspaces) ? $user->workspaces['default']['maxfilenames'] : 50;
+  $max = isset($user->workspaces['default']['maxfilenames']) ? $user->workspaces['default']['maxfilenames'] : 50;
   $download = t('download');
   $rows = array();
   $header = array(
