Index: modules/block/block.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.install,v
retrieving revision 1.46
diff -u -p -r1.46 block.install
--- modules/block/block.install	28 Sep 2010 03:30:37 -0000	1.46
+++ modules/block/block.install	8 Oct 2010 23:20:31 -0000
@@ -155,8 +155,8 @@ function block_schema() {
         'description' => 'Block description.',
       ),
       'format' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
+        'type' => 'varchar',
+        'length' => 255,
         'not null' => FALSE,
         'description' => 'The {filter_format}.format of the block body.',
       ),
Index: modules/field/modules/text/text.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.install,v
retrieving revision 1.2
diff -u -p -r1.2 text.install
--- modules/field/modules/text/text.install	29 Sep 2010 01:37:02 -0000	1.2
+++ modules/field/modules/text/text.install	8 Oct 2010 23:20:31 -0000
@@ -48,8 +48,8 @@ function text_field_schema($field) {
   }
   $columns += array(
     'format' => array(
-      'type' => 'int',
-      'unsigned' => TRUE,
+      'type' => 'varchar',
+      'length' => 255,
       'not null' => FALSE,
     ),
   );
Index: modules/field/modules/text/text.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.test,v
retrieving revision 1.29
diff -u -p -r1.29 text.test
--- modules/field/modules/text/text.test	24 Sep 2010 00:37:42 -0000	1.29
+++ modules/field/modules/text/text.test	8 Oct 2010 23:20:31 -0000
@@ -198,12 +198,16 @@ 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(
+      'format' => drupal_strtolower($this->randomName()),
+      'name' => $this->randomName(),
+    );
     $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
     filter_formats_reset();
     $this->checkPermissions(array(), TRUE);
-    $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
-    $permission = filter_permission_name(filter_format_load($format_id));
+    $format = filter_format_load($edit['format']);
+    $format_id = $format->format;
+    $permission = filter_permission_name($format);
     $rid = max(array_keys($this->web_user->roles));
     user_role_grant_permissions($rid, array($permission));
     $this->drupalLogin($this->web_user);
@@ -360,8 +364,8 @@ class TextSummaryTestCase extends Drupal
     // Test text_summary() for different sizes.
     for ($i = 0; $i <= 37; $i++) {
       $this->callTextSummary($text, $expected[$i],    NULL, $i);
-      $this->callTextSummary($text, $expected_lb[$i], 1,    $i);
-      $this->callTextSummary($text, $expected_lb[$i], 2,    $i);
+      $this->callTextSummary($text, $expected_lb[$i], 'plain_text', $i);
+      $this->callTextSummary($text, $expected_lb[$i], 'filtered_html', $i);
     }
   }
 
@@ -386,8 +390,15 @@ class TextTranslationTestCase extends Dr
   function setUp() {
     parent::setUp('locale', 'translation');
 
-    $this->format = 3;
-    $this->admin = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages', 'bypass node access', "use text format $this->format"));
+    $full_html_format = filter_format_load('full_html');
+    $this->format = $full_html_format->format;
+    $this->admin = $this->drupalCreateUser(array(
+      'administer languages',
+      'administer content types',
+      'access administration pages',
+      'bypass node access',
+      filter_permission_name($full_html_format),
+    ));
     $this->translator = $this->drupalCreateUser(array('create article content', 'edit own article content', 'translate content'));
 
     // Enable an additional language.
@@ -456,11 +467,11 @@ class TextTranslationTestCase extends Dr
 
     // Populate the body field: the first item gets the "Full HTML" input
     // format, the second one "Filtered HTML".
-    $format = $this->format;
+    $formats = array('full_html', 'filtered_html');
     foreach ($body as $delta => $value) {
       $edit = array(
         "body[$langcode][$delta][value]" => $value,
-        "body[$langcode][$delta][format]" => $format--,
+        "body[$langcode][$delta][format]" => array_shift($formats),
       );
       $this->drupalPost('node/1/edit', $edit, t('Save'));
       $this->assertText($body[$delta], t('The body field with delta @delta has been saved.', array('@delta' => $delta)));
Index: modules/filter/filter.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.admin.inc,v
retrieving revision 1.66
diff -u -p -r1.66 filter.admin.inc
--- modules/filter/filter.admin.inc	29 Sep 2010 19:52:12 -0000	1.66
+++ modules/filter/filter.admin.inc	8 Oct 2010 23:43:13 -0000
@@ -96,7 +96,10 @@ 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' => NULL,
+      'name' => '',
+    );
   }
   return drupal_get_form('filter_admin_format_form', $format);
 }
