Index: includes/actions.inc
===================================================================
RCS file: includes/actions.inc
diff -N includes/actions.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ includes/actions.inc	18 Jun 2007 22:25:04 -0000
@@ -0,0 +1,228 @@
+<?php
+
+// $Id$
+
+/**
+* @file
+* This is the actions engine for executing stored actions.
+*/
+
+/**
+ * Given the IDs of actions to perform, find out what the callbacks
+ * for the actions are by querying the database. Then call each callback
+ * using the function call $function('do', $object, $context, $a1, $2)
+ * where $function is the name of a function written in compliance with
+ * the action specification. The $params parameter is an array of
+ * stored parameters that have been previously configured through the
+ * web using actions.module.
+ *
+ * @param $action_ids
+ *   The ID of the action to perform. Can be a single action ID or an array
+ *   of IDs. IDs of instances will be numeric; IDs of singletons will be
+ *   function names.
+ * @param $object
+ *   Parameter that will be passed along to the callback. Typically the
+ *   object that the action will act on; a node, user or comment object.
+ * @param $context
+ *   Parameter that will be passed along to the callback. $context is a
+ *   keyed array containing extra information about what is currently
+ *   happening at the time of the call. Typically $context['hook'] and
+ *   $context['op'] will tell which hook-op combination resulted in this
+ *   call to actions_do().
+ * @param $a1
+ *   Parameter that will be passed along to the callback.
+ * @param $a2
+ *   Parameter that will be passed along to the callback.
+ *
+ * @return
+ *   An associative array containing the result of the function that
+ *   performs the action, keyed on action ID.
+ *
+ */
+function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a2 = NULL) {
+  static $stack;
+  $stack++;
+  if ($stack > variable_get('actions_max_stack', 35)) {
+    watchdog('actions', t('Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.'), WATCHDOG_ERROR);
+    return;
+  }
+  $actions = array();
+  $available_actions = actions_list();
+  $result = array();
+  if (is_array($action_ids)) {
+    $where = array();
+    $where_values = array();
+    foreach ($action_ids as $action_id) {
+      if (is_numeric($action_id)) {
+        $where[] = 'OR aid = %d';
+        $where_values[] = $action_id;
+      }
+      elseif (isset($available_actions[$action_id])) {
+        $actions[$action_id] = $available_actions[$action_id];
+      }
+    }
+
+    // When we have action instances we must go to the database to
+    // retrieve instance data.
+    if ($where) {
+      $where_clause = implode(' ', $where);
+      // Strip off leading 'OR '.
+      $where_clause = '(' . strstr($where_clause, " ") . ')';
+      $result_db = db_query('SELECT * FROM {actions} WHERE ' . $where_clause, $where_values);
+      while ($action = db_fetch_object($result_db)) {
+        $action_id = $action->action_id;
+        $actions[$action_id] = $action->params ? unserialize($data->parameters) : array();
+        $actions[$action_id]['callback'] = $action->callback;
+        $actions[$action_id]['type'] = $action->type;
+      }
+    }
+
+    // Fire actions, in no particular order.
+    foreach ($actions as $action_id => $params) {
+      if (is_numeric($action_id)) { // Configurable actions need parameters.
+        $function = $params['callback'];
+        $context = array_merge($context, $params);
+        $result[$action_id] = $function($object, $context, $a1, $a2);
+      }
+      // Singleton action; $action_id is the function name.
+      else {
+        $result[$action_id] = $action_id($object, $context, $a1, $a2);
+      }
+    }
+  }
+  // Optimized execution of single action.
+  else {
+    // If it's a configurable action, retrieve stored parameters.
+    if (is_numeric($action_ids)) {
+      $action = db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", $action_ids));
+      $function = $action->callback;
+      $context = array_merge($context, unserialize($action->parameters));
+      $result[$action_ids] = $function($object, $context, $a1, $a2);
+    }
+    // Singleton action; $action_ids is the function name.
+    else {
+      $result[$action_ids] = $action_ids($object, $context, $a1, $a2);
+    }
+  }
+  return $result;
+}
+
+
+/**
+ * Discover all action functions by invoking hook_action_info().
+ *
+ * mymodule_action_info() {
+ *   return array(
+ *     'mymodule_functiondescription_action' => array(
+ *       'type' => 'node',
+ *       'description' => t('Save node'),
+ *       'configurable' => FALSE,
+ *       'hooks' => array(
+ *         'nodeapi' => array('delete','insert','update', 'view'),
+ *         'comment' => array('delete','insert','update', 'view'),
+ *       )
+ *     )
+ *   );
+ * }
+ *
+ * The description is used in presenting possible actions to the user for
+ * configuration. The type is used to present these actions in a logical
+ * grouping and to denote context. Some types are 'node', 'user', 'comment',
+ * and 'system'. If an action is configurable it will provide form,
+ * validation and submission functions. The hooks the action supports
+ * are declared in the 'hooks' array.
+ *
+ * @return
+ *   An associative array keyed on function name. The value of each key is
+ *   an array containing information about the action, such as type of
+ *   action and description of the action, e.g.,
+ *
+ *   $actions['actions_node_publish'] = ('description' => 'Publish a node' ... )
+ *
+ */
+function actions_list() {
+  static $actions;
+  if (isset($actions)) {
+    return $actions;
+  }
+
+  $actions = module_invoke_all('action_info');
+  return $actions;
+}
+
+/**
+ * Retrieve all action instances from the database.
+ * Compare with actions_list() which gathers actions by
+ * invoking hook_action_info(). The two are synchronized
+ * by visiting /admin/build/actions (when actions.module is
+ * enabled) which runs actions_synchronize().
+ *
+ * @return
+ *   Associative array keyed by action ID. Each value is
+ *   an associative array with keys 'callback', 'description',
+ *   'type' and 'configurable'.
+ */
+function actions_get_all_actions() {
+  $actions = array();
+  $result = db_query("SELECT * FROM {actions}");
+  while ($action = db_fetch_object($result)) {
+    $actions[$action->aid] = array(
+      'callback' => $action->callback,
+      'description' => $action->description,
+      'type' => $action->type,
+      'configurable' => (bool) $action->parameters,
+    );
+  }
+  return $actions;
+}
+
+/**
+ * Create an associative array keyed by md5 hashes of function names.
+ * Hashes are used to prevent actual function names from going out into
+ * HTML forms and coming back.
+ *
+ * @param $actions
+ *   An associative array with function names as keys and associative
+ *   arrays with keys 'description', 'type', etc. as values. Generally
+ *   the output of actions_list() or actions_get_all_actions() is given
+ *   as input to this function.
+ *
+ * @return
+ *   An associative array keyed on md5 hash of function name. The value of
+ *   each key is an associative array of function, description, and type
+ *   for the action.
+ */
+function actions_actions_map($actions) {
+  $actions_map = array();
+  foreach ($actions as $callback => $array) {
+    $key = md5($callback);
+    $actions_map[$key]['callback']     = isset($array['callback']) ? $array['callback'] : $callback;
+    $actions_map[$key]['description']  = $array['description'];
+    $actions_map[$key]['type']         = $array['type'];
+    $actions_map[$key]['configurable'] = $array['configurable'];
+  }
+  return $actions_map;
+}
+
+/**
+ * Given an md5 hash of a function name, return the function name.
+ * Faster than actions_actions_map() when you only need the function name.
+ *
+ * @param $hash
+ *   MD5 hash of a function name
+ *
+ * @return
+ *   Function name
+ */
+function actions_function_lookup($hash) {
+  $actions_list = actions_list();
+  foreach ($actions_list as $function => $array) {
+    if (md5($function) == $hash) {
+      return $function;
+    }
+  }
+
+  // Must be an instance; must check database.
+  $aid = db_result(db_query("SELECT aid FROM {actions} WHERE MD5(aid) = '%s' AND parameters != ''", $hash));
+  return $aid;
+}
\ No newline at end of file
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.656
diff -u -u -p -r1.656 common.inc
--- includes/common.inc	18 Jun 2007 06:59:11 -0000	1.656
+++ includes/common.inc	18 Jun 2007 22:25:04 -0000
@@ -2235,6 +2235,7 @@ function _drupal_bootstrap_full() {
   require_once './includes/unicode.inc';
   require_once './includes/image.inc';
   require_once './includes/form.inc';
+  require_once './includes/actions.inc';
   // Set the Drupal custom error handler.
   set_error_handler('drupal_error_handler');
   // Emit the correct charset HTTP header.
@@ -2290,6 +2291,60 @@ function page_set_cache() {
   }
 }
 
