Index: modules/field/field.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.module,v
retrieving revision 1.59
diff -u -p -r1.59 field.module
--- modules/field/field.module	2 Jan 2010 18:50:51 -0000	1.59
+++ modules/field/field.module	3 Jan 2010 16:09:50 -0000
@@ -248,6 +248,13 @@ function field_modules_disabled($modules
 }
 
 /**
+ * Implement hook_filter_format_update().
+ */
+function field_filter_format_update($format) {
+  field_cache_clear();
+}
+
+/**
  * Allows a module to update the database for fields and columns it controls.
  *
  * @param string $module
Index: modules/filter/filter.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.admin.inc,v
retrieving revision 1.55
diff -u -p -r1.55 filter.admin.inc
--- modules/filter/filter.admin.inc	22 Dec 2009 14:47:14 -0000	1.55
+++ modules/filter/filter.admin.inc	3 Jan 2010 16:09:50 -0000
@@ -17,8 +17,16 @@ function filter_admin_overview($form) {
   $formats = filter_formats();
   $fallback_format = filter_fallback_format();
 
+  // Output a warning if there are formats containing missing filters.
+  $broken_filters = _filter_get_broken_filters();
+  if ($broken_filters) {
+    drupal_set_message(format_plural(count($broken_filters), 'The highlighted text format needs to be re-configured, because it is using filters that no longer exist.', 'The highlighted text formats need to be re-configured, because they are using filters that no longer exist.'), 'error');
+  }
+
   $form['#tree'] = TRUE;
   foreach ($formats as $id => $format) {
+    // Indicate broken formats.
+    $form['formats'][$id]['#is_broken'] = isset($broken_filters[$id]);
     // Check whether this is the fallback text format. This format is available
     // to all roles and cannot be deleted via the admin interface.
     $form['formats'][$id]['#is_fallback'] = ($id == $fallback_format);
@@ -73,7 +81,7 @@ function theme_filter_admin_overview($va
         drupal_render($form['formats'][$id]['configure']),
         drupal_render($form['formats'][$id]['delete']),
       ),
-      'class' => array('draggable'),
+      'class' => array('draggable', ($form['formats'][$id]['#is_broken'] ? 'error' : '')),
     );
   }
   $header = array(t('Name'), t('Roles'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2));
Index: modules/filter/filter.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.install,v
retrieving revision 1.27
diff -u -p -r1.27 filter.install
--- modules/filter/filter.install	8 Dec 2009 06:52:38 -0000	1.27
+++ modules/filter/filter.install	3 Jan 2010 16:09:50 -0000
@@ -7,6 +7,27 @@
  */
 
 /**
+ * Implements hook_requirements().
+ */
+function filter_requirements($phase) {
+  $requirements = array();
+
+  if ($phase == 'runtime') {
+    // Check for text formats containing missing/vanished filters.
+    if (_filter_get_broken_filters()) {
+      $requirements['filter'] = array(
+        'title' => t('Text formats'),
+        'value' => t('Missing filters'),
+        'severity' => REQUIREMENT_ERROR,
+        'description' => t('At least one text format contains a filter that was provided by a module that has been disabled. All content using one of these text formats will be hidden until <a href="@text-format-url">text formats have been re-configured</a>.', array('@text-format-url' => url('admin/config/content/formats'))),
+      );
+    }
+  }
+
+  return $requirements;
+}
+
+/**
  * Implements hook_schema().
  */
 function filter_schema() {
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.314
diff -u -p -r1.314 filter.module
--- modules/filter/filter.module	28 Dec 2009 21:52:13 -0000	1.314
+++ modules/filter/filter.module	3 Jan 2010 16:09:50 -0000
@@ -172,6 +172,17 @@ function filter_format_save(&$format) {
   }
   else {
     $return = drupal_write_record('filter_format', $format, 'format');
+
+    // When a text format is updated, we need to assume that its filter
+    // configuration has been verified and we are safe to remove any pointers to
+    // vanished filters.
+    if ($broken_filters = _filter_get_broken_filters($format->format)) {
+      db_delete('filter')
+        ->condition('format', $format->format)
+        ->condition('name', $broken_filters, 'IN')
+        ->condition('name', array_keys($format->filters), 'NOT IN')
+        ->execute();
+    }
   }
 
   $filter_info = filter_get_filters();
@@ -571,9 +582,14 @@ function filter_list_format($format_id) 
         $filter->title = $filter_info[$name]['title'];
         // Unpack stored filter settings.
         $filter->settings = (isset($filter->settings) ? unserialize($filter->settings) : array());
-
-        $format_filters[$name] = $filter;
       }
