From f312734467a90bafdc0e8a92434da562522e6cb6 Mon Sep 17 00:00:00 2001
From: Benedikt Forchhammer <b.forchhammer@mind2.de>
Date: Sat, 26 Feb 2011 16:19:47 +0100
Subject: [PATCH] Applied patches #24, #31, #32, #35

---
 revision_moderation.info        |    5 +-
 revision_moderation.install     |   20 +-
 revision_moderation.module      |  408 ++++++++++++++++++++++++---------------
 revision_moderation_actions.inc |   14 +-
 4 files changed, 270 insertions(+), 177 deletions(-)

diff --git a/revision_moderation.info b/revision_moderation.info
index b7cbcf8..578d8b2 100644
--- a/revision_moderation.info
+++ b/revision_moderation.info
@@ -1,3 +1,6 @@
 name = Revision Moderation
 description = Allows moderation of new node revisions while existing approved revisions stay visible.
-core = "6.x"
\ No newline at end of file
+core = 7.x
+files[] = revision_moderation.module
+files[] = revision_moderation_actions.inc
+
diff --git a/revision_moderation.install b/revision_moderation.install
index 795b141..107274e 100644
--- a/revision_moderation.install
+++ b/revision_moderation.install
@@ -1,22 +1,30 @@
 <?php
 
 /**
+ * @file
+ * Install, update and uninstall functions for the revision_moderation module.
+ */
+
+/**
  * Implementation of hook_schema().
  */ 
 function revision_moderation_schema() {
   $schema['revision_moderation'] = array(
+    'description' => 'holds the last approved revision of the node',
     'fields' => array(
       'nid' => array(
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
+        'description' => 'Node ID',
         'default' => 0
       ),
       'revision_moderation' => array(
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
-        'size' => 'tiny'
+        'size' => 'tiny',
+        'description' => 'last approved revision for the {nid}'
       ),
     ),
     'primary key' => array('nid'),
@@ -26,18 +34,8 @@ function revision_moderation_schema() {
 }
 
 /**
- * Implementation of hook_install().
- */
-function revision_moderation_install() {
-  // Create table
-  drupal_install_schema('revision_moderation');
-}
-  
-/**
  * Implementation of hook_uninstall().
  */
 function revision_moderation_uninstall() {
-  // Drop the table
-  drupal_uninstall_schema('revision_moderation');
   variable_del('revision_moderation_exempt');
 }
diff --git a/revision_moderation.module b/revision_moderation.module
index 329abe9..7e6a8d3 100644
--- a/revision_moderation.module
+++ b/revision_moderation.module
@@ -6,7 +6,7 @@
  */
 
 // Actions module support.
-include_once drupal_get_path('module', 'revision_moderation') .'/revision_moderation_actions.inc';
+include_once drupal_get_path('module', 'revision_moderation') . '/revision_moderation_actions.inc';
 
 /**
  * Implementation of hook_menu().
@@ -16,24 +16,24 @@ function revision_moderation_menu() {
 
   // Admin menu
   $items['admin/content/node/revisions'] = array(
-    'title' => t('Pending revisions'),
+    'title' => 'Pending revisions',
     'page callback' => 'revision_moderation_pending_revisions_admin',
     'access arguments' => array('administer nodes'),
     'type' => MENU_LOCAL_TASK,
   );
 
   // Admin menu
-  $items['admin/settings/revision_moderation'] = array(
-    'title' => t('Revision moderation'),
+  $items['admin/config/content/revision_moderation'] = array(
+    'title' => 'Revision moderation',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('revision_moderation_settings'),
-    'description' => t('Configure revision publishing options.'),
+    'description' => 'Configure revision publishing options.',
     'access arguments' => array('administer nodes'),
   );
 
   // Callback to allow users to edit revisions.
   $items['node/%node/revisions/%/edit'] = array(
-    'title' => t('Edit revision'),
+    'title' => 'Edit revision',
     'load arguments' => array(3),
     'page callback' => 'revision_moderation_edit',
     'page arguments' => array(1),
@@ -46,7 +46,7 @@ function revision_moderation_menu() {
 
   // Callback to allow users to publish revisions directly.
   $items['node/%node/revisions/%/publish'] = array(
-    'title' => t('Publish revision'),
+    'title' => 'Publish revision',
     'load arguments' => array(3),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('revision_moderation_publish_confirm', 1),
@@ -61,7 +61,7 @@ function revision_moderation_menu() {
 /**
  * Menu permission callback.
  */
-function revision_moderation_admin_perm($nid) {
+function revision_moderation_admin_permission($nid) {
   $node = node_load($nid);
   $access = user_access('administer nodes') || (user_access('view revisions') && node_access('update', $node));
   return $access;
@@ -82,160 +82,249 @@ function revision_moderation_settings() {
 }
 
 /**
- * Implementation of hook_form_alter().
+ * Implementation of hook_form_FORM_ID_alter().
  */
-function revision_moderation_form_alter(&$form, $form_state, $form_id) {
-  // On node edit forms, add in the "New revisions in moderation" option.
-  if (isset($form['#id']) && $form['#id'] == 'node-form') {
-    $default_value = in_array('revision_moderation', variable_get("node_options_{$form['type']['#value']}", array('status', 'promote')));
-    if ($form['nid']['#value']) {
-      $result = db_result(db_query('SELECT revision_moderation FROM {revision_moderation} WHERE nid = %d', $form['nid']['#value']));
-      if ($result !== FALSE) {
-        $default_value = $result;
-      }
+function revision_moderation_form_node_form_alter(&$form, &$form_state, $form_id) {
+  $default_value = in_array('revision_moderation', variable_get("node_options_{$form['type']['#value']}", array('status', 'promote')));
+  if ($form['nid']['#value']) {
+    $result = db_query('SELECT revision_moderation FROM {revision_moderation} WHERE nid = :nid', array(':nid' => $form['nid']['#value']))->fetchField();
+    if ($result !== FALSE) {
+      $default_value = $result;
     }
-    // Only show the checkbox if user has 'administer nodes' privileges.
-    if (!empty($node->revision) || user_access('administer nodes')) {
-      $form['revision_information']['revision_moderation'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('New revisions in moderation'),
-        '#default_value' => $default_value,
-      );
+  }
+  // Only show the checkbox if user has 'administer nodes' privileges.
+  if (!empty($node->revision) || user_access('administer nodes')) {
+    $form['revision_information']['revision_moderation'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('New revisions in moderation'),
+      '#default_value' => $default_value,
+    );
+  }
+  else {
+    $form['revision_moderation'] = array(
+      '#type' => 'value',
+      '#value' => $default_value,
+    );
+  }
+}
+
+/**
+ * Implementation of hook_form_FORM_ID_alter().
+ */
+function revision_moderation_form_node_type_form_alter(&$form, &$form_state, $form_id) {
+  $form['workflow']['node_options']['#options']['revision_moderation'] = t('New revisions in moderation');
+}
+
+/**
+ * Implementation of hook_node_insert().
+ */
+function revision_moderation_node_insert($node) {
+  // Store revision moderation setting of this node.
+  drupal_write_record('revision_moderation', $node);
+}
+
+/**
+ * Implementation of hook_node_update().
+ */
+function revision_moderation_node_update($node) {
+  $args = arg();
+
+  // Update revision moderation setting of this node.
+  // Check to see if a record exists before trying to update it
+  $has_rows = (bool) db_query_range('SELECT 1 FROM {revision_moderation} WHERE nid = :nid', 0, 1, array(':nid' => $node->nid))->fetchField();
+  if (!$has_rows) {
+    drupal_write_record('revision_moderation', $node);
+  }
+  else {
+    drupal_write_record('revision_moderation', $node, 'nid');
+  }
+
+  // Only do this logic for non-admin users on nodes with revision moderation
+  // turned on.
+  // And not editing a chose revision
+  if ($node->nid && $node->revision_moderation == 1 && arg(2) != 'revisions' && (!user_access('administer nodes') || !variable_get('revision_moderation_exempt', 1))) {
+    if (isset($node->original)) {
+      // Update node table's vid to the original value.
+
+      db_update('node')
+      ->fields(array(
+        'vid' => $node->original->vid,
+        'title' => $node->original->title,
+        'status' => $node->original->status,
+        ))
+      ->condition('nid', $node->nid, '=')
+      ->execute();
+      // If node doesn't exist in revision_moderation table, add it.
+      $in_db = db_query('SELECT revision_moderation FROM {revision_moderation} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField();
+      if ($in_db === FALSE) {
+        db_insert('revision_moderation')
+        ->fields(array(
+          'nid' => $node->nid,
+          'revision_moderation' => 1,
+          ))
+        ->execute();
+      }
+      
+      // evil evil hack
+      drupal_write_record('node', $node->original, 'nid');
+      field_attach_update('node', $node->original);
+
+      drupal_set_message(t('Your changes have been submitted for moderation.'));
     }
-    else {
-      $form['revision_moderation'] = array(
-        '#type' => 'value',
-        '#value' => $default_value,
-      );
+  }
+  elseif ($node->nid && $node->revision_moderation == 1 && end($args) == 'edit') {
+    if (isset($node->original)) {
+      // Exempt admin users publish their version immediately
+      if (!user_access('administer nodes') || !variable_get('revision_moderation_exempt', 1)) {
+        // Update node table's vid to the original value.
+
+        db_update('node')
+        ->fields(array(
+          'vid' => $node->original->vid,
+          'title' => $node->original->title,
+          'status' => $node->original->status,
+          ))
+        ->condition('nid', $node->nid, '=')
+        ->execute();
+      
+        // evil evil hack
+        drupal_write_record('node', $node->original, 'nid');
+        field_attach_update('node', $node->original);
+
+        drupal_set_message(t('Your changes have been submitted for moderation.'));
+      }
     }
   }
-  // Also add option to node settings form
-  elseif ($form_id == 'node_type_form') {
-    $form['workflow']['node_options']['#options']['revision_moderation'] = t('New revisions in moderation');
+
+}
+
+/**
+ * Implementation of hook_node_delete().
+ */
+function revision_moderation_node_delete($node) {
+  // Delete record from revision_moderation table when node is deleted.
+  db_delete('revision_moderation')
+    ->condition('nid',$node->nid)
+    ->execute();
+}
+
+/**
+ * Implementation of hook_node_load().
+ */
+function revision_moderation_node_load($nodes, $types) {
+  // Set a revision_moderation property which can be checked later.
+  foreach ($nodes as $node) {
+    $node->revision_moderation = db_query('SELECT revision_moderation FROM {revision_moderation} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField();
   }
 }
 
 /**
- * Implementation of hook_nodeapi().
+ * Implementation of hook_node_view().
  */
-function revision_moderation_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
-  switch ($op) {
-    case 'insert':
-      // Store revision moderation setting of this node.
-      drupal_write_record('revision_moderation', $node);
-      break;
-
-    case 'update':
-      // Update revision moderation setting of this node.
-      drupal_write_record('revision_moderation', $node, 'nid');
-      break;
-
-    case 'delete':
-      // Delete record from revision_moderation table when node is deleted.
-      db_query('DELETE FROM {revision_moderation} WHERE nid = %d', $node->nid);
-      break;
-
-    case 'load':
-      // Set a revision_moderation property which can be checked later.
-      $node->revision_moderation = db_result(db_query('SELECT revision_moderation FROM {revision_moderation} WHERE nid = %d', $node->nid));
-      break;
-
-    case 'view':
-      // Cannot use _node_revision_access() here, it's static cached with 1 op
-      $access_update = user_access('revert revisions');
-      $access_delete = user_access('delete revisions');
-      // Display more descriptive message at the top of node revision views, including operations
-      // that the current user has available to them.
-      $current_vid = db_result(db_query('SELECT vid FROM {node} WHERE nid = %d', $node->nid));
-      if ($node->vid != $current_vid) {
-        $links = array(); // Array of links to show along with the message.
-        if ($access_update) {
-          // Add a link directly to the diff if we have Diff module installed.
-          if (module_exists('diff')) {
-            if ($node->vid > $current_vid) {
-             $difflink = "node/$node->nid/revisions/view/$current_vid/$node->vid";
-            }
-            else {
-             $difflink = "node/$node->nid/revisions/view/$node->vid/$current_vid";
-            }
-            $links[] = l(t('Compare revisions'), $difflink);
-          }
-          $links[] = l(t('Edit revision'), "node/$node->nid/revisions/$node->vid/edit");
-          // If this revision is old, show an option to revert to it.
-          // Otherwise, show an option to publish it.
-          if ($node->vid < $current_vid) {
-            $links[] = l(t('Revert to revision'), "node/$node->nid/revisions/$node->vid/revert");
-          }
-          else {
-            $links[] = l(t('Publish revision'), "node/$node->nid/revisions/$node->vid/publish");
-          }
+function revision_moderation_node_view($node, $view_mode, $langcode) {
+  // Cannot use _node_revision_access() here, it's static cached with 1 op
+  $access_update = user_access('revert revisions');
+  $access_delete = user_access('delete revisions');
+  // Display more descriptive message at the top of node revision views, including operations
+  // that the current user has available to them.
+  $current_vid = db_query('SELECT vid FROM {node} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField();
+  if ($node->vid != $current_vid) {
+    $links = array(); // Array of links to show along with the message.
+    if ($access_update) {
+      // Add a link directly to the diff if we have Diff module installed.
+      if (module_exists('diff')) {
+        if ($node->vid > $current_vid) {
+          $difflink = "node/$node->nid/revisions/view/$current_vid/$node->vid";
         }
-        if ($access_delete) {
-          $links[] = l(t('Delete revision'), "node/$node->nid/revisions/$node->vid/delete");
+        else {
+          $difflink = "node/$node->nid/revisions/view/$node->vid/$current_vid";
         }
-        // Get username for the revision rather than the original node.
-        $revision_author = user_load($node->revision_uid);
-        drupal_set_message(t('You are currently viewing a revision of this post created on @date by !author.', array('@date' => format_date($node->revision_timestamp, 'small'), '!author' => theme('username', $revision_author))) . theme('item_list', $links));
+        $links[] = l(t('Compare revisions'), $difflink);
       }
-      elseif ($node->revision_moderation == 1 && !$teaser) {
-        // Notify admin if a node has pending revisions.
-        if ($access_update && arg(2) != 'revisions' && revision_moderation_get_node_pending_revisions($node->nid)) {
-          drupal_set_message(t('This post has one or more pending revisions: <a href="@list">view list of revisions</a>.', array('@list' => url("node/$node->nid/revisions"))));
-        }
+      $links[] = l(t('Edit revision'), "node/$node->nid/revisions/$node->vid/edit");
+      // If this revision is old, show an option to revert to it.
+      // Otherwise, show an option to publish it.
+      if ($node->vid < $current_vid) {
+        $links[] = l(t('Revert to revision'), "node/$node->nid/revisions/$node->vid/revert");
+      }
+      else {
+        $links[] = l(t('Publish revision'), "node/$node->nid/revisions/$node->vid/publish");
       }
-      break;
+    }
+    if ($access_delete) {
+      $links[] = l(t('Delete revision'), "node/$node->nid/revisions/$node->vid/delete");
+    }
+    // Get username for the revision rather than the original node.
+    $revision_author = array('account' => user_load($node->revision_uid));
+    drupal_set_message(t('You are currently viewing a revision of this post created on @date by !author.', array('@date' => format_date($node->revision_timestamp, 'small'), '!author' => theme('username', array('username' => $revision_author)))) . theme('item_list', array('items' => $links)));
+  }
+  elseif ($node->revision_moderation == 1) {
+    // Notify admin if a node has pending revisions.
+    if ($access_update && arg(2) != 'revisions' && revision_moderation_get_node_pending_revisions($node->nid)) {
+      drupal_set_message(t('<a href="@url">@title</a> has one or more pending revisions: <a href="@list">view list of revisions</a>.', array('@url' => url("node/$node->nid"), '@title' => check_plain($node->title), '@list' => url("node/$node->nid/revisions"))));
+    }
   }
+}
+
+/**
+ * Implementation of hook_node_prepare().
+ */
+function revision_moderation_node_prepare($node) {
+  $args = arg();
 
   // Only do this logic for non-admin users on nodes with revision moderation
   // turned on.
   // And not editing a chose revision
-  if ($node->nid && $node->revision_moderation == 1 && arg(2) != 'revisions'
-    && (!user_access('administer nodes') || !variable_get('revision_moderation_exempt', 1))) {
-    switch ($op) {
-      case 'prepare':
-        // If user has a pending revision for this node, load the latest version of
-        // it instead.
-        if ($revisions = revision_moderation_get_node_pending_revisions($node->nid)) {
-          global $user;
-          foreach ($revisions as $revision) {
-            if ($revision->uid == $user->uid) {
-              drupal_set_message(t('Editing your latest revision, which is still pending moderation.'));
-              $node = node_load($node->nid, $revision->vid);
-              break;
-            }
-          }
+  if (isset($node->nid) && isset($node->revision_moderation) && $node->revision_moderation == 1 && arg(2) != 'revisions' && (!user_access('administer nodes') || !variable_get('revision_moderation_exempt', 1))) {
+    // If user has a pending revision for this node, load the latest version of
+    // it instead.
+    if ($revisions = revision_moderation_get_node_pending_revisions($node->nid)) {
+      global $user;
+      foreach ($revisions as $revision) {
+        if ($revision->uid == $user->uid) {
+          drupal_set_message(t('Editing your latest revision, which is still pending moderation.'));
+          $node = node_load($node->nid, $revision->vid);
         }
-        break;
-
-      case 'presave':
-        $current_vid = db_result(db_query('SELECT vid FROM {node} WHERE nid = %d', $node->nid));
-        $node->original_node = node_load($node->nid, $current_vid);
-        break;
-
-      case 'update':
-        if (isset($node->original_node)) {
-          // Update node table's vid to the original value.
+      }
+    }
 
-          db_query("UPDATE {node} SET vid = %d, title = '%s', status = %d, moderate = %d WHERE nid = %d", $node->original_node->vid, $node->original_node->title, $node->original_node->status, $node->original_node->moderate, $node->nid);
-          drupal_set_message(t('Your changes have been submitted for moderation.'));
+  }
+  elseif (isset($node->nid) && isset($node->revision_moderation) && $node->revision_moderation == 1 && end($args) == 'edit') {
+    $revision_author = array('account' => user_load($node->revision_uid));
+    $current_vid = db_query('SELECT vid FROM {node} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField();
+    if ($node->vid > $current_vid) {
+      drupal_set_message(t('You are currently editing a pending update of this post created on @date by !author.', array('@date' => format_date($node->revision_timestamp, 'small'), '!author' => theme('username', $revision_author))));
+    }
+    if ($node->vid == $current_vid) {
+      if (revision_moderation_get_node_pending_revisions($node->nid)) {
+        if (variable_get('revision_moderation_exempt', 1)) {
+          drupal_set_message(t('You are currently editing the current published version of this post, created on @date by !author. Note that there are other pending revisions, and that pressing save will publish this version of the post instead.', array('@date' => format_date($node->revision_timestamp, 'small'), '!author' => theme('username', $revision_author))));
+        }
+        else {
+          drupal_set_message(t('You are currently editing the current published version of this post, created on @date by !author.', array('@date' => format_date($node->revision_timestamp, 'small'), '!author' => theme('username', $revision_author))));
         }
-        break;
+      }
     }
+
   }
+
 }
 
 /**
- * Implementation of hook_block().
+ * Implementation of hook_block_info().
  */
-function revision_moderation_block($op = 'list', $delta = 0, $edit = array()) {
-  if ($op == 'list') {
-    $blocks[0]['info'] = t('Pending revisions');
+function revision_moderation_block_info() {
+  $block['pending_revisions'] = array('info' => t('Pending revisions'));
+  return $block;
+}
 
-    return $blocks;
-  }
-  elseif ($op == 'view') {
+/**
+ * Implementation of hook_block_view().
+ */
+function revision_moderation_block_view($delta = '') {
+  switch ($delta) {
+    case 'pending_revisions':
     $block = array();
-
     if (user_access('administer nodes')) {
       $output = '';
       $list = array();
@@ -245,19 +334,17 @@ function revision_moderation_block($op = 'list', $delta = 0, $edit = array()) {
         foreach ($nodes as $node) {
           $list[] = l($node->title, "node/$node->nid/revisions/$node->vid/view");
         }
-        $output .= theme('item_list', $list);
-        $output .= '<p>'. l(t('View all pending revisions'), 'admin/content/node/revisions') .'</p>';
+        $output .= theme('item_list', array('list' => $list));
+        $output .= '<p>' . l(t('View all pending revisions'), 'admin/content/node/revisions') . '</p>';
       }
       else {
         $output .= t('No pending revisions found.');
       }
-
       $block['subject'] = t('Pending revisions');
       $block['content'] = $output;
     }
-
-    return $block;
   }
+  return $block;
 }
 
 /**
@@ -273,7 +360,7 @@ function revision_moderation_pending_revisions_admin() {
 function revision_moderation_theme() {
   return array(
     'revision_moderation_pending_revisions_admin' => array(
-      'arguments' => array(),
+      'variables' => array(),
     ),
   );
 }
@@ -294,15 +381,15 @@ function theme_revision_moderation_pending_revisions_admin() {
     foreach ($nodes as $node) {
       $rows[] = array(
         l($node->title, "node/$node->nid/revisions"),
-        check_plain(node_get_types('name', $node)),
-        theme('username', user_load(array('uid' => $node->uid))),
+        check_plain(node_type_get_name($node)),
+        theme('username', array('username' => user_load($node->uid))), // should this key be account instead?
         format_date($node->timestamp),
       );
     }
-    return theme('table', $header, $rows);
+    return theme('table', array('header' => $header, 'rows' => $rows));
   }
   else {
-    return '<p>'. t('No pending revisions found.') .'</p>';
+    return '<p>' . t('No pending revisions found.') . '</p>';
   }
 }
 
@@ -314,10 +401,9 @@ function theme_revision_moderation_pending_revisions_admin() {
  */
 function revision_moderation_get_all_pending_revisions($limit) {
   // Obtain a list of nodes with revisions higher than current published revision.
-  $sql = "SELECT n.nid, r.vid, n.type, r.title, r.body, r.uid, r.timestamp FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid WHERE r.vid > n.vid ORDER BY r.vid DESC LIMIT %d";
-  $result = db_query($sql, $limit);
+  $result = db_query_range("SELECT n.nid, r.vid, n.type, r.title, r.uid, r.timestamp FROM {node} n INNER JOIN {node_revision} r ON n.nid = r.nid WHERE r.vid > n.vid ORDER BY r.vid DESC", 0, $limit);
   $revisions = array();
-  while ($revision = db_fetch_object($result)) {
+  foreach ($result as $revision) {
     $revisions[$revision->nid] = $revision;
   }
 
@@ -332,10 +418,9 @@ function revision_moderation_get_all_pending_revisions($limit) {
  */
 function revision_moderation_get_node_pending_revisions($nid) {
   // Obtain a list of revisions higher than current published revision for a given node.
-  $sql = "SELECT n.nid, r.vid, r.uid FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid WHERE r.vid > n.vid AND n.nid = %d ORDER BY r.vid DESC";
-  $result = db_query($sql, $nid);
+  $result = db_query('SELECT n.nid, r.vid, r.uid FROM {node} n INNER JOIN {node_revision} r ON n.nid = r.nid WHERE r.vid > n.vid AND n.nid = :nid ORDER BY r.vid DESC', array(':nid' => $nid));
   $revisions = array();
-  while ($revision = db_fetch_object($result)) {
+  foreach ($result as $revision) {
     $revisions[$revision->vid] = $revision;
   }
 
@@ -347,9 +432,9 @@ function revision_moderation_get_node_pending_revisions($nid) {
  */
 function revision_moderation_edit($node) {
   // Get username for the revision rather than the original node.
-  $revision_author = user_load($node->revision_uid);
+  $revision_author = array('account' => user_load($node->revision_uid));
   drupal_set_message(t('You are currently editing a revision of this post created on @date by !author.', array('@date' => format_date($node->revision_timestamp, 'small'), '!author' => theme('username', $revision_author))));
-  return drupal_get_form($node->type .'_node_form', $node);
+  return drupal_get_form($node->type . '_node_form', $node);
 }
 
 /**
@@ -358,13 +443,13 @@ function revision_moderation_edit($node) {
  * @param $node
  *   The node object for which revision is to be published.
  */
-function revision_moderation_publish_confirm($form_state, $node) {
+function revision_moderation_publish_confirm($form, &$form_state, $node) {
   $form['node_id'] = array('#type' => 'value', '#value' => $node->nid);
   $form['title'] = array('#type' => 'value', '#value' => $node->title);
   $form['revision'] = array('#type' => 'value', '#value' => $node->vid);
   $form['type'] = array('#type' => 'value', '#value' => $node->type);
 
-  return confirm_form($form, t('Are you sure you want to publish this revision for %title?', array('%title' => $node->title)), 'node/'. $node->nid .'/revisions/'. $node->vid, t('Publishing this revision will make it public for all users.'), t('Publish'), t('Cancel'));
+  return confirm_form($form, t('Are you sure you want to publish this revision for %title?', array('%title' => $node->title)), 'node/' . $node->nid . '/revisions/' . $node->vid, t('Publishing this revision will make it public for all users.'), t('Publish'), t('Cancel'));
 }
 
 /**
@@ -376,11 +461,24 @@ function revision_moderation_publish_confirm_submit($form, &$form_state) {
   $title = $form_state['values']['title'];
   $vid = $form_state['values']['revision'];
   $type = $form_state['values']['type'];
+  
+  // this seems a bit... arbitrary...  Best way to do this?
+  $node = $form_state['build_info']['args'][0];
+
+  db_update('node')
+          ->fields(array(
+            'vid' => $vid,
+            'title' => $title,
+          ))
+          ->condition('nid', $nid, '=')
+          ->execute();
+  
+  // Save fields.
+  field_attach_update('node', $node);
 
-  db_query("UPDATE {node} SET vid = %d, title = '%s' WHERE nid = %d", $vid, $title, $nid);
   // Clear the cache so an anonymous poster can see the changes
   cache_clear_all();
-  drupal_set_message('The selected revision has been published.');
+  drupal_set_message(t('The selected revision has been published.'));
   watchdog('content', '@type: published %title revision %revision', array('@type' => t($type), '%title' => $title, '%revision' => $vid), WATCHDOG_NOTICE, l(t('view'), "node/$nid/revisions/$vid/view"));
-  $form_state['redirect'] = 'node/'. $nid;
+  $form_state['redirect'] = 'node/' . $nid;
 }
diff --git a/revision_moderation_actions.inc b/revision_moderation_actions.inc
index 4ccf349..00454f7 100644
--- a/revision_moderation_actions.inc
+++ b/revision_moderation_actions.inc
@@ -11,21 +11,15 @@
 function revision_moderation_action_info() {
   $actions['revision_moderation_enable_action'] = array(
     'type' => 'node',
-    'description' => t('Enable revision moderation on node'),
+    'label' => t('Enable revision moderation on node'),
     'configurable' => FALSE,
-    'hooks' => array(
-      'nodeapi' => array('presave', 'insert', 'update'),
-      'comment' => array('delete', 'insert', 'update')
-     ),
+    'triggers' => array('node_presave', 'node_insert', 'node_update', 'comment_delete', 'comment_insert', 'comment_update'),
   );
   $actions['revision_moderation_disable_action'] = array(
     'type' => 'node',
-    'description' => t('Disable revision moderation on node'),
+    'label' => t('Disable revision moderation on node'),
     'configurable' => FALSE,
-    'hooks' => array(
-      'nodeapi' => array('presave', 'insert', 'update'),
-      'comment' => array('delete', 'insert', 'update')
-     ),
+    'triggers' => array('node_presave', 'node_insert', 'node_update', 'comment_delete', 'comment_insert', 'comment_update'),
   );
   return $actions;
 }
-- 
1.7.0.4

