Index: modr8/modr8.info
===================================================================
--- modr8/modr8.info	(revision 20063)
+++ modr8/modr8.info	(working copy)
@@ -1,10 +1,9 @@
-; $Id: modr8.info,v 1.2 2008/03/03 02:59:20 pwolanin Exp $
+; $Id$
 name = Modr8
 description = Easy, dedicated moderation of content
-core = 6.x
-; Information added by drupal.org packaging script on 2010-04-02
-version = "6.x-1.3"
-core = "6.x"
-project = "modr8"
-datestamp = "1270244409"
+core = 7.x
+configure = admin/config/system/modr8
 
+files[] = modr8.install
+files[] = modr8.module
+files[] = modr8_admin.inc
Index: modr8/modr8_admin.inc
===================================================================
--- modr8/modr8_admin.inc	(revision 20063)
+++ modr8/modr8_admin.inc	(working copy)
@@ -1,6 +1,10 @@
 <?php
 // $Id: modr8_admin.inc,v 1.31 2010/04/02 03:11:13 pwolanin Exp $
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_settings_form($form_state) {
 
   $form['modr8_default_option'] = array(
@@ -27,7 +31,7 @@
     '#title' => t('Discard log entries older than'),
     '#default_value' => variable_get('modr8_log_clear', 0),
     '#options' => $period,
-    '#description' => t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab.')
+    '#description' => t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab.'),
   );
   $form['text'] = array(
     '#type' => 'fieldset',
@@ -37,7 +41,7 @@
   $form['text']['modr8_email_from'] = array(
     '#type' => 'textfield',
     '#title' => t('Moderator email address'),
-    '#description' => t('E-mail notices sent by modr8 will have this as the "From" address. Leave empty to use same "From" address  as is used for user registration other administrative notices as set at <a href="@site-info">Site information</a>.', array('@site-info' => url('admin/settings/site-information'))),
+    '#description' => t('E-mail notices sent by modr8 will have this as the "From" address. Leave empty to use same "From" address  as is used for user registration other administrative notices as set at <a href="@site-info">Site information</a>.', array('@site-info' => url('admin/config/site-information'))),
     '#default_value' => variable_get('modr8_email_from', ''),
   );
 
@@ -110,6 +114,10 @@
   return system_settings_form($form);
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_settings_validate($form, &$form_state) {
   if ($form_state['values']['modr8_email_from'] && !valid_email_address($form_state['values']['modr8_email_from'])) {
     form_set_error('modr8_email_from', t('You must either enter a valid e-mail address, or leave the moderator e-mail field empty.'));
@@ -121,16 +129,20 @@
  */
 function modr8_response_page($node) {
   if ($node->moderate) {
-    drupal_set_title(t('Submit response regarding %title', array('%title' => $node->title)));
+    drupal_set_title(t('Submit response regarding %title', array('%title' => $node->title)), PASS_THROUGH);
     return drupal_get_form('modr8_response_form', $node);
   }
   else {
-    drupal_set_title(t('The moderator already approved %title', array('%title' => $node->title)));
+    drupal_set_title(t('The moderator already approved %title', array('%title' => $node->title)), PASS_THROUGH);
     return '<p>'. t('This post has already been approved by the moderator. No response is needed.') .'</p>';
   }
 }
 
-function modr8_response_form($form_state, $node) {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function modr8_response_form($form, $form_state, $node) {
   $form = array();
   $form['title'] = array(
     '#type' => 'textfield',
@@ -151,10 +163,11 @@
     '#value' => t('Submit'),
     '#weight' => 5,
   );
-  // This flag can be used by modr8, or other modules to change the teaser specifically
-  // for when it's being shown in the moderation list.
+  // This flag can be used by modr8, or other modules to change the
+  // teaser specifically for when it's being shown in the moderation
+  // list.
   $node->modr8_form_teaser = TRUE;
-  $teaser = node_view($node, TRUE, FALSE, FALSE);
+  $teaser = drupal_render (node_view($node, 'teaser'));
   $form['preview'] = array(
     '#type' => 'value',
     '#value' => $teaser,
@@ -194,27 +207,42 @@
     // Users who don't have the 'administer nodes' permission can only see published nodes.
     $is_published = 'n.status = 1 AND ';
   }
-  $count_sql = db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE '. $is_published .' n.moderate = 1');
-  $page_sql = db_rewrite_sql('SELECT n.nid, n.changed FROM {node} n WHERE '. $is_published .' n.moderate = 1 ORDER BY n.changed DESC');
-  $result = pager_query($page_sql, variable_get('modr8_nodes_per_page', 10), 0, $count_sql);
-  $output = '<p>'. l(t('Show log of all actions on moderated content.'), 'admin/reports/modr8') .'</p>';
+  $qry = db_select('modr8_moderate', 'm')
+    ->extend('PagerDefault')
+    ->limit(variable_get('modr8_nodes_per_page', 10))
+    ->fields ('n', array ('nid', 'changed'))
+    ->condition('m.moderate', 1);
+  $qry->join('node', 'n', 'n.nid = m.nid');
+  $result = $qry->execute()->fetchAll();
+
+  $output['header'] = array (
+    '#type' => 'markup',
+    '#markup' => '<p>' . l(t('Show log of all actions on moderated content.'), 'admin/reports/modr8') . '</p>',
+  );
 
   $nid_list = array();
-  while ($r = db_fetch_object($result)) {
+  foreach ($result as $r) {
     $nid_list[] = $r->nid;
   }
   if ($nid_list) {
-    $output .= drupal_get_form('modr8_form', $nid_list);
-    $output .= theme('pager');
-
+    $output['form'] = drupal_get_form('modr8_form', $nid_list);
+    // TODO Please change this theme call to use an associative array for the $variables parameter.
+    //$output .= theme('pager');
   }
   else {
-    $output .= '<p>'. t('@items in moderation', array('@items' => format_plural(0, '1 post', '@count posts'))) .'</p>';
+    $output['footer'] = array (
+      '#type' => 'markup',
+      '#markup' => '<p>'. t('@items in moderation', array('@items' => format_plural(0, '1 post', '@count posts'))) .'</p>',
+    );
   }
   return $output;
 }
 
-function modr8_form($form_state, $nid_list = array()) {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function modr8_form($form, $form_state, $nid_list = array()) {
   $form = array(
     '#theme' => 'modr8_form',
     '#tree' => TRUE,
@@ -227,7 +255,7 @@
     // for when it's being shown in the moderation list.
     $node->modr8_form_teaser = TRUE;
     $node->build_mode = NODE_BUILD_MODR8_TEASER;
-    $teaser = node_view($node, TRUE, FALSE, FALSE);
+    $teaser = drupal_render (node_view($node, 'teaser'));
 
     $form[$node->nid] = array(
       '#tree' => TRUE,
@@ -257,11 +285,11 @@
     );
 
     $log_link = '';
-    $events = db_query("SELECT modid FROM {modr8_log} WHERE nid = %d", $node->nid);
-    $count = db_result(db_query("SELECT COUNT(modid) FROM {modr8_log} WHERE nid = %d", $node->nid));
+    $events = db_query("SELECT modid FROM {modr8_log} WHERE nid = :nid", array(':nid' => $node->nid));
+    $count = db_query("SELECT COUNT(modid) FROM {modr8_log} WHERE nid = :nid", array(':nid' => $node->nid))->fetchField();
     if ($count) {
       if ($count == 1) {
-        $url = 'admin/reports/modr8/event/'. db_result($events);
+        $url = 'admin/reports/modr8/event/' . $events->fetchField();
       }
       else {
         $url = 'node/'. $node->nid .'/modr8/';
@@ -270,7 +298,8 @@
       $log_link .= l($message, $url);
     }
     $form[$node->nid]['log_link'] = array(
-      '#value' => $log_link,
+      '#type' => 'markup',
+      '#markup' => $log_link,
     );
     $form[$node->nid]['author_uid'] = array(
       '#type' => 'value',
@@ -283,7 +312,7 @@
 
     $form[$node->nid]['type'] = array(
       '#type' => 'value',
-      '#value' => node_get_types('name', $node),
+      '#value' => node_type_get_name($node),
     );
   }
   $form['submit'] = array(
@@ -297,11 +326,13 @@
 /**
  * Themes the content moderation form.
  */
-function theme_modr8_form($form) {
+function theme_modr8_form($variables) {
+  $form = $variables['form'];
   $headers = array(
     t('Operations'),
-    t('Content')
+    t('Content'),
   );
+  $rows = array();
   foreach (element_children($form) as $key) {
     // Only do this for nodes; not the submit button.
     if (is_numeric($key)) {
@@ -312,13 +343,11 @@
       }
       $row[] = array(
         'data' => drupal_render($form[$key]['ops']) . $note_field,
-        'style' => 'vertical-align:top;'
+        'style' => 'vertical-align:top;',
       );
-      // Apply extra filtering to insure we don't have nested form elements,
-      // unexpected script, etc.
-      $preview = filter_xss_admin($form[$key]['preview']['#value']);
+      $preview = $form[$key]['preview']['#value'];
 
-      if (!empty($form[$key]['log_link']['#value'])) {
+      if (!empty($form[$key]['log_link']['#markup'])) {
         $preview .= '<div><em>'. drupal_render($form[$key]['log_link']) .'</em></div>';
       }
       $row[] = array(
@@ -328,8 +357,8 @@
       $rows[] = $row;
     }
   }
-  $output = theme('table', $headers, $rows);
-  $output .= drupal_render($form);
+  $output = theme('table', array('header' => $headers, 'rows' => $rows));
+  $output .= drupal_render_children($form);
 
   return $output;
 }
@@ -372,16 +401,42 @@
   }
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_log_action($op, $nid, $values, $message) {
   global $user;
-  $actions = array('approve' => 'Approve', 'delete' => 'Delete', 'nada' => 'No action', 'response' => 'Response');
+  $actions = array(
+    'approve' => 'Approve',
+    'delete' => 'Delete',
+    'nada' => 'No action',
+    'response' => 'Response',
+  );
 
-  db_query("INSERT INTO {modr8_log} (nid, uid, author_uid, action, title, message, teaser, timestamp) VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', %d)", $nid, $user->uid, $values['author_uid'], $actions[$op], $values['title'], $message, $values['preview'], time());
+  // TODO Please review the conversion of this statement to the D7 database API syntax.
+  /* db_query("INSERT INTO {modr8_log} (nid, uid, author_uid, action, title, message, teaser, timestamp) VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', %d)", $nid, $user->uid, $values['author_uid'], $actions[$op], $values['title'], $message, $values['preview'], REQUEST_TIME) */
+  $id = db_insert('modr8_log')
+  ->fields(array(
+    'nid' => $nid,
+    'uid' => $user->uid,
+    'author_uid' => $values['author_uid'],
+    'action' => $actions[$op],
+    'title' => $values['title'],
+    'message' => $message,
+    'teaser' => $values['preview'],
+    'timestamp' => REQUEST_TIME,
+  ))
+  ->execute();
   // Notify modules interested in each action we took.
   // modules have to implement the function: hook_modr8_log ( $op ,$nid , $values, $message);
   module_invoke_all('modr8_log', $op, $nid, $values, $message);
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_usermail($op, $nid, $values) {
   $node = node_load($nid);
 
@@ -406,9 +461,9 @@
     }
 
     // get the user info for author
-    $account = user_load(array('uid' => $node->uid));
+    $account = user_load($node->uid);
 
-    $note = theme('modr8_note', $values['note']);
+    $note = theme('modr8_note', array('0' => $values['note']));
 
     $sendmail_from = '';
     $site_mail = variable_get('modr8_email_from', '');
@@ -417,11 +472,17 @@
       $site_mail = variable_get('site_mail', $sendmail_from);
     }
     if (empty($site_mail) || $site_mail == $sendmail_from) {
-      drupal_set_message(t('You should create an administrator mail address for your site! <a href="@url">Do it here</a>.', array('@url' => url('admin/settings/site-information'))), 'error');
+      drupal_set_message(t('You should create an administrator mail address for your site! <a href="@url">Do it here</a>.', array('@url' => url('admin/config/site-information'))), 'error');
     }
     // send the email
     $language = user_preferred_language($account);
-    $params = array('account' => $account, 'node' => $node, 'subject' => $subject, 'message' => $message, 'note' => $note);
+    $params = array(
+      'account' => $account,
+      'node' => $node,
+      'subject' => $subject,
+      'message' => $message,
+      'note' => $note,
+    );
 
     if ($account->uid == 0) {
       $message = t('Anonymous user; no %type message was sent.', array('%type' => $optype));
@@ -446,7 +507,7 @@
 }
 
 /**
- * Implementation of hook_mail()
+ * Implements hook_mail().
  */
 function modr8_mail($key, &$message, $params) {
   $language = $message['language'];
@@ -468,7 +529,12 @@
   }
 }
 
-function theme_modr8_note($note) {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function theme_modr8_note($variables) {
+  $note = $variables['0'];
   if ($note) {
     // Do not filter here (use !) since this note is sanitized after e-mailing
     $note = t("Note:
@@ -477,6 +543,10 @@
   return $note;
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_replacements() {
   return array(
     '%title' => '$node->title',
@@ -497,6 +567,10 @@
   );
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_accept_default() {
   return t(
 'Your %type entry entitled "%title" has been approved by our content moderator! Other visitors to %site will now be able to view it.
@@ -509,6 +583,10 @@
 The %site team');
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_denial_default() {
   return t(
 'Your %type entry entitled "%title" has been denied by our content moderator. The content has been deleted from our site.
@@ -519,6 +597,10 @@
 The %site team');
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_noact_default() {
   return t(
 'Your %type entry entitled "%title" has been reviewed by our content moderator, but not yet approved.
@@ -546,7 +628,7 @@
       if (is_numeric($id)) {
         $node = node_load($id);
         if (!empty($node->title)) {
-          drupal_set_title(check_plain($node->title));
+          drupal_set_title($node->title);
         }
         return modr8_log_overview($id);
       }
@@ -562,12 +644,23 @@
   drupal_not_found();
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_log_overview($nid = 0) {
 
   $header = array(
-    array('data' => t('Action'), ),
-    array('data' => t('User'), 'field' => 'u.name'),
-    array('data' => t('Date'), 'field' => 'ml.modid', 'sort' => 'desc'),
+    array('data' => t('Action')),
+    array(
+      'data' => t('User'),
+      'field' => 'u.name',
+    ),
+    array(
+      'data' => t('Date'),
+      'field' => 'ml.modid',
+      'sort' => 'desc',
+    ),
     array('data' => t('Title (view event)')),
   );
   $tablesort = tablesort_sql($header);
@@ -585,52 +678,83 @@
   $rows = array();
 
   while ($event = db_fetch_object($result)) {
-    $rows[] = array(t($event->action), theme('username', $event), format_date($event->timestamp, 'small'),
-    l(truncate_utf8($event->title, 50, TRUE, TRUE), 'admin/reports/modr8/event/'. $event->modid, array(), NULL, NULL, FALSE, TRUE)
+    $rows[] = array(
+      t($event->action),
+      theme('username', array('account' => $event)),
+      format_date($event->timestamp, 'short'),
+      l(truncate_utf8($event->title, 50, TRUE, TRUE), 'admin/reports/modr8/event/' . $event->modid, array(), NULL, NULL, FALSE, TRUE),
     );
   }
 
   if (!$rows) {
-    $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => 4));
+    $rows[] = array(array(
+        'data' => t('No log messages available.'),
+        'colspan' => 4,
+      ));
   }
   $output = '';
-  $output .= theme('table', $header, $rows);
-  $output .= theme('pager', NULL, 50, 0);
+  $output .= theme('table', array('header' => $header, 'rows' => $rows));
+  $output .= theme('pager', array('tags' => NULL, 'element' => 0));
 
   return $output;
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_log_event($modid) {
 
   if (is_numeric($modid)) {
     $sql = db_rewrite_sql("SELECT ml.*, u.name FROM {modr8_log} ml LEFT JOIN {users} u ON u.uid = ml.uid WHERE ml.modid = %d", 'ml');
+    // TODO Please convert this statement to the D7 database API syntax.
     $event = db_fetch_object(db_query($sql, $modid));
     if ($event) {
-      $event->author = db_fetch_object(db_query("SELECT u.name, u.uid from {users} u WHERE u.uid = %d", $event->author_uid));
-      return theme('moderation_event', $event);
+      $event->author = db_fetch_object(db_query("SELECT u.name, u.uid from {users} u WHERE u.uid = :u.uid", array(':u.uid' => $event->author_uid)));
+      return theme('moderation_event', array('0' => $event));
     }
   }
 
   drupal_not_found();
 }
 
-function theme_moderation_event($event) {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function theme_moderation_event($variables) {
+  $event = $variables['0'];
 
-  $rows[] = array(array('data' => l(t('Overview of all moderation log events for this post'), 'node/'. $event->nid .'/modr8/'), 'colspan' => 2));
+  $rows[] = array(array(
+      'data' => l(t('Overview of all moderation log events for this post'), 'node/' . $event->nid . '/modr8/'),
+      'colspan' => 2,
+    ));
   $rows[] = array(t('Action:'), t($event->action));
-  $rows[] = array(t('Date:'), format_date($event->timestamp, 'small'));
+  $rows[] = array(t('Date:'), format_date($event->timestamp, 'short'));
   if ($event->action == 'Response') {
-    $rows[] = array(t('Author:'), theme('username', $event));
+    $rows[] = array(t('Author:'), theme('username', array('account' => $event)));
     $rows[] = array(t('Response title:'), $event->title);
-    $rows[] = array('data' => array(t('Response message:'), $event->message), 'style' => 'vertical-align:top;');
-    $rows[] = array('data' => array(t('Teaser (as of response):'), $event->teaser), 'style' => 'vertical-align:top;');
+    $rows[] = array(
+      'data' => array(t('Response message:'), $event->message),
+      'style' => 'vertical-align:top;',
+    );
+    $rows[] = array(
+      'data' => array(t('Teaser (as of response):'), $event->teaser),
+      'style' => 'vertical-align:top;',
+    );
   }
   else {
-    $rows[] = array(t('Moderator:'), theme('username', $event));
-    $rows[] = array('data' => array(t('E-mail message:'), $event->message), 'style' => 'vertical-align:top;');
-    $rows[] = array(t('Author:'), theme('username', $event->author));
-    $rows[] = array('data' => array(t('Teaser (as reviewed):'), $event->teaser), 'style' => 'vertical-align:top;');
+    $rows[] = array(t('Moderator:'), theme('username', array('account' => $event)));
+    $rows[] = array(
+      'data' => array(t('E-mail message:'), $event->message),
+      'style' => 'vertical-align:top;',
+    );
+    $rows[] = array(t('Author:'), theme('username', array('account' => $event->author)));
+    $rows[] = array(
+      'data' => array(t('Teaser (as reviewed):'), $event->teaser),
+      'style' => 'vertical-align:top;',
+    );
   }
 
-  return theme('table', NULL, $rows);
+  return theme('table', array('header' => NULL, 'rows' => $rows));
 }
Index: modr8/README.txt
===================================================================
--- modr8/README.txt	(revision 20063)
+++ modr8/README.txt	(working copy)
@@ -1,6 +1,6 @@
 $Id: README.txt,v 1.8 2008/09/05 01:13:10 pwolanin Exp $
 
-Modr8 module for Drupal 6.x.
+Modr8 module for Drupal 7.x.
 
 The moderation of content was removed from core in 5.x.  This module adds back
 that capability and also prevents posts that are in moderation from showing
@@ -22,14 +22,14 @@
 preview content in moderation, as well as approve or delete each moderated post,
 and (optionally) to send an e-mail to the author informing him/her of the choice.
 *Important note:* as of version 5.x-2.3 unpublished nodes in the WILL be shown
-in the moderation queue listing for users with the "adminiser nodes" permission.
-For these users, approving a post in the queue will also publish it. However,
-posts to be moderated should generally be set to be published so that users
-without the "administer nodes" permission can also effectively work as
-moderators.
+in the moderation queue listing for users with the "administer nodes"
+permission. For these users, approving a post in the queue will also publish it.
+However, posts to be moderated should generally be set to be published
+so that users without the "administer nodes" permission can also
+effectively work as moderators.
 
 Visit the settings page to customize the e-mail messages and set other defaults
-(path: admin/settings/modr8).
+(path: admin/config/system/modr8).
 
 As of version 5.x-2.0, modr8 also includes a moderation log to record the
 actions of moderators on items in the moderation queue.  This may be especially
@@ -47,3 +47,4 @@
 (jjeff@drupal).  Upgrade to 5.x and 5.x, 6.x maintenance by 
 Peter Wolanin (pwolanin@drupal).
 Initial upgrade to 6.x by Croitor Alexander (Placinta@drupal)
+Initial upgrade to 7.x by Berend de Boer (berend@pobox.com).
Index: modr8/modr8.module
===================================================================
--- modr8/modr8.module	(revision 20063)
+++ modr8/modr8.module	(working copy)
@@ -13,7 +13,7 @@
 define('NODE_BUILD_MODR8_TEASER', 1242526499);
 
 /**
- * Implementation of hook_help().
+ * Implements hook_help().
  */
 function modr8_help($path, $arg) {
   switch ($path) {
@@ -26,12 +26,12 @@
 /**
  * An access function for Moderation Menu Tab
  */
-function modr8_moderation_access($nid) {
-  return user_access('moderate content') && db_result(db_query("SELECT COUNT(*) FROM {modr8_log} ml WHERE ml.nid = %d", $nid));
+function modr8_moderation_access($node) {
+  return user_access('moderate content') && db_query("SELECT COUNT(*) FROM {modr8_log} ml WHERE ml.nid = :nid", array(':nid' => $node->nid))->fetchField();
 }
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function modr8_menu() {
   $items = array();
@@ -43,6 +43,7 @@
     'access arguments' => array('moderate content'),
     'page callback' => 'modr8_page',
     'file' => 'modr8_admin.inc',
+    'type' => MENU_LOCAL_TASK,
   );
   $items['admin/reports/modr8'] = array(
     'title' => 'Content moderation log',
@@ -52,7 +53,7 @@
     'page callback' => 'modr8_log_view',
     'file' => 'modr8_admin.inc',
   );
-  $items['admin/settings/modr8'] = array(
+  $items['admin/config/system/modr8'] = array(
     'title' => 'Modr8 settings',
     'description' => 'Configure content moderation.',
     'page callback' => 'modr8_settings',
@@ -60,7 +61,7 @@
     'access arguments' => array('administer site configuration'),
     'file' => 'modr8_admin.inc',
   );
-  $items['node/%/modr8'] = array(
+  $items['node/%node/modr8'] = array(
     'title' => 'Moderation',
     'page callback' => 'modr8_log_view',
     'page arguments' => array('node', 1),
@@ -68,7 +69,7 @@
     'access arguments' => array(1),
     'file' => 'modr8_admin.inc',
     'weight' => 10,
-    'type' => MENU_LOCAL_TASK
+    'type' => MENU_LOCAL_TASK,
   );
   $items['node/%node/log/response/%'] = array(
     'title' => 'Moderation response',
@@ -107,10 +108,19 @@
 }
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_permission().
  */
-function modr8_perm() {
-  return array('moderate content', 'bypass moderation queue');
+function modr8_permission() {
+  return array(
+    'moderate content' => array(
+      'title' => t('moderate content'),
+      'description' => t('TODO Add a description for \'moderate content\''),
+    ),
+    'bypass moderation queue' => array(
+      'title' => t('bypass moderation queue'),
+      'description' => t('TODO Add a description for \'bypass moderation queue\''),
+    ),
+  );
 }
 
 /**
@@ -122,54 +132,93 @@
 }
 
 /**
- * Implementation of hook_nodeapi().
+ * Implements hook_node_load().
  */
-function modr8_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
-  // add messages here..
-  switch ($op) {
-    case 'load':
-      return db_fetch_array(db_query('SELECT n.moderate FROM {node} n WHERE n.nid = %d', $node->nid));
-    case 'prepare':
-      if (!isset($node->nid)) {//a new node
-        $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
-	$node->moderate = in_array('moderate', $node_options) && !user_access('bypass moderation queue');
+function modr8_node_load($nodes) {
+ $result = db_query('SELECT nid, moderate FROM {modr8_moderate} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes)));
+  foreach ($result as $record) {
+    $nodes[$record->nid]->moderate = $record->moderate;
+  }
+  foreach ($nodes as &$node) {
+    if (! isset($node->moderate))
+      $node->moderate = false;
+  }
       }
-      break;
 
-    case 'submit':
-      if ($node->moderate && user_access('bypass moderation queue')) {
-        if (!user_access('administer nodes')) { // Don't reset for admins
-          $node->moderate = 0;
+/**
+ * Implements hook_node_prepare().
+ */
+function modr8_node_prepare($node) {
+  if (!isset($node->nid)) {
+    //a new node
+    $node_options = variable_get('node_options_' . $node->type, array('status', 'promote'));
+    $node->moderate = in_array('moderate', $node_options) && !user_access('bypass moderation queue');
         }
       }
-      break;
 
-    case 'view':
-      if ($node->moderate && empty($node->modr8_form_teaser) && ($node->build_mode == NODE_BUILD_NORMAL) && ($teaser || $page)) {
+/**
+ * Implements hook_node_view().
+ */
+function modr8_node_view($node, $view_mode = 'full', $langcode) {
+  if ($node->moderate && ($view_mode = 'full' || $view_mode == 'teaser')) {
         $node->content['modr8_message'] = array(
-          '#value' => theme('modr8_message', $teaser, $node->type, 'view'),
+      '#type' => 'markup',
+      '#markup' => theme('modr8_message', array('0' => $view_mode == 'teaser', '1' => $node->type, '2' => 'view')),
           '#weight' => -100,
         );
       }
-      break;
-    case 'update' :
-    case 'insert' :
-      db_query('UPDATE {node} SET moderate = %d WHERE nid = %d', $node->moderate, $node->nid);
-      if ($node->moderate) { //cut this?
-        theme('modr8_message', FALSE, $node->type, $op);
       }
-      break;
-    case 'delete':
+
+/**
+ * Implements hook_node_update().
+ */
+function modr8_node_update($node) {
+  db_delete('modr8_moderate')->condition('nid', $node->nid)->execute();
+  if ($node->moderate) {
+    db_insert('modr8_moderate')
+      ->fields(array(
+          'nid' => $node->nid,
+          'moderate' => $node->moderate,
+        ))
+      ->execute();
+    //cut this?
+    theme('modr8_message', array('0' => FALSE, '1' => $node->type, '2' => 'update'));
+  }
+}
+
+/**
+ * Implements hook_node_insert().
+ */
+function modr8_node_insert($node) {
+  // We only put a node in moderation if explicitly set.
+  if ($node->moderate) {
+    db_insert('modr8_moderate')
+      ->fields(array(
+          'nid' => $node->nid,
+          'moderate' => $node->moderate,
+        ))
+      ->execute();
+    //cut this?
+    theme('modr8_message', array('0' => FALSE, '1' => $node->type, '2' => 'insert'));
+  }
+}
+
+/**
+ * Implements hook_node_delete().
+ */
+function modr8_node_delete($node) {
       // Delete log entries when a node is deleted, unless it's deleted while
       // in moderation.  In the latter case, we want to retain the log to see
       // which moderator deleted the node  and any message they sent.
-      if (!$node->moderate) {
-        db_query("DELETE FROM {modr8_log} WHERE nid = %d", $node->nid);
-      }
-      break;
-  }
+  db_delete('modr8_log')
+    ->condition('nid', $node->nid)
+    ->execute();
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function modr8_form_alter(&$form, $form_state, $form_id) {
 
   if (isset($form['type']['#value']) && $form['type']['#value'] .'_node_form' == $form_id)  {
@@ -179,7 +228,7 @@
       '#title' => t('In moderation queue'),
       '#default_value' => $form['#node']->moderate,
       '#weight' => 24,
-      '#description' => t('This %type will be placed in moderation if the %moderate checkbox is selected.', array('%type' => node_get_types('name', $form['#node']), '%moderate' => t('In moderation queue'))),
+      '#description' => t('This %type will be placed in moderation if the %moderate checkbox is selected.', array('%type' => node_type_get_name($form['#node']), '%moderate' => t('In moderation queue'))),
     );
     if (user_access('administer nodes')) {
       $form['options']['moderate'] = $moderate_checkbox;
@@ -194,7 +243,8 @@
       );
       if ($form['#node']->moderate) {
         $form['modr8_message'] = array(
-          '#value' => theme('modr8_message', FALSE, $form['#node']->type, 'node_form'),
+          '#type' => 'markup',
+          '#markup' => theme('modr8_message', array('0' => FALSE, '1' => $form['#node']->type, '2' => 'node_form')),
           '#weight' => -100,
         );
       }
@@ -206,7 +256,7 @@
 }
 
 /**
- * Implementation of hook_db_rewrite_sql().
+ * Implements hook_db_rewrite_sql().
  */
 function modr8_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
   $node_table = $primary_table;
@@ -235,38 +285,47 @@
 }
 
 /**
- * Implementation of hook_cron().
+ * Implements hook_cron().
  *
  * Remove expired moderation log events.
  */
 function modr8_cron() {
   if ($log_clear = variable_get('modr8_log_clear', 0)) {
-    db_query('DELETE FROM {modr8_log} WHERE timestamp < %d', time() - $log_clear);
+    db_delete('modr8_log')
+      ->condition('timestamp', REQUEST_TIME - $log_clear, '<')
+      ->execute();
   }
 }
 
 /**
- * Implementation of hook_block().
+ * Implements hook_block_info().
  */
-function modr8_block($op = 'list', $delta = 0) {
-  if ($op == 'list') {
-    $blocks[0]['info'] = t("Modr8 moderator's block");
+function modr8_block_info() {
+  // TODO Rename block deltas (e.g. delta-0) to readable strings.
+  if (TRUE) {
+    $blocks['delta-0']['info'] = t("Modr8 moderator's block");
     $blocks['modr8-moderators']['info'] = t("Modr8 moderators credit list");
-    $blocks['modr8-moderators']['cache'] = BLOCK_CACHE_GLOBAL;
+    $blocks['modr8-moderators']['cache'] = DRUPAL_CACHE_GLOBAL;
     return $blocks;
   }
-  elseif ($op == 'view') {
+}
+
+/**
+ * Implements hook_block_view().
+ */
+function modr8_block_view($delta) {
+  if (TRUE) {
     if ($delta == 'modr8-moderators') {
       $block = array();
       $cutoff = strtotime('now -6 months');
-      $result = db_query_range("SELECT COUNT(ml.modid) AS number, u.* FROM {modr8_log} ml INNER JOIN {users} u on u.uid = ml.uid WHERE ml.action != 'Response' AND ml.timestamp > %d AND u.status = 1 GROUP BY u.uid ORDER BY number DESC", $cutoff, 0, variable_get('modr8_top_moderators_limit', 10));
+      $result = db_query_range("SELECT COUNT(ml.modid) AS number, u.* FROM {modr8_log} ml INNER JOIN {users} u on u.uid = ml.uid WHERE ml.action != :ml.action AND ml.timestamp > :ml.timestamp AND u.status = :u.status GROUP BY u.uid ORDER BY number DESC", array(':ml.action' => 'Response', ':ml.timestamp' => $cutoff, ':u.status' => 1));
       $header = array(t('User'), t('Number of actions'));
       $rows = array();
       while ($account = db_fetch_object($result)) {
-        $rows[] = array(theme('username', $account), $account->number);
+        $rows[] = array(theme('username', array('account' => $account)), $account->number);
       }
       if ($rows) {
-        $block['content'] = t('Last 6 months:') . '<br />' . theme('table', $header, $rows);
+        $block['content'] = t('Last 6 months:') . '<br />' . theme('table', array('header' => $header, 'rows' => $rows));
         $block['subject'] = t('Top moderators');
       }
       return $block;
@@ -278,11 +337,13 @@
         // Users who don't have the 'administer nodes' permission can only see published nodes.
         $is_published = 'n.status = 1 AND ';
       }
-      $count = db_result(db_query(db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE '. $is_published .' n.moderate = 1')));
+      // TODO Please convert this statement to the D7 database API syntax.
+      $count = db_query(db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE ' . $is_published . ' n.moderate = 1'))->fetchField();
       $content = '<p>'. l(t('@items in moderation', array('@items' => format_plural($count, '1 post', '@count posts'))), 'admin/content/modr8') .'</p>';
       if ($count) {
         $sql = db_rewrite_sql('SELECT n.nid, n.title FROM {node} n WHERE '. $is_published .' n.moderate = 1 ORDER BY n.changed DESC');
-        $result = db_query_range($sql, 0, 6);
+        // TODO Please convert this statement to the D7 database API syntax.
+        $result = db_query_range($sql);
         $content .= node_title_list($result, t('Recent additions:'));
       }
       $block['content'] = $content;
@@ -290,22 +351,31 @@
     }
   }
 }
+
 /**
- * Implementation of hook_theme().
+ * Implements hook_block().
  */
-function modr8_theme() {
-  return array(
-    'modr8_message' => array('arguments' => array('teaser', 'nodetype', 'op')),
-    'modr8_form' => array('arguments' => array('form')),
-    'moderation_event' => array('arguments' => array('event')),
-    'modr8_note' => array('arguments' => array('note')),
+function modr8_block_OLD($op = 'list', $delta = 0) { }
+
 
+/**
+ * Implements hook_theme().
+ */
+function modr8_theme($existing, $type, $theme, $path) {
+  return array(
+    'modr8_message' => array('variables' => array('teaser', 'nodetype', 'op')),
+    'modr8_form' => array('render element' => 'form'),
+    'moderation_event' => array('variables' => array('event')),
+    'modr8_note' => array('variables' => array('note')),
   );
 }
 /**
  * Theming function for messages.
  */
-function theme_modr8_message($teaser = FALSE, $nodetype = 'page', $op = 'view') {
+function theme_modr8_message($variables) {
+  $teaser = $variables['0'];
+  $nodetype = $variables['1'];
+  $op = $variables['2'];
   static $already_messaged = FALSE;
   // Don't add the message more than once per page load.
   if ($already_messaged) {
@@ -321,7 +391,7 @@
         break;
       case 'node_form':
         if (!user_access('bypass moderation queue')) {
-          drupal_set_message(t('This %type will be submitted for moderation and will not be accessible to other users until it has been approved.', array('%type' => node_get_types('name', $nodetype))));
+          drupal_set_message(t('This %type will be submitted for moderation and will not be accessible to other users until it has been approved.', array('%type' => node_type_get_name($nodetype))));
         }
         break;
     }
Index: modr8/modr8.install
===================================================================
--- modr8/modr8.install	(revision 20063)
+++ modr8/modr8.install	(working copy)
@@ -2,20 +2,82 @@
 // $Id: modr8.install,v 1.5 2010/04/02 02:59:08 pwolanin Exp $
 
 /**
- * Implementation of hook_schema().
+ * @file
+ * Install, update and uninstall functions for the modr8 module.
+ * TODO: write upgrade from Drupal 6.
+ *
+ */
+
+/**
+ * Implements hook_schema().
  */
 function modr8_schema() {
+  $schema['modr8_moderate'] = array(
+    'fields' => array(
+      'nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'moderate' => array(
+        'description' => 'Boolean indicating if a node is "in moderation".',
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0),
+    ),
+    'primary key' => array('nid'),
+  );
   $schema['modr8_log'] = array(
     'fields' => array(
-      'modid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
-      'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-      'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'author_uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'action' => array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''),
-      'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
-      'message' => array('type' => 'text', 'size' => 'big',  'not null' => TRUE),
-      'teaser' => array('type' => 'text', 'size' => 'big',  'not null' => TRUE),
-      'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0)
+      'modid' => array(
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'uid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'author_uid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'action' => array(
+        'type' => 'varchar',
+        'length' => 16,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'title' => array(
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'message' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => TRUE,
+      ),
+      'teaser' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => TRUE,
+      ),
+      'timestamp' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
     ),
     'indexes' => array(
       'nid_time' => array('nid', 'modid'),
@@ -28,22 +90,6 @@
 }
 
 /**
- * Implementation of hook_install().
- */
-function modr8_install() {
-  // Create tables.
-  drupal_install_schema('modr8');
-}
-
-/**
- * Implementation of hook_uninstall().
- */
-function modr8_uninstall() {
-  // Remove tables.
-  drupal_uninstall_schema('modr8');
-}
-
-/**
  * Update table definitions.
  */
 function modr8_update_1000() {
@@ -51,24 +97,66 @@
   $name = 'modr8_log';
   $table = array(
     'fields' => array(
-      'modid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
-      'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-      'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'author_uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'action' => array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''),
-      'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
-      'message' => array('type' => 'text', 'size' => 'big',  'not null' => TRUE),
-      'teaser' => array('type' => 'text', 'size' => 'big',  'not null' => TRUE),
-      'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0)
+      'modid' => array(
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'uid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'author_uid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'action' => array(
+        'type' => 'varchar',
+        'length' => 16,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'title' => array(
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'message' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => TRUE,
+      ),
+      'teaser' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => TRUE,
+      ),
+      'timestamp' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
     ),
     'indexes' => array(
       'nid_time' => array('nid', 'modid'),
-      'action' => array('action')
+      'action' => array('action'),
     ),
     'primary key' => array('modid'),
   );
-  db_create_table($ret, $name, $table);
-  return $ret;
+  db_create_table($name, $table);
+  // hook_update_N() no longer returns a $ret array. Instead, return
+  // nothing or a translated string indicating the update ran successfully.
+  // See http://drupal.org/node/224333#update_sql.
+  return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
 }
 
 /**
@@ -76,7 +164,10 @@
  */
 function modr8_update_6001() {
   $ret = array();
-  db_drop_index($ret, 'modr8_log', 'action');
-  db_add_index($ret, 'modr8_log', 'time_action', array('timestamp', 'action'));
-  return $ret;
+  db_drop_index('modr8_log', 'action');
+  db_add_index('modr8_log', 'time_action', array('timestamp', 'action'));
+  // hook_update_N() no longer returns a $ret array. Instead, return
+  // nothing or a translated string indicating the update ran successfully.
+  // See http://drupal.org/node/224333#update_sql.
+  return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
 }
