--- node.module Thu Mar 23 13:09:59 2006 +++ patches/node.module.patched Thu Mar 23 13:09:53 2006 @@ -484,7 +484,12 @@ } // Insert the node into the database: - db_query($node_query, $node_table_values); + if (!$node->draft) { + db_query($node_query, $node_table_values); + } + else { + 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 +590,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'); } /** @@ -1339,14 +1344,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')) { @@ -1358,15 +1367,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"); @@ -1380,26 +1396,22 @@ } /** - * 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->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'); } @@ -1407,6 +1419,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. */ @@ -1692,6 +1726,8 @@ foreach (array('nid', 'vid', 'uid', 'created', 'changed', 'type') as $key) { $form[$key] = array('#type' => 'value', '#value' => $node->$key); } + $form['draft'] = array('#type' => 'value', '#value' => 1); + $form['#node'] = $node; // Get the node-specific bits. $form = array_merge_recursive($form, node_invoke($node, 'form')); @@ -1715,6 +1751,8 @@ $form['#node'] = $node; if (user_access('administer nodes')) { + $form['draft'] = array('#type' => 'value', '#value' => $node->draft); + // Node author information $form['author'] = array('#type' => 'fieldset', '#title' => t('Authoring information'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 20); $form['author']['name'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#default_value' => $node->name ? $node->name : '', '#weight' => -1, '#description' => t('Leave blank for %anonymous.', array('%anonymous' => theme('placeholder', variable_get('anonymous', 'Anonymous'))))); @@ -1901,7 +1939,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->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 { @@ -2007,15 +2050,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(); } /**