Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.872
diff -u -p -r1.872 comment.module
--- modules/comment/comment.module	28 Apr 2010 16:08:51 -0000	1.872
+++ modules/comment/comment.module	29 Apr 2010 01:44:45 -0000
@@ -1607,7 +1607,7 @@ class CommentController extends DrupalDe
     $query->addField('n', 'type', 'node_type');
     $query->innerJoin('users', 'u', 'base.uid = u.uid');
     $query->addField('u', 'name', 'registered_name');
-    $query->fields('u', array('uid', 'signature', 'picture'));
+    $query->fields('u', array('uid', 'signature', 'signature_format', 'picture'));
     return $query;
   }
 
Index: modules/comment/comment.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.pages.inc,v
retrieving revision 1.38
diff -u -p -r1.38 comment.pages.inc
--- modules/comment/comment.pages.inc	13 Apr 2010 15:13:41 -0000	1.38
+++ modules/comment/comment.pages.inc	29 Apr 2010 01:44:45 -0000
@@ -48,7 +48,7 @@ function comment_reply($node, $pid = NUL
       // $pid indicates that this is a reply to a comment.
       if ($pid) {
         // Load the comment whose cid = $pid
-        $comment = db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.picture, u.data FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array(
+        $comment = db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array(
           ':cid' => $pid,
           ':status' => COMMENT_PUBLISHED,
         ))->fetchObject();
Index: modules/user/user.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.install,v
retrieving revision 1.45
diff -u -p -r1.45 user.install
--- modules/user/user.install	13 Apr 2010 15:15:07 -0000	1.45
+++ modules/user/user.install	29 Apr 2010 01:44:45 -0000
@@ -160,6 +160,13 @@ function user_schema() {
         'default' => '',
         'description' => "User's signature.",
       ),
+      'signature_format' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => 'The {filter_format}.format of the signature.',
+      ),
       'created' => array(
         'type' => 'int',
         'not null' => TRUE,
@@ -228,6 +235,9 @@ function user_schema() {
       'name' => array('name'),
     ),
     'primary key' => array('uid'),
+    'foreign keys' => array(
+      'signature_format' => array('filter_format' => 'format'),
+    ),
   );
 
   $schema['users_roles'] = array(
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.1164
diff -u -p -r1.1164 user.module
--- modules/user/user.module	28 Apr 2010 19:47:45 -0000	1.1164
+++ modules/user/user.module	29 Apr 2010 01:51:34 -0000
@@ -1020,11 +1020,26 @@ function user_account_form(&$form, &$for
     '#weight' => 1,
     '#access' => (!$register && variable_get('user_signatures', 0)),
   );
+
+  // Prevent denial of access to the user signature field, if an invalid or
+  // inaccessible text format is assigned. {users}.signature_format was
+  // introduced in Drupal 6, globally set to the site's default format, and
+  // requiring every user to update their user account manually.
+  if (isset($account->signature_format) && empty($_POST)) {
+    // If there is a format assigned, but it doesn't exist or is not accessible
+    // for the user account that is edited, unset it, so the user can select a
+    // new one.
+    if (!($format = filter_format_load($account->signature_format)) || !filter_access($format, $account)) {
+      drupal_set_message(t('Your signature needs to be updated.'), 'warning');
+      $account->signature_format = NULL;
+    }
+  }
   $form['signature_settings']['signature'] = array(
-    '#type' => 'textarea',
+    '#type' => 'text_format',
     '#title' => t('Signature'),
     '#default_value' => isset($account->signature) ? $account->signature : '',
     '#description' => t('Your signature will be publicly displayed at the end of your comments.'),
+    '#format' => isset($account->signature_format) ? $account->signature_format : NULL,
   );
 
   // Picture/avatar.
@@ -1117,6 +1132,8 @@ function user_account_form_validate($for
       if (drupal_strlen($form_state['values']['signature']) > $user_schema['fields']['signature']['length']) {
         form_set_error('signature', t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length'])));
       }
+      // Move text format value for user signature into 'signature_format'.
+      $form_state['values']['signature_format'] = $form_state['values']['format'];
     }
   }
 }
@@ -3121,7 +3138,11 @@ function user_forms() {
  */
 function user_comment_view($comment) {
   if (variable_get('user_signatures', 0) && !empty($comment->signature)) {
-    $comment->signature = check_markup($comment->signature, $comment->format, '', TRUE);
+    // @todo This alters and replaces the original object value, so a
+    //   hypothetical process of loading, viewing, and saving will hi-jack the
+    //   stored data. Consider to use $comment->signature_safe or similar here
+    //   and elsewhere.
+    $comment->signature = check_markup($comment->signature, $comment->signature_format, '', TRUE);
   }
   else {
     $comment->signature = '';
@@ -3497,6 +3518,16 @@ function user_modules_uninstalled($modul
 }
 
 /**
+ * Implements hook_filter_format_delete().
+ */
+function user_filter_format_delete($format, $fallback) {
+  db_update('users')
+    ->fields(array('signature_format' => $fallback->format))
+    ->condition('signature_format', $format->format)
+    ->execute();
+}
+
+/**
  * Helper function to rewrite the destination to avoid redirecting to login page after login.
  *
  * Third-party authentication modules may use this function to determine the
Index: modules/user/user.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.test,v
retrieving revision 1.89
diff -u -p -r1.89 user.test
--- modules/user/user.test	20 Apr 2010 09:48:06 -0000	1.89
+++ modules/user/user.test	29 Apr 2010 01:44:45 -0000
@@ -1423,6 +1423,54 @@ class UserEditTestCase extends DrupalWeb
 }
 
 /**
+ * Test case for user signatures.
+ */
+class UserSignatureTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'User signatures',
+      'description' => 'Test user signatures.',
+      'group' => 'User',
+    );
+  }
+
+  function setUp() {
+    parent::setUp();
+
+    // Enable user signatures.
+    variable_set('user_signatures', 1);
+
+    // Prefetch text formats.
+    $this->filtered_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchObject();
+    $this->plain_text_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Plain text'))->fetchObject();
+  }
+
+  /**
+   * Test user edit page.
+   */
+  function testUserSignature() {
+    // Verify that user signature field is not displayed on registration form.
+    $this->drupalGet('user/register');
+    $this->assertNoText(t('Signature'));
+
+    // Create a user and edit signature.
+    $this->web_user = $this->drupalCreateUser(array());
+    $this->drupalLogin($this->web_user);
+
+    $edit = array(
+      'signature[value]' => $this->randomName(),
+      'signature[format]' => $this->plain_text_format->format,
+    );
+    $this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save'));
+
+    // Verify that values were stored.
+    $this->assertFieldByName('signature[value]', $edit['signature[value]'], 'Submitted signature text found.');
+    $this->assertFieldByName('signature[format]', $edit['signature[format]'], 'Submitted signature format found.');
+    $this->assertNoText(t('Your signature needs to be updated.'));
+  }
+}
+
+/**
  * Test that a user, having editing their own account, can still log in.
  */
 class UserEditedOwnAccountTestCase extends DrupalWebTestCase {
