Index: epublish.install
===================================================================
--- epublish.install	(revision 282)
+++ epublish.install	(working copy)
@@ -13,6 +13,7 @@
   ) TYPE=MyISAM;");
   db_query("CREATE TABLE {epublish_abstract} (
     nid int(10) NOT NULL default '0',
+    vid int(10) NOT NULL default '0',
     epublish_abstract longtext NOT NULL,
     use_as_teaser int(2) NOT NULL default '0',
     UNIQUE KEY nid (nid)
@@ -35,6 +36,7 @@
   db_query("CREATE TABLE {epublish_edition_node} (
     eid int(10) unsigned NOT NULL default '0',
     nid int(10) unsigned NOT NULL default '0',
+    vid int(10) unsigned NOT NULL default '0',
     weight tinyint(4) NOT NULL default '0',
     tid int(10) NOT NULL default '0',
     KEY eid (eid,nid),
@@ -75,4 +77,53 @@
  		'epublish_section', 'epublish_topic', 'epublish_volume'));
 }
 
-?>
+function epublish_update_2() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $sql = "SELECT nid FROM {epublish_abstract} ORDER BY nid";
+      $sql2 = "UPDATE {epublish_abstract} SET vid = %d WHERE nid = %d";
+      $sql3 = "SELECT vid FROM {node} WHERE nid = %d";
+      $ret[] = update_sql("ALTER TABLE {epublish_abstract} ADD vid int(10) unsigned default '0' NOT NULL");
+      $results = db_query($sql);
+      while ($result = db_fetch_object($results)) {
+        $vid = db_fetch_object(db_query($sql3, $result->nid));
+        db_query($sql2, $vid->vid, $result->nid);
+      }
+      $sql4 = "SELECT nid FROM {epublish_edition_node} ORDER BY nid";
+      $sql5 = "UPDATE {epublish_edition_node} SET vid = %d WHERE nid = %d";
+      $sql6 = "SELECT vid FROM {node} WHERE nid = %d";
+      $ret[] = update_sql("ALTER TABLE {epublish_edition_node} ADD vid int(10) unsigned default '0' NOT NULL");
+      $results = db_query($sql4);
+      while ($result = db_fetch_object($results)) {
+        $vid = db_fetch_object(db_query($sql6, $result->nid));
+        db_query($sql5, $vid->vid, $result->nid);
+      }
+      break;
+  }
+  return $ret;
+}
+
+function epublish_uninstall() {
+  $vardel = FALSE;
+  $query1 = db_query('DROP TABLE {epublish_publication}');
+  $query2 = db_query('DROP TABLE {epublish_abstract}');
+  $query3 = db_query('DROP TABLE {epublish_edition}');
+  $query4 = db_query('DROP TABLE {epublish_edition_node}');
+  $query5 = db_query('DROP TABLE {epublish_section}');
+  $query6 = db_query('DROP TABLE {epublish_topic}');
+  $query7 = db_query('DROP TABLE {epublish_volume}');
+  //TODO delte every item from the variable table
+  //if(variable_del('accounttypes_default')) {
+    $vardel = TRUE;
+  //}
+  
+  if ($query1 && $query2 && $query3 && $query4 && $query5 && $varde6 && $varde7 && $vardel) {
+    drupal_set_message('The epublish module was uninstalled successfully.');
+  }
+  else {
+    drupal_set_message('There was an error removing the epublish database tables.', 'error');
+  }
+  
+}
\ No newline at end of file
Index: epublish.module
===================================================================
--- epublish.module	(revision 282)
+++ epublish.module	(working copy)
@@ -1,29 +1,4 @@
 <?php
-// $Id: epublish.module,v 1.14.4.1 2007/05/17 22:50:05 gloscon Exp $
-
-/*
-		epublish.module - Part of the epublish module for Drupal		
-
-		This program is free software; you can redistribute it and/or modify
-		it under the terms of the GNU General Public License as published by
-		the Free Software Foundation; either version 2 of the License, or
-		(at your option) any later version.
-
-		This program is distributed in the hope that it will be useful,
-		but WITHOUT ANY WARRANTY; without even the implied warranty of
-		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
-		GNU General Public License for more details.
-
-		You should have received a copy of the GNU General Public License
-		along with this program; if not, write to the Free Software
-		Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-/* Updated for Drupal 4.7, 2006/05/28
-   Thanks to Ben Shell http://www.benjaminshell.com
-   for his contributions to the upgrade.
-*/
-
 /**
  * @file epublish.module
  * This module helps organize a group of nodes into a publication, such as
@@ -34,6 +9,29 @@
  * as "international," "national," "sports," etc.
  *
  * @note See the module help for usage and administration information.
+ * epublish.module - Part of the epublish module for Drupal
+ * 
+ * $Id:$
+ * 
+ * Updated for Drupal 4.7, 2006/05/28
+ * Thanks to Ben Shell http://www.benjaminshell.com
+ * for his contributions to the upgrade.		
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * TODO allow group publications to be marked as public; recurse through attached nodes and set to public as well
+ * TODO set site-wide and group defaults for 'Time frame:' setting so users don't have to set each one
  */
 
 /**
@@ -50,7 +48,7 @@
 		case 'admin/node/configure/defaults':
 			$output = t('<p>If you want users to be able to enter brief abstracts of postings for displays on headlines and publication pages, check the <em>has abstract</em> box.</p>');
 			break;
-	case 'admin/help#epublish':
+	  case 'admin/help#epublish':
 			$output = t("<p>This module helps organize a publication or group of publications, each with multiple editions.</p>".
 									"<h3>Configuration</h3><p>To use this module, you have to take a few steps:</p>".
 					"<ul><li>Install and enable the module.</li>".
@@ -121,8 +119,8 @@
 /**
  * hook_perm: Define user permissions for module epublish
  */
-function epublish_perm() {
-	return array('administer publications');
+function epublish_perm() {//TODO probably need to add more granular perms for OG, or check against other perms down below
+	return array('administer publications', 'edit abstract');
 }
 
 /**
@@ -309,7 +307,8 @@
 		'#title' => t('Custom layouts?'),
 		'#return_value' => 1,
 		'#default_value' => variable_get('epublish_custom_layouts', '0'),
-		'#description' => t('If this option is checked, publications, sections and editions can each have their own own layouts that override the global layouts selected above.'),
+		'#description' => t('If this option is checked, publications, sections and editions can each have their own own layouts
+		 that override the global layouts selected above.'),
 	);
 
 	// sections
@@ -342,32 +341,35 @@
  * Implementation of hook_form_alter().
  */
 function epublish_form_alter($form_id, &$form) {
-	if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id)
-	 {
-	   $form['submission']['epublish_abstract_'. $form['type']['#value']] = array(
+	if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {//TODO make the visibility of this depend on a perm
+    $form['epublish'] = array(
+     '#type' => 'fieldset',
+     '#title' => t('Abstract settings'),
+     '#weight' => 5,
+     '#collapsible' => FALSE,
+     '#collapsed' => FALSE,
+    );
+    $form['epublish']['epublish_abstract'] = array(
 			'#type' => 'checkbox',
 			'#title' => t('Has abstract'),
 			'#return_value' => 1,
-			'#default_value' => variable_get('epublish_abstract_'. $form['type']
-					    ['#value'], TRUE),
-			'#description' => t('Users can enter a brief abstract summarizing the 						   content of each node.'),
-		);
-	 }
-	 else if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id)
-	 {
-	      if (variable_get('epublish_abstract_'. $form['type']['#value'], TRUE))
-	 {
-			$node = $form['#node'];
-			$form['epublish_abstract'] = array(
-				'#type' => 'textarea',
-				'#title' => t('Abstract'),
-				'#default_value' => $node->epublish_abstract,
-				'#cols' => 70,
-				'#rows' => 4,
-				'#description' => t('A brief summary of this item.'),
-			);
-	 }
-	 }
+			'#default_value' => variable_get('epublish_abstract_'. $form['#node_type']->type, TRUE),
+      '#description' => t('Users can enter a brief abstract summarizing the content of each node.'),	
+    );
+  }
+  elseif (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {//TODO make the visibility of this depend on a perm
+    if (variable_get('epublish_abstract_'. $form['type']['#value'], TRUE)) {
+  	  $node = $form['#node'];
+  		$form['epublish_abstract'] = array(
+  			'#type' => user_access('edit abstract') ? 'textarea' : 'hidden',
+  			'#title' => t('Abstract'),
+  			'#default_value' => $node->epublish_abstract,
+  			'#cols' => 70,
+  			'#rows' => 4,
+  			'#description' => t('A brief summary of this item for possible use in newsletters and other site or group publications.'),
+  		);
+  	}
+	}
 }
 
 /**
@@ -377,58 +379,59 @@
 	switch ($op) {
 		case 'insert':
 			if (variable_get('epublish_abstract_'. $node->type, TRUE)) {
-				db_query("INSERT INTO {epublish_abstract} (nid, epublish_abstract) VALUES ('%d', '%s')", $node->nid, $node->epublish_abstract);
+				db_query("INSERT INTO {epublish_abstract} (nid, vid, epublish_abstract) VALUES (%d, %d, '%s')", $node->nid, $node->vid, $node->epublish_abstract);
 			}
 			break;
 		case 'update':
 			if (variable_get('epublish_abstract_'. $node->type, TRUE)) {
 				db_query("DELETE FROM {epublish_abstract} WHERE nid = '%d'", $node->nid);
 				if ($node->epublish_abstract) {
-					db_query("INSERT INTO {epublish_abstract} (nid, epublish_abstract) VALUES ('%d', '%s')", $node->nid, $node->epublish_abstract);
+					db_query("INSERT INTO {epublish_abstract} (nid, epublish_abstract) VALUES (%d, '%s')", $node->nid, $node->vid, $node->epublish_abstract);
 				}
 			}
 			break;
 		case 'delete':
-			db_query("DELETE FROM {epublish_edition_node} WHERE nid = '%d'", $node->nid);
+			db_query("DELETE FROM {epublish_edition_node} WHERE nid = %d AND vid = %d", $node->nid, $node->vid);
 			if (variable_get('epublish_abstract_'. $node->type, TRUE)) {
-				db_query("DELETE FROM {epublish_abstract} WHERE nid = '%d'", $node->nid);
+				db_query("DELETE FROM {epublish_abstract} WHERE nid = %d AND vid = %d", $node->nid, $node->vid);
 			}
 			break;
 		case 'load':
 			if (variable_get('epublish_abstract_'. $node->type, TRUE)) {
-				$object = db_fetch_object(db_query("SELECT epublish_abstract FROM {epublish_abstract} WHERE nid = '%d'", $node->nid));
+				$object = db_fetch_object(db_query("SELECT epublish_abstract FROM {epublish_abstract} WHERE nid = %d AND vid = %d", $node->nid, $node->vid));
 				return array('epublish_abstract' => $object->epublish_abstract);
 			}
 			break;
-    		case 'view':
-			// append epublish navigation to all nodes that belong to an edition
-      			if (!$a3) {
-        			$eid = db_result(db_query('SELECT eid FROM {epublish_edition_node} een WHERE nid = %d', $node->nid));
-        		if ($eid) {
-          			$node = theme('epublish_navigation', $node, $eid);
-        		}
-      			}
-      			break;
-		}
+		case 'view'://TODO what about having a 'mode' to be in, rather than always showing the controls?
+	// append epublish navigation to all nodes that belong to an edition
+			if ($a4) {
+  			$eid = db_result(db_query('SELECT eid FROM {epublish_edition_node} een WHERE vid = %d', $node->vid));
+    		if ($eid) {
+      			$node = theme('epublish_navigation', $node, $eid);
+    		}
+			}
+			break;
+  }
 }
 
 /**
  * Implementation of hook_block().
  */
