Index: mollom.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mollom/mollom.admin.inc,v
retrieving revision 1.33
diff -u -p -r1.33 mollom.admin.inc
--- mollom.admin.inc	9 Sep 2010 15:05:03 -0000	1.33
+++ mollom.admin.inc	14 Sep 2010 13:50:15 -0000
@@ -10,6 +10,11 @@
  * Menu callback; Displays a list of forms configured for Mollom.
  */
 function mollom_admin_form_list() {
+  // This page is no form, but we want the testing mode warning to appear on it,
+  // too. We therefore pretend there was a form.
+  $form = $form_state = array();
+  mollom_form_alter($form, $form_state, 'mollom_admin_form_list');
+
   $modes = array(
     MOLLOM_MODE_DISABLED => t('None'),
     MOLLOM_MODE_CAPTCHA => t('CAPTCHA'),
Index: mollom.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mollom/mollom.css,v
retrieving revision 1.4
diff -u -p -r1.4 mollom.css
--- mollom.css	12 Sep 2010 18:12:50 -0000	1.4
+++ mollom.css	14 Sep 2010 13:50:15 -0000
@@ -5,6 +5,7 @@
 }
 
 /* Help themes to properly display Mollom's log messages. */
-.dblog-event pre {
+.dblog-event pre,
+#simpletest-result-form table td {
   white-space: pre-wrap;
 }
Index: mollom.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mollom/mollom.module,v
retrieving revision 1.75
diff -u -p -r1.75 mollom.module
--- mollom.module	13 Sep 2010 00:17:24 -0000	1.75
+++ mollom.module	14 Sep 2010 13:56:06 -0000
@@ -493,8 +493,8 @@ function mollom_data_delete_form_alter(&
  * @see mollom_form_alter()
  */
 function mollom_data_delete_form_submit($form, &$form_state) {
-  $forms = mollom_delete_form_list();
-  $mollom_form = mollom_form_load($forms[$form_state['values']['form_id']]);
+  $forms = mollom_form_cache();
+  $mollom_form = mollom_form_load($forms['delete'][$form_state['values']['form_id']]);
   $data = mollom_form_get_values($form_state['values'], $mollom_form['enabled_fields'], $mollom_form['mapping']);
 
   $entity = $mollom_form['entity'];
@@ -551,7 +551,7 @@ function mollom_data_report_multiple($en
  * necessary.
  */
 function mollom_form_alter(&$form, &$form_state, $form_id) {
-  static $protected_forms;
+  $forms = &drupal_static(__FUNCTION__);
 
   // Skip installation and update forms.
   if (defined('MAINTENANCE_MODE')) {
@@ -563,8 +563,16 @@ function mollom_form_alter(&$form, &$for
     return;
   }
 
-  // @todo Show this message on all protected forms, regardless of permissions.
-  if (empty($_POST) && variable_get('mollom_testing_mode', 0)) {
+  // Retrieve a list of all protected forms once.
+  if (!isset($forms)) {
+    $forms = mollom_form_cache();
+  }
+
+  // Remind of enabled testing mode on all protected forms.
+  if (!isset($forms['testing']) && variable_get('mollom_testing_mode', 0) && empty($_POST) && (isset($forms['protected'][$form_id]) || strpos($_GET['q'], 'admin/config/content/mollom') === 0)) {
+    // Re-use the static form cache variable to only output this warning once.
+    $forms['testing'] = TRUE;
+
     $admin_message = '';
     if (user_access('administer mollom') && $_GET['q'] != 'admin/config/content/mollom/settings') {
       $admin_message = t('Visit the <a href="@settings-url">Mollom settings page</a> to disable it.', array(
@@ -579,12 +587,8 @@ function mollom_form_alter(&$form, &$for
 
   // Site administrators don't have their content checked with Mollom.
   if (!user_access('bypass mollom protection')) {
-    // Retrieve a list of all protected forms once.
-    if (!isset($protected_forms)) {
-      $protected_forms = db_query("SELECT form_id, module FROM {mollom_form}")->fetchAllKeyed();
-    }
     // Retrieve configuration for this form.
-    if (isset($protected_forms[$form_id]) && $mollom_form = mollom_form_load($form_id)) {
+    if (isset($forms['protected'][$form_id]) && ($mollom_form = mollom_form_load($form_id))) {
       // Determine whether to bypass validation for the current user.
       foreach ($mollom_form['bypass access'] as $permission) {
         if (user_access($permission)) {
@@ -625,70 +629,71 @@ function mollom_form_alter(&$form, &$for
     }
   }
   // Integrate with delete confirmation forms to send feedback to Mollom.
-  $forms = mollom_delete_form_list();
-  if (isset($forms[$form_id])) {
+  if (isset($forms['delete'][$form_id])) {
     mollom_data_delete_form_alter($form, $form_state);
-    // Report before deletion.
+    // Report before deleting. This needs to be handled here, since
+    // mollom_data_delete_form_alter() is re-used for mass-operation forms.
     array_unshift($form['#submit'], 'mollom_data_delete_form_submit');
   }
 }
 
 /**
- * Returns a mapping of entity delete forms to registered Mollom form ids.
+ * Returns a cached mapping of protected and delete confirmation form ids.
  *
  * @param $reset
- *   (optional) Boolean whether to reset the static cache and flush the database
- *   cache and return nothing. Defaults to FALSE.
+ *   (optional) Boolean whether to reset the static cache, flush the database
+ *   cache, and return nothing (TRUE). Defaults to FALSE.
  *
  * @return
- *   An associative array whose keys are 'delete form' ids and whose values are
- *   registered Mollom form ids, e.g.
- *   @code
+ *   An associative array containing:
+ *   - protected: An associative array whose keys are protected form IDs and
+ *     whose values are the corresponding module names the form belongs to.
+ *   - delete: An associative array whose keys are 'delete form' ids and whose
+ *     values are protected form ids; e.g.
+ *     @code
  *     array(
  *       'node_delete_confirm' => 'article_node_form',
  *     )
- *   @endcode
- *   Note that a single delete form id can map to multiple registered $form_ids,
- *   and only the first actively protected $form_id that defines a delete form
- *   is taken into account. As in the example above, we presume that all
- *   '$type_node_form' definitions belong to the same 'entity' and use the same
- *   'post_id' mapping.
+ *     @endcode
+ *     A single delete confirmation form id can map to multiple registered
+ *     $form_ids, but only the first is taken into account. As in above example,
+ *     we assume that all 'TYPE_node_form' definitions belong to the same entity
+ *     and therefore have an identical 'post_id' mapping.
  */
-function mollom_delete_form_list($reset = FALSE) {
-  $forms = &drupal_static(__FUNCTION__);
-
+function mollom_form_cache($reset = FALSE) {
   if ($reset) {
-    $forms = NULL;
+    // This catches both 'mollom_form_cache' as well as mollom_form_load()'s
+    // 'mollom:form:*' entries.
     cache_clear_all('mollom', 'cache', TRUE);
     return;
   }
 
-  if (!isset($forms)) {
-    // Try to fetch from database cache first.
-    $cache = cache_get('mollom:delete_form_list');
-    if ($cache) {
-      $forms = $cache->data;
+  if ($cache = cache_get('mollom_form_cache')) {
+    return $cache->data;
+  }
+
+  $forms['protected'] = db_query("SELECT form_id, module FROM {mollom_form}")->fetchAllKeyed();
+
+  // Build a list of delete confirmation forms of entities integrating with
+  // Mollom, so we are able to alter the delete confirmation form to display
+  // our feedback options.
+  $forms['delete'] = array();
+  foreach (mollom_form_list() as $form_id => $info) {
+    if (!isset($info['delete form']) || !isset($info['entity'])) {
+      continue;
     }
-    else {
-      $forms = array();
-      foreach (mollom_form_list() as $form_id => $info) {
-        // Skip forms that neither define 'delete form' nor 'entity'.
-        if (!isset($info['delete form']) || !isset($info['entity'])) {
-          continue;
-        }
-        // Process multiple 'delete form' definitions only once.
-        if (!isset($forms[$info['delete form']])) {
-          // Check whether this form is protected and whether it defines a
-          // 'post_id' mapping.
-          $mollom_form = mollom_form_load($form_id);
-          if (isset($mollom_form['mapping']['post_id'])) {
-            $forms[$info['delete form']] = $form_id;
-          }
-        }
+    // We expect that the same delete confirmation form uses the same form
+    // element mapping, so multiple 'delete form' definitions are only processed
+    // once. Additionally, we only care for protected forms.
+    if (!isset($forms['delete'][$info['delete form']]) && isset($forms['protected'][$form_id])) {
+      // A delete confirmation form integration requires a 'post_id' mapping.
+      $form_info = mollom_form_info($form_id, $info['module']);
+      if (isset($form_info['mapping']['post_id'])) {
+        $forms['delete'][$info['delete form']] = $form_id;
       }
-      cache_set('mollom:delete_form_list', $forms);
     }
   }
+  cache_set('mollom_form_cache', $forms);
 
   return $forms;
 }
@@ -781,17 +786,25 @@ function mollom_form_new($form_id = NULL
  * Menu argument loader; Loads Mollom configuration and form information for a given form id.
  */
 function mollom_form_load($form_id) {
-  $mollom_form = db_query_range('SELECT * FROM {mollom_form} WHERE form_id = :form_id', 0, 1, array(':form_id' => $form_id))->fetchAssoc();
-  if ($mollom_form) {
-    $mollom_form['checks'] = unserialize($mollom_form['checks']);
-    $mollom_form['enabled_fields'] = unserialize($mollom_form['enabled_fields']);
+  $cid = 'mollom:form:' . $form_id;
+  if ($cache = cache_get($cid)) {
+    return $cache->data;
+  }
+  else {
+    $mollom_form = db_query('SELECT * FROM {mollom_form} WHERE form_id = :form_id', array(':form_id' => $form_id))->fetchAssoc();
+    if ($mollom_form) {
+      $mollom_form['checks'] = unserialize($mollom_form['checks']);
+      $mollom_form['enabled_fields'] = unserialize($mollom_form['enabled_fields']);
+
+      // Attach form registry information.
+      $form_list = mollom_form_list();
+      if (isset($form_list[$form_id])) {
+        $mollom_form += $form_list[$form_id];
+      }
+      $mollom_form += mollom_form_info($form_id, $mollom_form['module']);
 
-    // Attach form registry information.
-    $form_list = mollom_form_list();
-    if (isset($form_list[$form_id])) {
-      $mollom_form += $form_list[$form_id];
+      cache_set($cid, $mollom_form);
     }
-    $mollom_form += mollom_form_info($form_id, $mollom_form['module']);
   }
   return $mollom_form;
 }
@@ -801,24 +814,18 @@ function mollom_form_load($form_id) {
  */
 function mollom_form_save(&$mollom_form) {
   $exists = db_query_range('SELECT 1 FROM {mollom_form} WHERE form_id = :form_id', 0, 1, array(':form_id' => $mollom_form['form_id']))->fetchField();
-  if ($exists) {
-    $status = drupal_write_record('mollom_form', $mollom_form, 'form_id');
+  $status = drupal_write_record('mollom_form', $mollom_form, ($exists ? 'form_id' : array()));
+
+  // Allow modules to react on saved form configurations.
+  if ($status === SAVED_NEW) {
+    module_invoke_all('mollom_form_insert', $mollom_form);
   }
   else {
-    $status = drupal_write_record('mollom_form', $mollom_form);
-  }
-  // Allow modules to react on saved form configurations.
-  if (isset($status) && $status) {
-    if ($status === SAVED_NEW) {
-      module_invoke_all('mollom_form_insert', $mollom_form);
-    }
-    elseif ($status === SAVED_UPDATED) {
-      module_invoke_all('mollom_form_update', $mollom_form);
-    }
+    module_invoke_all('mollom_form_update', $mollom_form);
   }
 
-  // Flush cache of delete form mappings.
-  mollom_delete_form_list(TRUE);
+  // Flush cached Mollom forms and the Mollom form mapping cache.
+  mollom_form_cache(TRUE);
 
   return $status;
 }
Index: tests/mollom.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mollom/tests/mollom.test,v
retrieving revision 1.57
diff -u -p -r1.57 mollom.test
--- tests/mollom.test	12 Sep 2010 22:05:55 -0000	1.57
+++ tests/mollom.test	14 Sep 2010 13:50:15 -0000
@@ -823,7 +823,7 @@ class MollomInstallationTestCase extends
     $this->assertNoText('The configured Mollom API keys are invalid.');
 
     // Verify presence of testing mode warning.
-    $this->drupalGet('admin/config/content/mollom/blacklist');
+    $this->drupalGet('admin/config/content/mollom');
     $this->assertText('Mollom testing mode is still enabled.');
   }
 }
