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 21:51:53 -0000
@@ -122,6 +122,14 @@ function filter_admin_format_form($form,
     '#default_value' => $format->name,
     '#required' => TRUE,
   );
+  $form['machine_name'] = array(
+    '#type' => 'machine_name',
+    '#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 21:52:39 -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,
@@ -88,7 +102,7 @@ function filter_schema() {
         'description' => 'Weight of text format to use when listing.',
       )
     ),
-    'primary key' => array('format'),
+    'primary key' => array('format', 'machine_name'),
     'unique keys' => array(
       'name' => array('name'),
     ),
@@ -113,6 +127,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 +468,48 @@ 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();
+    }
+  }
+  db_drop_primary_key('filter_format');
+  db_add_primary_key('filter_format', array('format', '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 21:51:53 -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/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 21:51:53 -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: 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 21:51:53 -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.
