Index: node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/Attic/node.module,v retrieving revision 1.641.2.10 diff -u -r1.641.2.10 node.module --- node.module 16 Jul 2006 17:07:36 -0000 1.641.2.10 +++ node.module 21 Jul 2006 19:32:36 -0000 @@ -481,7 +481,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): @@ -582,7 +588,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', 'edit revisions'); } /** @@ -1257,14 +1263,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')) { @@ -1276,15 +1286,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"); @@ -1301,23 +1318,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'); } @@ -1325,6 +1339,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. */ @@ -1504,7 +1540,7 @@ } // Force defaults in case people modify the form: $node_options = variable_get('node_options_'. $node->type, array('status', 'promote')); - foreach (array('status', 'moderate', 'promote', 'sticky', 'revision') as $key) { + foreach (array('status', 'moderate', 'promote', 'sticky', 'revision', 'draft') as $key) { if (!$access || !isset($node->$key)) { $node->$key = in_array($key, $node_options); } @@ -1600,6 +1636,7 @@ foreach (array('nid', 'vid', 'uid', 'created', 'type') as $key) { $form[$key] = array('#type' => 'value', '#value' => $node->$key); } + $form['#node'] = $node; // Changed must be sent to the client, for later overwrite error checking. $form['changed'] = array('#type' => 'hidden', '#value' => $node->changed); @@ -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; @@ -1641,7 +1680,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. @@ -1839,7 +1881,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 { @@ -1947,15 +1994,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(); } /** @@ -2143,6 +2196,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 administer nodes permission will be able to override these options.'), );