-function epublish_block($op = 'list', $delta = 0) {
+function epublish_block($op = 'list', $delta = 0) {//TODO limit view to site-wide/subscribed/public group pub's
 	if ($op == 'list') {
 		$blocks = array();
 		$blocks[0]['info'] = t('E-Publish');
 		foreach (epublish_sections() as $sid => $title) {
-		$blocks[$sid]['info'] = t('E-publish section: ') . t($title);
-	}
+		  $blocks[$sid]['info'] = t('E-publish section: ') . t($title);
+	  }
 		$publications = db_query("SELECT * FROM {epublish_publication}");
 		while ($publication = db_fetch_object($publications)) {
 			$blocks['pub_' . $publication->pid]['info'] = t($publication->name);
       $blocks['cur_edition_' . $publication->pid]['info'] = t("Current edition of !pub", array('!pub' => $publication->name));
 		}
 	return $blocks;
-	} else if ($op == 'view') {
+	} 
+	else if ($op == 'view') {
 
 		// publication blocks
     if (substr($delta, 0, 12) == 'cur_edition_') {
@@ -441,20 +444,31 @@
 			$topics = epublish_section_topics($sid, $edition->eid);
 			$items = array();
 			foreach ($topics as $topic) {
-				foreach ($topic->nodes as $nid) {
-					$node = node_load($nid);
-					$items[] = l($node->title, "node/$nid");
+				foreach ($topic->nodes as $vid) {
+				  $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
+          $nid = db_fetch_object(db_query($sql, $vid));
+					$node = node_load($nid->nid);
+					$sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+          $count = db_num_rows(db_query($sql_count, $node->nid));
+          if ($count > 1) {
+					  $items[] = l($node->title, "node/$nid->nid/revisions/$vid/view");
+          }
+          else {
+            $items[] = l($node->title, "node/$nid->nid");
+          }
 				}
 			}
 			$data['content'] = theme('item_list', $items);
       return $data;
-    } else if (substr($delta, 0, 4) == 'pub_') {
+    } 
+    elseif (substr($delta, 0, 4) == 'pub_') {
 			$pid = substr($delta, 4);
 		$publication = epublish_get_pub($pid);
 			$data['subject'] = t($publication->name);
 			$items = array();
 			$order = variable_get('epublish_edition_order', 'DESC');
-			$result = db_query("SELECT * FROM {epublish_edition} WHERE published=1 AND pid='%d' ORDER BY volume $order, number $order, pubdate $order, eid $order LIMIT 10", $publication->pid);
+			$result = db_query("SELECT * FROM {epublish_edition} WHERE published=1 AND pid='%d' 
+			ORDER BY volume $order, number $order, pubdate $order, eid $order LIMIT 10", $publication->pid);
 			while (($edition = db_fetch_object($result)) && $i++ < 10) {
 				$items[] = l(theme('epublish_edition_reference', $edition), "epublish/$publication->pid/$edition->eid");
 			}
@@ -465,7 +479,8 @@
 			return $data;
 
 		// section blocks
-		} else if ($delta) {
+		} 
+		elseif ($delta) {
 			$section = epublish_get_section($delta);
 			$topics = epublish_topic_selection_list($delta);
 			$data['subject'] = l(t($section->title), "headlines/$delta");
@@ -477,11 +492,12 @@
 			}
 			$data['content'] = theme('item_list', $items);
 			return $data;
-		} else {
+		} 
+		else {
 			$data['subject'] = t('Publications');
 			$result = db_query("SELECT * from {epublish_publication}");
 			$items = array();
-		while ($publication = db_fetch_object($result)) {
+		  while ($publication = db_fetch_object($result)) {
 				$items[] = l($publication->name, "epublish/$publication->pid");
 			}
 			$data['content'] .= theme('item_list', $items);
@@ -504,7 +520,7 @@
  *	 An array of sections and their titles, suitable for use as the $options in a form_select call, e.g.,
  *			form_select($title, $name, $value, epublish_sections(), $description)
  */
-function epublish_sections($include_default = false) {
+function epublish_sections($include_default = false) {//TODO allow groups to maintain their own sections
 	$result = db_query("SELECT * FROM {epublish_section}");
 	$sections = array();
 	// if no sections exist, create a default section
@@ -675,19 +691,21 @@
 /**
  * epublish_pub_page: Display the publication(s).
  */
-function epublish_pub_page() {
+function epublish_pub_page() {//TODO I think this is where I limit the view according to what the user is allowed to see.
 	$pub = arg(1);
 	$ed = arg(2); //) ? arg(2) : 'current';
 	if (is_numeric($pub)) {
 		$publication = epublish_get_pub($pub);
-	} else if ($pub) {
+	} 
+	elseif ($pub) {
 		$publication = epublish_get_pub_by_name($pub);
 	}
 	if ($publication) {
 		if ($ed == t('current')) {
 			$ed = epublish_current_edition($publication->pid);
 		}
-	} else {
+	} 
+	else {
 		return theme('epublish_format_pub');
 	}
 	if (is_numeric($ed)) {
@@ -695,18 +713,21 @@
 		$sid = epublish_assign_section($edition);
 		$topics = epublish_section_topics($sid, $edition->eid);
 		$output = theme('epublish_topics', $topics, $sid, $edition, 'page');
-	} else {
+	} 
+	else {
 		$order = variable_get('epublish_edition_order', 'DESC');
 		preg_match('/(v([0-9]+))?(n([0-9]+))?/i', $ed, $match);
 		$volume = $match[2] ? (" AND volume=" . $match[2]) : '';
 		$number = $match[4] ? (" AND number=" . $match[4]) : '';
-		$editions = db_query("SELECT * FROM {epublish_edition} WHERE published=1 AND pid='%d'$volume$number ORDER BY volume $order, number $order, pubdate $order, eid $order", $publication->pid);
+		$editions = db_query("SELECT * FROM {epublish_edition} WHERE published=1 AND pid='%d'$volume$number 
+		ORDER BY volume $order, number $order, pubdate $order, eid $order", $publication->pid);
 		if (db_num_rows($editions) == 1) {
 			$edition = db_fetch_object($editions);
 			$sid = epublish_assign_section($edition);
 			$topics = epublish_section_topics($sid, $edition->eid);
 			$output = theme('epublish_topics', $topics, $sid, $edition, 'page');
-		} else {
+		} 
+		else {
 			$edition = NULL;
 		if (!$ed) {
 			$output .= '<div class="content">' . $publication->description . '</div>';
@@ -767,7 +788,7 @@
 /**
  * epublish_headlines_page: Display the headlines.
  */
-function epublish_headlines_page() {
+function epublish_headlines_page() {//TODO if this is for a single pub, then it's probably okay
 	$sid = arg(1);
 	$sids = epublish_sections();
 	if (!$sid) {
@@ -778,31 +799,36 @@
 	if ($section->timeframe) {
 		$timeframe = " AND (n.created >= '" . strtotime('-' . $section->timeframe) . "' OR n.sticky=1)";
 	}
-	$result = db_query("SELECT et.tid, et.count, et.node_types, td.name FROM {epublish_topic} et LEFT JOIN {term_data} td USING (tid) WHERE et.sid='%d' ORDER BY et.weight", $sid);
+	$result = db_query("SELECT et.tid, et.count, et.node_types, td.name FROM {epublish_topic} et 
+	LEFT JOIN {term_data} td USING (tid) WHERE et.sid='%d' ORDER BY et.weight", $sid);
 	$all_nodes = array();
 	$topics = array();
 	while ($topic = db_fetch_object($result)) {
 		$included_node_types = _epublish_build_node_inclusions(array_unique(array_merge(explode(',', $section->node_types), explode(',', $topic->node_types))));
-	$exclusions = _epublish_build_node_exclusions($all_nodes);
-	// Condition to handle another default section
+	  $exclusions = _epublish_build_node_exclusions($all_nodes);
+	  // Condition to handle another default section
 			if ($topic->tid == -2) {
 			$topic->name = variable_get('epublish_advertisement', t('advertisement'));
-			$result2 = db_query("SELECT DISTINCT(n.nid) FROM {node} n WHERE ($exclusions) AND ($included_node_types) AND n.promote = 1 AND n.status = 1$timeframe AND n.sticky = 1 ORDER by n.created DESC LIMIT $topic->count");
+			$result2 = db_query("SELECT DISTINCT(v.vid), n.nid FROM {node_revisions} INNER JOIN {node} n ON n.nid = v.nid 
+			WHERE ($exclusions) AND ($included_node_types) AND n.promote = 1 AND n.status = 1$timeframe AND n.sticky = 1 ORDER by n.created DESC LIMIT $topic->count");
 		} else if ($topic->tid == -1) {
-
 			$topic->name = variable_get('epublish_top_stories', t('top stories'));
-			$result2 = db_query("SELECT DISTINCT(n.nid) FROM {node} n WHERE ($exclusions) AND ($included_node_types) AND n.promote = 1 AND n.status = 1$timeframe AND n.sticky = 1 ORDER by n.created DESC LIMIT $topic->count");
+			$result2 = db_query("SELECT DISTINCT(v.vid), n.nid FROM {node_revisions} INNER JOIN {node} n ON n.nid = v.nid 
+			WHERE ($exclusions) AND ($included_node_types) AND n.promote = 1 AND n.status = 1$timeframe AND n.sticky = 1 ORDER by n.created DESC LIMIT $topic->count");
 		} else if ($topic->tid == 0) {
 			$topic->name = variable_get('epublish_miscellaneous', t('miscellaneous'));
-			$result2 = db_query("SELECT DISTINCT(n.nid) FROM {node} n WHERE ($exclusions) AND ($included_node_types) AND n.promote = 1 AND n.status = 1$timeframe ORDER by n.sticky DESC, n.created DESC LIMIT $topic->count");
+			$result2 = db_query("SELECT DISTINCT(v.vid), n.nid FROM {node_revisions} INNER JOIN {node} n ON n.nid = v.nid 
+			WHERE ($exclusions) AND ($included_node_types) AND n.promote = 1 AND n.status = 1$timeframe ORDER by n.sticky DESC, v.timestamp DESC LIMIT $topic->count");
 		} else {
 		$included_terms = _epublish_topic_term_inclusions($topic->tid, $sid);
-			$result2 = db_query("SELECT DISTINCT(n.nid) FROM {node} n INNER JOIN {term_node} tn ON n.nid=tn.nid WHERE ($exclusions) AND ($included_node_types) AND ($included_terms) AND n.promote = 1 AND n.status = 1$timeframe ORDER by n.sticky DESC, n.created DESC LIMIT $topic->count");
+			$result2 = db_query("SELECT DISTINCT(v.vid), n.nid FROM {node_revisions} INNER JOIN {node} n ON n.nid = v.nid 
+			INNER JOIN {term_node} tn ON n.nid=tn.nid WHERE ($exclusions) AND ($included_node_types) AND ($included_terms) 
+			AND n.promote = 1 AND n.status = 1$timeframe ORDER by n.sticky DESC, v.timestamp DESC LIMIT $topic->count");
 		}
 	$topic->nodes = array();
 		while ($node = db_fetch_object($result2)) {
-		$topic->nodes[] = $node->nid;
-			$all_nodes[] = $node->nid;
+		$topic->nodes[] = $node->vid;
+			$all_nodes[] = $node->vid;
 	}
 		if (count($topic->nodes)) {
 			$topics[] = $topic;
@@ -849,9 +875,10 @@
 	$sid = epublish_assign_section($edition);
 	$topics = epublish_section_topics($sid, $edition->eid);
   if (is_numeric($edition->volume) && is_numeric($edition->number) && $edition->volume > 0 && $edition->number > 0) {
-		$output = "<li><div class=\"reference\">" . l(theme('epublish_edition_reference', $edition), "epublish/$edition->pid/v$edition->volume" . "n$edition->number") . "</div></li>\n";
+		$output = "<li><div class=\"reference\">".
+		l(theme('epublish_edition_reference', $edition), "epublish/$edition->pid/v$edition->volume" . "n$edition->number") . "</div></li>\n";
 	} else {
-		$output = "<li><div class=\"reference\">" . l(theme('epublish_edition_reference', $edition), "epublish/$edition->pid/$edition->eid") . "</div></li>\n";
+		$output = "<li><div class=\"reference\">". l(theme('epublish_edition_reference', $edition), "epublish/$edition->pid/$edition->eid") . "</div></li>\n";
 	}
 	$output .= theme('epublish_topics', $topics, $sid, $edition, 'list');
 	return '<div class="edition">' . "$output</div>\n";
@@ -873,7 +900,7 @@
 		}
 	}
 	$output .= "</dl>\n";
-	drupal_set_title(t('publications'));
+	drupal_set_title(t('Publications'));
 	return "<div class=\"epublish\">$output</div>";
 }
 
@@ -902,7 +929,7 @@
  * @return
  *	 the name of the layout to use
  */
-function epublish_assign_layout($sid, &$edition, $context) {
+function epublish_assign_layout($sid, &$edition, $context) {//TODO probably need to og-ify this
 	$layout = "layout_$context";
 	if (variable_get('epublish_custom_layouts', '0')) {
 		$section = epublish_get_section($sid);
@@ -938,7 +965,7 @@
  * @return
  *	 the headlines section ID number
  */
-function epublish_assign_section(&$edition) {
+function epublish_assign_section(&$edition) {//TODO probably need to og-ify this 
 	$sids = epublish_sections();
 	if (variable_get('epublish_custom_sections', false)) {
 		if ($sids[$edition->sid]) {
@@ -1026,7 +1053,7 @@
  */
 
 
-function epublish_sections_table() {
+function epublish_sections_table() {//TODO will need to create a similar interface at the group level; leave this to the site-wide pub's
 	$sections = epublish_sections();
 	$result = db_query("SELECT * FROM {epublish_section}");
 	$header = array(t('sections/topics'), array("data" => t("operations"), "colspan" => 2));
@@ -1054,7 +1081,7 @@
 * @return
 * An array
 */
-function epublish_sections_button_form() {
+function epublish_sections_button_form() {//TODO this seems like a waste; see above and below
 
 	$form[] = array(
 		'#type' => 'submit',
@@ -1067,7 +1094,7 @@
 /**
 * Renders a form returned by epublish_sections_button_form()
 */
-function epublish_sections_button() {
+function epublish_sections_button() {//TODO this seems like a waste; see above
 $output = drupal_get_form('epublish_sections_button_form');
 	return $output;
 }
@@ -1079,11 +1106,11 @@
 	drupal_goto('admin/epublish/add/section');
 }
 
-function section_form() {
+//function section_form() {//TODO this isn't used? the function below calls epublish_form_section too
 
-$output = drupal_get_form('epublish_form_section');
-	return $output;
-}
+//$output = drupal_get_form('epublish_form_section');
+//	return $output;
+//}
 
 /**
  * Page to add or edit a section
@@ -1182,7 +1209,8 @@
 			'#title' => t("Page layout"),
 			'#default_value' => $edit->layout_page,
 			'#options' => $layouts,
-			'#description' => t("Select a page layout for this section. If none is selected, the default !settings will be used.", array('!settings' => l(t('layout settings'), 'admin/settings/epublish'))),
+			'#description' => t("Select a page layout for this section. If none is selected, the default !settings will be used.", 
+			array('!settings' => l(t('layout settings'), 'admin/settings/epublish'))),
 		);
 		$layouts = epublish_layouts('list', TRUE);
 		$form["layout_list"] = array(
@@ -1190,7 +1218,8 @@
 			'#title' => t("Listing layout"),
 			'#default_value' => $edit->layout_list,
 			'#options' => $layouts,
-			'#description' => t("Select a layout to control the display of headline listings for this section. If none is selected, the default settings will be used."),
+			'#description' => t("Select a layout to control the display of headline listings for this section. 
+			If none is selected, the default settings will be used."),
 		);
 	} else {
 		// Even if custom layouts are turned off, pass through the layout values as hidden inputs.
@@ -1215,7 +1244,8 @@
 		'#type' => 'fieldset',
 		'#title' => t('Automatic selection rules'),
 	);
-	$form['rules'][] = array('#value' => t('The automatic selection rules determine which postings will be selected to display in the !heads (where no publication or edition is specified).', array('!heads' => l(t('headlines listing'), 'headlines/' . $edit->sid))));
+	$form['rules'][] = array('#value' => t('The automatic selection rules determine which postings will be 
+	selected to display in the !heads (where no publication or edition is specified).', array('!heads' => l(t('headlines listing'), 'headlines/' . $edit->sid))));
 	$nodetypes = array();
 	foreach (node_get_types() as $type => $name_obj) {
 
@@ -1239,7 +1269,9 @@
 		'#default_value' => $edit->timeframe,
 		'#size' => 20,
 		'#maxlength' => 16,
-		'#description' => t('The time frame covered by the headlines listing. For example, "30 days" means that headlines will be selected from items that have been posted within the last 30 days. Other possibilities could be "2 years" or "3 months" or "1 week." If left blank, there is no time limit.'),
+		'#description' => t('The time frame covered by the headlines listing. For example, "30 days" means 
+		that headlines will be selected from items that have been posted within the last 30 days. 
+		Other possibilities could be "2 years" or "3 months" or "1 week." If left blank, there is no time limit.'),
 	);
 	$form['submit'] = array(
 		'#type' => 'submit',
@@ -1258,7 +1290,7 @@
 	return $form;
 }
 
-function epublish_sec() {
+function epublish_sec() {//TODO again, an unused function???
 $output = drupal_get_form('epublish_form_section');
 	return $output;
 }
@@ -1302,7 +1334,9 @@
 		$form_values['node_types'] = array();
 	}
 	if ($form_values['sid'] && $form_values['action'] != 'delete') {
-		db_query("UPDATE {epublish_section} SET title = '%s', vid = '%d', node_types = '%s', timeframe='%s', layout_list='%s', layout_page='%s' WHERE sid = '%d'", $form_values['title'], $form_values['vid'], implode(',', $form_values['node_types']), $form_values['timeframe'], $form_values['layout_list'], $form_values['layout_page'], $form_values['sid']);
+		db_query("UPDATE {epublish_section} SET title = '%s', vid = '%d', node_types = '%s', timeframe='%s', layout_list='%s', layout_page='%s' 
+		WHERE sid = '%d'", $form_values['title'], $form_values['vid'], implode(',', $form_values['node_types']), $form_values['timeframe'], 
+		$form_values['layout_list'], $form_values['layout_page'], $form_values['sid']);
 		// Handle operations:
 		if (isset($form_values['weight'])) {
 			foreach ($form_values['weight'] as $tid => $value) {
@@ -1314,7 +1348,9 @@
 		epublish_del_section($form_values['sid']);
 	} else {
 		$form_values['sid'] = db_next_id('{epublish_section}_sid');
-		db_query("INSERT INTO {epublish_section} (sid, title, vid, node_types, timeframe, layout_list, layout_page) VALUES ('%d', '%s', '%d', '%s', '%s', '%s', '%s')", $form_values['sid'], $form_values['title'], $form_values['vid'], implode(',', $form_values['node_types']), $form_values['timeframe'], $form_values['layout_list'], $form_values['layout_page']);
+		db_query("INSERT INTO {epublish_section} (sid, title, vid, node_types, timeframe, layout_list, layout_page) 
+		VALUES ('%d', '%s', '%d', '%s', '%s', '%s', '%s')", $form_values['sid'], $form_values['title'], $form_values['vid'], 
+		implode(',', $form_values['node_types']), $form_values['timeframe'], $form_values['layout_list'], $form_values['layout_page']);
 		// Every section has a "miscellaneous" topic that can't be deleted, with a weight of 99 (so it always appears at the bottom of the section)
 		$misc_topic = array('sid' => $form_values['sid'], 'tid' => 0, 'count' => 0, 'weight' => 99, 'node_types' => array());
 		epublish_form_topic_submit(NULL, $misc_topic);
@@ -1492,7 +1528,8 @@
     '#title' => t('Additional Types'),
     '#default_value' => $types_array, // $types_array,
     '#options' => $nodetypes,
-    '#description' => t('A list of node types you want to associate with this topic. Node types checked here will be included <i>in addition</i> to node types selected for this section.'),
+    '#description' => t('A list of node types you want to associate with this topic. Node types checked here will be included <i>in addition</i> 
+    to node types selected for this section.'),
   );
 
 	$edit->count = $edit->count ? $edit->count : 0;
@@ -1581,7 +1618,8 @@
 	if ($edit['sid'] && $edit['action'] != 'delete') {
 		$result = db_query("SELECT * FROM {epublish_topic} WHERE sid = '%d' AND tid = '%d'", $edit['sid'], $edit['tid']);
 		db_query("DELETE FROM {epublish_topic} WHERE sid = '%d' AND tid = '%d'", $edit['sid'], $edit['tid']);
-		db_query("INSERT INTO {epublish_topic} (sid, tid, count, weight, node_types) VALUES (%d, %d, %d, %d, '%s')", $edit['sid'], $edit['tid'], $edit['count'], $edit['weight'], implode(',', $edit['node_types']));
+		db_query("INSERT INTO {epublish_topic} (sid, tid, count, weight, node_types) 
+		VALUES (%d, %d, %d, %d, '%s')", $edit['sid'], $edit['tid'], $edit['count'], $edit['weight'], implode(',', $edit['node_types']));
 		$term = epublish_get_term($edit['tid'], $edit['sid']);
 		if ($form_id) {
 			if (db_num_rows($result)) {
@@ -1645,24 +1683,26 @@
  *
  * @return
  *	 An array of topics. Each topic is an object that contains the following values:
- *		 --> tid: the topic ID. The values 0 and -1 correspond to "miscellaneous" and "top stories," respectively. All other values correspond to a taxonomy term with the same numeric term ID.
+ *		 --> tid: the topic ID. The values 0 and -1 correspond to "miscellaneous" and "top stories," respectively. 
+ *              All other values correspond to a taxonomy term with the same numeric term ID.
  *		 --> name: the topic name (either a taxonomy term or the special topic names "miscellaneous" or "top stories")
  *		 --> nodes: an array of node IDs for each article associated with the topic
  */
 
 function epublish_section_topics($sid, $eid) {
 	$section = epublish_get_section($sid);
-	$result = db_query("SELECT DISTINCT(n.nid), een.tid, et.weight FROM {node} n LEFT JOIN {epublish_edition_node} een USING (nid) LEFT JOIN {epublish_topic} et ON et.tid=een.tid WHERE eid='$eid' AND et.sid='$sid' ORDER BY et.weight, een.weight, n.changed DESC");
-
+	$result = db_query("SELECT DISTINCT(v.vid), v.nid, een.tid, et.weight FROM {node_revisions} v LEFT JOIN {epublish_edition_node} een ON een.vid = v.vid 
+	LEFT JOIN {epublish_topic} et ON et.tid=een.tid WHERE eid='$eid' AND et.sid='$sid' ORDER BY et.weight, een.weight, v.timestamp DESC");
 	$last_tid = NULL;
 	$topics = array();
 	$topic = NULL;
 	while ($node = db_fetch_object($result)) {
 		if ($last_tid != $node->tid) {
-		if ($topic) {
-			$topics[] = $topic;
-		}
-			$topic = db_fetch_object(db_query("SELECT et.tid, td.name, et.weight FROM {epublish_topic} et LEFT JOIN {term_data} td USING (tid) WHERE et.sid='%d' AND et.tid='%d'", $sid, $node->tid));
+  		if ($topic) {
+  			$topics[] = $topic;
+  		}
+			$topic = db_fetch_object(db_query("SELECT et.tid, td.name, et.weight FROM {epublish_topic} et LEFT JOIN {term_data} td USING (tid) 
+			WHERE et.sid='%d' AND et.tid='%d'", $sid, $node->tid));
 				if ($topic->tid == -2) {
 				$topic->name = variable_get('epublish_advertisement', t('advertisement'));
 			} else if ($topic->tid == -1) {
@@ -1672,7 +1712,7 @@
 			}
 			$last_tid = $node->tid;
 		}
-		$topic->nodes[] = $node->nid;
+		$topic->nodes[] = $node->vid;
 	}
 	if ($topic) {
 		$topics[] = $topic;
@@ -1719,7 +1759,7 @@
  * @return
  *	 An HTML-formatted table listing each publication and its editions
  */
-function epublish_pub_list() {
+function epublish_pub_list() {//TODO show only those that the user should see, or move the directory elsewhere
 	$order = variable_get('epublish_edition_order', 'DESC');
 	$publications = db_query("SELECT * FROM {epublish_publication}");
 	$header = array(t('publication/editions'), array("data" => t("operations"), "colspan" => 2));
@@ -1734,7 +1774,8 @@
 		while ($edition = db_fetch_object($result)) {
 			if ($edition->volume != $previous_volume) {
 			if ($previous_volume != -1) {
-			$rows[] = array(implode('<br />', $editions), array('data' => t('volume name: ') . l(theme('epublish_volume_reference', $publication->pid, $previous_volume), "admin/epublish/edit/volume/$publication->pid/$previous_volume"), 'colspan' => 2));
+			$rows[] = array(implode('<br />', $editions), array('data' => t('volume name: ') . 
+			l(theme('epublish_volume_reference', $publication->pid, $previous_volume), "admin/epublish/edit/volume/$publication->pid/$previous_volume"), 'colspan' => 2));
 					$editions = array();
 		}
 		}
@@ -1742,7 +1783,8 @@
 			$previous_volume = $edition->volume;
 		}
 		if ($editions) {
-			$rows[] = array(implode('<br />', $editions), array('data' => t('volume name: ') . l(theme('epublish_volume_reference', $publication->pid, $previous_volume), "admin/epublish/edit/volume/$publication->pid/$previous_volume"), 'colspan' => 2));
+			$rows[] = array(implode('<br />', $editions), array('data' => t('volume name: ') . 
+			l(theme('epublish_volume_reference', $publication->pid, $previous_volume), "admin/epublish/edit/volume/$publication->pid/$previous_volume"), 'colspan' => 2));
 		}
 	}
 	$output = theme("table", $header, $rows);
@@ -1831,7 +1873,8 @@
 			'#title' => t("Page layout"),
 			'#default_value' => $edit->layout_page,
 			'#options' => $layouts,
-			'#description' => t("Select a page layout for this publication. If none is selected, the default !settings will be used.", array('!settings' => l(t('layout settings'), 'admin/settings/epublish'))),
+			'#description' => t("Select a page layout for this publication. If none is selected, the default !settings will be used.", 
+			array('!settings' => l(t('layout settings'), 'admin/settings/epublish'))),
 		);
 		$layouts = epublish_layouts('list', TRUE);
 		$form["layout_list"] = array(
@@ -1839,10 +1882,12 @@
 			'#title' => t("Listing layout"),
 			'#default_value' => $edit->layout_list,
 			'#options' => $layouts,
-			'#description' => t("Select a layout to control the display of headline listings for this publication. If none is selected, the default settings will be used."),
+			'#description' => t("Select a layout to control the display of headline listings for this publication. 
+			If none is selected, the default settings will be used."),
 		);
 	} else {
-		// Even if custom layouts are turned off, pass through the value as a hidden input. That way the settings are still there if custom layouts gets turned on again later.
+		// Even if custom layouts are turned off, pass through the value as a hidden input. 
+		//That way the settings are still there if custom layouts gets turned on again later.
 		$form['layout_page'] = array(
 			'#type' => 'hidden',
 			'#value' => $edit->layout_page,
@@ -1861,7 +1906,8 @@
 			'#title' => t("Section"),
 			'#default_value' => $edit->sid,
 			'#options' => $sids,
-			'#description' => t("Select a section to control which topics are headlined for each edition of this publication. If none is selected, the default section from !settings will be used.", array('!settings' => l(t('publication settings'), 'admin/settings/epublish'))),
+			'#description' => t("Select a section to control which topics are headlined for each edition of this publication. 
+			If none is selected, the default section from !settings will be used.", array('!settings' => l(t('publication settings'), 'admin/settings/epublish'))),
 		);
 	} else {
 		$form['sid'] = array(
@@ -1975,7 +2021,8 @@
 }
 
 /**
- * epublish_current_edition: return the current edition ID number for a publication. If no edition is specified, returns the edition with the latest publication date.
+ * epublish_current_edition: return the current edition ID number for a publication. 
+ * If no edition is specified, returns the edition with the latest publication date.
  *
  * @param $pid
  *	 A publication ID number
@@ -2026,7 +2073,7 @@
  * @return
  *	 An HTML-formatted form
  */
-function epublish_form_edition($edit = NULL, $pid=NULL) {
+function epublish_form_edition($edit = NULL, $pid=NULL) {//TODO makes sure a given user only sees nodes for the group the pub belongs to or public posts to add to pub
 	$edit = (object) $edit;
 	if ($pid) {
 		$edit->pid = $pid;
@@ -2085,7 +2132,8 @@
 		$edit->day = substr($edit->pubdate, 6, 2);
 	}
 	$years = drupal_map_assoc(range(date("Y", time())-15, date("Y", time())+1));
-	$months = array('01' => t("January"), '02' => t("February"), '03' => t("March"), '04' => t("April"), '05' => t("May"), '06' => t("June"), '07' => t("July"), '08' => t("August"), '09' => t("September"), '10' => t("October"), '11' => t("November"), '12' => t("December"));
+	$months = array('01' => t("January"), '02' => t("February"), '03' => t("March"), '04' => t("April"), '05' => t("May"), '06' => t("June"), 
+	    '07' => t("July"), '08' => t("August"), '09' => t("September"), '10' => t("October"), '11' => t("November"), '12' => t("December"));
 	$days = array('01' => '1', '02' => '2', '03' => '3', '04' => '4', '05' => '5', '06' => '6', '07' => '7', '08' => '8', '09' => '9', '10' => '10',
 			'11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20',
 			'21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30',
@@ -2120,7 +2168,8 @@
 			'#title' => t("Page layout"),
 			'#default_value' => $edit->layout_page,
 			'#options' => $layouts,
-			'#description' => t("Select a page layout for this edition. If none is selected, the default !settings will be used.", array('!settings' => l(t('layout for this publication'), 'admin/epublish/edit/publication/' . $edit->pid))),
+			'#description' => t("Select a page layout for this edition. If none is selected, the default !settings will be used.", 
+			array('!settings' => l(t('layout for this publication'), 'admin/epublish/edit/publication/' . $edit->pid))),
 		);
 		$layouts = epublish_layouts('list', TRUE);
 		$form["layout_list"] = array(
@@ -2128,10 +2177,12 @@
 			'#title' => t("Listing layout"),
 			'#default_value' => $edit->layout_list,
 			'#options' => $layouts,
-			'#description' => t("Select a layout to control the display of headline listings for this edition. If none is selected, the default for this publication will be used."),
+			'#description' => t("Select a layout to control the display of headline listings for this edition. 
+			If none is selected, the default for this publication will be used."),
 		);
 	} else {
-		// Even if custom layouts are turned off, pass through the value as a hidden input. That way the settings are still there if custom layouts gets turned on again later.
+		// Even if custom layouts are turned off, pass through the value as a hidden input. 
+		//That way the settings are still there if custom layouts gets turned on again later.
 		$form['layout_page'] = array(
 			'#type' => 'hidden',
 			'#value' => $edit->layout_page,
@@ -2150,10 +2201,12 @@
 			'#title' => t("Section"),
 			'#default_value' => $edit->sid,
 			'#options' => $sids,
-			'#description' => t("Select a section to control which topics are headlined in this edition. If none is selected, the default section for this publication will be used."),
+			'#description' => t("Select a section to control which topics are headlined in this edition. 
+			If none is selected, the default section for this publication will be used."),
 		);
 	} else {
-		// Even if custom sections are turned off, pass through the value as a hidden input. That way the settings are still there if custom sections gets turned on again later.
+		// Even if custom sections are turned off, pass through the value as a hidden input. 
+		//That way the settings are still there if custom sections gets turned on again later.
 		$form['sid'] = array(
 			'#type' => 'hidden',
 			'#value' => $edit->sid,
@@ -2210,24 +2263,33 @@
 		$header = array(NULL, t('Stories'), t('Topic'), t('Type'), t('Status'), t('Weight'));
 		$topics = epublish_topic_selection_list($sid);
 
-		$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, n.changed, n.status, n.type, een.weight, een.tid
-			FROM {node} n LEFT JOIN {epublish_edition_node} een ON n.nid = een.nid
+		$result = db_query(db_rewrite_sql("SELECT v.vid, v.nid, v.title, v.timestamp, n.status, n.type, een.weight, een.tid
+			FROM {node_revisions} v LEFT JOIN {epublish_edition_node} een ON v.vid = een.vid INNER JOIN {node} n ON n.nid = v.nid
 			LEFT JOIN {epublish_topic} et ON et.tid=een.tid
-			WHERE eid='" . $edit->eid . "' AND et.sid='" . $sid . "' ORDER BY et.weight, een.weight, n.changed DESC"));
+			WHERE eid='" . $edit->eid . "' AND et.sid='" . $sid . "' ORDER BY et.weight, een.weight, v.timestamp DESC"));
 		while ($node = db_fetch_object($result)) {
-			$nodes[$node->nid] = '';
-			$form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
-			$form['name'][$node->nid] =  array('#value' => node_get_types('name', $node));
-			$form['tid']['tid_' . $node->nid] =  array('#type' => 'select', '#default_value' => $node->tid,
-			  '#options' => $topics, '#attributes' => array('onchange'=>'onChangeTID(' . $node->nid . ')'));
-			$form['status'][$node->nid] =  array('#value' =>  ($node->status ? t('published') : t('not published')));
-			$form['weight']['weight_' . $node->nid] =  array('#type' => 'weight', '#default_value' => $node->weight,
-			  '#delta' => 30, '#attributes' => array('onchange'=>'onChangeWeight(' . $node->nid . ')'));
+			$nodes[$node->vid] = '';
+			$sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+			$count = db_num_rows(db_query($sql_count, $node->nid));
+			if ($count > 1) {
+			  $form['title'][$node->vid] = array('#value' => 
+			  l($node->title, 'node/'. $node->nid .'/revisions/'. $node->vid .'/view') .' '. theme('mark', node_mark($node->nid, $node->changed)));
+			}
+			else {
+			  $form['title'][$node->vid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
+			}
+			$form['name'][$node->vid] =  array('#value' => node_get_types('name', $node));
+			$form['tid']['tid_' . $node->vid] =  array('#type' => 'select', '#default_value' => $node->tid,
+			  '#options' => $topics, '#attributes' => array('onchange'=>'onChangeTID(' . $node->vid . ')'));
+			$form['status'][$node->vid] =  array('#value' =>  ($node->status ? t('published') : t('not published')));
+			$form['weight']['weight_' . $node->vid] =  array('#type' => 'weight', '#default_value' => $node->weight,
+			  '#delta' => 30, '#attributes' => array('onchange'=>'onChangeWeight(' . $node->vid . ')'));
 		}
 		$form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes);
 
 		drupal_set_title(t('edit ') . "$publication->name, " . theme('epublish_edition_reference', $edition));
-	} else {
+	}
+	else {
 		$form['published'] = array(
 			'#type' => 'checkbox',
 			'#title' => t('Published?'),
@@ -2248,7 +2310,7 @@
 	return $form;
 }
 
-function epublish_edition() {
+function epublish_edition() {//TODO another not-called function?
 $output = drupal_get_form('epublish_form_edition');
 	return $output;
 }
@@ -2297,28 +2359,36 @@
 
 function epublish_form_edition_submit($form_id, $edit) {
 	if ($edit['eid'] && $edit['action'] != 'delete') {
-		db_query("UPDATE {epublish_edition} SET pid='%d', dateline='%s', description='%s', volume='%d', number='%d', pubdate='%d', layout_list='%s', layout_page='%s', sid='%d', published='%d' WHERE eid = '%d'", $edit['pid'], $edit['dateline'], $edit['description'], $edit['volume'], $edit['number'], $edit['year'].$edit['month'].$edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published'], $edit['eid']);
+		db_query("UPDATE {epublish_edition} SET pid=%d, dateline='%s', description='%s', volume=%d, number=%d, pubdate=%d, layout_list='%s', 
+		layout_page='%s', sid=%d, published=%d WHERE eid = %d", $edit['pid'], $edit['dateline'], $edit['description'], $edit['volume'], 
+		$edit['number'], $edit['year'].$edit['month'].$edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published'], $edit['eid']);
 		// Handle operations:
 		if (isset($edit['operation']) && isset($edit['nodes'])) {
-			foreach ($edit['nodes'] as $nid => $value) {
+			foreach ($edit['nodes'] as $vid => $value) {
 				if ($value) {
 					switch ($edit['operation']) {
 						case 'add':
-							epublish_add_node($edit['eid'], $nid, $edit['weight_' . $nid], $edit['tid_' . $nid]);
+              $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
+              $nid = db_fetch_object(db_query($sql, $vid));
+							epublish_add_node($edit['eid'], $nid->nid, $vid, $edit['weight_' . $vid], $edit['tid_' . $vid]);
 							break;
 						case 'del':
-							epublish_del_node($edit['eid'], $nid);
+							epublish_del_node($edit['eid'], $nid->nid, $vid);
 							break;
 					}
 				}
 			}
 			drupal_set_message(t('The "!title" edition has been updated.', array('!title' => $edit['dateline'])));
 		}
-	} else if ($edit['action'] == 'delete') {
+	} 
+	elseif ($edit['action'] == 'delete') {
 		epublish_del_edition($edit);
-	}	else {
+	}	
+	else {
 		$edit['eid'] = db_next_id('{epublish_edition}_eid');
-		db_query("INSERT INTO {epublish_edition} (eid, pid, dateline, description, volume, number, pubdate, layout_list, layout_page, sid, published) VALUES ('%d', '%d', '%s', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%d')", $edit['eid'], $edit['pid'], $edit['dateline'], $edit['description'], $edit['volume'], $edit['number'], $edit['year'].$edit['month'].$edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published']);
+		db_query("INSERT INTO {epublish_edition} (eid, pid, dateline, description, volume, number, pubdate, layout_list, layout_page, sid, published) 
+		VALUES ('%d', '%d', '%s', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%d')", $edit['eid'], $edit['pid'], $edit['dateline'], $edit['description'], 
+		$edit['volume'], $edit['number'], $edit['year'].$edit['month'].$edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published']);
 		drupal_set_message(t('The "!title" edition has been added.', array('!title' => $edit['dateline'])));
 	}
 	if ($edit['make_current']) {
@@ -2343,20 +2413,24 @@
 		$publication = epublish_get_pub($edition->pid);
 		db_query("DELETE FROM {epublish_edition} WHERE eid = '%d'", $edition->eid);
 		db_query("DELETE FROM {epublish_edition_node} WHERE eid = '%d'", $edition->eid);
-		drupal_set_message(t('Deleted "!edition" edition from publication "!publication."', array('!edition' => $edition->dateline, '!publication' => $publication->name)));
+		drupal_set_message(t('Deleted "!edition" edition from publication "!publication."', 
+		array('!edition' => $edition->dateline, '!publication' => $publication->name)));
 		drupal_goto("admin/epublish");
-	} else if ($edition->eid) {
+	} 
+	else if ($edition->eid) {
 
 		$publication = epublish_get_pub($edition->pid);
 
 		return drupal_get_form('confirm_form', array('eid' => array('#type' => hidden,
 				'#value' => $edition->eid)),
-				t('Are you sure you want to delete the "!edition" edition from publication "!publication"?',array('!edition' => $edition->dateline, '!publication' => $publication->name)),
+				t('Are you sure you want to delete the "!edition" edition from publication "!publication"?',
+				array('!edition' => $edition->dateline, '!publication' => $publication->name)),
 				'admin/epublish',
 				t('This action cannot be undone.'),
 				t('Delete'),
 				t('Cancel'),'','');
-	} else {
+	} 
+	else {
 
 		drupal_set_message(t('The edition no longer exists.'));
 		return 'admin/epublish';
@@ -2416,7 +2490,8 @@
 function epublish_form_volume($edit = NULL) {
 	$edit = (object) $edit;
 	$publication = epublish_get_pub($edit->pid);
-	$form[] = array('#value' => '<h3>' . t('Volume !vol of publication "!pub"', array('!vol' => $edit->volume, '!pub' => l($publication->name, "admin/epublish/edit/publication/$publication->pid"))) . "</h3>\n");
+	$form[] = array('#value' => '<h3>' . t('Volume !vol of publication "!pub"', 
+	array('!vol' => $edit->volume, '!pub' => l($publication->name, "admin/epublish/edit/publication/$publication->pid"))) . "</h3>\n");
 	$form["pid"] = array(
 		'#type' => 'hidden',
 		'#value' => $edit->pid,
@@ -2431,7 +2506,8 @@
 		'#default_value' => $edit->dateline,
 		'#size' => 50,
 		'#maxlength' => 128,
-		'#description' => t('A name for this volume. Since many publications begin a new volume annually, the name might simply be the name of that year, e.g., "2004."'),
+		'#description' => t('A name for this volume. Since many publications begin a new volume annually, 
+		the name might simply be the name of that year, e.g., "2004."'),
 	);
 	$form[] = array(
 		'#type' => 'submit',
@@ -2485,14 +2561,16 @@
 	$vol = epublish_get_volume($pid, $volume);
 	if (($_POST['op'] == t('Delete')) && ($_POST ['form_id'] == 'confirm_form' )) {
 		db_query("DELETE FROM {epublish_volume} WHERE pid = '%d' AND volume = '%d'", $pid, $volume);
-		drupal_set_message(t('Removed volume name "!volume" from publication "!publication."', array('!volume' => $vol->dateline, '!publication' => $publication->name)));
+		drupal_set_message(t('Removed volume name "!volume" from publication "!publication."', 
+		array('!volume' => $vol->dateline, '!publication' => $publication->name)));
 		drupal_goto("admin/epublish");
 	} else {
 
 		return drupal_get_form('confirm_form',
 				 array('pid' => array( '#type' => hidden,'#value' => $pid),
 				 'volume' => array( '#type' => hidden, '#value' => $volume)),
-	  	        	 t('Are you sure you want to remove volume name !volume from publication !publication?',	 array('!volume' => $vol->dateline, '!publication' => $publication->name)),
+	  	        	 t('Are you sure you want to remove volume name !volume from publication !publication?',
+	  	        	 array('!volume' => $vol->dateline, '!publication' => $publication->name)),
 				 'admin/epublish',
 				 t('This action cannot be undone.'),
 				 t('Delete'),
@@ -2516,9 +2594,10 @@
  *	 An array containing all of the node IDs from that edition
  */
 function epublish_get_edition_nodes($eid) {
-	$result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n, {epublish_edition_node} een WHERE een.nid = n.nid AND een.eid='%d' AND n.status='1' ORDER BY n.sticky DESC, n.created DESC"), $eid);
+	$result = db_query(db_rewrite_sql("SELECT v.vid, v.nid FROM {node_revisions} v LEFT JOIN {epublish_edition_node} een ON v.vid = een.vid
+	LEFT JOIN {node} n ON v.nid = n.nid WHERE een.eid='%d' AND n.status='1' ORDER BY n.sticky DESC, n.created DESC"), $eid);
 	while ($node = db_fetch_object($result)) {
-		$nodes[] = $node->nid;
+		$nodes[] = $node->vid;
 	}
 	return $nodes;
 }
@@ -2531,9 +2610,9 @@
  * @param $nid
  *	 A node ID
  */
-function epublish_add_node($eid, $nid, $weight=0, $tid=0) {
-	epublish_del_node($eid, $nid);
-	db_query("INSERT INTO {epublish_edition_node} (eid, nid, weight, tid) VALUES ('%d', '%d', '%d', '%d')", $eid, $nid, $weight, $tid);
+function epublish_add_node($eid, $nid, $vid, $weight=0, $tid=0) {
+	epublish_del_node($eid, $nid, $vid);
+	db_query("INSERT INTO {epublish_edition_node} (eid, nid, weight, tid, vid) VALUES ('%d', '%d', '%d', '%d', '%d')", $eid, $nid, $weight, $tid, $vid);
 }
 
 /**
@@ -2544,8 +2623,8 @@
  * @param $nid
  *	 A node ID
  */
-function epublish_del_node($eid, $nid) {
-	db_query("DELETE FROM {epublish_edition_node} WHERE eid = '%d' AND nid = '%d'", $eid, $nid);
+function epublish_del_node($eid, $nid, $vid) {
+	db_query("DELETE FROM {epublish_edition_node} WHERE eid = '%d' AND nid = '%d' AND vid = '%d'", $eid, $nid, $vid);
 }
 
 /**
@@ -2554,7 +2633,6 @@
  * @param $edit
  *	 an array of values to be saved
  */
-
 function epublish_admin_node_head() {
 $output = drupal_get_form('epublish_admin_node');
 	return $output;
@@ -2598,7 +2676,8 @@
 	);
 	$form[] = array('#value' => '</div>');
 
-	$result = pager_query("SELECT DISTINCT (n.nid), n.title, n.changed, n.type, n.status FROM {node} n ". $filters[$filter][1], 50);
+	$result = pager_query("SELECT DISTINCT (v.vid), v.nid, v.title, n.changed, n.type, n.status 
+	FROM {node_revisions} v LEFT JOIN {node} n ON v.nid = n.nid ". $filters[$filter][1], 50);
 
 	// Make sure the update controls are disabled if we don't have any rows to select from.
 	$disabled = !db_num_rows($result);
@@ -2609,17 +2688,25 @@
 	);
 
 	while ($node = db_fetch_object($result)) {
-		$nodes[$node->nid] = '';
+		$nodes[$node->vid] = '';
 		$node->tid = 0;
 		$node->weight = 0;
 		$topics = epublish_topic_selection_list($sid);
-		$form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
-		$form['name'][$node->nid] =  array('#value' => node_get_types('name', $node));
-		$form['tid']['tid_' . $node->nid] =  array('#type' => 'select', '#default_value' => $node->tid,
-			'#options' => $topics, '#attributes' => array('onchange'=>'onChangeTID(' . $node->nid . ')'));
-		$form['status'][$node->nid] =  array('#value' =>  ($node->status ? t('published') : t('not published')));
-		$form['weight']['weight_' . $node->nid] =  array('#type' => 'weight', '#default_value' => $node->weight,
-			'#delta' => 30, '#attributes' => array('onchange'=>'onChangeWeight(' . $node->nid . ')'));
+		$sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+    $count = db_num_rows(db_query($sql_count, $node->nid));
+    if ($count > 1) {
+		  $form['title'][$node->vid] = array('#value' => l($node->title, 'node/'. $node->nid .'/revisions/'. $node->vid .'/view') .' '. 
+		  theme('mark', node_mark($node->nid, $node->changed)));
+    }
+    else {
+      $form['title'][$node->vid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
+    }
+		$form['name'][$node->vid] =  array('#value' => node_get_types('name', $node));
+		$form['tid']['tid_' . $node->vid] =  array('#type' => 'select', '#default_value' => $node->tid,
+			'#options' => $topics, '#attributes' => array('onchange'=>'onChangeTID(' . $node->vid . ')'));
+		$form['status'][$node->vid] =  array('#value' =>  ($node->status ? t('published') : t('not published')));
+		$form['weight']['weight_' . $node->vid] =  array('#type' => 'weight', '#default_value' => $node->weight,
+			'#delta' => 30, '#attributes' => array('onchange'=>'onChangeWeight(' . $node->vid . ')'));
 	}
 	$form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes);
 	$form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
@@ -2630,7 +2717,7 @@
 
 }
 
-function epublish_headlines() {
+function epublish_headlines() {//TODO another mystery function???
 $output = drupal_get_form('epublish_admin_node');
 return $output;
 }
@@ -2669,9 +2756,11 @@
 
 	if ($op == t('Add checked items to this edition') && isset($edit['nodes'])) {
 		$nodes_added = 0;
-		foreach ($edit['nodes'] as $nid => $checked) {
+		foreach ($edit['nodes'] as $vid => $checked) {
 			if ($checked) {
-				epublish_add_node($edit['eid'], $nid, $edit['weight_' . $nid], $edit['tid_' . $nid]);
+			  $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
+			  $nid = db_fetch_object(db_query($sql, $vid));
+				epublish_add_node($edit['eid'], $nid->nid, $vid, $edit['weight_' . $vid], $edit['tid_' . $vid]);
 				$nodes_added++;
 			}
 		}
@@ -2746,9 +2835,9 @@
  */
 function _epublish_build_node_exclusions($nodes = array()) {
 	if (count($nodes)) {
-		return 'n.nid!=' . implode(' AND n.nid!=', $nodes);
+		return 'v.vid!=' . implode(' AND v.vid!=', $nodes);
 	} else {
-		return 'n.nid!=0';
+		return 'v.vid!=0';
 	}
 }
 
@@ -2806,20 +2895,42 @@
 		$node->breadcrumb = array();
 		$node->breadcrumb[] = array('path' => "epublish/$publication->pid", 'title' => $publication->name);
 		$node->breadcrumb[] = array('path' => "epublish/$edition->pid/$edition->eid", 'title' => theme('epublish_edition_reference', $edition));
-		$node->breadcrumb[] = array('path' => "node/$node->nid", 'title' => $node->title);
+		$sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+    $count = db_num_rows(db_query($sql_count, $node->nid));
+    if ($count > 1) {
+		  $node->breadcrumb[] = array('path' => "node/$node->nid/revisions/$node->vid/view", 'title' => $node->title);
+    }
+    else {
+      $node->breadcrumb[] = array('path' => "node/$node->nid", 'title' => $node->title);
+    }
 		menu_set_location($node->breadcrumb);
 
     if ($prev = epublish_prev($node, $topics)) {
-			$links[] = "Previous story: " . l($prev->title, 'node/'. $prev->nid);
+      $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+      $count = db_num_rows(db_query($sql_count, $prev->nid));
+      if ($count > 1) {
+			  $links[] = "Previous story: " . l($prev->title, 'node/'. $prev->nid .'/revisions/'. $prev->vid .'/view');
+      }
+      else {
+        $links[] = "Previous story: " . l($prev->title, 'node/'. $prev->nid);
+      }
     }
     if ($next = epublish_next($node, $topics)) {
-			$links[] = "Next story: " . l($next->title, 'node/'. $next->nid);
+      $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+      $count = db_num_rows(db_query($sql_count, $next->nid));
+      if ($count > 1) {
+			  $links[] = "Next story: " . l($next->title, 'node/'. $next->nid .'/revisions/'. $next->vid .'/view');
+      }
+      else {
+        $links[] = "Next story: " . l($next->title, 'node/'. $next->nid);
+      }
     }
-		$output .= "<h3>Published in " . l("$publication->name", "epublish/$publication->pid") . ", " .l(theme('epublish_edition_reference', $edition), "epublish/$publication->pid/$edition->eid") . "</h3><br/>\n";
+		$output .= "<h3>Published in " . l("$publication->name", "epublish/$publication->pid") .", ".
+		l(theme('epublish_edition_reference', $edition), "epublish/$publication->pid/$edition->eid") ."</h3><br/>\n";
 		$output .= theme('item_list', $links);
     $output .= '</div>';
   }
-  $node->body = $node->body.$output;
+  $node->content['body']['#value'] = $node->body.$output;
   return $node;
 }
 
@@ -2849,5 +2960,3 @@
 	}
 	return NULL;
 }
-
-?>
Index: layout_indexed.inc
===================================================================
--- layout_indexed.inc	(revision 282)
+++ layout_indexed.inc	(working copy)
@@ -65,13 +65,15 @@
       }
 
 	// for translation
-      foreach ($topic->nodes as $nid) { // beigin of foreach (one)
+      foreach ($topic->nodes as $vid) { // beigin of foreach (one)
+        $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
+        $nid = db_fetch_object(db_query($sql, $vid));
 				if (module_exists('translation')) {
  					$lang = i18n_get_lang();
-		 			$transnid .= translation_node_nid($nid, $lang);
-					if ($transnid) { $nid = $transnid; $transnid = '';}
+		 			$transnid .= translation_node_nid($nid->nid, $lang);
+					if ($transnid) { $nid->nid = $transnid; $transnid = '';}
 				}
-        $node = node_load((array('nid' => $nid)));
+        $node = node_load((array('nid' => $nid->nid)));
 
 				// if it is not top or bottom topic add node title
        	if ( ($topic->weight != 99) && ($topic->weight != (-99)) && ($topic->weight != (-98)) ){
@@ -82,17 +84,20 @@
 					else {
 						$o_index .= '<div class="' . $css_title . '"><span class="bullet">o </span>'. l( $node->title, arg(0)."/".arg(1), array(), NULL, 'N'.$sid. '_'.$counter, FALSE, TRUE).'</div> ';
 					}
-				$o_detail .= '<div class="' . $css_linktitle . ' ' . strtolower(preg_replace('|[^a-zA-Z0-9_]+|','-',$topic->name) ) . '-' .   $css_title . '"><span class="bullet">o </span>' . l(t($node->title), "node/$nid") . '<a name="N'.$sid.'_'.$counter.'">&nbsp;</a>' . "</div>\n" ;
-
+					$sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+          $count = db_num_rows(db_query($sql_count, $node->nid));
+          if ($count > 1) {
+				    $o_detail .= '<div class="' . $css_linktitle . ' ' . strtolower(preg_replace('|[^a-zA-Z0-9_]+|','-',$topic->name) ) . '-' .   $css_title . '"><span class="bullet">o </span>' . l(t($node->title), "node/$nid->nid/revisions/$vid/view") . '<a name="N'.$sid.'_'.$counter.'">&nbsp;</a>' . "</div>\n" ;
+          }
+          else {
+            $o_detail .= '<div class="' . $css_linktitle . ' ' . strtolower(preg_replace('|[^a-zA-Z0-9_]+|','-',$topic->name) ) . '-' .   $css_title . '"><span class="bullet">o </span>' . l(t($node->title), "node/$nid->nid") . '<a name="N'.$sid.'_'.$counter.'">&nbsp;</a>' . "</div>\n" ;
+          }
 				}
-
-	// Add commented section
+	      // Add commented section
         //$o_index .= '<div class="user">' . t('by') . ' ' . l($node->name, "blog/" . $node->uid) . "</div>\n";
         //$o_detail .= '<div class="user">' . t('by') . ' ' . l($node->name, "blog/" . $node->uid) . "</div>\n";
-
-
-	// Now detail has got additional information
-	// Add Abstract
+	      // Now detail has got additional information
+	      // Add Abstract
         if ($node->epublish_abstract) {
 	        if ( ($topic->weight != 99) && ($topic->weight != (-99)) && ($topic->weight != (-98)) ) {
 				    $o_detail .= '<div class="' . $css_abstract . '">' . check_markup($node->epublish_abstract . ' <span class="morelink"> ' . l("[more..]", "node/$nid")  . ' </span>', $node->format) . " </div>\n";
@@ -111,10 +116,10 @@
 							//$o_advertisement .= ''. check_output($node->epublish_abstract, $node->format );
 							$o_advertisement .= ''. check_markup($node->epublish_abstract, $node->format ); // Changed check_output -> check_markup(check_output not supported in 5.0)
 						}
-	      }
-      } // end of if for abstract
+  	      }
+        } // end of if for abstract
 
-	$counter++ ;
+	    $counter++ ;
       } // end of foreach statement (one)
 
     }
Index: layout_list.inc
===================================================================
--- layout_list.inc	(revision 282)
+++ layout_list.inc	(working copy)
@@ -27,14 +27,23 @@
   }
   $output = '<div class="pub_list">' . $description . '<ul>';
   foreach ($topics as $topic) {
-    foreach ($topic->nodes as $nid) {
+    foreach ($topic->nodes as $vid) {
+      $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
+      $nid = db_fetch_object(db_query($sql, $vid));
 			if (module_exists('translation')) {
  				$lang = i18n_get_lang();
-	 			$transnid .= translation_node_nid($nid, $lang);
-				if ($transnid) { $nid = $transnid; $transnid = '';}
+	 			$transnid .= translation_node_nid($nid->nid, $lang);
+				if ($transnid) { $nid->nid = $transnid; $transnid = '';}
 			}
-      $node = node_load($nid);
-      $output .= "<li>" . l(t($node->title), "node/$nid");
+      $node = node_load($nid->nid);
+      $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+      $count = db_num_rows(db_query($sql_count, $node->nid));
+      if ($count > 1) {
+        $output .= "<li>" . l(t($node->title), "node/$nid->nid/revisions/$vid/view");
+      }
+      else {
+        $output .= "<li>" . l(t($node->title), "node/$nid->nid");
+      }
       if ($node->epublish_abstract) {
         $output .= ': ' . check_markup($node->epublish_abstract, $node->format);
       }
Index: layout_nodes.inc
===================================================================
--- layout_nodes.inc	(revision 282)
+++ layout_nodes.inc	(working copy)
@@ -32,25 +32,30 @@
         } else {
           $output .= '<div class="topic">' . $topic->name . "</div>\n";
         }
-        foreach ($topic->nodes as $nid) {
+        foreach ($topic->nodes as $vid) {
+          $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
+          $nid = db_fetch_object(db_query($sql, $vid));
 					if (module_exists('translation')) {
  						$lang = i18n_get_lang();
-			 			$transnid .= translation_node_nid($nid, $lang);
-						if ($transnid) { $nid = $transnid; $transnid = '';}
+			 			$transnid .= translation_node_nid($nid->nid, $lang);
+						if ($transnid) { $nid->nid = $transnid; $transnid = '';}
 					}
-          $output .= node_view(node_load($nid), 1);
+          $output .= node_view(node_load($nid->nid), 1);
         }
       }
     }
-  } else {
+  } 
+  else {
     foreach ($topics as $topic) {
-      foreach ($topic->nodes as $nid) {
+      foreach ($topic->nodes as $vid) {
+        $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
+        $nid = db_fetch_object(db_query($sql, $vid));
 	 			if (module_exists('translation')) {
 					$lang = i18n_get_lang();
-					$transnid = translation_node_nid($nid, $lang);
-					if ($transnid) { $nid = $transnid; $transnid = ''; }
+					$transnid = translation_node_nid($nid->nid, $lang);
+					if ($transnid) { $nid->nid = $transnid; $transnid = ''; }
 				}
-        $output .= node_view(node_load($nid), 1);
+        $output .= node_view(node_load($nid->nid), 1);
       }
     }
   }
Index: layout_one_two.inc
===================================================================
--- layout_one_two.inc	(revision 282)
+++ layout_one_two.inc	(working copy)
@@ -27,14 +27,23 @@
     $output = '	<div class="epublish"><div class="one_two">' . "$description\n";
   if ($topics) {
     $topic = array_shift($topics);
-    foreach ($topic->nodes as $nid) {
+    foreach ($topic->nodes as $vid) {
+      $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
+      $nid = db_fetch_object(db_query($sql, $vid));
 			if (module_exists('translation')) {
  				$lang = i18n_get_lang();
-			 	$transnid .= translation_node_nid($nid, $lang);
-				if ($transnid) { $nid = $transnid; $transnid = '';}
+			 	$transnid .= translation_node_nid($nid->nid, $lang);
+				if ($transnid) { $nid->nid = $transnid; $transnid = '';}
 			}
-      $node = node_load($nid);
-      $output .= '<div class="title">' . l(t($node->title), "node/$nid") . "</div>\n";
+      $node = node_load($nid->nid);
+      $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+      $count = db_num_rows(db_query($sql_count, $node->nid));
+      if ($count > 1) {
+        $output .= '<div class="title">' . l(t($node->title), "node/$nid->nid/revisions/$vid/view") . "</div>\n";
+      }
+      else {
+        $output .= '<div class="title">' . l(t($node->title), "node/$nid->nid") . "</div>\n";
+      }
       $output .= '<div class="user">' . t('By') . ' ' . '<span class="all_caps">' . $node->name . "</span></div>\n";
       if ($node->epublish_abstract) {
         $output .= '<div class="abstract">' . check_markup($node->epublish_abstract, $node->format) . "</div>\n";
@@ -56,14 +65,24 @@
       }
       $position++;
       $output .= '    		  <div class="topic">' . $topic->name . "</div>\n";
-      foreach ($topic->nodes as $nid) {
-			if (module_exists('translation')) {
-				$lang = i18n_get_lang();
-				$transnid = translation_node_nid($nid, $lang);
-				if ($transnid) { $nid = $transnid; $transnid = ''; }
-			}
-	    $node = node_load($nid);
-        $output .= '<div class="topic_title">' . l(t($node->title), "node/$nid") . "</div>\n";
+      foreach ($topic->nodes as $vid) {
+        $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
+        $nid = db_fetch_object(db_query($sql, $vid));
+  			if (module_exists('translation')) {
+  				$lang = i18n_get_lang();
+  				$transnid = translation_node_nid($nid->nid, $lang);
+  				if ($transnid) { $nid->nid = $transnid; $transnid = ''; }
+  			}
+	      $node = node_load($nid->nid);
+	      $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+        $count = db_num_rows(db_query($sql_count, $node->nid));
+        if ($count > 1) {
+          $output .= '<div class="topic_title">' . l(t($node->title), "node/$nid->nid/revisions/$vid/view") . "</div>\n";
+        }
+        else {
+          $output .= '<div class="topic_title">' . l(t($node->title), "node/$nid->nid") . "</div>\n";
+        }
+        $output .= '<div class="abstract">' . check_markup($node->epublish_abstract, $node->format) . "</div>\n";
       }
     }
     $output .= '            </td>
Index: layout_regular.inc
===================================================================
--- layout_regular.inc	(revision 282)
+++ layout_regular.inc	(working copy)
@@ -30,15 +30,23 @@
       } else {
         $output .= '<div class="topic">' . $topic->name . "</div>\n";
       }
-      foreach ($topic->nodes as $nid) {
+      foreach ($topic->nodes as $vid) {
+        $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
+        $nid = db_fetch_object(db_query($sql, $vid));
 				if (module_exists('translation')) {
  					$lang = i18n_get_lang();
-		 			$transnid .= translation_node_nid($nid, $lang);
-					if ($transnid) { $nid = $transnid; $transnid = '';}
+		 			$transnid .= translation_node_nid($nid->nid, $lang);
+					if ($transnid) { $nid->nid = $transnid; $transnid = '';}
 				}
-        $node = node_load($nid);
-
-        $output .= '<div class="title">' . l(t($node->title), "node/$nid") . "</div>\n";
+        $node = node_load($nid->nid);
+        $sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
+        $count = db_num_rows(db_query($sql_count, $node->nid));
+        if ($count > 1) {
+          $output .= '<div class="title">' . l(t($node->title), "node/$nid->nid/revisions/$vid/view") . "</div>\n";
+        }
+        else {
+          $output .= '<div class="title">' . l(t($node->title), "node/$nid->nid") . "</div>\n";
+        }
         $output .= '<div class="user">' . t('by') . ' ' . l($node->name, "blog/" . $node->uid) . "</div>\n";
         if ($node->epublish_abstract) {
           $output .= '<div class="abstract">' . check_markup($node->epublish_abstract, $node->format) . "</div>\n";
@@ -48,4 +56,3 @@
   }
   return '<div class="epublish"><div class="regular">' . $description . $output . '</div></div>';
 }
-?>
