Index: revision_moderation.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/revision_moderation/revision_moderation.info,v
retrieving revision 1.1
diff -u -p -r1.1 revision_moderation.info
--- revision_moderation.info	13 Feb 2007 03:37:32 -0000	1.1
+++ revision_moderation.info	10 Jun 2008 08:44:55 -0000
@@ -1,5 +1,4 @@
-; $Id: revision_moderation.info,v 1.1 2007/02/13 03:37:32 webchick Exp $
+; $Id$
 name = Revision Moderation
 description = Allows moderation of new node revisions while existing approved revisions stay visible.
-version = "$Name:  $"
-
+core = 6.x
\ No newline at end of file
Index: revision_moderation.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/revision_moderation/revision_moderation.install,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 revision_moderation.install
--- revision_moderation.install	14 Feb 2007 14:09:01 -0000	1.2.2.1
+++ revision_moderation.install	10 Jun 2008 08:44:55 -0000
@@ -1,75 +1,48 @@
 <?php
-// $Id: revision_moderation.install,v 1.2.2.1 2007/02/14 14:09:01 webchick Exp $
+// $Id$
 
 /**
- * Implementation of hook_install().
- */
-function revision_moderation_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("
-      CREATE TABLE {revision_moderation} (
-        nid int unsigned NOT NULL,
-        revision_moderation int NOT NULL default '0',
-        PRIMARY KEY(nid)
-      ) /*!40100 DEFAULT CHARACTER SET UTF8 */
-      ");
-      break;
-    case 'pgsql':
-      db_query("
-      CREATE TABLE {revision_moderation} (
-        nid int NOT NULL,
-        revision_moderation int NOT NULL default '0',
-        PRIMARY KEY(nid)
-      );
-      ");
-      break;
-  }
+ * Implementation of hook_schema().
+ */ 
+function revision_moderation_schema() {
+  $schema['revision_moderation'] = array(
+    'fields' => array(
+      'nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0
+      ),
+      'revision_moderation' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'size' => 'tiny'
+      ),
+    ),
+    'primary key' => array('nid'),
+  );
+
+  return $schema;
 }
 
 /**
- * Install revision_moderation table.
+ * Implementation of hook_install().
  */