+      else {
+        // The filter is assigned to the text format, but the module providing
+        // the filter no longer exists. We assign a negative status, so
+        // check_markup() can bail out.
+        $filter->status = -1;
+      }
+      $format_filters[$name] = $filter;
     }
     $filters[$format_id] = $format_filters;
   }
@@ -582,6 +598,49 @@ function filter_list_format($format_id) 
 }
 
 /**
+ * Helper function to return a list of vanished filters keyed by text format.
+ *
+ * @param $format_id
+ *   (optional) A text format id to limit the query to.
+ * @param $modules
+ *   (optional) A list of module names to limit the query to.
+ *
+ * @return
+ *   A list of assigned filters that no longer exist, keyed by text format. If
+ *   $format_id was passed, only filters for the given text format are returned.
+ *
+ * @see filter_list_format()
+ */
+function _filter_get_broken_filters($format_id = NULL, $modules = NULL) {
+  // Retrieve all filters exposed by modules.
+  $filter_info = filter_get_filters();
+
+  // Query all filters not contained in the list of available filters.
+  $query = db_select('filter', 'f')
+    ->fields('f', array('format', 'name'))
+    ->condition('name', array_keys($filter_info), 'NOT IN');
+  // Optionally limit to text format.
+  if (isset($format_id)) {
+    $query->condition('format', $format_id);
+  }
+  // Optionally limit to a list of modules.
+  if (isset($modules)) {
+    $query->condition('module', $modules, 'IN');
+  }
+  $result = $query->execute()->fetchAll();
+
+  // Compile a list of vanished filters.
+  $broken_filters = array();
+  foreach ($result as $filter) {
+    $broken_filters[$filter->format][] = $filter->name;
+  }
+  if (isset($format_id)) {
+    return isset($broken_filters[$format_id]) ? $broken_filters[$format_id] : array();
+  }
+  return $broken_filters;
+}
+
+/**
  * Run all the enabled filters on a piece of text.
  *
  * Note: Because filters can inject JavaScript or execute PHP code, security is
@@ -608,7 +667,13 @@ function check_markup($text, $format_id 
   if (empty($format_id)) {
     $format_id = filter_fallback_format();
   }
-  $format = filter_format_load($format_id);
+  // If the requested text format does not exist, we return an empty text for
+  // security reasons. The text stays empty until the text format has been
+  // re-configured.
+  if (!$format = filter_format_load($format_id)) {
+    watchdog('filter', 'Missing text format: %format.', array('%format' => $format_id), WATCHDOG_ALERT);
+    return '';
+  }
 
   // Check for a cached version of this piece of text.
   $cache = $cache && !empty($format->cache);
@@ -630,9 +695,17 @@ function check_markup($text, $format_id 
 
   // Give filters the chance to escape HTML-like data such as code or formulas.
   foreach ($filters as $name => $filter) {
-    if ($filter->status && isset($filter_info[$name]['prepare callback']) && function_exists($filter_info[$name]['prepare callback'])) {
-      $function = $filter_info[$name]['prepare callback'];
-      $text = $function($text, $filter, $format, $langcode, $cache, $cache_id);
+    if ($filter->status != -1) {
+      if ($filter->status && isset($filter_info[$name]['prepare callback']) && function_exists($filter_info[$name]['prepare callback'])) {
+        $function = $filter_info[$name]['prepare callback'];
+        $text = $function($text, $filter, $format, $langcode, $cache, $cache_id);
+      }
+    }
+    // If a filter ought to run, but no longer exists, return an empty text.
+    // The text stays empty until the text format has been re-configured.
+    else {
+      watchdog('filter', 'Missing filter %name in text format %format.', array('%name' => $name, '%format' => $format->name), WATCHDOG_ALERT);
+      return '';
     }
   }
 
@@ -1219,3 +1292,38 @@ function _filter_html_escape_tips($filte
 /**
  * @} End of "Standard filters".
  */
