--- workflow_ng_token.inc.orig	2008-01-09 18:36:21.000000000 +0200
+++ workflow_ng_token.inc	2008-01-11 11:03:14.000000000 +0200
@@ -100,6 +100,8 @@ function workflow_ng_token_replace($text
       $token_cache[$token_id] = $name;
     }
   }
+  // Finally, substitute the global tokens:
+  $text = token_replace($text, 'global', NULL, '[', ']');
   return $text;
 }
 
@@ -114,16 +116,29 @@ function workflow_ng_token_replacement_h
       '#description' => t('You can make use of the replacement patterns of all available arguments.'),
     );
     foreach ($argument_info as $name => $argument) {
-      $form['token_help'][$name] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Replacement patterns for @name', array('@name' => t($argument['#label']))),
-        '#collapsible' => TRUE,
-        '#collapsed' => TRUE,
-      );
-      $form['token_help'][$name]['content'] = array(
-        '#value' => theme('token_help', $argument['#entity'], '['. $name . ':', ']'),
-      );
+      $tokens_for_argument = workflow_ng_token_get_list($argument['#entity']);
+      if ($tokens_for_argument) {
+        $form['token_help'][$name] = array(
+          '#type' => 'fieldset',
+          '#title' => t('Replacement patterns for @name', array('@name' => t($argument['#label']))),
+          '#collapsible' => TRUE,
+          '#collapsed' => TRUE,
+        );
+        $form['token_help'][$name]['content'] = array(
+          '#value' => theme('workflow_ng_token_help', $tokens_for_argument, '['. $name . ':', ']'),
+        );
+      }
     }
+    // Finally, list the global tokens:
+    $form['token_help']['_global'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Global replacement patterns'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    );
+    $form['token_help']['_global']['content'] = array(
+      '#value' => theme('workflow_ng_token_help', 'global', '[', ']'),
+    );
   }
   $form['arguments'] = array('#type' => 'value', '#value' => $argument_info);
 }
@@ -161,3 +176,54 @@ function workflow_ng_token_replace_all($
   }
   return $return;
 }
+
+/*
+ * This is a wrapper around token_get_list(). It allow us to filter out
+ * global tokens.
+ */
+function workflow_ng_token_get_list($type = 'all', $return_global = FALSE) {
+  $list = token_get_list($type);
+  if (!$return_globals && isset($list['global'])) {
+    unset($list['global']);
+  }
+  return $list;
+}
+
+/**
+ * For a given context, builds a formatted list of tokens and descriptions
+ * of their replacement values.
+ *
+ * NOTE:
+ * This is a duplicate of the Token module's theme_token_help(), but with a
+ * small modification. The Token module's version insists on listing the
+ * 'global' tokens as well, so we can't use it. The only difference is that
+ * we replaced the $type parameter with a $type_or_list one.
+ *
+ * TODO: incorporate this feature into the Token module(?)
+ *
+ * @return An HTML table containing the formatting docs.
+ **/
+function theme_workflow_ng_token_help($type_or_list = 'all', $prefix = '[', $suffix = ']') {
+  token_include();
+  if (is_string($type_or_list)) {
+    $full_list = token_get_list($type_or_list);
+  } else {
+    $full_list = $type_or_list;
+  }
+  
+  $headers = array(t('Token'), t('Replacement value'));
+  $rows = array();
+  foreach ($full_list as $key => $category) {
+    $rows[] = array(array('data' => drupal_ucfirst($key) . ' ' . t('tokens'), 'class' => 'region', 'colspan' => 2));
+    foreach ($category as $token => $description) {
+      $row = array();
+      $row[] = $prefix . $token . $suffix;
+      $row[] = $description;
+      $rows[] = $row;
+    }
+  }
+
+  $output = theme('table', $headers, $rows, array('class' => 'description'));
+  return $output;
+}
+