-function revision_moderation_update_1() {
-  $ret = array();
-
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("
-      CREATE TABLE {revision_moderation} (
-        nid int unsigned NOT NULL,
-        revision_moderation int NOT NULL default '0',
-        PRIMARY KEY(nid)
-      ) /*!40100 DEFAULT CHARACTER SET UTF8 */
-      ");
-      break;
-    case 'pgsql':
-      $ret[] = update_sql("
-      CREATE TABLE {revision_moderation} (
-        nid int NOT NULL,
-        revision_moderation int NOT NULL default '0',
-        PRIMARY KEY(nid)
-      );
-      ");
-      break;
-  }
-
-  return $ret;
+function revision_moderation_install() {
+  // Create table
+  drupal_install_schema('revision_moderation');
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function revision_moderation_uninstall() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("DROP TABLE {revision_moderation}");
-      break;
-    case 'pgsql':
-      db_query("DROP TABLE {revision_moderation}");
-      break;
-  }
+  // Drop the table
+  drupal_uninstall_schema('revision_moderation');
+  variable_del('revision_moderation_exempt');
+  variable_del('revision_moderation_cron_enable');
+  variable_del('revision_moderation_cron_older_than');
+  variable_del('revision_moderation_cron_more_than');
+  variable_del('revision_moderation_cron_amount');
 }
Index: revision_moderation.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/revision_moderation/revision_moderation.module,v
retrieving revision 1.26.2.10
diff -u -p -r1.26.2.10 revision_moderation.module
--- revision_moderation.module	20 Feb 2007 15:55:17 -0000	1.26.2.10
+++ revision_moderation.module	10 Jun 2008 08:44:56 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: revision_moderation.module,v 1.26.2.10 2007/02/20 15:55:17 webchick Exp $
+// $Id$
 
 /**
  * @file
@@ -7,60 +7,55 @@
  */
 
 // Actions module support.
-if (module_exists('actions')) {
-  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().
  */
-function revision_moderation_menu($may_cache) {
+function revision_moderation_menu() {
   $items = array();
+  
+  // Admin menu
+  $items['admin/content/node/revisions'] = array(
+    'title' => t('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'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('revision_moderation_settings'),
+    'description' => t('Configure revision publishing options.'),
+    'access arguments' => array('administer nodes'),
+  );
 
-  if ($may_cache) {
-    // An admin page listing all nodes with revisions in moderation.
-    $items[] = array(
-      'path' => 'admin/content/node/revisions',
-      'title' => t('Pending revisions'),
-      'callback' => 'revision_moderation_pending_revisions_admin',
-      'type' => MENU_LOCAL_TASK,
-      'access' => user_access('administer nodes'),
-    );
-    $items[] = array(
-      'path' => 'admin/settings/revision_moderation',
-      'title' => t('Revision moderation'),
-      'description' => t('Configure revision publishing options.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('revision_moderation_settings'),
-    );
-  }
-  else {
-    if (arg(0) == 'node' && is_numeric(arg(1))) {
-      $node = node_load(arg(1));
-      $access = user_access('administer nodes') || (user_access('view revisions') && node_access('update', $node));
-
-      // Callback to allow users to edit revisions.
-      $items[] = array(
-        'path' => 'node/'. arg(1) .'/revisions/'. arg(3) .'/edit',
-        'title' => t('Edit revision'),
-        'callback' => 'drupal_get_form',
-        'callback arguments' => array('revision_moderation_edit', arg(1), arg(3)),
-        'access' => $access,
-        'type' => MENU_CALLBACK,
-      );
-
-      // Callback to allow users to publish revisions directly.
-      $items[] = array(
-        'path' => 'node/'. arg(1) .'/revisions/'. arg(3) .'/publish',
-        'title' => t('Publish revision'),
-        'callback' => 'revision_moderation_publish',
-        'callback arguments' => array(arg(1), arg(3)),
-        'access' => $access,
-        'type' => MENU_CALLBACK,
-      );
-    }
-  }
+  // Callback to allow users to edit revisions.
+  $items['node/%node/revisions/%/edit'] = array(
+    'title' => t('Edit revision'),
+    'load arguments' => array(3),
+    'page callback' => 'revision_moderation_edit',
+    'page arguments' => array(1),
+    'access callback' => '_node_revision_access',
+    'access arguments' => array(1, 'update'),
+    'file' => 'node.pages.inc',
+    'file path' => drupal_get_path('module', 'node'),
+    'type' => MENU_CALLBACK,
+  );
 
+  // Callback to allow users to publish revisions directly.
+  $items['node/%node/revisions/%/publish'] = array(
+    'title' => t('Publish revision'),
+    'load arguments' => array(3),
+    'page callback' => 'revision_moderation_publish',
+    'page arguments' => array(1),
+    'access callback' => '_node_revision_access',
+    'access arguments' => array(1, 'update'),
+    'type' => MENU_CALLBACK,
+  );
+  
   return $items;
 }
 
@@ -74,15 +69,72 @@ function revision_moderation_settings() 
     '#default_value' => variable_get('revision_moderation_exempt', 1),
     '#description' => t('With this option enabled, users with the "administer nodes" privilege will bypass the moderation system, and their revisions will be published immediately.'),
   );
+  $form['revision_moderation_cron'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Cron job'),
+  );
+  $form['revision_moderation_cron']['revision_moderation_cron_enable'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable this cron job'),
+    '#default_value' => variable_get('revision_moderation_cron_enable', 0),
+    '#description' => t('to delete revisions. This operation can be very slow.'),
+  );
+  $form['revision_moderation_cron']['revision_moderation_cron_older_than'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Delete revisions older than'),
+    '#default_value' => variable_get('revision_moderation_cron_older_than', 0),
+    '#size' => 6,
+    '#maxlength' => 6,
+    '#description' => t('in days.'),
+  );
+  $form['revision_moderation_cron']['revision_moderation_cron_more_than'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Delete revisions of nodes having more than this amount of revisions'),
+    '#default_value' => variable_get('revision_moderation_cron_more_than', 0),
+    '#size' => 6,
+    '#maxlength' => 6,
+    '#description' => t(''),
+  );
+  $form['revision_moderation_cron']['revision_moderation_cron_amount'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Total amount'),
+    '#default_value' => variable_get('revision_moderation_cron_amount', 0),
+    '#size' => 6,
+    '#maxlength' => 6,
+    '#description' => t('Amount of total revisions to be deleted.'),
+  );
   return system_settings_form($form);
 }
 
+function revision_moderation_settings_validate($form, &$form_state) {
+  if (!empty($form_state['values']['revision_moderation_cron_enable'])) {
+    if (!is_numeric($form_state['values']['revision_moderation_cron_older_than']) || $form_state['values']['revision_moderation_cron_older_than'] < 0) {
+      form_set_error('revision_moderation_cron_older_than', t('Please input a number (bigger or equal than 0).'));
+    }
+    if (empty($form_state['values']['revision_moderation_cron_more_than'])) {
+      form_set_error('revision_moderation_cron_more_than', t('Please input an amount.'));
+    }
+    elseif (!is_numeric($form_state['values']['revision_moderation_cron_more_than']) || $form_state['values']['revision_moderation_cron_more_than'] < 1) {
+      form_set_error('revision_moderation_cron_more_than', t('Please input a number (bigger than 0).'));
+    }
+    if (empty($form_state['values']['revision_moderation_cron_amount'])) {
+      form_set_error('revision_moderation_cron_amount', t('Please input an amount.'));
+    }
+    elseif (!is_numeric($form_state['values']['revision_moderation_cron_amount']) || $form_state['values']['revision_moderation_cron_amount'] < 1) {
+      form_set_error('revision_moderation_cron_amount', t('Please input a number (bigger than 0).'));
+    }
+  }
+  $form_state['values']['revision_moderation_cron_older_than'] = (int)$form_state['values']['revision_moderation_cron_older_than'];
+  $form_state['values']['revision_moderation_cron_more_than'] = (int)$form_state['values']['revision_moderation_cron_more_than'];
+  $form_state['values']['revision_moderation_cron_amount'] = (int)$form_state['values']['revision_moderation_cron_amount'];
+}
+
 /**
  * Implementation of hook_form_alter().
  */
-function revision_moderation_form_alter($form_id, &$form) {
+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['#base']) && $form['#base'] == 'node_form') {
+  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']));
@@ -92,8 +144,8 @@ function revision_moderation_form_alter(
     }
 
     // Only show the checkbox if user has 'administer nodes' privileges.
-    if (user_access('administer nodes')) {
-      $form['options']['revision_moderation'] = array(
+    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,
@@ -119,31 +171,35 @@ function revision_moderation_nodeapi(&$n
   switch ($op) {
     case 'insert':
       // Store revision moderation setting of this node.
-      db_query('INSERT INTO {revision_moderation} (nid, revision_moderation) VALUES (%d, %d)', $node->nid, $node->revision_moderation);
+      drupal_write_record('revision_moderation', $node);
       break;
+      
     case 'update':
       // Update revision moderation setting of this node.
-      db_query('DELETE FROM {revision_moderation} WHERE nid = %d', $node->nid);
-      db_query('INSERT INTO {revision_moderation} (nid, revision_moderation) VALUES (%d, %d)', $node->nid, $node->revision_moderation);
+      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) {
         drupal_set_message(t('You are currently viewing a revision of this post created on @date by @author.', array('@date' => format_date($node->changed, 'small'), '@author' => $node->name)));
-        if (node_access('update', $node)) {
+        if ($access_update) {
           drupal_set_message(l(t('Edit revision'), "node/$node->nid/revisions/$node->vid/edit"));
-        }
-        if (user_access('revert revisions')) {
           // If this revision is old, show an option to revert to it.
           // Otherwise, show an option to publish it.
           if ($node->vid < $current_vid) {
@@ -152,12 +208,14 @@ function revision_moderation_nodeapi(&$n
           else {
             drupal_set_message(l(t('Publish revision'), "node/$node->nid/revisions/$node->vid/publish"));
           }
+        }
+        if ($access_delete) {
           drupal_set_message(l(t('Delete revision'), "node/$node->nid/revisions/$node->vid/delete"));
         }
       }
-      elseif ($node->revision_moderation == 1) {
+      elseif ($node->revision_moderation == 1 && empty($teaser)) {
         // Notify admin if a node has pending revisions.
-        if (user_access('view revisions') && arg(2) != 'revisions' && revision_moderation_get_node_pending_revisions($node->nid)) {
+        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"))));
         }
       }
@@ -166,7 +224,9 @@ function revision_moderation_nodeapi(&$n
 
   // Only do this logic for non-admin users on nodes with revision moderation
   // turned on.
-  if ($node->nid && $node->revision_moderation == 1 && (!user_access('administer nodes') || !variable_get('revision_moderation_exempt', 1))) {
+  // 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
@@ -182,10 +242,12 @@ function revision_moderation_nodeapi(&$n
           }
         }
         break;
-      case 'submit':
+        
+      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.
@@ -300,19 +362,42 @@ function revision_moderation_get_node_pe
 /**
  * Menu callback; edit revision.
  */
-function revision_moderation_edit($nid, $vid) {
-  $node = node_load($nid, $vid);
+function revision_moderation_edit($node) {
   drupal_set_message(t('You are currently editing a revision of this post created on @date by @author.', array('@date' => format_date($node->changed, 'small'), '@author' => $node->name)));
-  return node_form($node);
+  return drupal_get_form($node->type .'_node_form', $node);
 }
 
 /**
  * Menu callback; publish revision directly.
  */
-function revision_moderation_publish($nid, $vid) {
-  $node = node_load($nid, $vid);
-  db_query("UPDATE {node} SET vid = %d, title = '%s' WHERE nid = %d", $vid, $node->title, $nid);
+function revision_moderation_publish($node) {
+  db_query("UPDATE {node} SET vid = %d, title = '%s' WHERE nid = %d", $node->vid, $node->title, $node->nid);
   drupal_set_message('The selected revision has been published.');
-  watchdog('content', t('@type: published %title revision %revision', array('@type' => t($node->type), '%title' => $node->title, '%revision' => $vid)), WATCHDOG_NOTICE, l(t('view'), "node/$nid/revisions/$vid/view"));
-  drupal_goto("node/$nid");
+  watchdog('content', '@type: published %title revision %revision', array('@type' => t($node->type), '%title' => $node->title, '%revision' => $node->vid), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid/revisions/$node->vid/view"));
+  drupal_goto("node/". $node->nid);
+}
+
+function revision_moderation_cron() {
+  $enable = variable_get('revision_moderation_cron_enable', 0);
+  $amount = variable_get('revision_moderation_cron_amount', 0);
+  $older_than = variable_get('revision_moderation_cron_older_than', 0);
+  $more_than = variable_get('revision_moderation_cron_more_than', 0);
+  if (empty($enable) || empty($older_than) || empty($more_than) || empty($amount)) { return; }
+  $timestamp = time() - (int)($older_than * 86400);
+  $count_result = db_query("SELECT nid, COUNT(*) as count, MIN(timestamp) as timestamp FROM {node_revisions}
+                            GROUP BY nid HAVING timestamp < $timestamp AND count > $more_than");
+  while ($count_object = db_fetch_object($count_result)) {
+    $limit = min(array($amount, $count_object->count - $more_than));
+    if ($limit < 1) { break; }
+    $result = db_query("SELECT n.nid, r.vid FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid
+                        WHERE n.nid = %d AND r.vid != n.vid AND r.timestamp < $timestamp
+                        ORDER BY r.timestamp LIMIT %d", $count_object->nid, $limit);
+    while ($object = db_fetch_object($result)) {
+      $node = node_load($object->nid, $object->vid);
+      db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $node->nid, $node->vid);
+      node_invoke_nodeapi($node, 'delete revision');
+      watchdog('cron', '@type: deleted %title revision %revision.', array('@type' => $node->type, '%title' => $node->title, '%revision' => $node->vid));
+      $amount -= 1;
+    }
+  }
 }
Index: revision_moderation_actions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/revision_moderation/revision_moderation_actions.inc,v
retrieving revision 1.2
diff -u -p -r1.2 revision_moderation_actions.inc
--- revision_moderation_actions.inc	2 Nov 2006 04:37:49 -0000	1.2
+++ revision_moderation_actions.inc	10 Jun 2008 08:44:56 -0000
@@ -1,51 +1,52 @@
 <?php
-// $Id: revision_moderation_actions.inc,v 1.2 2006/11/02 04:37:49 webchick Exp $
+// $Id$
 
 /**
  * @file
- * Actions module support for revision moderation module.
+ * Actions support for revision moderation module.
  */
 
 /**
+ * Implementation of hook_action_info.
+ */
+function revision_moderation_action_info() {
+  $actions['revision_moderation_enable_action'] = array(
+    'type' => 'node',
+    'description' => t('Enable revision moderation on node'),
+    'configurable' => FALSE,
+    'hooks' => array(
+      'nodeapi' => array('presave', 'insert', 'update'),
+      'comment' => array('delete', 'insert', 'update')
+     ),
+  );
+  $actions['revision_moderation_disable_action'] = array(
+    'type' => 'node',
+    'description' => t('Disable revision moderation on node'),
+    'configurable' => FALSE,
+    'hooks' => array(
+      'nodeapi' => array('presave', 'insert', 'update'),
+      'comment' => array('delete', 'insert', 'update')
+     ),
+  );
+  return $actions;
+}
+
+/**
  * Implementation of a Drupal action; enables revision moderation
  * on a node.
  */
-function action_revision_moderation_enable($op, $edit = array(), &$node) {
-  switch ($op) {
-    case 'metadata':
-      return array(
-        'description' => t('Enable revision moderation on node'),
-        'type' => t('Node'),
-        'batchable' => true,
-        'configurable' => false,
-      );
-      break;
-    case 'do':
-      $node->revision_moderation = 1;
-      // Also enable "Create new revisions" option, in case it isn't yet.
-      $node->revision = 1;
-      node_save($node);
-      break;
-  }
+function revision_moderation_enable_action(&$node, $context) {
+  $node->revision_moderation = 1;
+  // Also enable "Create new revisions" option, in case it isn't yet.
+  $node->revision = 1;
+  node_save($node);
 }
 
 /**
  * Implementation of a Drupal action; disables revision moderation
  * on a node.
  */
-function action_revision_moderation_disable($op, $edit = array(), &$node) {
-  switch ($op) {
-    case 'metadata':
-      return array(
-        'description' => t('Disable revision moderation on node'),
-        'type' => t('Node'),
-        'batchable' => true,
-        'configurable' => false,
-      );
-      break;
-    case 'do':
-      $node->revision_moderation = 0;
-      node_save($node);
-      break;
-  }
+function revision_moderation_disable_action(&$node, $context) {
+  $node->revision_moderation = 0;
+  node_save($node);
 }
