diff -N -u filefield.inc filefield.inc
--- filefield.inc	1970-01-01 01:00:00.000000000 +0100
+++ filefield.inc	2007-04-10 19:05:06.000000000 +0200
@@ -0,0 +1,129 @@
+<?php
+// $Id$
+
+/**
+ * insert a file into the database.
+ * @param $node
+ *    node object file will be associated with.
+ * @param $file
+ *    file to be inserted, passed by reference since fid should be attached.
+ *
+ */
+function filefield_file_insert($node, $field, &$file) {
+  $fieldname = $field['field_name'];
+
+  // allow tokenized paths.
+  if (function_exists('token_replace')) {
+    global $user;
+    $widget_file_path = token_replace($field['widget']['file_path'], 'user', $user);
+  }
+  else {
+    $widget_file_path = $field['widget']['file_path'];
+  }
+
+  $filepath = file_create_path($widget_file_path) .'/'. $file['filename'];
+
+  if (filefield_check_directory($widget_file_path) && $file = file_save_upload((object)$file, $filepath)) {
+    $file = (array)$file;
+    $file['fid'] = db_next_id('{files}_fid');
+    db_query('INSERT into {files} (fid, nid, filename, filepath, filemime, filesize)
+             VALUES (%d, %d, "%s","%s","%s",%d)',
+            $file['fid'], $node->nid, $file['filename'], $file['filepath'],
+            $file['filemime'], $file['filesize']);
+    db_query('INSERT into {file_revisions} (fid, vid, description, list)
+             VALUES (%d, %d, "%s", %d)',
+             $file['fid'], $node->vid, $file['filename'], 0);
+    module_invoke_all('filefield', 'file_save', $node, $field, $file);
+    return (array)$file;
+  }
+  else {
+    // Include file name in upload error.
+    form_set_error(NULL, t('File upload was unsuccessful.'));
+    return FALSE;
+  }
+}
+
+/**
+ * update the file record if necessary
+ * @param $node
+ * @param $file
+ * @param $field
+ */
+function filefield_file_update($node, $field, &$file) {
+  $file = (array)$file;
+  if ($file['remove'] == TRUE) {
+     module_invoke_all('filefield', 'file_delete', $node, $field, $file);
+     filefield_file_delete($node, $field, $file);
+     // should I return an array here instead as imagefield does, or is that a bug in 
+     // in imagefield. I remember I was working on a content.module patch that would
+     // delete multivalue fields whose value was NULL. Maybe a leftover.
+     return NULL;
+  }
+  if ($file['fid'] == 'upload') {
+    return filefield_file_insert($node, $field, $file);
+  }
+  else {
+    // if fid is not numeric here we should complain.
+    // else we update the file table.
+  }
+  return $file;
+}
+
+function filefield_file_delete($node, $field, $file) {
+  if (is_numeric($file['fid'])) {
+    db_query('DELETE FROM {files} WHERE fid = %d', $file['fid']);
+    db_query('DELETE FROM {file_revisions} WHERE fid = %d', $file['fid']);
+  }
+  else {
+    unset($_SESSION['filefield'][$field['field_name']][$file['sessionid']]);
+  }
+  module_invoke_all('filefield', 'delete', $node, $field, $file);
+  return file_delete($file['filepath']);
+}
+
+function filefield_file_load($fid = NULL) {
+  if (isset($fid)) {
+    if (is_numeric($fid)) {
+      $result = db_query('SELECT * FROM {files} WHERE fid = %d', $fid);
+      $file = db_fetch_array($result);
+      if ($file) {
+        // let modules load extended attributes.
+        $file += module_invoke_all('filefield', 'file_load', $node, $field, $file);
+        return $file;
+      }
+    }
+  }
+  // return an empty array if nothing was found.
+  return array();
+}
+
+if (!function_exists('upload_file_download')) {
+  function filefield_file_download($file) {
+    $file = file_create_path($file);
+    $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $file);
+    if ($file = db_fetch_object($result)) {
+      if (user_access('view uploaded files')) {
+        $node = node_load($file->nid);
+        if (node_access('view', $node)) {
+          $name = mime_header_encode($file->filename);
+          $type = mime_header_encode($file->filemime);
+          // Serve images and text inline for the browser to display rather than download.
+          $disposition = ereg('^(text/|image/)', $file->filemime) ? 'inline' : 'attachment';
+          return array(
+            'Content-Type: '. $type .'; name='. $name,
+            'Content-Length: '. $file->filesize,
+            'Content-Disposition: '. $disposition .'; filename='. $name,
+            'Cache-Control: private',
+          );
+        }
+        else {
+          return -1;
+        }
+      }
+      else {
+        return -1;
+      }
+    }
+  }
+
+}
diff -N -u filefield.module filefield.module
--- filefield.module	2007-03-30 05:20:24.000000000 +0200
+++ filefield.module	2007-04-10 19:12:25.000000000 +0200
@@ -8,6 +8,7 @@
  * uses content.module to store the fid, and the drupal files 
  * table to store the actual file data.
  */
