Index: modules/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node.module,v retrieving revision 1.596 diff -u -r1.596 node.module --- modules/node.module 8 Feb 2006 00:47:14 -0000 1.596 +++ modules/node.module 9 Feb 2006 21:52:09 -0000 @@ -484,7 +484,9 @@ } // Insert the node into the database: - db_query($node_query, $node_table_values); + if (! $node->draft) { + db_query($node_query, $node_table_values); + } db_query($revisions_query, $revisions_table_values); // Call the node specific callback (if any): @@ -585,7 +587,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', 'publish revisions', 'delete revisions'); } /** @@ -1268,15 +1270,19 @@ 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); $i = 0; $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')) { @@ -1288,15 +1294,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 != '') ? '
'. filter_xss($revision->log) .'
' : ''), - 'class' => 'revision-current'); - $operations[] = array('data' => theme('placeholder', t('current revision')), 'class' => 'revision-current', 'colspan' => 2); + . (($revision->log != '') ? ''. filter_xss($revision->log) .'
' : ''), + '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[] =" "; + } } 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 != '') ? ''. filter_xss($revision->log) .'
' : ''); - 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"); @@ -1308,33 +1321,52 @@ return $output; } - -/** - * 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. + /** + * Set specified revision as the published revision. */ -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_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'); } drupal_access_denied(); } + +/** + * 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. @@ -1628,7 +1660,7 @@ $form['created'] = array('#type' => 'value', '#value' => $node->created); $form['changed'] = array('#type' => 'value', '#value' => $node->changed); $form['type'] = array('#type' => 'value', '#value' => $node->type); - $form['#node'] = $node; + $form['draft'] = array('#type' => 'value', '#value' => 1); // Get the node-specific bits. $form = array_merge_recursive($form, node_invoke($node, 'form')); @@ -1957,15 +1989,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(); } /**