? sites/default/files
? sites/default/settings.php
Index: includes/file.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/file.inc,v
retrieving revision 1.177
diff -u -p -r1.177 file.inc
--- includes/file.inc	20 Jul 2009 19:02:38 -0000	1.177
+++ includes/file.inc	21 Jul 2009 02:57:14 -0000
@@ -1554,13 +1554,12 @@ function file_upload_max_size() {
  *   file_default_mimetype_mapping()
  */
 function file_get_mimetype($filename, $mapping = NULL) {
-  if (!isset($mapping)) {
-    $mapping = variable_get('mime_extension_mapping', NULL);
-    if (!isset($mapping) && drupal_function_exists('file_default_mimetype_mapping')) {
-      // The default file map, defined in file.mimetypes.inc is quite big.
-      // We only load it when necessary.
-      $mapping = file_default_mimetype_mapping();
-    }
+  if (!isset($mapping) && drupal_function_exists('file_default_mimetype_mapping')) {
+    // The default file map, defined in file.mimetypes.inc is quite big.
+    // We only load it when necessary.
+    $mapping = file_default_mimetype_mapping();
+    // Allow modules to alter the default mapping.
+    drupal_alter('file_mimetype_mapping', $mapping);
   }
 
   $extension = '';
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.499
diff -u -p -r1.499 theme.inc
--- includes/theme.inc	15 Jul 2009 17:40:17 -0000	1.499
+++ includes/theme.inc	21 Jul 2009 02:57:14 -0000
@@ -1041,6 +1041,7 @@ function theme_get_settings($key = NULL)
     'logo_path'                        =>  '',
     'default_favicon'                  =>  1,
     'favicon_path'                     =>  '',
+    'favicon_mimetype'                 =>  'image/vnd.microsoft.icon',
     'main_menu'                        =>  1,
     'secondary_menu'                   =>  1,
     'toggle_logo'                      =>  1,
@@ -1902,11 +1903,7 @@ function template_preprocess_page(&$vari
   // Add favicon.
   if (theme_get_setting('toggle_favicon')) {
     $favicon = theme_get_setting('favicon');
-    $type = file_get_mimetype($favicon);
-    // Use the genereic MIME type for favicons if no other was found.
-    if ($type == 'application/octet-stream') {
-      $type = 'image/x-icon';
-    }
+    $type = theme_get_setting('favicon_mimetype');
     drupal_add_html_head('<link rel="shortcut icon" href="' . check_url($favicon) . '" type="' . check_plain($type) . '" />');
   }
 
Index: includes/theme.maintenance.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.maintenance.inc,v
retrieving revision 1.32
diff -u -p -r1.32 theme.maintenance.inc
--- includes/theme.maintenance.inc	14 Jul 2009 10:22:17 -0000	1.32
+++ includes/theme.maintenance.inc	21 Jul 2009 02:57:14 -0000
@@ -216,11 +216,7 @@ function template_preprocess_maintenance
   // Add favicon
   if (theme_get_setting('toggle_favicon')) {
     $favicon = theme_get_setting('favicon');
-    $type = file_get_mimetype($favicon);
-    // Use the genereic MIME type for favicons if no other was found.
-    if ($type == 'application/octet-stream') {
-      $type = 'image/x-icon';
-    }
+    $type = theme_get_setting('favicon_mimetype');
     drupal_add_html_head('<link rel="shortcut icon" href="' . check_url($favicon) . '" type="' . check_plain($type) . '" />');
   }
 
Index: modules/simpletest/tests/file.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/file.test,v
retrieving revision 1.36
diff -u -p -r1.36 file.test
--- modules/simpletest/tests/file.test	20 Jul 2009 19:02:38 -0000	1.36
+++ modules/simpletest/tests/file.test	21 Jul 2009 02:57:14 -0000
@@ -575,6 +575,8 @@ class FileSaveUploadTest extends FileHoo
     $this->assertTrue($max_fid_after > $this->maxFidBefore, t('A new file was created.'));
     $file1 = file_load($max_fid_after);
     $this->assertTrue($file1, t('Loaded the file.'));
+    // MIME type of the uploaded image may be either image/jpeg or image/png.
+    $this->assertEqual(substr($file1->filemime, 0, 5), 'image', t('A MIME type was set.'));
 
     // Reset the hook counters to get rid of the 'load' we just called.
     file_test_reset();
@@ -593,6 +595,8 @@ class FileSaveUploadTest extends FileHoo
 
     $file2 = file_load($max_fid_after);
     $this->assertTrue($file2);
+    // MIME type of the uploaded image may be either image/jpeg or image/png.
+    $this->assertEqual(substr($file2->filemime, 0, 5), 'image', t('A MIME type was set.'));
 
     // Load both files using file_load_multiple().
     $files = file_load_multiple(array($file1->fid, $file2->fid));
@@ -2007,6 +2011,10 @@ class FileNameMungingTest extends FileTe
  * Tests for file_get_mimetype().
  */
 class FileMimeTypeTest extends DrupalWebTestCase {
+  function setUp() {
+    parent::setUp('file_test');
+  }
+
   public static function getInfo() {
     return array(
       'name' => 'File mimetypes',
@@ -2030,16 +2038,17 @@ class FileMimeTypeTest extends DrupalWeb
       'pcf.z' => 'application/octet-stream',
       'jar' => 'application/octet-stream',
       'some.junk' => 'application/octet-stream',
+      'foo.file_test_1' => 'madeup/file_test_1',
+      'foo.file_test_2' => 'madeup/file_test_2',
+      'foo.doc' => 'madeup/doc',
     );
 
-    // Test using default mappings (not using 'mime_extension_mapping').
-    variable_del('mime_extension_mapping');
     foreach ($test_case as $input => $expected) {
       $output = file_get_mimetype($input);
       $this->assertIdentical($output, $expected, t('Mimetype (using default mappings) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
     }
 
-    // Now test using mappings from the mime_extension_mapping variable.
+    // Now test passing in the map.
     $mapping = array(
       'mimetypes' => array(
         0 => 'application/java-archive',
@@ -2061,16 +2070,11 @@ class FileMimeTypeTest extends DrupalWeb
       'pcf.z' => 'application/octet-stream',
       'jar' => 'application/octet-stream',
       'some.junk' => 'application/octet-stream',
+      'foo.file_test_1' => 'application/octet-stream',
+      'foo.file_test_2' => 'application/octet-stream',
+      'foo.doc' => 'application/octet-stream',
     );
 
-    variable_set('mime_extension_mapping', $mapping);
-    foreach ($test_case as $input => $expected) {
-      $output = file_get_mimetype($input);
-      $this->assertIdentical($output, $expected, t('Mimetype (using mappings from variable) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
-    }
-
-    // Now test the same when passing in the map.
-    variable_del('mime_extension_mapping');
     foreach ($test_case as $input => $expected) {
       $output = file_get_mimetype($input, $mapping);
       $this->assertIdentical($output, $expected, t('Mimetype (using passed-in mappings) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
Index: modules/simpletest/tests/file_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/file_test.module,v
retrieving revision 1.10
diff -u -p -r1.10 file_test.module
--- modules/simpletest/tests/file_test.module	27 May 2009 18:34:00 -0000	1.10
+++ modules/simpletest/tests/file_test.module	21 Jul 2009 02:57:14 -0000
@@ -238,3 +238,18 @@ function file_test_file_move($file, $sou
 function file_test_file_delete($file) {
   _file_test_log_call('delete', array($file));
 }
+
+/**
+ * Implementation of hook_file_mimetype_mapping_alter().
+ */
+function file_test_file_mimetype_mapping_alter(&$mapping) {
+  // Add new mappings.
+  $mapping['mimetypes']['file_test_mimetype_1'] = 'madeup/file_test_1';
+  $mapping['mimetypes']['file_test_mimetype_2'] = 'madeup/file_test_2';
+  $mapping['mimetypes']['file_test_mimetype_3'] = 'madeup/doc';
+  $mapping['extensions']['file_test_1'] = 'file_test_mimetype_1';
+  $mapping['extensions']['file_test_2'] = 'file_test_mimetype_2';
+  $mapping['extensions']['file_test_3'] = 'file_test_mimetype_2';
+  // Override existing mapping.
+  $mapping['extensions']['doc'] = 'file_test_mimetype_3';
+}
Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.163
diff -u -p -r1.163 system.admin.inc
--- modules/system/system.admin.inc	20 Jul 2009 18:51:34 -0000	1.163
+++ modules/system/system.admin.inc	21 Jul 2009 02:57:14 -0000
@@ -507,6 +507,13 @@ function system_theme_settings(&$form_st
  */
 function system_theme_settings_submit($form, &$form_state) {
   $values = $form_state['values'];
+  if (empty($values['default_favicon']) && !empty($values['favicon_path'])) {
+    $mimetype = file_get_mimetype($values['favicon_path']);
+    // Use the default MIME type for favicons if no other was found.
+    if ($mimetype != 'application/octet-stream') {
+      $values['favicon_mimetype'] = $mimetype;
+    }
+  }
   $key = $values['var'];
 
   // Exclude unnecessary elements before saving.
Index: modules/upload/upload.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.test,v
retrieving revision 1.21
diff -u -p -r1.21 upload.test
--- modules/upload/upload.test	13 Jul 2009 21:51:42 -0000	1.21
+++ modules/upload/upload.test	21 Jul 2009 02:57:14 -0000
@@ -205,12 +205,11 @@ class UploadTestCase extends DrupalWebTe
    * @param string $filename Name of file to verify.
    */
   function checkUploadedFile($filename) {
-    global $base_url;
     $file = file_directory_path() . '/' . $filename;
     $this->drupalGet(file_create_url($file), array('external' => TRUE));
-    $this->assertResponse(array(200), 'Uploaded ' . $filename . ' is accessible.');
+    $this->assertResponse(array(200), t('Uploaded %filename is accessible.', array('%filename' => $filename)));
     $this->assertTrue(strpos($this->drupalGetHeader('Content-Type'), 'text/plain') === 0, t('MIME type is text/plain.'));
-    $this->assertEqual(file_get_contents($file), $this->drupalGetContent(), 'Uploaded contents of ' . $filename . ' verified.');
+    $this->assertEqual(file_get_contents($file), $this->drupalGetContent(), t('Uploaded contents of %filename verified.', array('%filename' => $filename)));
     // Verify file actually is readable and writeable by PHP.
     $this->assertTrue(is_readable($file), t('Uploaded file is readable.'));
     $this->assertTrue(is_writeable($file), t('Uploaded file is writeable.'));