+include_once(drupal_get_path('module', 'filefield') .'/filefield.inc');
 
 
 function filefield_menu($maycache) {
@@ -83,70 +84,6 @@
   }
 }
 
-/**
- * insert a file into the database.
- * @param $node
- *    node object file will be associated with.
- * @param $file
- *    file to be inserted, passed by reference since fid should be attached.
- *    
- */
-function filefield_file_insert($node, $field, &$file) {
-  $fieldname = $field['field_name'];
-  
-  // allow tokenized paths.
-  if (function_exists('token_replace')) {
-    global $user;
-    $widget_file_path = token_replace($field['widget']['file_path'], 'user', $user);
-  }
-  else {
-    $widget_file_path = $field['widget']['file_path'];
-  }
- 
-  $filepath = file_create_path($widget_file_path) . '/' . $file['filename'];
-  
-  if (filefield_check_directory($widget_file_path) && $file = file_save_upload((object)$file, $filepath)) {
-    $file = (array)$file;
-    $file['fid'] = db_next_id('{files}_fid');
-    db_query('INSERT into {files} (fid, nid, filename, filepath, filemime, filesize)  
-             VALUES (%d, %d, "%s","%s","%s",%d)',
-            $file['fid'], $node->nid, $file['filename'], $file['filepath'], $file['filemime'], $file['filesize']);
-    module_invoke_all('filefield', 'file_save', $node, $field, $file);
-    return (array)$file;
-  }
-  else {
-    // Include file name in upload error.
-    form_set_error(NULL, t('file upload was unsuccessful.'));
-    return FALSE;
-  }
-}
-
-
-/**
- * update the file record if necessary
- * @param $node
- * @param $file
- * @param $field
- */
-function filefield_file_update($node, $field, &$file) {
-  $file = (array)$file; 
-  if ($file['remove'] == TRUE) {
-     module_invoke_all('filefield', 'file_delete', $node, $field, $file);
-     _filefield_file_delete($node, $field, $file);
-     // should I return an array here instead as imagefield does, or is that a bug in 
-     // in imagefield. I remember I was working on a content.module patch that would
-     // delete multivalue fields whose value was NULL. Maybe a leftover.
-     return NULL;
-  }
-  if ($file['fid'] == 'upload') {  
-    return filefield_file_insert($node, $field, $file);
-  }
-  else {
-    // if fid is not numeric here we should complain.
-    // else we update the file table.  
-  }
-  return $file;
-}
 
 /**
  * Implementation of hook_field().
@@ -160,7 +97,7 @@
         $values = array();
         foreach ($node_field as $delta => $file) {
           if (!empty($file)) {
-            $node_field[$delta] += _filefield_file_load($file['fid']);
+            $node_field[$delta] += filefield_file_load($file['fid']);
           }
           $output = array($fieldname => $node_field);
         }
@@ -183,7 +120,7 @@
 
     case 'delete':
       foreach ($node_field as $delta => $item) {
-        _filefield_file_delete($node, $field, $item); 
+        filefield_file_delete($node, $field, $item); 
       }
       break;
   }
@@ -258,17 +195,6 @@
   }
 }
 
-function _filefield_file_delete($node, $field, $file) {
-  if (is_numeric($file['fid'])) {
-    db_query('DELETE FROM {files} WHERE fid = %d', $file['fid']);
-  }
-  else {
-    unset($_SESSION['filefield'][$field['field_name']][$file['sessionid']]);
-  }
-  module_invoke_all('filefield', 'delete', $node, $field, $file);
-  return file_delete($file['filepath']);
-}
-
 /**
  * Implementation of hook_widget().
  */
