Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.871
diff -u -p -r1.871 comment.module
--- modules/comment/comment.module	26 Apr 2010 14:26:46 -0000	1.871
+++ modules/comment/comment.module	28 Apr 2010 13:07:49 -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	28 Apr 2010 13:07:49 -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	28 Apr 2010 13:08:19 -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.1163
diff -u -p -r1.1163 user.module
--- modules/user/user.module	24 Apr 2010 14:51:49 -0000	1.1163
+++ modules/user/user.module	28 Apr 2010 13:28:06 -0000
@@ -1010,11 +1010,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' => $account->signature_format,
   );
 
   // Picture/avatar.
@@ -3111,7 +3126,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 = '';
@@ -3487,6 +3506,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
