--- node.module.original	Thu Apr 13 10:33:09 2006
+++ node.module	Thu Apr 13 10:21:09 2006
@@ -484,7 +484,13 @@
   }
 
   // Insert the node into the database:
-  db_query($node_query, $node_table_values);
+  if (($node->revision && !$node->draft) || $node->is_new || !$node->revision) {
+    db_query($node_query, $node_table_values);
+  }
+  else {
+    // The node table should be updated when a draft revision is created ...
+    db_query('UPDATE {node} SET moderate = %d WHERE nid = %d', $node->moderate, $node->nid);
+  }
   db_query($revisions_query, $revisions_table_values);
 
   // Call the node specific callback (if any):
@@ -585,7 +591,7 @@
  * Implementation of hook_perm().
  */
 function node_perm() {
-  return array('administer nodes', 'access content', 'view revisions', 'revert revisions');
+  return array('administer nodes', 'access content', 'view revisions', 'publish revisions', 'delete revisions');
 }
 
 /**
@@ -1261,14 +1267,18 @@
 function node_revision_overview($node) {
   drupal_set_title(t('Revisions for %title', array('%title' => check_plain($node->title))));
 
-  $header = array(t('Revision'), array('data' => t('Operations'), 'colspan' => 2));
+  $header = array(t('Revision'), array('data' => t('Operations'), 'colspan' => 3));
 
   $revisions = node_revision_list($node);
 
   $rows = array();
-  $revert_permission = FALSE;
-  if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) {
-    $revert_permission = TRUE;
+  $publish_permission = FALSE;
+  if ((user_access('publish revisions') || user_access('administer nodes')) && node_access('update', $node)) {
+    $publish_permission = TRUE;
+  }
+  $edit_permission = FALSE;
+  if ((user_access('edit revisions') || user_access('administer nodes')) && node_access('update', $node)) {
+    $edit_permission = TRUE;
   }
   $delete_permission = FALSE;
   if (user_access('administer nodes')) {
@@ -1280,15 +1290,22 @@
 
     if ($revision->current_vid > 0) {
       $row[] = array('data' => t('%date by %username', array('%date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid"), '%username' => theme('username', $revision)))
-                               . (($revision->log != '') ? '<p class="revision-log">'. filter_xss($revision->log) .'</p>' : ''),
-                     'class' => 'revision-current');
-      $operations[] = array('data' => theme('placeholder', t('current revision')), 'class' => 'revision-current', 'colspan' => 2);
+            	    . (($revision->log != '') ? '<p class="revision-log">'. filter_xss($revision->log) .'</p>' : ''),
+      		'class' => 'revision-current');
+      $operations[] = array('data' => theme('placeholder', t('published')), 'class' => 'revision-current');
+      if ($edit_permission) {
+        $operations[] = l(t('edit'), "node/$node->nid/revisions/$revision->vid/edit");
+        $operations[] ="&nbsp;";
+      }   
     }
     else {
       $row[] = t('%date by %username', array('%date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid/revisions/$revision->vid/view"), '%username' => theme('username', $revision)))
                . (($revision->log != '') ? '<p class="revision-log">'. filter_xss($revision->log) .'</p>' : '');
-      if ($revert_permission) {
-        $operations[] = l(t('revert'), "node/$node->nid/revisions/$revision->vid/revert");
+	  if ($publish_permission) {
+        $operations[] = l(t('publish'), "node/$node->nid/revisions/$revision->vid/publish");
+      }
+      if ($edit_permission) {
+        $operations[] = l(t('edit'), "node/$node->nid/revisions/$revision->vid/edit");
       }
       if ($delete_permission) {
         $operations[] = l(t('delete'), "node/$node->nid/revisions/$revision->vid/delete");
@@ -1305,23 +1322,20 @@
  * Revert to the revision with the specified revision number. A node and nodeapi "update" event is triggered
  * (via the node_save() call) when a revision is reverted.
  */
