Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.196
diff -u -r1.196 system.install
--- modules/system/system.install	26 Nov 2007 19:55:15 -0000	1.196
+++ modules/system/system.install	29 Nov 2007 07:27:18 -0000
@@ -2734,6 +2734,14 @@
   return $ret;
 }
 
+/**
+ * Add a weight column to the upload table.
+ */
+function system_update_6040() {
+  $ret = array();
+  db_add_field($ret, 'upload', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
+  return $ret;
+}
 
 /**
  * @} End of "defgroup updates-5.x-to-6.x"
Index: modules/upload/upload.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.module,v
retrieving revision 1.189
diff -u -r1.189 upload.module
--- modules/upload/upload.module	21 Nov 2007 19:13:22 -0000	1.189
+++ modules/upload/upload.module	29 Nov 2007 07:27:18 -0000
@@ -186,6 +186,7 @@
   if (($user->uid != 1 || user_access('upload files')) && ($file = file_save_upload('upload', $validators, file_directory_path()))) {
     $file->list = variable_get('upload_list_default', 1);
     $file->description = $file->filename;
+    $file->weight = 0;
     $_SESSION['upload_current_file'] = $file->fid;
     $_SESSION['upload_files'][$file->fid] = $file;
   }
@@ -408,12 +409,12 @@
 
     // Create a new revision, or associate a new file needed.
     if (!empty($node->old_vid) || isset($_SESSION['upload_files'][$fid])) {
-      db_query("INSERT INTO {upload} (fid, nid, vid, list, description) VALUES (%d, %d, %d, %d, '%s')", $file->fid, $node->nid, $node->vid, $file->list, $file->description);
+      db_query("INSERT INTO {upload} (fid, nid, vid, list, description, 'weight') VALUES (%d, %d, %d, %d, '%s', %d)", $file->fid, $node->nid, $node->vid, $file->list, $file->description, $file->weight);
       file_set_status($file, FILE_STATUS_PERMANENT);
     }
     // Update existing revision.
     else {
-      db_query("UPDATE {upload} SET list = %d, description = '%s' WHERE fid = %d AND vid = %d", $file->list, $file->description, $file->fid, $node->vid);
+      db_query("UPDATE {upload} SET list = %d, description = '%s', weight = %d WHERE fid = %d AND vid = %d", $file->list, $file->description, $file->weight, $file->fid, $node->vid);
       file_set_status($file, FILE_STATUS_PERMANENT);
     }
   }
@@ -479,6 +480,7 @@
       if (isset($_SESSION['upload_current_file']) && $_SESSION['upload_current_file'] == $file->fid) {
         $form['files'][$key]['list']['#value'] = variable_get('upload_list_default', 1);
       }
+      $form['files'][$key]['weight'] = array('#type' => 'weight', '#delta' => count($node->files), '#default_value' => $file->weight);
       $form['files'][$key]['filename'] = array('#type' => 'value',  '#value' => $file->filename);
       $form['files'][$key]['filepath'] = array('#type' => 'value',  '#value' => $file->filepath);
       $form['files'][$key]['filemime'] = array('#type' => 'value',  '#value' => $file->filemime);
@@ -517,17 +519,22 @@
  * Theme the attachments list.
  */
 function theme_upload_form_current(&$form) {
-  $header = array(t('Delete'), t('List'), t('Description'), t('Size'));
+  $header = array('', t('Delete'), t('List'), t('Description'), t('Weight'), t('Size'));
+  drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
 
   foreach (element_children($form) as $key) {
-    $row = array();
+    // Add class to group weight fields for drag and drop.
+    $form[$key]['weight']['#attributes']['class'] = 'upload-weight';
+
+    $row = array('');
     $row[] = drupal_render($form[$key]['remove']);
     $row[] = drupal_render($form[$key]['list']);
     $row[] = drupal_render($form[$key]['description']);
+    $row[] = drupal_render($form[$key]['weight']);
     $row[] = drupal_render($form[$key]['size']);
-    $rows[] = $row;
+    $rows[] = array('data' => $row, 'class' => 'draggable');
   }
-  $output = theme('table', $header, $rows);
+  $output = theme('table', $header, $rows, array('id' => 'upload-attachments'));
   $output .= drupal_render($form);
   return $output;
 }
@@ -545,7 +552,7 @@
   $files = array();
 
   if ($node->vid) {
-    $result = db_query('SELECT * FROM {files} f INNER JOIN {upload} r ON f.fid = r.fid WHERE r.vid = %d ORDER BY f.fid', $node->vid);
+    $result = db_query('SELECT * FROM {files} f INNER JOIN {upload} r ON f.fid = r.fid WHERE r.vid = %d ORDER BY r.weight, f.fid', $node->vid);
     while ($file = db_fetch_object($result)) {
       $files[$file->fid] = $file;
     }
Index: modules/upload/upload.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.install,v
retrieving revision 1.4
diff -u -r1.4 upload.install
--- modules/upload/upload.install	4 Nov 2007 14:33:07 -0000	1.4
+++ modules/upload/upload.install	29 Nov 2007 07:27:18 -0000
@@ -60,6 +60,13 @@
         'size' => 'tiny',
         'description' => t('Whether the file should be visibly listed on the node: yes(1) or no(0).'),
       ),
+      'weight' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'size' => 'tiny',
+        'description' => t('Weight of this upload in relation to other uploads in this node.'),
+      ),
     ),
     'primary key' => array('fid', 'vid'),
     'indexes' => array('vid' => array('vid'), 'nid' => array('nid')),
