Index: revision_moderation.module
===================================================================
--- revision_moderation.module	(revision 51)
+++ revision_moderation.module	(working copy)
@@ -1,5 +1,5 @@
 <?php
-// $Id: revision_moderation.module,v 1.39.2.14 2010/03/19 02:08:32 brauerranch Exp $
+// $Id: revision_moderation.module,v 1.39.2.12 2009/12/17 06:18:07 brauerranch Exp $
 
 /**
  * @file
@@ -9,27 +9,28 @@
 // Actions module support.
 include_once drupal_get_path('module', 'revision_moderation') .'/revision_moderation_actions.inc';
 
+
 /**
- * Implementation of hook_views_api().
+ * Implementation of hook_perm().
+ *
  */
-function revision_moderation_views_api() {
-  return array(
-    'api' => 2,
-    'path' => drupal_get_path('module', 'revision_moderation') .'/views',
-  );
+function revision_moderation_perm() {
+  return array('approve revisions');
 }
 
+
+
 /**
  * Implementation of hook_menu().
  */
 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'),
+    'access arguments' => array('approve revisions'),
     'type' => MENU_LOCAL_TASK,
   );
 
@@ -39,7 +40,7 @@
     'page callback' => 'drupal_get_form',
     'page arguments' => array('revision_moderation_settings'),
     'description' => t('Configure revision publishing options.'),
-    'access arguments' => array('administer nodes'),
+    'access arguments' => array('approve revisions'),
   );
 
   // Callback to allow users to edit revisions.
@@ -48,8 +49,7 @@
     'load arguments' => array(3),
     'page callback' => 'revision_moderation_edit',
     'page arguments' => array(1),
-    'access callback' => '_node_revision_access',
-    'access arguments' => array(1, 'update'),
+    'access arguments' => array("approve revisions"),
     'file' => 'node.pages.inc',
     'file path' => drupal_get_path('module', 'node'),
     'type' => MENU_CALLBACK,
@@ -61,8 +61,7 @@
     'load arguments' => array(3),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('revision_moderation_publish_confirm', 1),
-    'access callback' => '_node_revision_access',
-    'access arguments' => array(1, 'update'),
+    'access arguments' => array("approve revisions"),
     'type' => MENU_CALLBACK,
   );
 
@@ -74,7 +73,7 @@
  */
 function revision_moderation_admin_perm($nid) {
   $node = node_load($nid);
-  $access = user_access('administer nodes') || (user_access('view revisions') && node_access('update', $node));
+  $access = user_access('administer nodes') || user_access("approve revisions") || (user_access('view revisions') && node_access('update', $node));
   return $access;
 }
 
@@ -89,6 +88,16 @@
     '#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_msg'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Moderation message'),
+    '#default_value' => variable_get('revision_moderation_msg', t('Your changes have been submitted for moderation.')),
+    '#description' => t('This is the message users see after submitting a node which requires moderation.
+                         For example: "Thank you for submitting.  Once an administrator approves, your revision
+                         will be live on the site."
+                         <br>Note: HTML is allowed in this field.'),
+  );
+  
   return system_settings_form($form);
 }
 
@@ -156,12 +165,14 @@
       // 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');