-function node_revision_revert($nid, $revision) {
+function node_revision_publish($nid, $vid) {
   global $user;
 
-  $node = node_load($nid, $revision);
-  if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) {
+  $node = node_load($nid, $vid);
+  if ((user_access('publish revisions') || user_access('administer nodes')) && node_access('update', $node)) {
     if ($node->vid) {
-      $node->revision = 1;
-      $node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp))));
-      $node->taxonomy = array_keys($node->taxonomy);
-
-      node_save($node);
-
-      drupal_set_message(t('%title has been reverted back to the revision from %revision-date', array('%revision-date' => theme('placeholder', format_date($node->revision_timestamp)), '%title' => theme('placeholder', check_plain($node->title)))));
-      watchdog('content', t('%type: reverted %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))));
+      db_query("UPDATE {node} SET vid=$vid WHERE nid = $nid");
+//Not sure if switching published should make a log entry
+//      $node->log = t('Publish revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp))));
+      drupal_set_message(t('The revision of %title from %revision-date has been published', array('%revision-date' => theme('placeholder', format_date($node->revision_timestamp)), '%title' => theme('placeholder', check_plain($node->title)))));
+      watchdog('content', t('%type: published %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $vid))));
     }
     else {
-      drupal_set_message(t('You tried to revert to an invalid revision.'), 'error');
+      drupal_set_message(t('You tried to publish an invalid revision.'), 'error');
     }
     drupal_goto('node/'. $nid .'/revisions');
   }
@@ -1329,6 +1343,28 @@
 }
 
 /**
+ * Edit a revision (probably create new revision)
+ */
+function node_revision_edit($nid, $vid, $copy=1) {
+  global $user;
+
+  $node = node_load($nid, $vid);
+  if ((user_access('edit revisions') || user_access('administer nodes')) && node_access('update', $node)) {
+    if ($node->nid) {
+      $node->revision=$copy ? 1 : 0;
+      #$node->draft=1;
+      drupal_set_title(check_plain($node->title));
+      return node_form($node);
+    }
+    else {
+      drupal_set_message(t('Invalid revision.'), 'error');
+      drupal_not_found();
+    }
+  }
+  else drupal_access_denied();
+}
+
+/**
  * Delete the revision with specified revision number. A "delete revision" nodeapi event is invoked when a
  * revision is deleted.
  */
@@ -1603,6 +1639,7 @@
   foreach (array('nid', 'vid', 'uid', 'created', 'changed', 'type') as $key) {
     $form[$key] = array('#type' => 'value', '#value' => $node->$key);
   }
+  $form['#node'] = $node;
 
   // Get the node-specific bits.
   $form = array_merge_recursive($form, node_invoke($node, 'form'));
@@ -1613,15 +1650,17 @@
   $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
   // If this is a new node, fill in the default values.
   if (!isset($node->nid)) {
-    foreach (array('status', 'moderate', 'promote', 'sticky', 'revision') as $key) {
+    foreach (array('status', 'moderate', 'promote', 'sticky', 'revision', 'draft') as $key) {
       $node->$key = in_array($key, $node_options);
     }
     global $user;
     $node->uid = $user->uid;
   }
   else {
-    // Nodes being edited should always be preset with the default revision setting.
-    $node->revision = in_array('revision', $node_options);
+    // Nodes being edited should always be preset with the default revision and draft settings.
+    foreach (array('revision', 'draft') as $key) {
+      $node->$key = in_array($key, $node_options);
+    }
   }
   $form['#node'] = $node;
 
@@ -1637,7 +1676,10 @@
     $form['options']['moderate'] = array('#type' => 'checkbox', '#title' => t('In moderation queue'), '#default_value' => $node->moderate);
     $form['options']['promote']  = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->promote);
     $form['options']['sticky']   = array('#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->sticky);
-    $form['options']['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision);
+	$form['options']['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => '');
+	$form['options']['draft'] = array('#type' => 'checkbox', '#title' => t('Save revision as draft'), '#default_value' => '');    
+	/*$form['options']['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision);
+	$form['options']['draft'] = array('#type' => 'checkbox', '#title' => t('Save revision as draft'), '#default_value' => $node->draft);*/
   }
   else {
     // Put all of these through as values if the user doesn't have access to them.
@@ -1811,7 +1853,12 @@
     if (node_access('update', $node)) {
       node_save($node);
       watchdog('content', t('%type: updated %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
-      drupal_set_message(t('The %post was updated.', array ('%post' => node_get_name($node))));
+      if($node->revision && $node->draft && $node->moderate) {
+        drupal_set_message(t('The %post revision was submitted for moderation.', array ('%post' => node_get_name($node))));
+      }
+      else {
+        drupal_set_message(t('The %post was updated.', array ('%post' => node_get_name($node))));
+      }
     }
   }
   else {
@@ -1917,15 +1964,21 @@
           }
         }
         break;
-      case 'revert':
-        node_revision_revert(arg(1), arg(3));
+      case 'publish':
+        node_revision_publish(arg(1), arg(3));
+        break;
+      case 'edit':
+        return node_revision_edit(arg(1), arg(3));
+        break;
+      case 'copy':
+        node_revision_copy(arg(1), arg(3));
         break;
       case 'delete':
         node_revision_delete(arg(1), arg(3));
         break;
     }
   }
-  drupal_not_found();
+  else drupal_not_found();
 }
 
 /**
@@ -2090,6 +2143,7 @@
         'promote' => t('Promoted to front page'),
         'sticky' => t('Sticky at top of lists'),
         'revision' => t('Create new revision'),
+        'draft' => t('Save revision as draft'),
       ),
       '#description' => t('Users with the <em>administer nodes</em> permission will be able to override these options.'),
     );