+
+/**
+ * Implement hook_modules_disabled().
+ *
+ * In case a module providing a filter is disabled, the site administrator needs
+ * to manually update the text formats that have it applied. We cannot
+ * automatically disable or remove filters, because that would most likely break
+ * the intended filtering logic in a text format.
+ *
+ * @see filter_formats()
+ * @see check_markup()
+ */
+function filter_modules_disabled($modules) {
+  if (_filter_get_broken_filters(NULL, $modules)) {
+    drupal_set_message(t('At least one text format contains a filter that was provided by a module that has been disabled. All content using one of these text formats will be hidden until <a href="@text-format-url">text formats have been re-configured</a>.', array('@text-format-url' => url('admin/config/content/formats'))), 'error');
+  }
+}
+
+/**
+ * Implement hook_modules_uninstalled().
+ *
+ * In case a module providing a filter is uninstalled, the site administrator
+ * needs to manually update the text formats that have it applied. We cannot
+ * automatically disable or remove filters, because that would most likely break
+ * the intended filtering logic in a text format.
+ *
+ * @see filter_formats()
+ * @see check_markup()
+ */
+function filter_modules_uninstalled($modules) {
+  if (_filter_get_broken_filters(NULL, $modules)) {
+    drupal_set_message(t('At least one text format contains a filter that was provided by a module that has been uninstalled. All content using one of these text formats will be hidden until <a href="@text-format-url">text formats have been re-configured</a>.', array('@text-format-url' => url('admin/config/content/formats'))), 'error');
+  }
+}
+
Index: modules/filter/filter.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v
retrieving revision 1.53
diff -u -p -r1.53 filter.test
--- modules/filter/filter.test	14 Dec 2009 13:32:53 -0000	1.53
+++ modules/filter/filter.test	3 Jan 2010 16:09:50 -0000
@@ -555,6 +555,77 @@ class FilterNoFormatTestCase extends Dru
 }
 
 /**
+ * Security tests for missing/vanished text formats or filters.
+ */
+class FilterBrokenTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Vanishing filters and text formats',
+      'description' => 'Test the behavior of check_markup() when a filter or text format vanishes.',
+      'group' => 'Filter',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('php', 'filter_test');
+    $this->admin_user = $this->drupalCreateUser(array('administer modules', 'administer filters'));
+    $this->drupalLogin($this->admin_user);
+  }
+
+  /**
+   * Test that filtered content is emptied when an actively used filter module is disabled.
+   */
+  function testDisableFilterModule() {
+    // Create a new node.
+    $node = $this->drupalCreateNode(array('promote' => 1));
+    $body_raw = $node->body[LANGUAGE_NONE][0]['value'];
+    $format_id = $node->body[LANGUAGE_NONE][0]['format'];
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertText($body_raw, t('Node body is displayed.'));
+
+    // Enable the filter_test_replace filter.
+    $edit = array(
+      'filters[filter_test_replace][status]' => 1,
+    );
+    $this->drupalPost('admin/config/content/formats/' . $format_id, $edit, t('Save configuration'));
+
+    // Verify that filter_test_replace filter replaced the content.
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertNoText($body_raw, t('Node body is replaced.'));
+    $this->assertText('Filter: Testing filter', t('Testing filter output is displayed.'));
+
+    // Disable the filter_test module.
+    $edit = array(
+      'modules[Testing][filter_test][enable]' => FALSE,
+    );
+    $this->drupalPost('admin/config/modules', $edit, t('Save configuration'));
+    $this->assertText(t('The configuration options have been saved.'), t('Module list has changed.'));
+    $this->assertRaw(t('At least one text format contains a filter that was provided by a module that has been disabled. All content using one of these text formats will be hidden until <a href="@text-format-url">text formats have been re-configured</a>.', array('@text-format-url' => url('admin/config/content/formats'))), t('Error message about disabled filter module displayed.'));
+
+    // Verify that the content is now empty, because the text format contains
+    // a filter that no longer exists.
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertNoText($body_raw, t('Node body is not displayed.'));
+    $this->assertNoText('Filter: Testing filter', t('Testing filter output is not displayed.'));
+
+    // Ensure we get an error message on the text format overview page.
+    $this->drupalGet('admin/config/content/formats');
+    $this->assertText(t('The highlighted text format needs to be re-configured, because it is using filters that no longer exist.'), t('Error message about broken text formats displayed.'));
+
+    // Update text format.
+    $this->drupalPost('admin/config/content/formats/' . $format_id, array(), t('Save configuration'));
+
+    // Verify no error message.
+    $this->drupalGet('admin/config/content/formats');
+    $this->assertNoText(t('The highlighted text format needs to be re-configured, because it is using filters that no longer exist.'), t('Error message about broken text formats is not displayed.'));
+
+    // Verify node content is displayed.
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertText($body_raw, t('Node body is displayed.'));
+  }
+}
+
+/**
  * Unit tests for core filters.
  */
 class FilterUnitTestCase extends DrupalUnitTestCase {
Index: modules/simpletest/tests/filter_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/filter_test.module,v
retrieving revision 1.4
diff -u -p -r1.4 filter_test.module
--- modules/simpletest/tests/filter_test.module	4 Dec 2009 16:49:47 -0000	1.4
+++ modules/simpletest/tests/filter_test.module	3 Jan 2010 16:09:50 -0000
@@ -28,6 +28,17 @@ function filter_test_filter_format_delet
 }
 
 /**
+ * Implement hook_system_info_alter().
+ */
+function filter_test_system_info_alter(&$info, $file) {
+  // Make this testing module visible on the module configuration page, so test
+  // cases can enable and disable it.
+  if ($file->name == 'filter_test') {
+    $info['hidden'] = FALSE;
+  }
+}
+
+/**
  * Implements hook_filter_info().
  */
 function filter_test_filter_info() {
@@ -36,6 +47,28 @@ function filter_test_filter_info() {
     'description' => 'Does nothing, but makes a text format uncacheable.',
     'cache' => FALSE,
   );
+  $filters['filter_test_replace'] = array(
+    'title' => 'Testing filter',
+    'description' => 'Replaces all content with filter and text format information.',
+    'process callback' => 'filter_test_replace',
+  );
   return $filters;
 }
 
+/**
+ * Process handler for filter_test_replace filter.
+ *
+ * Replaces all text with filter and text format information.
+ */
+function filter_test_replace($text, $filter, $format, $langcode, $cache, $cache_id) {
+  $text = array();
+  $text[] = 'Filter: ' . $filter->title . ' (' . $filter->name . ')';
+  $text[] = 'Format: ' . $format->name . ' (' . $format->format . ')';
+  $text[] = 'Language: ' . $langcode;
+  $text[] = 'Cache: ' . ($cache ? 'Enabled' : 'Disabled');
+  if ($cache_id) {
+    $text[] = 'Cache ID: ' . $cache_id;
+  }
+  return implode("<br />\n", $text);
+}
+
Index: modules/system/system.css
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.css,v
retrieving revision 1.70
diff -u -p -r1.70 system.css
--- modules/system/system.css	2 Jan 2010 10:39:01 -0000	1.70
+++ modules/system/system.css	3 Jan 2010 16:09:50 -0000
@@ -66,7 +66,7 @@ div.tree-child-horizontal {
 div.error {
   border: 1px solid #d77;
 }
-div.error, tr.error {
+div.error, table tr.error {
   background: #fcc;
   color: #200;
   padding: 2px;