@@ -496,26 +422,10 @@
   if(!isset($item['fid'])) {
     return '';
   }
-  $file = _filefield_file_load($item['fid']);
+  $file = filefield_file_load($item['fid']);
   return theme('filefield', $file, $item);
 }
 
-function _filefield_file_load($fid = NULL) {
-  if (isset($fid)) { 
-    if (is_numeric($fid)) {
-      $result = db_query('SELECT * FROM {files} WHERE fid = %d', $fid);
-      $file = db_fetch_array($result);
-      if ($file) {
-        // let modules load extended attributes.
-        $file += module_invoke_all('filefield', 'file_load', $node, $field, $file);
-        return $file;
-      }
-    }
-  }
-  // return an empty array if nothing was found.
-  return array();
-}
-
 function theme_filefield_icon($file) {
   $ext = array_pop(explode('.',$file['filename']));
   $known_extensions = array('0','ace','aif','ai','ani','asf','asp','avi','bak','bat','bin','bmp','bz2','bz','cab','cdr','cfg','com','conf','cpt','css','cur','dat','db','dcr','dic','diff','dir','dll','dmg','doc','dwg','edir','eml','eps','exe','fla','flv','fon','gif','gz','hqx','html','htm','ico','inc','ini','iso','jpeg','jpg','js','lnk','log','m3u','mdb','midi','mid','mov','mp3','mpeg','mpg','nfo','odb','odc','odf','odg','odm','odp','ods','odt','ogg','otg','oth','otp','ots','ott','patch','pdf','php3','php','phtml','pl','png','pps','ppt','psd','pwl','qt','ram','ra','rar','reg','rpm','rtf','sh','shtml','sit','sql','svg','swf','sxc','sxi','sxw','sys','tar','tgz','tiff','tif','tmp','tpl','ttf','txt','wav','wma','wmv','wp','xls','xml','zip');
@@ -548,37 +458,6 @@
   }
 }
 
-if (!function_exists('upload_file_download')) {
-  function filefield_file_download($file) {
-    $file = file_create_path($file);
-    $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $file);
-    if ($file = db_fetch_object($result)) {
-      if (user_access('view uploaded files')) {
-        $node = node_load($file->nid);
-        if (node_access('view', $node)) {
-          $name = mime_header_encode($file->filename);
-          $type = mime_header_encode($file->filemime);
-          // Serve images and text inline for the browser to display rather than download.
-          $disposition = ereg('^(text/|image/)', $file->filemime) ? 'inline' : 'attachment';
-          return array(
-            'Content-Type: '. $type .'; name='. $name,
-            'Content-Length: '. $file->filesize,
-            'Content-Disposition: '. $disposition .'; filename='. $name,
-            'Cache-Control: private'
-          );
-        }
-        else {
-          return -1; 
-        }
-      }   
-      else {
-        return -1; 
-      }   
-    }   
-  }
-
-}
-
 /**
  * Wrapper function for filefield_check_directory that accepts a form element
  * to validate - if user specified one. Won't allow form submit unless the
