Index: modules/field/modules/text/text.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.test,v
retrieving revision 1.27
diff -u -p -r1.27 text.test
--- modules/field/modules/text/text.test	17 Aug 2010 18:25:31 -0000	1.27
+++ modules/field/modules/text/text.test	6 Sep 2010 23:45:33 -0000
@@ -198,7 +198,10 @@ class TextFieldTestCase extends DrupalWe
     // Create a new text format that does not escape HTML, and grant the user
     // access to it.
     $this->drupalLogin($this->admin_user);
-    $edit = array('name' => $this->randomName());
+    $edit = array(
+      'name' => $this->randomName(),
+      'machine_name' => drupal_strtolower($this->randomName()),
+    );
     $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
     filter_formats_reset();
     $this->checkPermissions(array(), TRUE);
Index: modules/filter/filter.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.admin.inc,v
retrieving revision 1.64
diff -u -p -r1.64 filter.admin.inc
--- modules/filter/filter.admin.inc	17 Aug 2010 13:50:52 -0000	1.64
+++ modules/filter/filter.admin.inc	6 Sep 2010 23:41:30 -0000
@@ -96,7 +96,11 @@ function theme_filter_admin_overview($va
 function filter_admin_format_page($format = NULL) {
   if (!isset($format->name)) {
     drupal_set_title(t('Add text format'));
-    $format = (object) array('name' => '', 'format' => 0);
+    $format = (object) array(
+      'format' => 0,
+      'machine_name' => '',
+      'name' => '',
+    );
   }
   return drupal_get_form('filter_admin_format_form', $format);
 }
@@ -122,6 +126,14 @@ function filter_admin_format_form($form,
     '#default_value' => $format->name,
     '#required' => TRUE,
   );
+  $form['machine_name'] = array(
+    '#type' => 'textfield', // @todo http://drupal.org/node/902644
+    '#default_value' => $format->machine_name,
+    '#machine_name_exists' => 'filter_format_load',
+    // Since the machine name needs to relate to the text format ID, it cannot
+    // be changed after initial creation.
+    '#disabled' => !empty($format->format),
+  );
 
   // Add user role access selection.
   $form['roles'] = array(
Index: modules/filter/filter.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.install,v
retrieving revision 1.43
diff -u -p -r1.43 filter.install
--- modules/filter/filter.install	5 Sep 2010 01:05:06 -0000	1.43
+++ modules/filter/filter.install	6 Sep 2010 23:29:05 -0000
@@ -19,6 +19,13 @@ function filter_schema() {
         'default' => 0,
         'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.',
       ),
+      'format_machine_name' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => 'Foreign key: The {filter_format}.machine_name to which this filter is assigned.',
+      ),
       'module' => array(
         'type' => 'varchar',
         'length' => 64,
@@ -66,6 +73,13 @@ function filter_schema() {
         'not null' => TRUE,
         'description' => 'Primary Key: Unique ID for format.',
       ),
+      'machine_name' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => 'Primary Key: Machine name of the format.',
+      ),
       'name' => array(
         'type' => 'varchar',
         'length' => 255,
@@ -90,6 +104,7 @@ function filter_schema() {
     ),
     'primary key' => array('format'),
     'unique keys' => array(
+      'machine_name' => array('machine_name'),
       'name' => array('name'),
     ),
     'indexes' => array(
@@ -113,6 +128,7 @@ function filter_install() {
   // installation profiles to have other properties.
   $plain_text_format = array(
     'name' => 'Plain text',
+    'machine_name' => 'plain_text',
     'weight' => 10,
     'filters' => array(
       // Escape all HTML.
@@ -453,6 +469,49 @@ function filter_update_7009() {
 }
 
 /**
+ * Adds {filter_format}.machine_name and {filter}.format_machine_name.
+ */
+function filter_update_7010() {
+  if (!db_field_exists('filter_format', 'machine_name')) {
+    db_add_field('filter_format', 'machine_name', array(
+      'type' => 'varchar',
+      'length' => 255,
+      'not null' => TRUE,
+      'default' => '',
+      'description' => 'Primary Key: Machine name of the format.',
+    ));
+    // Auto-generate machine names.
+    $formats = db_query('SELECT format, name FROM {filter_format}')->fetchAllKeyed();
+    foreach ($formats as $format => $name) {
+      $machine_name = preg_replace('@[^a-z0-9]+@', '_', drupal_strtolower($name));
+      db_update('filter_format')
+        ->fields(array('machine_name' => $machine_name))
+        ->condition('format', $format)
+        ->execute();
+    }
+  }
+  if (!db_index_exists('filter_format', 'machine_name')) {
+    db_add_unique_key('filter_format', 'machine_name', array('machine_name'));
+  }
+
+  if (!db_field_exists('filter', 'format_machine_name')) {
+    db_add_field('filter', 'format_machine_name', array(
+      'type' => 'int',
+      'not null' => TRUE,
+      'default' => 0,
+      'description' => 'Foreign key: The {filter_format}.machine_name to which this filter is assigned.',
+    ));
+    $formats = db_query('SELECT format, machine_name FROM {filter_format}')->fetchAllKeyed();
+    foreach ($formats as $format => $machine_name) {
+      db_update('filter')
+        ->fields(array('format_machine_name' => $machine_name))
+        ->condition('format', $format)
+        ->execute();
+    }
+  }
+}
+
+/**
  * @} End of "defgroup updates-6.x-to-7.x"
  * The next series of updates should start at 8000.
  */
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.342
diff -u -p -r1.342 filter.module
--- modules/filter/filter.module	4 Sep 2010 17:55:43 -0000	1.342
+++ modules/filter/filter.module	6 Sep 2010 23:26:12 -0000
@@ -221,6 +221,7 @@ function filter_format_save(&$format) {
     }
 
     $fields = array();
+    $fields['format_machine_name'] = $format->machine_name;
     $fields['weight'] = $format->filters[$name]['weight'];
     $fields['status'] = $format->filters[$name]['status'];
     $fields['module'] = $format->filters[$name]['module'];
@@ -384,6 +385,10 @@ function filter_formats($account = NULL)
       ->orderBy('weight')
       ->execute()
       ->fetchAllAssoc('format');
+
+    // Allow modules to alter the list of formats; e.g., to load formats
+    // exported into code.
+    drupal_alter('filter_formats', $formats['all']);
   }
 
   // Build a list of user-specific formats.
Index: modules/filter/filter.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v
retrieving revision 1.75
diff -u -p -r1.75 filter.test
--- modules/filter/filter.test	4 Sep 2010 17:55:43 -0000	1.75
+++ modules/filter/filter.test	6 Sep 2010 23:47:45 -0000
@@ -24,6 +24,7 @@ class FilterCRUDTestCase extends DrupalW
     // Add a text format with minimum data only.
     $format = new stdClass();
     $format->name = 'Empty format';
+    $format->machine_name = 'empty_format';
     filter_format_save($format);
     $this->verifyTextFormat($format);
     $this->verifyFilters($format);
@@ -31,6 +32,7 @@ class FilterCRUDTestCase extends DrupalW
     // Add another text format specifying all possible properties.
     $format = new stdClass();
     $format->name = 'Custom format';
+    $format->machine_name = 'custom_format';
     $format->filters = array(
       'filter_url' => array(
         'status' => 1,
@@ -79,6 +81,7 @@ class FilterCRUDTestCase extends DrupalW
       ->execute()
       ->fetchObject();
     $this->assertEqual($db_format->format, $format->format, t('Database: Proper format id for text format %format.', $t_args));
+    $this->assertEqual($db_format->machine_name, $format->machine_name, t('Database: Proper machine name for text format %format.', $t_args));
     $this->assertEqual($db_format->name, $format->name, t('Database: Proper title for text format %format.', $t_args));
     $this->assertEqual($db_format->cache, $format->cache, t('Database: Proper cache indicator for text format %format.', $t_args));
     $this->assertEqual($db_format->weight, $format->weight, t('Database: Proper weight for text format %format.', $t_args));
@@ -86,6 +89,7 @@ class FilterCRUDTestCase extends DrupalW
     // Verify filter_format_load().
     $filter_format = filter_format_load($format->format);
     $this->assertEqual($filter_format->format, $format->format, t('filter_format_load: Proper format id for text format %format.', $t_args));
+    $this->assertEqual($filter_format->machine_name, $format->machine_name, t('filter_format_load: Proper machine name for text format %format.', $t_args));
     $this->assertEqual($filter_format->name, $format->name, t('filter_format_load: Proper title for text format %format.', $t_args));
     $this->assertEqual($filter_format->cache, $format->cache, t('filter_format_load: Proper cache indicator for text format %format.', $t_args));
     $this->assertEqual($filter_format->weight, $format->weight, t('filter_format_load: Proper weight for text format %format.', $t_args));
@@ -121,7 +125,8 @@ class FilterCRUDTestCase extends DrupalW
       // Verify that filter settings were properly stored.
       $this->assertEqual(unserialize($filter->settings), isset($format_filters[$name]['settings']) ? $format_filters[$name]['settings'] : array(), t('Database: Proper filter settings for %filter in text format %format.', $t_args));
 
-      // Verify that each filter has a module name assigned.
+      // Verify that each filter has a machine and module name assigned.
+      $this->assertEqual($filter->format_machine_name, $format->machine_name, t('Database: Proper machine name for %filter in text format %format.', $t_args));
       $this->assertTrue(!empty($filter->module), t('Database: Proper module name for %filter in text format %format.', $t_args));
 
       // Remove the filter from the copy of saved $format to check whether all
@@ -143,7 +148,8 @@ class FilterCRUDTestCase extends DrupalW
       // Verify that filter settings were properly stored.
       $this->assertEqual($filter->settings, isset($format_filters[$name]['settings']) ? $format_filters[$name]['settings'] : array(), t('filter_list_format: Proper filter settings for %filter in text format %format.', $t_args));
 
-      // Verify that each filter has a module name assigned.
+      // Verify that each filter has a machine and module name assigned.
+      $this->assertEqual($filter->format_machine_name, $format->machine_name, t('filter_list_format: Proper machine name for %filter in text format %format.', $t_args));
       $this->assertTrue(!empty($filter->module), t('filter_list_format: Proper module name for %filter in text format %format.', $t_args));
 
       // Remove the filter from the copy of saved $format to check whether all
@@ -270,6 +276,7 @@ class FilterAdminTestCase extends Drupal
     // Add format.
     $edit = array();
     $edit['name'] = $this->randomName();
+    $edit['machine_name'] = drupal_strtolower($this->randomName());
     $edit['roles[2]'] = 1;
     $edit['filters[' . $second_filter . '][status]'] = TRUE;
     $edit['filters[' . $first_filter . '][status]'] = TRUE;
@@ -424,7 +431,10 @@ class FilterFormatAccessTestCase extends
     $this->drupalLogin($this->admin_user);
     $formats = array();
     for ($i = 0; $i < 2; $i++) {
-      $edit = array('name' => $this->randomName());
+      $edit = array(
+        'name' => $this->randomName(),
+        'machine_name' => drupal_strtolower($this->randomName()),
+      );
       $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
       $this->resetFilterCaches();
       $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
@@ -577,7 +587,10 @@ class FilterDefaultFormatTestCase extend
     $this->drupalLogin($admin_user);
     $formats = array();
     for ($i = 0; $i < 2; $i++) {
-      $edit = array('name' => $this->randomName());
+      $edit = array(
+        'name' => $this->randomName(),
+        'machine_name' => drupal_strtolower($this->randomName()),
+      );
       $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
       $this->resetFilterCaches();
       $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
@@ -1606,6 +1619,7 @@ class FilterHooksTestCase extends Drupal
     $name = $this->randomName();
     $edit = array();
     $edit['name'] = $name;
+    $edit['machine_name'] = drupal_strtolower($this->randomName());
     $edit['roles[1]'] = 1;
     $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
     $this->assertRaw(t('Added text format %format.', array('%format' => $name)), t('New format created.'));
Index: modules/php/php.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/php/php.install,v
retrieving revision 1.17
diff -u -p -r1.17 php.install
--- modules/php/php.install	9 Jan 2010 23:03:21 -0000	1.17
+++ modules/php/php.install	6 Sep 2010 23:26:12 -0000
@@ -18,6 +18,7 @@ function php_enable() {
   if (!$format_exists) {
     $php_format = array(
       'name' => 'PHP code',
+      'machine_name' => 'php_code',
       // 'Plain text' format is installed with a weight of 10 by default. Use a
       // higher weight here to ensure that this format will not be the default
       // format for anyone.
Index: modules/search/search.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.test,v
retrieving revision 1.74
diff -u -p -r1.74 search.test
--- modules/search/search.test	4 Sep 2010 13:33:53 -0000	1.74
+++ modules/search/search.test	6 Sep 2010 23:44:04 -0000
@@ -696,9 +696,9 @@ class SearchCommentTestCase extends Drup
     // Enable check_plain() for 'Filtered HTML' text format.
     $filtered_html_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchField();
     $edit = array(
-      'filters[filter_html_escape][status]' => $filtered_html_format_id,
+      'filters[filter_html_escape][status]' => TRUE,
     );
-    $this->drupalPost('admin/config/content/formats/1', $edit, t('Save configuration'));
+    $this->drupalPost('admin/config/content/formats/' . $filtered_html_format_id, $edit, t('Save configuration'));
     // Allow anonymous users to search content.
     $edit = array(
       DRUPAL_ANONYMOUS_RID . '[search content]' => 1,
Index: profiles/standard/standard.install
===================================================================
RCS file: /cvs/drupal/drupal/profiles/standard/standard.install,v
retrieving revision 1.22
diff -u -p -r1.22 standard.install
--- profiles/standard/standard.install	9 Aug 2010 19:55:57 -0000	1.22
+++ profiles/standard/standard.install	6 Sep 2010 23:26:12 -0000
@@ -10,6 +10,7 @@ function standard_install() {
   // Add text formats.
   $filtered_html_format = array(
     'name' => 'Filtered HTML',
+    'machine_name' => 'filtered_html',
     'weight' => 0,
     'filters' => array(
       // URL filter.
@@ -39,6 +40,7 @@ function standard_install() {
 
   $full_html_format = array(
     'name' => 'Full HTML',
+    'machine_name' => 'full_html',
     'weight' => 1,
     'filters' => array(
       // URL filter.