@@ -122,6 +125,16 @@ function filter_admin_format_form($form,
     '#default_value' => $format->name,
     '#required' => TRUE,
   );
+  $form['format'] = array(
+    '#type' => 'textfield', // @todo http://drupal.org/node/902644
+    '#required' => TRUE,
+    '#default_value' => $format->format,
+    '#maxlength' => 255,
+    '#machine_name' => array(
+      'exists' => 'filter_format_load',
+    ),
+    '#disabled' => !empty($format->format),
+  );
 
   // Add user role access selection.
   $form['roles'] = array(
@@ -227,9 +240,6 @@ function filter_admin_format_form($form,
     }
   }
 
-  if (!empty($format->format)) {
-    $form['format'] = array('#type' => 'value', '#value' => $format->format);
-  }
   $form['actions'] = array('#type' => 'actions');
   $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
 
@@ -268,20 +278,6 @@ function theme_filter_admin_format_filte
 }
 
 /**
- * Validate text format form submissions.
- */
-function filter_admin_format_form_validate($form, &$form_state) {
-  if (!isset($form_state['values']['format'])) {
-    $format_name = trim($form_state['values']['name']);
-    form_set_value($form['name'], $format_name, $form_state);
-    $result = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $format_name))->fetchField();
-    if ($result) {
-      form_set_error('name', t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name)));
-    }
-  }
-}
-
-/**
  * Process text format form submissions.
  */
 function filter_admin_format_form_submit($form, &$form_state) {
Index: modules/filter/filter.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.install,v
retrieving revision 1.46
diff -u -p -r1.46 filter.install
--- modules/filter/filter.install	28 Sep 2010 03:30:37 -0000	1.46
+++ modules/filter/filter.install	8 Oct 2010 23:45:14 -0000
@@ -14,9 +14,9 @@ function filter_schema() {
     'description' => 'Table that maps filters (HTML corrector) to text formats (Filtered HTML).',
     'fields' => array(
       'format' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => FALSE,
         'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.',
       ),
       'module' => array(
@@ -62,16 +62,17 @@ function filter_schema() {
     'description' => 'Stores text formats: custom groupings of filters, such as Filtered HTML.',
     'fields' => array(
       'format' => array(
-        'type' => 'serial',
+        'type' => 'varchar',
+        'length' => 255,
         'not null' => TRUE,
-        'description' => 'Primary Key: Unique ID for format.',
+        'description' => 'Primary Key: Unique machine name of the format.',
       ),
       'name' => array(
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
         'default' => '',
-        'description' => 'Name of the text format (Filtered HTML).',
+        'description' => 'Name of the format.',
         'translatable' => TRUE,
       ),
       'cache' => array(
@@ -97,9 +98,6 @@ function filter_schema() {
       ),
     ),
     'primary key' => array('format'),
-    'unique keys' => array(
-      'name' => array('name'),
-    ),
     'indexes' => array(
       'status_weight' => array('status', 'weight'),
     ),
@@ -120,6 +118,7 @@ function filter_install() {
   // plain text format with very basic formatting, but it can be modified by
   // installation profiles to have other properties.
   $plain_text_format = array(
+    'format' => 'plain_text',
     'name' => 'Plain text',
     'weight' => 10,
     'filters' => array(
@@ -470,6 +469,28 @@ function filter_update_7009() {
 }
 
 /**
+ * Change {filter_format}.format and {filter}.format into varchar.
+ */
+function filter_update_7010() {
+  // Remove the unique index for 'name'. Text formats have sufficient uniqueness
+  // through machine names.
+  db_drop_unique_key('filter_format', 'name');
+
+  db_change_field('filter_format', 'format', 'format', array(
+    'type' => 'varchar',
+    'length' => 255,
+    'not null' => TRUE,
+    'description' => 'Primary Key: Unique machine name of the format.',
+  ));
+  db_change_field('filter', 'format', 'format', array(
+    'type' => 'varchar',
+    'length' => 255,
+    'not null' => FALSE,
+    'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.',
+  ));
+}
+
+/**
  * @} 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.352
diff -u -p -r1.352 filter.module
--- modules/filter/filter.module	8 Oct 2010 05:07:53 -0000	1.352
+++ modules/filter/filter.module	9 Oct 2010 01:20:24 -0000
@@ -182,23 +182,31 @@ function filter_format_load($format_id) 
  *     - 'settings': (optional) An array of configured settings for the filter.
  *       See hook_filter_info() for details.
  */
-function filter_format_save(&$format) {
+function filter_format_save($format) {
   $format->name = trim($format->name);
   $format->cache = _filter_format_is_cacheable($format);
-  $format->status = 1;
+  if (!isset($format->status)) {
+    $format->status = 1;
+  }
+  if (!isset($format->weight)) {
+    $format->weight = 0;
+  }
+
+  // Insert or update the text format.
+  $return = db_merge('filter_format')
+    ->key(array('format' => $format->format))
+    ->fields(array(
+      'name' => $format->name,
+      'cache' => (int) $format->cache,
+      'status' => (int) $format->status,
+      'weight' => (int) $format->weight,
+    ))
+    ->execute();
+
   // Programmatic saves may not contain any filters.
   if (!isset($format->filters)) {
     $format->filters = array();
   }
-
-  // Add a new text format.
-  if (empty($format->format)) {
-    $return = drupal_write_record('filter_format', $format);
-  }
-  else {
-    $return = drupal_write_record('filter_format', $format, 'format');
-  }
-
   $filter_info = filter_get_filters();
   foreach ($filter_info as $name => $filter) {
     // Add new filters without weight to the bottom.
@@ -241,8 +249,8 @@ function filter_format_save(&$format) {
     module_invoke_all('filter_format_update', $format);
     // Explicitly indicate that the format was updated. We need to do this
     // since if the filters were updated but the format object itself was not,
-    // the call to drupal_write_record() above would not return an indication
-    // that anything had changed.
+    // the merge query above would not return an indication that anything had
+    // changed.
     $return = SAVED_UPDATED;
 
     // Clear the filter cache whenever a text format is updated.
Index: modules/filter/filter.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v
retrieving revision 1.77
diff -u -p -r1.77 filter.test
--- modules/filter/filter.test	28 Sep 2010 03:30:37 -0000	1.77
+++ modules/filter/filter.test	8 Oct 2010 23:20:31 -0000
@@ -23,6 +23,7 @@ class FilterCRUDTestCase extends DrupalW
   function testTextFormatCRUD() {
     // Add a text format with minimum data only.
     $format = new stdClass();
+    $format->format = 'empty_format';
     $format->name = 'Empty format';
     filter_format_save($format);
     $this->verifyTextFormat($format);
@@ -30,6 +31,7 @@ class FilterCRUDTestCase extends DrupalW
 
     // Add another text format specifying all possible properties.
     $format = new stdClass();
+    $format->format = 'custom_format';
     $format->name = 'Custom format';
     $format->filters = array(
       'filter_url' => array(
@@ -184,6 +186,7 @@ class FilterAdminTestCase extends Drupal
     $this->drupalGet('admin/config/content/formats');
     $this->clickLink('Add text format');
     $edit = array(
+      'format' => drupal_strtolower($this->randomName()),
       'name' => $this->randomName(),
     );
     $this->drupalPost(NULL, $edit, t('Save configuration'));
@@ -268,6 +271,7 @@ class FilterAdminTestCase extends Drupal
 
     // Add format.
     $edit = array();
+    $edit['format'] = drupal_strtolower($this->randomName());
     $edit['name'] = $this->randomName();
     $edit['roles[2]'] = 1;
     $edit['filters[' . $second_filter . '][status]'] = TRUE;
@@ -424,7 +428,10 @@ class FilterFormatAccessTestCase extends
     $this->drupalLogin($this->filter_admin_user);
     $formats = array();
     for ($i = 0; $i < 2; $i++) {
-      $edit = array('name' => $this->randomName());
+      $edit = array(
+        'format' => drupal_strtolower($this->randomName()),
+        'name' => $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();
@@ -656,7 +663,10 @@ class FilterDefaultFormatTestCase extend
     $this->drupalLogin($admin_user);
     $formats = array();
     for ($i = 0; $i < 2; $i++) {
-      $edit = array('name' => $this->randomName());
+      $edit = array(
+        'format' => drupal_strtolower($this->randomName()),
+        'name' => $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();
@@ -1684,6 +1694,7 @@ class FilterHooksTestCase extends Drupal
     // Add a text format.
     $name = $this->randomName();
     $edit = array();
+    $edit['format'] = drupal_strtolower($this->randomName());
     $edit['name'] = $name;
     $edit['roles[1]'] = 1;
     $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
Index: modules/php/php.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/php/php.install,v
retrieving revision 1.18
diff -u -p -r1.18 php.install
--- modules/php/php.install	13 Sep 2010 01:11:08 -0000	1.18
+++ modules/php/php.install	8 Oct 2010 23:20:31 -0000
@@ -17,6 +17,7 @@ function php_enable() {
   // subsequent clean installs.
   if (!$format_exists) {
     $php_format = array(
+      'format' => 'php_code',
       '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
Index: modules/search/search.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.test,v
retrieving revision 1.76
diff -u -p -r1.76 search.test
--- modules/search/search.test	5 Oct 2010 06:17:29 -0000	1.76
+++ modules/search/search.test	8 Oct 2010 23:20:31 -0000
@@ -370,7 +370,11 @@ class SearchRankingTestCase extends Drup
 
     // Create nodes for testing.
     foreach ($node_ranks as $node_rank) {
-      $settings = array('type' => 'page', 'title' => array(LANGUAGE_NONE => array(array('value' => 'Drupal rocks'))), 'body' => array(LANGUAGE_NONE => array(array('value' => "Drupal's search rocks"))));
+      $settings = array(
+        'type' => 'page',
+        'title' => 'Drupal rocks',
+        'body' => array(LANGUAGE_NONE => array(array('value' => "Drupal's search rocks"))),
+      );
       foreach (array(0, 1) as $num) {
         if ($num == 1) {
           switch ($node_rank) {
@@ -444,18 +448,18 @@ class SearchRankingTestCase extends Drup
     shuffle($shuffled_tags);
     $settings = array(
       'type' => 'page',
-      'title' => array(LANGUAGE_NONE => array(array('value' => 'Simple node'))),
+      'title' => 'Simple node',
     );
     foreach ($shuffled_tags as $tag) {
       switch ($tag) {
         case 'a':
-          $settings['body'] = array(LANGUAGE_NONE => array(array('value' => l('Drupal Rocks', 'node'), 'format' => 3)));
+          $settings['body'] = array(LANGUAGE_NONE => array(array('value' => l('Drupal Rocks', 'node'), 'format' => 'full_html')));
           break;
         case 'notag':
           $settings['body'] = array(LANGUAGE_NONE => array(array('value' => 'Drupal Rocks')));
           break;
         default:
-          $settings['body'] = array(LANGUAGE_NONE => array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 3)));
+          $settings['body'] = array(LANGUAGE_NONE => array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 'full_html')));
           break;
       }
       $nodes[$tag] = $this->drupalCreateNode($settings);
@@ -488,7 +492,7 @@ class SearchRankingTestCase extends Drup
     // Test tags with the same weight against the sorted tags.
     $unsorted_tags = array('u', 'b', 'i', 'strong', 'em');
     foreach ($unsorted_tags as $tag) {
-      $settings['body'] = array(LANGUAGE_NONE => array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 3)));
+      $settings['body'] = array(LANGUAGE_NONE => array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 'full_html')));
       $node = $this->drupalCreateNode($settings);
 
       // Update the search index.
@@ -523,7 +527,7 @@ class SearchRankingTestCase extends Drup
     // See testRankings() above - build a node that will rank high for sticky.
     $settings = array(
       'type' => 'page', 
-      'title' => array(LANGUAGE_NONE => array(array('value' => 'Drupal rocks'))), 
+      'title' => 'Drupal rocks',
       'body' => array(LANGUAGE_NONE => array(array('value' => "Drupal's search rocks"))),
       'sticky' => 1,
     );
@@ -712,9 +716,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: modules/simpletest/tests/form_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/form_test.module,v
retrieving revision 1.51
diff -u -p -r1.51 form_test.module
--- modules/simpletest/tests/form_test.module	4 Oct 2010 18:00:46 -0000	1.51
+++ modules/simpletest/tests/form_test.module	8 Oct 2010 23:20:31 -0000
@@ -999,14 +999,14 @@ function _form_test_disabled_elements($f
     '#title' => 'Text format',
     '#disabled' => TRUE,
     '#default_value' => 'Text value',
-    '#format' => 1,
+    '#format' => 'plain_text',
     '#expected_value' => array(
       'value' => 'Text value',
-      'format' => 1,
+      'format' => 'plain_text',
     ),
     '#test_hijack_value' => array(
       'value' => 'HIJACK',
-      'format' => 2,
+      'format' => 'filtered_html',
     ),
   );
 
Index: modules/taxonomy/taxonomy.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.install,v
retrieving revision 1.51
diff -u -p -r1.51 taxonomy.install
--- modules/taxonomy/taxonomy.install	6 Oct 2010 21:53:41 -0000	1.51
+++ modules/taxonomy/taxonomy.install	8 Oct 2010 23:20:31 -0000
@@ -51,8 +51,8 @@ function taxonomy_schema() {
         'translatable' => TRUE,
       ),
       'format' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
+        'type' => 'varchar',
+        'length' => 255,
         'not null' => FALSE,
         'description' => 'The {filter_format}.format of the description.',
       ),
Index: modules/user/user.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.install,v
retrieving revision 1.67
diff -u -p -r1.67 user.install
--- modules/user/user.install	5 Oct 2010 06:17:29 -0000	1.67
+++ modules/user/user.install	8 Oct 2010 23:20:31 -0000
@@ -167,8 +167,8 @@ function user_schema() {
         'description' => "User's signature.",
       ),
       'signature_format' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
+        'type' => 'varchar',
+        'length' => 255,
         'not null' => FALSE,
         'description' => 'The {filter_format}.format of the signature.',
       ),
@@ -838,6 +838,18 @@ function user_update_7014() {
 }
 
 /**
+ * Change {users}.signature_format into varchar.
+ */
+function user_update_7015() {
+  db_change_field('users', 'signature_format', 'signature_format', array(
+    'type' => 'varchar',
+    'length' => 255,
+    'not null' => FALSE,
+    'description' => 'The {filter_format}.format of the signature.',
+  ));
+}
+
+/**
  * @} End of "defgroup user-updates-6.x-to-7.x"
  * The next series of updates should start at 8000.
  */
Index: profiles/standard/standard.install
===================================================================
RCS file: /cvs/drupal/drupal/profiles/standard/standard.install,v
retrieving revision 1.26
diff -u -p -r1.26 standard.install
--- profiles/standard/standard.install	5 Oct 2010 06:17:29 -0000	1.26
+++ profiles/standard/standard.install	8 Oct 2010 23:20:31 -0000
@@ -9,6 +9,7 @@
 function standard_install() {
   // Add text formats.
   $filtered_html_format = array(
+    'format' => 'filtered_html',
     'name' => 'Filtered HTML',
     'weight' => 0,
     'filters' => array(
@@ -38,6 +39,7 @@ function standard_install() {
   filter_format_save($filtered_html_format);
 
   $full_html_format = array(
+    'format' => 'full_html',
     'name' => 'Full HTML',
     'weight' => 1,
     'filters' => array(