+      $access_approve = user_access("approve 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) {
         $links = array(); // Array of links to show along with the message.
-        if ($access_update) {
+        if ($access_update || $access_approve) {
           // Add a link directly to the diff if we have Diff module installed.
           if (module_exists('diff')) {
            if ($node->vid > $current_vid) {
@@ -175,7 +186,7 @@
           $links[] = l(t('Edit revision'), "node/$node->nid/revisions/$node->vid/edit");
           // If this revision is old, show an option to revert to it.
           // Otherwise, show an option to publish it.
-          if ($node->vid < $current_vid) {
+          if ($node->vid < $current_vid && $access_update) {
             $links[] = l(t('Revert to revision'), "node/$node->nid/revisions/$node->vid/revert");
           }
           else {
@@ -198,11 +209,12 @@
       break;
   }
 
+  $moderation_msg = variable_get('revision_moderation_msg', t('Your changes have been submitted for moderation.'));
   // Only do this logic for non-admin users on nodes with revision moderation
   // turned on.
   // 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))) {
+    && ((!user_access('administer nodes') && !user_access("approve revisions")) || !variable_get('revision_moderation_exempt', 1))) {
     switch ($op) {
       case 'prepare':
         // If user has a pending revision for this node, load the latest version of
@@ -236,7 +248,7 @@
             db_query("INSERT INTO {revision_moderation} (nid, revision_moderation) VALUES(%d, 1)", $node->nid);
           }
 
-          drupal_set_message(t('Your changes have been submitted for moderation.'));
+          drupal_set_message($moderation_msg);
         }
         break;
     }
@@ -244,21 +256,8 @@
   else if ($node->nid && $node->revision_moderation == 1 && end($args) == 'edit') {
     switch ($op) {
       case 'prepare':
-        $revision_author = user_load($node->revision_uid);
-        $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 editing a pending update of this post created on @date by !author.', array('@date' => format_date($node->revision_timestamp, 'small'), '!author' => theme('username', $revision_author))));
-        }
-        if($node->vid == $current_vid) {
-          if(revision_moderation_get_node_pending_revisions($node->nid)) {
-            if(variable_get('revision_moderation_exempt', 1)) {
-              drupal_set_message(t('You are currently editing the current published version of this post, created on @date by !author. Note that there are other pending revisions, and that pressing save will publish this version of the post instead.', array('@date' => format_date($node->revision_timestamp, 'small'), '!author' => theme('username', $revision_author))));
-            }
-            else {
-              drupal_set_message(t('You are currently editing the current published version of this post, created on @date by !author.', array('@date' => format_date($node->revision_timestamp, 'small'), '!author' => theme('username', $revision_author))));
-            }
-          }
-        }
+      	   $revision_author = user_load($node->revision_uid);
+  	   		    drupal_set_message(t('You are currently editing a revision of this post created on @date by !author.', array('@date' => format_date($node->revision_timestamp, 'small'), '!author' => theme('username', $revision_author))));
         break;
       case 'presave':
         $current_vid = db_result(db_query('SELECT vid FROM {node} WHERE nid = %d', $node->nid));
@@ -267,16 +266,14 @@
 
       case 'update':
         if (isset($node->original_node)) {
-          // Exempt admin users publish their version immediately
-          if(!user_access('administer nodes') || !variable_get('revision_moderation_exempt', 1)) {
-            // Update node table's vid to the original value.
-            db_query("UPDATE {node} SET vid = %d, title = '%s', status = %d, moderate = %d WHERE nid = %d", $node->original_node->vid, $node->original_node->title, $node->original_node->status, $node->original_node->moderate, $node->nid);
-            drupal_set_message(t('Your changes have been submitted for moderation.'));
-          }
+          // Update node table's vid to the original value.
+          db_query("UPDATE {node} SET vid = %d, title = '%s', status = %d, moderate = %d WHERE nid = %d", $node->original_node->vid, $node->original_node->title, $node->original_node->status, $node->original_node->moderate, $node->nid);
+          drupal_set_message($moderation_msg);
         }
         break;
     }
   }
+ 
 }
 
 /**
@@ -291,11 +288,12 @@
   elseif ($op == 'view') {
     $block = array();
 
-    if (user_access('administer nodes')) {
+    if (user_access('administer nodes') || user_access("approve revisions")) {
       $output = '';
       $list = array();
 
       $nodes = revision_moderation_get_all_pending_revisions(10);
+
       if (count($nodes)) {
         foreach ($nodes as $node) {
           $list[] = l($node->title, "node/$node->nid/revisions/$node->vid/view");
@@ -369,11 +367,17 @@
  */
 function revision_moderation_get_all_pending_revisions($limit) {
   // Obtain a list of nodes with revisions higher than current published revision.
-  $sql = "SELECT n.nid, r.vid, n.type, r.title, r.body, r.uid, r.timestamp FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid WHERE r.vid > n.vid ORDER BY r.vid DESC LIMIT %d";
+  $sql = "SELECT n.nid, r.vid, n.type, r.title, r.body, r.uid, r.timestamp 
+          FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid 
+          WHERE r.vid > n.vid 
+          ORDER BY r.vid DESC
+          LIMIT %d";
   $result = db_query($sql, $limit);
   $revisions = array();
   while ($revision = db_fetch_object($result)) {
-    $revisions[$revision->nid] = $revision;
+    if (!isset($revisions[$revision->nid])) {
+      $revisions[$revision->nid] = $revision;
+    }
   }
 
   return $revisions;
