Adding Content Between Drupal Book Navigation and Content

I recently wanted to add a variable to my book template with a list of contributors to a wiki page. My "wiki" is a node type and I am using the excellent revision moderation module to let users submit revisions to nodes. I really want to recognize those who submit revisions. To do so, I decided to add a list of revision authors on each wiki page.

This ended up being trickier than I expected. First, I ran into difficulty getting my list to show up in the correct spot. If I added my list to the node template (node-wiki.tpl.php), then it would show up below the book navigation. However, I wanted my list to show up below the main node content but above the book navigation.

To get the list to show up in the correct location, I ended up adding the following to book-navigation.tpl.php in my custom Zen subtheme.

if (isset($revision_authors)):
  print theme_item_list($revision_authors, $title = 'Contributors', 'ul', array('class' => 'contributors')); ?>
endif;

You might be wondering where $revision_authors is coming from. To get this variable to show up in my book-navigation.tpl.php template, I had to first define it in template.php. To add a variable to book-navigation.tpl.php, you need to create a special template preprocess function. Mine is called mytheme_preprocess_book_navigation((&$variables) and is in my template.php file.

/**
* Adding $revision_authors to book-navigation.tpl.php
*/
function mytheme_preprocess_book_navigation(&$variables) {
  $variables['revision_authors'] = get_all_revision_authors(arg(1));
}

Finally, if you're curious, here's the function I'm using to retrieve the revision authors. I am passing arg(1), which corresponds to the node ID of my wiki nodes. I am only retrieving the authors of approved revisions.

/**
* Retrieve list of all revision authors for a given node.
*
* @param $nid
*  The node ID to retrieve.
*/
function get_all_revision_authors($nid) {
//Get revision authors for a node
  $sql = "SELECT DISTINCT r.uid AS uid FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid WHERE r.vid < n.vid AND n.nid = %d ORDER BY r.vid DESC";
//  $sql = 'SELECT DISTINCT uid FROM {node_revisions} WHERE nid = %d ORDER BY timestamp DESC';
  $result = db_query($sql, $nid);
  $revision_authors = array();
  while ($revision_uid = db_fetch_object($result)) {
//   $revision_authors[] = $revision_uid;
$revision_authors[] = theme('username', user_load(array('uid' => $revision_uid->uid)));
  }
  return $revision_authors;
}