+function _drupal_mail_urls($url = 0) {
+  static $urls = array();
+  if ($url) {
+    $urls[] = strpos($url, '://') ? $url : url($url, NULL, NULL, 1);
+    return count($urls);
+  }
+  return $urls;
+}
+
+/**
+ * Transform a string into plain text, optionally preserving the
+ * structure of the text. Useful for preparing the body of a node
+ * to be sent by email.
+ *
+ * @param $string
+ *   The string to be transformed.
+ * @return
+ *   The transformed string.
+ */
+function drupal_html_to_plain($string) {
+  static $i = 0;
+
+  $pattern = '@(<a href="(.+?)">(.+?)</a>)@ei';
+  $string = preg_replace($pattern, "'\\3 ['. _drupal_mail_urls('\\2') .']'", $string);
+  $urls = _drupal_mail_urls();
+  if (count($urls)) {
+    $string .= "\n";
+    for ($max = count($urls); $i < $max; $i++) {
+      $string .= '['. ($i + 1) .'] '. $urls[$i] ."\n";
+    }
+  }
+
+  $string = preg_replace('!</?blockquote>!i', '"', $string);
+  $string = preg_replace('!</?(em|i)>!i', '/', $string);
+  $string = preg_replace('!</?(b|strong)>!i', '*', $string);
+  $string = preg_replace("@<br />(?!\n)@i", "\n", $string);
+  $string = preg_replace("@</p.*>(?!\n\n)@i", "\n\n", $string);
+  $string = preg_replace("@</h1>(?!\n\n)@i", " #\n", $string);
+  $string = preg_replace("@</h2>(?!\n\n)@i", " ##\n", $string);
+  $string = preg_replace("@</h3>(?!\n\n)@i", " ###\n", $string);
+  $string = preg_replace("@</h4>(?!\n\n)@i", " ####\n", $string);
+  $string = preg_replace("@</(li|dd)>\n?@i", "\n", $string);
+  $string = preg_replace("@<h1.*>@i", "\n\n# ", $string);
+  $string = preg_replace("@<h2.*>@i", "\n\n## ", $string);
+  $string = preg_replace("@<h3.*>@i", "\n\n### ", $string);
+  $string = preg_replace("@<h4.*>@i", "\n\n#### ", $string);
+  $string = preg_replace("@<li.*>@i", "* ", $string);
+  $string = strip_tags($string);
+  $string = decode_entities($string);
+  $string = wordwrap($string, 72);
+
+  return $string;
+}
+
 /**
  * Send an e-mail message, using Drupal variables and default settings.
  * More information in the <a href="http://php.net/manual/en/function.mail.php">
@@ -3140,3 +3195,42 @@ function watchdog_severity_levels() {
   );
 }
 
+/**
+ * Explode a string of given tags into an array.
+ */
+function drupal_explode_tags($tags) {
+  // This regexp allows the following types of user input:
+  // this, "somecompany, llc", "and ""this"" w,o.rks", foo bar
+  $regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
+  preg_match_all($regexp, $tags, $matches);
+  $typed_tags = array_unique($matches[1]);
+
+  $tags = array();
+  foreach ($typed_tags as $tag) {
+    // If a user has escaped a term (to demonstrate that it is a group,
+    // or includes a comma or quote character), we remove the escape
+    // formatting so to save the term into the database as the user intends.
+    $tag = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\1', $tag)));
+    if ($tag != "") {
+      $tags[] = $tag;
+    }
+  }
+
+  return $tags;
+}
+
+/**
+ * Implode an array of tags into a string.
+ */
+function drupal_implode_tags($tags) {
+  $encoded_tags = array();
+  foreach ($tags as $tag) {
+    // Commas and quotes in tag names are special cases, so encode them.
+    if (strpos($tag, ',') !== FALSE || strpos($tag, '"') !== FALSE) {
+      $tag = '"'. str_replace('"', '""', $tag) .'"';
+    }
+
+    $encoded_tags[] = $tag;
+  }
+  return implode(', ', $encoded_tags);
+}
\ No newline at end of file
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.553
diff -u -u -p -r1.553 comment.module
--- modules/comment/comment.module	15 Jun 2007 07:10:47 -0000	1.553
+++ modules/comment/comment.module	18 Jun 2007 22:25:05 -0000
@@ -2061,3 +2061,91 @@ function int2vancode($i = 0) {
 function vancode2int($c = '00') {
   return base_convert(substr($c, 1), 36, 10);
 }
+
+/**
+ * Implementation of hook_action_info().
+ */
+function comment_action_info() {
+  return array(
+    'comment_unpublish_action' => array(
+      'description' => t('Unpublish comment'),
+      'type' => 'comment',
+      'configurable' => FALSE,
+      'hooks' => array(
+        'comment' => array('insert', 'update', 'view'),
+      )
+    ),
+    'comment_unpublish_by_keyword_action' => array(
+      'description' => t('Unpublish comment containing keyword(s)'),
+      'type' => 'comment',
+      'configurable' => TRUE,
+      'hooks' => array(
+        'comment' => array('insert', 'update'),
+      )
+    )
+  );
+}
+
+/**
+ * Drupal action to unpublish a comment.
+ *
+ * @param $context
+ *   Keyed array. Must contain the id of the comment if $comment is not passed.
+ * @param $comment
+ *   An optional comment object.
+ */
+function comment_unpublish_action($comment, $context = array()) {
+  if (isset($comment->cid)) {
+    $cid = $comment->cid;
+    $subject = $comment->subject;
+  }
+  else {
+    $cid = $context['cid'];
+    $subject = db_result(db_query("SELECT subject FROM {comments} WHERE cid = %d", $cid));
+  }
+  db_query('UPDATE {comments} SET status = %d WHERE cid = %d', COMMENT_NOT_PUBLISHED, $cid);
+  watchdog('action', 'Unpublished comment %subject.', array('%subject' => $subject));
+}
+
+function comment_unpublish_by_keyword_action_form($context) {
+  if (!module_exists('taxonomy')) {
+    $form['warning'] = array(
+      '#prefix' => "<div class='error'>",
+      '#suffix' => '</div>',
+      '#value' => t('This action requires the !taxonomy_module to be enabled.', array('!taxonomy_module' => l('taxonomy module', 'admin/build/modules'))),
+      '#weight' => -8,
+    );
+  }
+  $form['keywords'] = array(
+    '#title' => t('Keywords'),
+    '#type' => 'textfield',
+    '#description' => t('The comment will be unpublished if it contains any of the character sequences above. Use a comma-separated list of character sequences. Example: funny, bungee jumping, "Company, Inc.".'),
+    '#default_value' => isset($context['keywords']) ? drupal_implode_tags($context['keywords']) : '',
+  );
+  return $form;
+}
+
+function comment_unpublish_by_keyword_action_submit($form, $form_state) {
+  return array('keywords' => drupal_explode_tags($form_state['values']['keywords']));
+}
+
+/**
+ * Implementation of a configurable Drupal action.
+ * Unpublish a comment if it contains a certain string.
+ *
+ * @param $context
+ *   An array providing more information about the context of the call to this action.
+ *   Unused here since this action currently only supports the insert and update ops of
+ *   the comment hook, both of which provide a complete $comment object.
+ * @param $comment
+ *   A comment object.
+ */
+function comment_unpublish_by_keyword_action($comment, $context) {
+  foreach ($context['keywords'] as $keyword) {
+    if (strstr($comment->comment, $keyword)) {
+      db_query('UPDATE {comments} SET status = %d WHERE cid = %d', COMMENT_NOT_PUBLISHED, $comment->cid);
+      watchdog('action', 'Unpublished comment %subject.', array('%subject' => $comment->subject));
+      break;
+    }
+  }
+}
\ No newline at end of file
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.833
diff -u -u -p -r1.833 node.module
--- modules/node/node.module	18 Jun 2007 16:09:38 -0000	1.833
+++ modules/node/node.module	18 Jun 2007 22:25:05 -0000
@@ -613,6 +613,8 @@ function node_load($param = array(), $re
  * Save a node object into the database.
  */
 function node_save(&$node) {
+  // Let modules modify the node before it is saved to the database.
+  node_invoke_nodeapi($node, 'presave');
   global $user;
 
   $node->is_new = FALSE;
@@ -3109,3 +3111,199 @@ function node_forms() {
   }
   return $forms;
 }
+
+/**
+ * Implementation of hook_action_info().
+ */
+function node_action_info() {
+  return array(
+    'node_publish_action' => array(
+      'type' => 'node',
+      'description' => t('Publish post'),
+      'configurable' => FALSE,
+      'hooks' => array(
+        'nodeapi' => array('presave','insert','update', 'view'),
+        'comment' => array('delete','insert','update', 'view'),
+      ),
+    ),
+    'node_unpublish_action' => array(
+      'type' => 'node',
+      'description' => t('Unpublish post'),
+      'configurable' => FALSE,
+      'hooks' => array(
+        'nodeapi' => array('presave','insert','update', 'view'),
+        'comment' => array('delete','insert','update', 'view'),
+      ),
+    ),
+    'node_make_sticky_action' => array(
+      'type' => 'node',
+      'description' => t('Make post sticky'),
+      'configurable' => FALSE,
+      'hooks' => array(
+        'nodeapi' => array('presave','insert','update', 'view'),
+        'comment' => array('delete','insert','update', 'view'),
+      ),
+    ),
+    'node_make_unsticky_action' => array(
+      'type' => 'node',
+      'description' => t('Make post unsticky'),
+      'configurable' => FALSE,
+      'hooks' => array(
+        'nodeapi' => array('presave','insert','update', 'view'),
+        'comment' => array('delete','insert','update', 'view'),
+      ),
+    ),
+    'node_promote_action' => array(
+      'type' => 'node',
+      'description' => t('Promote post to front page'),
+      'configurable' => FALSE,
+      'hooks' => array(
+        'nodeapi' => array('presave','insert','update', 'view'),
+        'comment' => array('delete','insert','update', 'view'),
+      ),
+    ),
+    'node_unpromote_action' => array(
+      'type' => 'node',
+      'description' => t('Remove post from node page'),
+      'configurable' => FALSE,
+      'hooks' => array(
+        'nodeapi' => array('presave','insert','update', 'view'),
+        'comment' => array('delete','insert','update', 'view'),
+      ),
+    ),
+    'node_assign_owner_action' => array(
+      'type' => 'node',
+      'description' => t('Change the author of a post'),
+      'configurable' => TRUE,
+      'hooks' => array(
+        'nodeapi' => array('presave','insert','update', 'view'),
+        'comment' => array('delete','insert','update', 'view'),
+      ),
+    ),
+    'node_save_action' => array(
+      'type' => 'node',
+      'description' => t('Save post'),
+      'configurable' => FALSE,
+      'hooks' => array(
+        'nodeapi' => array('delete','insert','update', 'view'),
+        'comment' => array('delete','insert','update', 'view'),
+      ),
+    ),
+  );
+}
+
+/**
+ * Implementation of a Drupal action.
+ * Sets the status of a node to 1, meaning published.
+ */
+function node_publish_action(&$node, $context = array()) {
+  $node->status = 1;
+  watchdog('action', 'Set @type %title to published.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
+}
+
+/**
+ * Implementation of a Drupal action.
+ * Sets the status of a node to 0, meaning unpublished.
+ */
+function node_unpublish_action(&$node, $context = array()) {
+  $node->status = 0;
+  watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
+}
+
+/**
+ * Implementation of a Drupal action.
+ * Sets the sticky-at-top-of-list property of a node to 1.
+ */
+function node_make_sticky_action(&$node, $context = array()) {
+  $node->sticky = 1;
+  watchdog('action', 'Set @type %title to sticky.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
+}
+
+/**
+ * Implementation of a Drupal action.
+ * Sets the sticky-at-top-of-list property of a node to 1.
+ */
+function node_make_unsticky_action(&$node, $context = array()) {
+  $node->sticky = 0;
+  watchdog('action', 'Set @type %title to unsticky.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
+}
+
+/**
+ * Implementation of a Drupal action.
+ * Sets the promote property of a node to 1.
+ */
+function node_promote_action($op, &$node, $context = array()) {
+  $node->promote = 1;
+  watchdog('action', 'Promoted @type %title to front page.', array('@type' => node_get_types('type', $node), '%title' => $node->title));
+}
+
+/**
+ * Implementation of a Drupal action.
+ * Sets the promote property of a node to 0.
+ */
+function node_unpromote_action($op, &$node, $context = array()) {
+  $node->promote = 1;
+  watchdog('action', 'Removed @type %title from front page.', array('@type' => node_get_types('type', $node), '%title' => $node->title));
+}
+
+/**
+ * Implementation of a configurable Drupal action.
+ * Assigns ownership of a node to a user.
+ */
+function node_assign_owner_action(&$node, $context = array()) {
+  $uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $context['owner_name']));
+  $node->uid = $uid;
+  watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' => node_get_types('type', $node), '%title' => $node->title, '%name' => $context['owner_name']));
+}
+
+function node_assign_owner_action_form($context) {
+  $description = t('The username of the user to which you would like to assign ownership.');
+  $count = db_result(db_query("SELECT COUNT(*) FROM {users}"));
+  // Use dropdown for fewer than 200 users; textbox for more than that.
+  if (intval($count) < 200) {
+    $options = array();
+    $result = db_query("SELECT uid, name FROM {users} WHERE uid > 0 ORDER BY name");
+    while ($data = db_fetch_object($result)) {
+      $options[$data->name] = $data->name;
+    }
+    $form['owner_name'] = array(
+      '#type' => 'select',
+      '#title' => t('Username'),
+      '#default_value' => isset($context['owner_name']) ? $context['owner_name'] : '',
+      '#options' => $options,
+      '#description' => $description,
+     );
+    }
+    else {
+      $form['owner_name'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Username'),
+        '#default_value' => isset($context['owner_name']) ? $context['owner_name'] : '',
+        '#autocomplete_path' => 'user/autocomplete',
+        '#size' => '6',
+        '#maxlength' => '7',
+        '#description' => $description,
+      );
+    }
+    return $form;
+}
+
+function node_assign_owner_action_validate($form, $form_state) {
+  $count = db_result(db_query("SELECT COUNT(*) FROM {users} WHERE name = '%s'", $form_state['values']['owner_name']));
+  if (intval($count) != 1) {
+    form_set_error('owner_name', t('Please enter a valid username.'));
+  }
+}
+
+function node_assign_owner_action_submit($form, $form_state) {
+  return array('owner_name' => $form_state['values']['owner_name']);
+}
+
+/**
+ * Implementation of a configurable Drupal action.
+ * Saves a node.
+ */
+function node_save_action($node) {
+  node_save($node);
+  watchdog('action', 'Saved @type %title', array('@type' => node_get_types('type', $node), '%title' => $node->title));
+}
\ No newline at end of file
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.493
diff -u -u -p -r1.493 system.module
--- modules/system/system.module	17 Jun 2007 10:49:49 -0000	1.493
+++ modules/system/system.module	18 Jun 2007 22:25:05 -0000
@@ -2718,3 +2718,213 @@ function system_batch_page() {
     print theme('page', $output, FALSE, FALSE);
   }
 }
+
+/**
+ * Implementation of hook_action_info().
+ */
+function system_action_info() {
+  return array(
+    'system_message_action' => array(
+      'type' => 'system',
+      'description' => t('Display a message to the user'),
+      'configurable' => TRUE,
+      'hooks' => array(
+        'nodeapi' => array('view', 'insert', 'update', 'delete'),
+        'comment' => array('view', 'insert', 'update', 'delete'),
+        'user' => array('view', 'insert', 'update', 'delete', 'login'),
+      ),
+    ),
+    'system_send_email_action' => array(
+      'description' => t('Send e-mail'),
+      'type' => 'system',
+      'configurable' => TRUE,
+      'hooks' => array(
+        'nodeapi' => array('view', 'insert', 'update', 'delete'),
+        'comment' => array('view', 'insert', 'update', 'delete'),
+        'user' => array('view', 'insert', 'update', 'delete', 'login'),
+      )
+    )
+  );
+}
+
+/**
+ * Implementation of a configurable Drupal action.
+ * Sends an email.
+ */
+function system_send_email_action($object, $context) {
+  switch($context['hook']) {
+    case 'nodeapi':
+      $node = $object;
+      break;
+    // The comment hook also provides the node, in context.
+    case 'comment':
+      $node = node_load($object['nid']);
+    case 'user':
+      $account = $object;
+      break;
+  }
+
+  // Note this is the user who owns the node, not global $user.
+  if (!isset($account)) {
+    $account = user_load(array('uid' => $node->uid));
+  }
+  $from = variable_get('site_mail', ini_get('sendmail_from'));
+  $subject = $context['subject'];
+  $message = $context['message'];
+  if (isset($node) && ($context['recipient'] == '%author')) {
+    $recipient = $account->mail;
+  }
+  else {
+    $recipient = $context['recipient'];
+  }
+  $variables['%site_name'] = variable_get('site_name', 'Drupal');
+  $variables['%username'] = $account->name;
+
+  // Node-based variable translation is only available if we have a node.
+  if (isset($node) && is_object($node)) {
+    $variables = array_merge(
+      $variables,
+      array(
+        '%username' => $account->name,
+        '%uid' => $node->uid,
+        '%node_url' => drupal_urlencode(url('node/' . $node->nid, NULL, NULL, TRUE)),
+        '%node_type' => $node->type,
+        '%title' => $node->title,
+        '%teaser' => $node->teaser,
+        '%body' => $node->body
+      )
+    );
+
+    $subject = strtr($subject, $variables);
+    $subject = str_replace(array("\r", "\n"), '', $subject);
+    $message = strtr($message, $variables);
+    $body = drupal_html_to_plain($message);
+  }
+  if (drupal_mail('action_send_email', $recipient, $subject, $message, $from )) {
+    watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
+  }
+  else {
+    watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
+  }
+}
+
+/**
+ * Return a form definition so the Send email action can be configured.
+ *
+ * @param $context
+ *   Default values (if we are editing an existing action instance).
+ * @return
+ *   Form definition.
+ */
+function system_send_email_action_form($context) {
+  // Set default values for form.
+  if (!isset($context['recipient'])) {
+    $context['recipient'] = '';
+  }
+  if (!isset($context['subject'])) {
+    $context['subject'] = '';
+  }
+  if (!isset($context['message'])) {
+    $context['message'] = '';
+  }
+
+  $form['recipient'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Recipient'),
+    '#default_value' => $context['recipient'],
+    '#size' => '20',
+    '#maxlength' => '254',
+    '#description' => t('The email address to which the message should be sent OR enter %author if you would like to send an e-mail to the original author of the post.', array('%author' => '%author')),
+  );
+  $form['subject'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Subject'),
+    '#default_value' => $context['subject'],
+    '#size' => '20',
+    '#maxlength' => '254',
+    '#description' => t('The subject of the message.'),
+  );
+  $form['message'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Message'),
+    '#default_value' => $context['message'],
+    '#cols' => '80',
+    '#rows' => '20',
+    '#description' => t('The message that should be sent. You may include the following variables: %site_name, %username, %node_url, %node_type, %title, %teaser, %body. Not all variables will be available in all contexts.'),
+  );
+  return $form;
+}
+
+function system_send_email_action_validate($form, $form_state) {
+  $form_values = $form_state['values'];
+  // Validate the configuration form.
+  if (!valid_email_address($form_values['recipient']) && $form_values['recipient'] != '%author') {
+    // We want the literal %author placeholder to be emphasized in the error message.
+    form_set_error('recipient', t('Please enter a valid email address or %author.', array('%author' => '%author')));
+   }
+}
+
+function system_send_email_action_submit($form, $form_state) {
+  $form_values = $form_state['values'];
+  // Process the HTML form to store configuration. The keyed array that
+  // we return will be serialized to the database.
+  $params = array(
+    'recipient' => $form_values['recipient'],
+    'subject'   => $form_values['subject'],
+    'message'   => $form_values['message'],
+  );
+  return $params;
+}
+
+function system_message_action_form($context) {
+  $form['message'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Message'),
+    '#default_value' => isset($context['message']) ? $context['message'] : '',
+    '#required' => TRUE,
+    '#rows' => '8',
+    '#description' => t('The message to be displayed to the current user.  You may include the following variables: %site_name, %username, %node_url, %node_type, %title, %teaser, %body.'),
+    );
+  return $form;
+}
+
+function system_message_action_submit($form, $form_state) {
+  return array('message' => $form_state['values']['message']);
+}
+
+/**
+ * Implementation of a configurable Drupal action.
+ * Sends a configurable message to the current user's screen.
+ */
+function system_message_action(&$object, $context = array()) {
+  global $user;
+
+  // This action can be called in any context, but if placeholders
+  // are used a node object must be present to be the source
+  // of substituted text.
+  switch($context['hook']) {
+    case 'nodeapi':
+      $node = &$object;
+      break;
+    // The comment hook gives us the nid of the node.
+    case 'comment':
+      $node = node_load($object['nid']);
+  }
+  $variables = array(
+    '%site_name' => variable_get('site_name', 'drupal'),
+    '%username' => $user->name ? $user->name : variable_get('anonymous', t('Anonymous')),
+   );
+
+  if (isset($node) && is_object($node)) {
+    $variables += array(
+      '%uid' => $node->uid,
+      '%node_url' => url('node/' . $node->nid, NULL, NULL, TRUE),
+      '%node_type' => check_plain($node->type),
+      '%title' => filter_xss($node->title),
+      '%teaser' => filter_xss($node->teaser),
+      '%body' => filter_xss($node->body),
+    );
+  }
+  $context['message'] = strtr($context['message'], $variables);
+  drupal_set_message($context['message']);
+}
\ No newline at end of file
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.360
diff -u -u -p -r1.360 taxonomy.module
--- modules/taxonomy/taxonomy.module	17 Jun 2007 10:47:12 -0000	1.360
+++ modules/taxonomy/taxonomy.module	18 Jun 2007 22:25:05 -0000
@@ -824,7 +824,7 @@ function taxonomy_node_save($node, $term
     unset($terms['tags']);
 
     foreach ($typed_input as $vid => $vid_value) {
-      $typed_terms = taxonomy_explode_tags($vid_value);
+      $typed_terms = drupal_explode_tags($vid_value);
 
       $inserted = array();
       foreach ($typed_terms as $typed_term) {
@@ -1500,7 +1500,7 @@ function _taxonomy_get_tid_from_term($te
  */
 function taxonomy_autocomplete($vid, $string = '') {
   // The user enters a comma-separated list of tags. We only autocomplete the last tag.
-  $array = taxonomy_explode_tags($string);
+  $array = drupal_explode_tags($string);
 
   // Fetch last tag
   $last_string = trim(array_pop($array));
@@ -1524,30 +1524,6 @@ function taxonomy_autocomplete($vid, $st
 }
 
 /**
- * Explode a string of given tags into an array.
- */
-function taxonomy_explode_tags($tags) {
-  // This regexp allows the following types of user input:
-  // this, "somecompany, llc", "and ""this"" w,o.rks", foo bar
-  $regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
-  preg_match_all($regexp, $tags, $matches);
-  $typed_tags = array_unique($matches[1]);
-
-  $tags = array();
-  foreach ($typed_tags as $tag) {
-    // If a user has escaped a term (to demonstrate that it is a group,
-    // or includes a comma or quote character), we remove the escape
-    // formatting so to save the term into the database as the user intends.
-    $tag = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\1', $tag)));
-    if ($tag != "") {
-      $tags[] = $tag;
-    }
-  }
-
-  return $tags;
-}
-
-/**
  * Implode a list of tags of a certain vocabulary into a string.
  */
 function taxonomy_implode_tags($tags, $vid = NULL) {
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.799
diff -u -u -p -r1.799 user.module
--- modules/user/user.module	17 Jun 2007 11:59:05 -0000	1.799
+++ modules/user/user.module	18 Jun 2007 22:25:05 -0000
@@ -3186,3 +3186,60 @@ function _user_password_dynamic_validati
     $complete = TRUE;
   }
 }
+
+/**
+ * Implementation of hook_action_info().
+ */
+function user_action_info() {
+  return array(
+    'user_block_user_action' => array(
+      'description' => t('Block current user'),
+      'type' => 'user',
+      'configurable' => FALSE,
+      'hooks' => array(
+        'user' => array('view', 'insert', 'update', 'delete', 'login', 'logout'),
+        'nodeapi' => array('presave', 'delete','insert','update','view'),
+        'comment' => array('view', 'insert', 'update', 'delete'),
+        ),
+      ),
+    'user_block_ip_action' => array(
+      'description' => t('Ban IP address of current user'),
+      'type' => 'user',
+      'configurable' => FALSE,
+      'hooks' => array(
+        'user' => array('view', 'insert', 'update', 'delete', 'login', 'logout'),
+        'nodeapi' => array('presave', 'delete','insert','update','view'),
+        'comment' => array('view', 'insert', 'update', 'delete'),
+      )
+    )
+  );
+}
+
+/**
+ * Implementation of a Drupal action.
+ * Blocks the current user.
+ */
+function user_block_user_action(&$object, $context = array()) {
+  if (isset($object->uid)) {
+    $uid = $object->uid;
+  }
+  elseif (isset($context['uid'])) {
+    $uid = $context['uid'];
+  }
+  else {
+    global $user;
+    $uid = $user->uid;
+  }
+  db_query("UPDATE {users} SET status = 0 WHERE uid = %d", $uid);
+  sess_destroy_uid($uid);
+  watchdog('action', 'Blocked user %name.', array('%name' => check_plain($user->name)));
+}
+
+/**
+ * Implementation of a Drupal action.
+ * Adds an access rule that blocks the user's IP address.
+ */
+function user_block_ip_action() {
+  db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $_SERVER['REMOTE_ADDR'], 'host', 0);
+  watchdog('action', 'Banned IP address %ip', array('%ip' => $_SERVER['REMOTE_ADDR']));
+}
\ No newline at end of file
Index: modules/actions/actions.info
===================================================================
RCS file: modules/actions/actions.info
diff -N modules/actions/actions.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/actions/actions.info	18 Jun 2007 22:25:06 -0000
@@ -0,0 +1,6 @@
+; $Id$
+name = Actions
+description = Enables triggerable Drupal actions.
+package = Core - optional
+version = VERSION
+core = 6.x
\ No newline at end of file
Index: modules/actions/actions.install
===================================================================
RCS file: modules/actions/actions.install
diff -N modules/actions/actions.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/actions/actions.install	18 Jun 2007 22:25:06 -0000
@@ -0,0 +1,25 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install().
+ */
+function actions_install() {
+  // Create tables.
+  drupal_install_schema('actions');
+  variable_set('actions_next_id', 0);
+
+  // Do initial sychronization of actions in code and the database.
+  // For that we need to run code from actions.module.
+  drupal_load('module', 'actions');
+  actions_synchronize(actions_list());
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function actions_uninstall() {
+  // Remove tables.
+  drupal_uninstall_schema('actions');
+  variable_del('actions_next_id');
+}
\ No newline at end of file
Index: modules/actions/actions.module
===================================================================
RCS file: modules/actions/actions.module
diff -N modules/actions/actions.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/actions/actions.module	18 Jun 2007 22:25:06 -0000
@@ -0,0 +1,981 @@
+<?php
+// $Id$
+
+/**
+* @file
+* Enables functions to be stored and executed at a later time when
+* triggered by other modules or by one of Drupal's core API hooks.
+*/
+
+/**
+* Implementation of hook_help().
+*/
+function actions_help($section) {
+  $output = '';
+  $explanation = t('Actions are functions that Drupal can execute when certain events happen, such as when a node is added or a user logs in. ');
+  switch ($section) {
+    case 'admin/build/actions/manage':
+      $output = '<p>'. $explanation . t('This page lists all actions that are available. Simple actions that do not require any configuration are listed automatically. Actions that need to be configured are listed in the dropdown below. To add a configurable action, select the action and click the <em>Configure</em> button. After completing the configuration form, the action will be available for use by Drupal.') . '</p>';
+      break;
+    case 'admin/build/actions/config':
+      $output = '<p>'. t('This is where you configure a certain action that will be performed at some time in the future. For example, you might configure an action to send email to your friend Royce. Your entry in the description field, below, should be descriptive enough to remind you of that.') . '</p>';
+      break;
+    case 'admin/build/actions/assign/comment':
+      $output = '<p>'. $explanation . t('Below you can assign actions to run when certain comment-related operations happen. For example, you could unpublish a node when a comment is added.') . '</p>';
+      break;
+    case 'admin/build/actions/assign/node':
+      $output = '<p>' . $explanation . t('Below you can assign actions to run when certain node-related operations happen. For example, you could remove a node from the front page when the node is updated. Note that if you are running actions that modify the characteristics of a node, you will need to add the %node_save action to save the changes.', array('%node_save' => t('Save node'))) . '</p>';
+      break;
+    case 'admin/build/actions/assign/user':
+      $output = '<p>'. $explanation . t("Below you can assign actions to run when certain user-related operations happen. For example, you could block a user when the user's account is edited by assigning the %block_user action to the user %update operation.", array('%block_user' => t('Block user'), '%update' => t('update'))) . '</p>';
+      break;
+    case 'admin/build/actions/assign/cron':
+      $output = '<p>'. t('Actions are functions that Drupal can execute when certain events happen, such as when a node is added or a user logs in. Below you can assign actions to run when cron runs.') . '</p>';
+      break;
+  }
+
+  return $output;
+}
+
+/**
+* Implementation of hook_menu().
+*/
+function actions_menu() {
+  $items['admin/build/actions'] = array(
+    'title' => 'Actions',
+    'description' => 'Manage the actions defined for your site.',
+    'access arguments' => array('administer actions'),
+    'page callback' => 'actions_assign'
+  );
+  $items['admin/build/actions/manage'] = array(
+    'title' => 'Manage actions',
+    'page callback' => 'actions_manage',
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 2,
+  );
+  $items['admin/build/actions/assign'] = array(
+    'title' => 'Assign actions',
+    'description' => 'Tell Drupal when to execute actions.',
+    'page callback' => 'actions_assign',
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+  );
+  $items['admin/build/actions/assign/node'] = array(
+    'title' => 'Node',
+    'page callback' => 'actions_assign',
+    'page arguments' => array('node'),
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['admin/build/actions/assign/user'] = array(
+    'title' => 'User',
+    'page callback' => 'actions_assign',
+    'page arguments' => array('user'),
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['admin/build/actions/assign/comment'] = array(
+    'title' => 'Comment',
+    'page callback' => 'actions_assign',
+    'page arguments' => array('comment'),
+    'access callback' => 'module_exists',
+    'access arguments' => array('comment'),
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['admin/build/actions/assign/cron'] = array(
+    'title' => 'Cron',
+    'page callback' => 'actions_assign',
+    'page arguments' => array('cron'),
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['admin/build/actions/assign/remove'] = array(
+    'title' => 'Unassign',
+    'description' => 'Remove an action assignment.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('actions_assign_remove'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/build/actions/config'] = array(
+    'title' => 'Configure an action',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('actions_configure'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/build/actions/assign/delete'] = array(
+    'title' => 'Delete action',
+    'description' => 'Delete an action.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('actions_delete_form'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/build/actions/orphan'] = array(
+    'title' => 'Remove orphans',
+    'page callback' => 'actions_remove_orphans',
+    'type' => MENU_CALLBACK,
+  );
+  return $items;
+}
+
+/**
+* Implementation of hook_perm().
+*/
+function actions_perm() {
+  return array('administer actions');
+}
+
+/**
+ * Menu callback.
+ * Display an overview of available and configured actions.
+  */
+function actions_manage() {
+  $output = '';
+  $actions = actions_list();
+  actions_synchronize($actions);
+  $actions_map = actions_actions_map($actions);
+  $options = array(t('Choose a configurable action'));
+  $unconfigurable = array();
+
+  foreach ($actions_map as $key => $array) {
+    if ($array['configurable']) {
+      $options[$key] = $array['description'] . '...';
+    }
+    else {
+      $unconfigurable[] = $array;
+    }
+  }
+
+  $row = array();
+  $instances_present = db_fetch_object(db_query("SELECT aid FROM {actions} WHERE parameters != ''"));
+  $header = array(
+    array('data' => t('Action Type'), 'field' => 'type'),
+    array('data' => t('Description'), 'field' => 'description'),
+    array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2')
+  );
+  $sql = 'SELECT * FROM {actions}';
+  $result = pager_query($sql . tablesort_sql($header), 50);
+  while ($action = db_fetch_object($result)) {
+    $row[] = array(
+      array('data' => $action->type),
+      array('data' => $action->description),
+      array('data' => $action->parameters ? l(t('configure'), "admin/build/actions/config/$action->aid") : ''),
+      array('data' => $action->parameters ? l(t('delete'), "admin/build/actions/delete/$action->aid") : '')
+    );
+  }
+
+  if ($row) {
+    $pager = theme('pager', NULL, 50, 0);
+    if (!empty($pager)) {
+      $row[] = array(array('data' => $pager, 'colspan' => '3'));
+    }
+    $output .= '<h3>' . t('Actions available to Drupal:') . '</h3>';
+    $output .= theme('table', $header, $row);
+  }
+
+  if ($actions_map) {
+    $output .= '<h3>' . t('Make a new configurable action instance available:') . '</h3>';
+    $output .= '<p>' . drupal_get_form('actions_manage_form', $options) . '</p>';
+  }
+
+  return $output;
+}
+
+/**
+ * Define the form for the actions overview page.
+ *
+ * @param $options
+ *   An array of configurable actions.
+ * @return
+ *   Form definition.
+ */
+function actions_manage_form($form_state, $options = array()) {
+  $form['parent'] = array(
+    '#prefix' => "<div class='container-inline'>",
+    '#suffix' => '</div>',
+  );
+  $form['parent']['action'] = array(
+    '#type' => 'select',
+    '#default_value' => '',
+    '#options' => $options,
+    '#description' => '',
+  );
+  $form['parent']['buttons']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Configure'),
+  );
+  return $form;
+}
+
+function actions_manage_form_submit($form, &$form_state) {
+  if ($form_state['values']['action']) {
+    $form_state['redirect'] = 'admin/build/actions/config/' . $form_state['values']['action'];
+  }
+}
+
+/**
+ * Menu callback. Create the form for configuration of a single action.
+ * We provide the "Description" field. The rest of the form
+ * is provided by the action. We then provide the Save button.
+ * Because we are combining unknown form elements with the action
+ * configuration form, we use actions_ prefix on our elements.
+ *
+ * @param $action
+ *   md5 hash of action ID or an integer. If it's an md5 hash, we
+ *   are creating a new instance. If it's an integer, we're editing
+ *   an existing instance.
+ */
+function actions_configure($form_state, $action = NULL) {
+  if ($action === NULL) {
+    drupal_goto('admin/build/actions');
+  }
+
+  $actions_map = actions_actions_map(actions_list());
+  $edit = array();
+
+  // Numeric action denotes saved instance of a configurable action;
+  // else we are creating a new action instance.
+  if (is_numeric($action)) {
+    $aid = $action;
+    // Load stored parameter values from database.
+    $data = db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", intval($aid)));
+    $edit['actions_description'] = $data->description;
+    $edit['actions_type'] = $data->type;
+    $function = $data->callback;
+    $action = md5($data->callback);
+    $params = unserialize($data->parameters);
+    if ($params) {
+      foreach ($params as $name => $val) {
+        $edit[$name] = $val;
+      }
+    }
+  }
+  else {
+    $function = $actions_map[$action]['callback'];
+    $edit['actions_description'] = $actions_map[$action]['description'];
+    $edit['actions_type'] = $actions_map[$action]['type'];
+  }
+
+
+  $form['actions_description'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Description'),
+    '#default_value' => $edit['actions_description'],
+    '#size' => '70',
+    '#maxlength' => '255',
+    '#description' => t('A unique description for this configuration of this action. This will be used to describe this action when assigning actions.'),
+    '#weight' => -10
+  );
+  $action_form = $function . '_form';
+  $form = array_merge($form, $action_form($edit));
+  $form['actions_type'] = array(
+    '#type' => 'value',
+    '#value' => $edit['actions_type'],
+  );
+  $form['actions_action'] = array(
+    '#type' => 'hidden',
+    '#value' => $action,
+  );
+  // $aid is set when configuring an existing action instance.
+  if (isset($aid)) {
+    $form['actions_aid'] = array(
+      '#type' => 'hidden',
+      '#value' => $aid,
+    );
+  }
+  $form['actions_configured'] = array(
+    '#type' => 'hidden',
+    '#value' => '1',
+  );
+  $form['buttons']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+    '#weight' => 13
+  );
+
+  return $form;
+}
+
+function actions_configure_validate($form, $form_state) {
+  $function = actions_function_lookup($form_state['values']['actions_action']) . '_validate';
+  // Hand off validation to the action.
+  if (function_exists($function)) {
+    $function($form, $form_state);
+  }
+}
+
+function actions_configure_submit($form, &$form_state) {
+  $function = actions_function_lookup($form_state['values']['actions_action']);
+  $submit_function = $function . '_submit';
+
+  // Action will return keyed array of values to store.
+  $params = $submit_function($form, $form_state);
+  $aid = isset($form_state['values']['actions_aid']) ? $form_state['values']['actions_aid'] : NULL;
+
+  actions_save($function, $form_state['values']['actions_type'], $params, $form_state['values']['actions_description'], $aid);
+  drupal_set_message(t('The action has been successfully saved.'));
+
+  $form_state['redirect'] = 'admin/build/actions/manage';
+}
+
+/**
+ * Create the form for confirmation of deleting an action.
+ *
+ * @param $aid
+ *   The action ID.
+ */
+function actions_delete_form($aid) {
+  if (!$aid) {
+    drupal_goto('admin/build/actions');
+  }
+  $action = actions_load($aid);
+  $form['aid'] = array(
+    '#type' => 'hidden',
+    '#value' => $aid
+  );
+
+  return confirm_form(
+    $form,
+    t('Are you sure you want to delete the action %action?', array('%action' => $action->description)),
+    'admin/build/actions',
+    t('This cannot be undone.'),
+    t('Delete'),
+    t('Cancel')
+  );
+}
+
+function actions_delete_form_submit($form, &$form_state) {
+  // TODO: note that in the future we need to check for dependencies here.
+  $aid = $form_state['values']['aid'];
+  $action = actions_load($aid);
+  actions_delete($aid);
+  $description = check_plain($action->description);
+  watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $aid, '%action' => $description));
+  drupal_set_message(t('Action %action was deleted', array('%action' => $description)));
+  $form_state['redirect'] = 'admin/build/actions';
+}
+
+
+/**
+ * Save an action and its associated user-supplied parameter values to
+ * the database.
+ *
+ * @param $function
+ *   The name of the function to be called when this action is performed.
+ * @param $params
+ *   An associative array with parameter names as keys and parameter values
+ *   as values.
+ * @param $desc
+ *   A user-supplied description of this particular action, e.g., 'Send
+ *   e-mail to Jim'.
+ * @param $aid
+ *   The ID of this action. If omitted, a new action is created.
+ *
+ * @return
+ *   The ID of the action.
+ */
+function actions_save($function, $type, $params, $desc, $aid = NULL) {
+  $serialized = serialize($params);
+  if ($aid) {
+    db_query("UPDATE {actions} SET callback = '%s', type = '%s', parameters = '%s', description = '%s' WHERE aid = %d", $function, $type, $serialized, $desc, $aid);
+    watchdog('user', 'Action %action saved.', array('%action' => $desc));
+  }
+  else {
+    $aid = variable_get('actions_next_id', 0);
+    $aid = $aid + 1;
+    variable_set('actions_next_id', $aid);
+    db_query("INSERT INTO {actions} (aid, callback, type, parameters, description) VALUES (%d, '%s', '%s', '%s', '%s')", $aid, $function, $type, $serialized, $desc);
+    watchdog('user', 'Action %action created.', array('%action' => $desc));
+  }
+
+  return $aid;
+}
+
+/**
+ * Retrieve a single action from the database.
+ *
+ * @param $aid
+ *   integer The ID of the action to retrieve.
+ *
+ * @return
+ *   The appropriate action row from the database as an object.
+ */
+function actions_load($aid) {
+  return db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", $aid));
+}
+
+/**
+ * Delete a single action from the database.
+ *
+ * @param $aid
+ *   integer The ID of the action to delete.
+ */
+function actions_delete($aid) {
+  db_query("DELETE FROM {actions} WHERE aid = %d", $aid);
+}
+
+/**
+ * Synchronize actions that are provided by modules with actions
+ * that are stored in the actions table. This is necessary so that
+ * actions that do not require configuration can receive action IDs.
+ * This is not necessarily the best approach, but it is the most
+ * straightforward.
+ */
+function actions_synchronize($actions_in_code = array(), $delete_orphans = FALSE) {
+  if (!$actions_in_code) {
+    $actions_in_code = actions_list();
+  }
+  $actions_in_db = array();
+  $result = db_query("SELECT * FROM {actions} WHERE parameters = ''");
+  while ($action = db_fetch_object($result)) {
+    $actions_in_db[$action->callback] = array('aid' => $action->aid, 'description' => $action->description);
+  }
+
+  // Go through all the actions provided by modules.
+  foreach ($actions_in_code as $callback => $array) {
+    // Ignore configurable actions since their instances get put in
+    // when the user adds the action.
+    if (!$array['configurable']) {
+      // If we already have an action ID for this action, no need to assign aid.
+      if (array_key_exists($callback, $actions_in_db)) {
+        unset($actions_in_db[$callback]);
+      }
+      else {
+        // This is a new singleton that we don't have an aid for; assign one.
+        db_query("INSERT INTO {actions} (aid, type, callback, parameters, description) VALUES ('%s', '%s', '%s', '%s', '%s')", $callback, $array['type'], $callback, '', $array['description']);
+        drupal_set_message(t("Action '%action' added.", array('%action' => filter_xss_admin($array['description']))));
+      }
+    }
+  }
+
+  // Any actions that we have left in $actions_in_db are orphaned.
+  if ($actions_in_db) {
+    $orphaned = array();
+
+    foreach ($actions_in_db as $callback => $array) {
+      if ($delete_orphans) {
+        db_query("DELETE FROM {actions} WHERE callback = '%s'", $callback);
+        drupal_set_message(t("Deleted orphaned action '%action'.", array('%action' => $callback)));
+      }
+      else {
+        $orphaned[] = $callback;
+      }
+    }
+
+    if (!$delete_orphans) {
+      $orphans = implode(',', $orphaned);
+      $link = l(t('Remove orphaned actions'), 'admin/build/actions/orphan');
+      $count = count($actions_in_db);
+      drupal_set_message(format_plural($count, 'One orphaned action (%orphans) exists in the actions table. !link', '@count orphaned actions (%orphans) exist in the actions table. !link', array('@count' => $count, '%orphans' => $orphans, '!link' => $link), 'warning'));
+    }
+  }
+}
+
+/**
+ * Menu callback. Remove any actions that are in the database but not supported
+ * by any currently enabled module.
+ */
+function actions_remove_orphans() {
+  actions_synchronize(actions_list(), TRUE);
+  drupal_goto('admin/build/actions/manage');
+}
+
+/**
+ * Get the actions that have already been defined for this
+ * type-hook-op combination.
+ *
+ * @param $type
+ *   One of 'node', 'user', 'comment'.
+ * @param $hook
+ *   The name of the hook for which actions have been assigned,
+ *   e.g. 'nodeapi'.
+ * @param $op
+ *   The hook operation for which the actions have been assigned,
+ *   e.g., 'view'.
+ * @return
+ *   An array of action descriptions keyed by action IDs.
+ */
+function _actions_get_hook_actions($hook, $op, $type = NULL) {
+  $actions = array();
+  if ($type) {
+    $result = db_query("SELECT h.aid, a.description FROM {actions_assignments} h LEFT JOIN {actions} a on a.aid = h.aid WHERE a.type = '%s' AND h.hook = '%s' AND h.op = '%s' ORDER BY h.weight", $type, $hook, $op);
+  }
+  else {
+    $result = db_query("SELECT h.aid, a.description FROM {actions_assignments} h LEFT JOIN {actions} a on a.aid = h.aid WHERE h.hook = '%s' AND h.op = '%s' ORDER BY h.weight", $hook, $op);
+  }
+  while ($action = db_fetch_object($result)) {
+    $actions[$action->aid] = $action->description;
+  }
+  return $actions;
+}
+
+/**
+ * Get the aids of actions to be executed for a hook-op combination.
+ *
+ * @param $hook
+ *   The name of the hook being fired.
+ * @param $op
+ *   The name of the operation being executed. Defaults to an empty string
+ *   because some hooks (e.g., hook_cron()) do not have operations.
+ * @return
+ *   An array of action IDs.
+ */
+function _actions_get_hook_aids($hook, $op = '') {
+  $aids = array();
+  $result = db_query("SELECT aa.aid, a.type FROM {actions_assignments} aa LEFT JOIN {actions} a ON aa.aid = a.aid WHERE aa.hook = '%s' AND aa.op = '%s' ORDER BY weight", $hook, $op);
+  while ($action = db_fetch_object($result)) {
+    $aids[$action->aid]['type'] = $action->type;
+  }
+  return $aids;
+}
+
+function actions_assign_form($form_state, $hook, $op) {
+  $form['hook'] = array(
+    '#type' => 'hidden',
+    '#value' => $hook,
+  );
+  $form['operation'] = array(
+    '#type' => 'hidden',
+    '#value' => $op,
+  );
+  // All of these forms use the same #submit function.
+  $form['#submit'][] = 'actions_assign_form_submit';
+
+  $options = array();
+  $functions = array();
+  // Restrict the options list to actions that declare support for this hook-op combination.
+  foreach (actions_list() as $func => $metadata) {
+    if (isset($metadata['hooks'][$hook]) && is_array($metadata['hooks'][$hook]) && in_array($op, $metadata['hooks'][$hook])) {
+      $functions[] = $func;
+    }
+  }
+  foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) {
+    if (in_array($action['callback'], $functions)) {
+      $options[$action['type']][$aid] = $action['description'];
+    }
+  }
+
+  $form[$op] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Actions to execute during the @hook %operation operation:', array('@hook' => $hook, '%operation' => $op)),
+    '#theme' => 'actions_display'
+    );
+  // Retrieve actions that are already assigned to this hook-op combination.
+  $actions = _actions_get_hook_actions($hook, $op);
+  $form[$op]['assigned']['#type'] = 'value';
+  $form[$op]['assigned']['#value'] = array();
+  foreach ($actions as $aid => $description) {
+    $form[$op]['assigned']['#value'][$aid] = array(
+      'description' => $description,
+      'link' => l(t('remove'), "admin/build/actions/assign/remove/$hook/$op/" . md5($aid))
+    );
+  }
+
+  $form[$op]['parent'] = array(
+    '#prefix' => "<div class='container-inline'>",
+    '#suffix' => '</div>',
+  );
+  // List possible actions that may be assigned.
+  if (count($options) != 0) {
+    array_unshift($options, t('Choose an action'));
+    $form[$op]['parent']['aid'] = array(
+      '#type' => 'select',
+      '#options' => $options,
+    );
+    $form[$op]['parent']['submit'] = array(
+      '#type' => 'submit',
+      '#value' => t('Assign')
+    );
+  }
+  else {
+    $form[$op]['none'] = array(
+      '#value' => t('No available actions support this context.')
+    );
+  }
+  return $form;
+}
+
+function actions_assign_form_submit($form, $form_state) {
+  $form_values = $form_state['values'];
+  if (isset($form_values['aid']) && $form_values['aid'] != '0') {
+    $aid = actions_function_lookup($form_values['aid']);
+    $weight = db_result(db_query("SELECT MAX(weight) FROM {actions_assignments} WHERE hook = '%s' AND op = '%s'", $form_values['hook'], $form_values['operation']));
+    db_query("INSERT INTO {actions_assignments} values ('%s', '%s', '%s', %d)", $form_values['hook'], $form_values['operation'], $aid, $weight + 1);
+  }
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function actions_theme() {
+  return array(
+    'actions_display' => array(
+      'arguments' => array('element')
+    ),
+  );
+}
+
+/**
+ * Display actions assigned to this hook-op combination in a table.
+ *
+ * @param array $element
+ *   The fieldset including all assigned actions.
+ * @return
+ *   The rendered form with the table prepended.
+ */
+function theme_actions_display($element) {
+  $header = array();
+  $rows = array();
+  if (count($element['assigned']['#value'])) {
+    $header = array(array('data' => t('Name')), array('data' => t('Operation')));
+    $rows = array();
+    foreach ($element['assigned']['#value'] as $aid => $info) {
+      $rows[] = array(
+        $info['description'],
+        $info['link']
+      );
+    }
+  }
+
+  $output = theme('table', $header, $rows) . drupal_render($element);
+  return $output;
+}
+
+/**
+ * Implementation of hook_forms().
+ */
+function actions_forms() {
+  $callback = array('callback' => 'actions_assign_form');
+  return array(
+    'actions_nodeapi_presave_assign_form' => $callback,
+    'actions_nodeapi_insert_assign_form' => $callback,
+    'actions_nodeapi_update_assign_form' => $callback,
+    'actions_nodeapi_delete_assign_form' => $callback,
+    'actions_nodeapi_view_assign_form' => $callback,
+    'actions_comment_insert_assign_form' => $callback,
+    'actions_comment_update_assign_form' => $callback,
+    'actions_comment_delete_assign_form' => $callback,
+    'actions_comment_view_assign_form' => $callback,
+    'actions_user_login_assign_form' => $callback,
+    'actions_user_logout_assign_form' => $callback,
+    'actions_user_insert_assign_form' => $callback,
+    'actions_user_update_assign_form' => $callback,
+    'actions_user_delete_assign_form' => $callback,
+    'actions_user_view_assign_form' => $callback,
+    'actions_cron_run_assign_form' => $callback,
+  );
+}
+
+/**
+ * Build the form that allows users to assign actions to hooks.
+ *
+ * @param $type
+ *   Name of hook.
+ * @return
+ *   HTML form.
+ */
+function actions_assign($type = NULL) {
+  // If no type is specificied we default to node actions, since they
+  // are the most common.
+  if (!isset($type)) {
+    drupal_goto('admin/build/actions/assign/node');
+  }
+
+  switch($type) {
+    case 'nodeapi':
+    case 'node':
+      $output = drupal_get_form('actions_nodeapi_presave_assign_form', 'nodeapi', 'presave');
+      $output .= drupal_get_form('actions_nodeapi_insert_assign_form', 'nodeapi', 'insert');
+      $output .= drupal_get_form('actions_nodeapi_update_assign_form', 'nodeapi', 'update');
+      $output .= drupal_get_form('actions_nodeapi_delete_assign_form', 'nodeapi', 'delete');
+      $output .= drupal_get_form('actions_nodeapi_view_assign_form', 'nodeapi', 'view');
+      break;
+    case 'comment':
+      $output = drupal_get_form('actions_comment_insert_assign_form', 'comment', 'insert');
+      $output .= drupal_get_form('actions_comment_update_assign_form', 'comment', 'update');
+      $output .= drupal_get_form('actions_comment_delete_assign_form', 'comment', 'delete');
+      $output .= drupal_get_form('actions_comment_view_assign_form', 'comment', 'view');
+      break;
+    case 'user':
+      $output = drupal_get_form('actions_user_login_assign_form', 'user', 'login');
+      $output .= drupal_get_form('actions_user_logout_assign_form', 'user', 'logout');
+      $output .= drupal_get_form('actions_user_insert_assign_form', 'user', 'insert');
+      $output .= drupal_get_form('actions_user_update_assign_form', 'user', 'update');
+      $output .= drupal_get_form('actions_user_delete_assign_form', 'user', 'delete');
+      $output .= drupal_get_form('actions_user_view_assign_form', 'user', 'view');
+      break;
+    case 'cron':
+      $output = drupal_get_form('actions_cron_run_assign_form', 'cron', 'run');
+      break;
+   }
+
+  return $output;
+}
+
+/**
+ * Confirm removal of an assigned action.
+ *
+ * @param $hook
+ * @param $op
+ * @param $aid
+ *   The action ID.
+ */
+function actions_assign_remove($form_state, $hook = NULL, $op = NULL, $aid = NULL) {
+  if (!($hook && $op && $aid)) {
+    drupal_goto('admin/build/actions/assign');
+  }
+  $form['hook'] = array(
+    '#type' => 'value',
+    '#value' => $hook
+    );
+  $form['operation'] = array(
+    '#type' => 'value',
+    '#value' => $op
+    );
+  $form['aid'] = array(
+    '#type' => 'value',
+    '#value' => $aid
+    );
+  $action = actions_function_lookup($aid);
+  $actions = actions_get_all_actions();
+  $description = $actions[$action]['description'];
+  return confirm_form(
+    $form,
+    t('Are you sure you want to delete the action %title?', array('%title' => $description)),
+    'admin/build/actions/assign/'. $actions[$action]['type'],
+    t('You can add it again later if you wish.'),
+    t('Delete'),
+    t('Cancel')
+  );
+}
+
+function actions_assign_remove_submit($form, &$form_state) {
+  $form_values = $form_state['values'];
+  if ($form_values['confirm'] == 1) {
+    $aid = actions_function_lookup($form_values['aid']);
+    db_query("DELETE FROM {actions_assignments} WHERE hook = '%s' AND op = '%s' AND aid = '%s'", $form_values['hook'], $form_values['operation'], $aid);
+    $actions = actions_get_all_actions();
+    watchdog('actions', 'Action %action deleted',  array('%action' => check_plain($actions[$aid]['description'])));
+    drupal_set_message(t('Action %action deleted.', array('%action' => $actions[$aid]['description'])));
+    $form_state['redirect'] = 'admin/build/actions/assign/'. $form_values['hook'];
+  }
+  else {
+    drupal_goto('admin/build/actions');
+  }
+}
+
+/**
+ * When an action is called in a context that does not match its type,
+ * the object that the action expects must be retrieved. For example, when
+ * an action that works on users is called during the node hook, the
+ * user object is not available since the node hook doesn't pass it.
+ * So here we load the object the action expects.
+ *
+ * @param $type
+ *   The type of action that is about to be called.
+ * @param $node
+ *   The node that was passed via the nodeapi hook.
+ * @return
+ *   The object expected by the action that is about to be called.
+ */
+function _actions_normalize_node_context($type, $node) {
+  switch($type) {
+    // TODO: An action that works on comments is being called in a node context.
+    // The action is expecting a comment object. Which will we give it?
+    // The first? The most recent? All of them?
+    case 'comment':
+
+    // An action that works on users is being called in a node context.
+    // Load the user object of the node's author.
+    case 'user':
+      return user_load(array('uid' => $node->uid));
+  }
+}
+
+/**
+ * Implementation of hook_nodeapi().
+ */
+function actions_nodeapi($node, $op, $a3, $a4) {
+  // We keep objects for reuse so that changes actions make to objects can persist.
+  static $objects;
+  // We prevent recursion by tracking which operations have already been called.
+  static $recursion;
+  if (!in_array($op, array('view', 'update', 'presave','insert', 'delete')) || isset($recursion[$op])) {
+    return;
+  }
+  $recursion[$op] = TRUE;
+
+  $aids = _actions_get_hook_aids('nodeapi', $op);
+  if (!$aids) {
+    return;
+  }
+  $context = array(
+    'hook' => 'nodeapi',
+    'op' => $op,
+  );
+
+  // We need to get the expected object if the action's type is not 'node'.
+  // We keep the object in $objects so we can reuse it if we have multiple actions
+  // that make changes to an object.
+  foreach ($aids as $aid => $action_info) {
+    if ($action_info['type'] != 'node') {
+      if (!isset($objects[$action_info['type']])) {
+        $objects[$action_info['type']] = _actions_normalize_node_context($action_info['type'], $node);
+      }
+      // Since we know about the node, we pass that info along to the action.
+      $context['node'] = $node;
+      $result = actions_do($aid, $objects[$action_info['type']], $context, $a4, $a4);
+    }
+    else {
+      actions_do($aid, $node, $context, $a3, $a4);
+    }
+
+  }
+}
+
+/**
+ * When an action is called in a context that does not match its type,
+ * the object that the action expects must be retrieved. For example, when
+ * an action that works on nodes is called during the comment hook, the
+ * node object is not available since the comment hook doesn't pass it.
+ * So here we load the object the action expects.
+ *
+ * @param $type
+ *   The type of action that is about to be called.
+ * @param $comment
+ *   The comment that was passed via the comment hook.
+ * @return
+ *   The object expected by the action that is about to be called.
+ */
+function _actions_normalize_comment_context($type, $comment) {
+  switch ($type) {
+    // An action that works with nodes is being called in a comment context.
+    case 'node':
+      return node_load(is_array($comment) ? $comment['nid'] : $comment->nid);
+
+    // An action that works on users is being called in a comment context.
+    case 'user':
+      return user_load(array('uid' => is_array($comment) ? $comment['uid'] : $comment->uid));
+  }
+}
+
+/**
+ * Implementation of hook_comment().
+ */
+function actions_comment($a1, $op) {
+  // We support a subset of ops.
+  if (!in_array($op, array('insert', 'update', 'delete', 'view'))) {
+    return;
+  }
+  $aids = _actions_get_hook_aids('comment', $op);
+  $context = array(
+    'hook' => 'comment',
+    'op' => $op,
+  );
+  static $objects;
+  // We need to get the expected object if the action's type is not 'comment'.
+  // We keep the object in $objects so we can reuse it if we have multiple actions
+  // that make changes to an object.
+  foreach ($aids as $aid => $action_info) {
+    if ($action_info['type'] != 'comment') {
+      //
+      if (!isset($objects[$action_info['type']])) {
+        $objects[$action_info['type']] = _actions_normalize_comment_context($action_info['type'], $a1);
+      }
+      // Since we know about the comment, we pass it along to the action
+      // in case it wants to peek at it.
+      $context['comment'] = (object) $a1;
+      actions_do($aid, $objects[$action_info['type']], $context);
+    }
+    else {
+      actions_do($aid, (object) $a1, $context);
+    }
+  }
+}
+
+/**
+ * Implementation of hook_cron().
+ */
+function actions_cron() {
+  $aids = _actions_get_hook_aids('cron');
+  $context = array(
+    'hook' => 'cron',
+    'op' => '',
+  );
+  // Cron does not act on any specific object.
+  $object = NULL;
+  actions_do(array_keys($aids), $object, $context);
+}
+
+/**
+ * When an action is called in a context that does not match its type,
+ * the object that the action expects must be retrieved. For example, when
+ * an action that works on nodes is called during the user hook, the
+ * node object is not available since the user hook doesn't pass it.
+ * So here we should load the object the action expects.
+ *
+ * @param $type
+ *   The type of action that is about to be called.
+ * @param $account
+ *   The account object that was passed via the user hook.
+ * @return
+ *   The object expected by the action that is about to be called.
+ */
+function _actions_normalize_user_context($type, $account) {
+  switch($type) {
+    // An action that works with nodes is being called in a user context.
+    // E.g., a node action is triggered by a user login.
+    // TODO: how to determine the current node in order to give it
+    // to the action?
+    case 'node':
+
+    // An action that works with comments is being called in a user context
+    // E.g., a comment action is triggered by a user login.
+    // TODO: how to determine the comment to give to the action?
+    case 'comment':
+
+  }
+}
+
+/**
+ * Implementation of hook_user().
+ */
+function actions_user($op, &$edit, &$account, $category = NULL) {
+  // We support a subset of ops.
+  if (!in_array($op, array('login', 'logout', 'insert', 'update', 'delete', 'view'))) {
+    return;
+  }
+  $aids = _actions_get_hook_aids('user', $op);
+  $context = array(
+    'hook' => 'user',
+    'op' => $op,
+    'form_values' => &$edit,
+  );
+  foreach ($aids as $aid => $action_info) {
+    if ($action_info['type'] != 'user') {
+      $object = _actions_normalize_user_context($account);
+      $context['account'] = $account;
+      actions_do($aid, $object, $context);
+    }
+  }
+
+  actions_do($aids, $account, $context, $category);
+}
+
+/**
+ * Often we generate a select field of all actions. This function
+ * generates the options for that select.
+ *
+ * @param $type
+ *   One of 'node', 'user', 'comment'.
+ * @return
+ *   Array keyed by action ID.
+ */
+function actions_options($type = 'all') {
+  $options = array(t('Choose an action'));
+  foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) {
+    $options[$action['type']][$aid] = $action['description'];
+  }
+
+  if ($type == 'all') {
+    return $options;
+  }
+  else {
+    return $options[$type];
+  }
+}
\ No newline at end of file
Index: modules/actions/actions.schema
===================================================================
RCS file: modules/actions/actions.schema
diff -N modules/actions/actions.schema
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/actions/actions.schema	18 Jun 2007 22:25:06 -0000
@@ -0,0 +1,26 @@
+<?php
+// $Id$
+
+function actions_schema() {
+  $schema['actions'] = array(
+    'fields' => array(
+      'aid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'),
+      'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
+      'callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+      'parameters' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big', 'default' => ''),
+      'description' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'),
+    ),
+    'primary key' => array('aid'),
+  );
+  $schema['actions_assignments'] = array(
+    'fields' => array(
+      'hook' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
+      'op' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
+      'aid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+      'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+    ),
+    'index keys' => array(
+      'hook_op' => array('hook', 'op'))
+  );
+  return $schema;
+}
\ No newline at end of file
