summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-08-31 05:47:34 +0000
committerDries Buytaert <dries@buytaert.net>2009-08-31 05:47:34 +0000
commit41dca3c4e0ec3d355977735f74af2e49ea0eedd7 (patch)
treebd4ac8b82e19e018b3a0c8d12f11d2541fa8488f /includes
parent26a5f0408b8db92f85af90695269cc69c67e41bf (diff)
downloadbrdo-41dca3c4e0ec3d355977735f74af2e49ea0eedd7.tar.gz
brdo-41dca3c4e0ec3d355977735f74af2e49ea0eedd7.tar.bz2
- Patch #331171 by pwolanin, mfb, drewish: allow modules to alter the MIME extension mapping rather than setting a huge variable.
Diffstat (limited to 'includes')
-rw-r--r--includes/file.inc8
-rw-r--r--includes/file.mimetypes.inc18
-rw-r--r--includes/stream_wrappers.inc11
3 files changed, 26 insertions, 11 deletions
diff --git a/includes/file.inc b/includes/file.inc
index 1ab7676a8..366bbc959 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -1684,12 +1684,12 @@ function file_upload_max_size() {
* An optional map of extensions to their mimetypes, in the form:
* - 'mimetypes': a list of mimetypes, keyed by an identifier,
* - 'extensions': the mapping itself, an associative array in which
- * the key is the extension (lowercase) and the value is the mimetype identifier.
- * If $mapping is omitted, the drupal variable mime_extension_mapping is checked
- * for a value and if that fails then file_default_mimetype_mapping() is called
+ * the key is the extension (lowercase) and the value is the mimetype
+ * identifier. If $mapping is NULL file_mimetype_mapping() is called.
*
* @return
- * The internet media type registered for the extension or application/octet-stream for unknown extensions.
+ * The internet media type registered for the extension or
+ * application/octet-stream for unknown extensions.
* @see
* file_default_mimetype_mapping()
*/
diff --git a/includes/file.mimetypes.inc b/includes/file.mimetypes.inc
index f0586f2fb..93b931e9a 100644
--- a/includes/file.mimetypes.inc
+++ b/includes/file.mimetypes.inc
@@ -6,6 +6,24 @@
* Provides mimetype mappings.
*/
+/**
+ * Return an array of MIME extension mappings.
+ *
+ * Returns the mapping after modules have altered the default mapping.
+ *
+ * @return
+ * Array of mimetypes correlated to the extensions that relate to them.
+ * @see file_get_mimetype()
+ */
+function file_mimetype_mapping() {
+ $mapping = &drupal_static(__FUNCTION__);
+ if (!isset($mapping)) {
+ $mapping = file_default_mimetype_mapping();
+ // Allow modules to alter the default mapping.
+ drupal_alter('file_mimetype_mapping', $mapping);
+ }
+ return $mapping;
+}
/**
* Default MIME extension mapping.
diff --git a/includes/stream_wrappers.inc b/includes/stream_wrappers.inc
index cb642d979..c58c58231 100644
--- a/includes/stream_wrappers.inc
+++ b/includes/stream_wrappers.inc
@@ -193,13 +193,10 @@ abstract class DrupalLocalStreamWrapper implements DrupalStreamWrapperInterface
*/
static function getMimeType($uri, $mapping = NULL) {
if (!isset($mapping)) {
- $mapping = variable_get('mime_extension_mapping', NULL);
- if (!isset($mapping)) {
- include_once DRUPAL_ROOT . '/includes/file.mimetypes.inc';
- // The default file map, defined in file.mimetypes.inc is quite big.
- // We only load it when necessary.
- $mapping = file_default_mimetype_mapping();
- }
+ // The default file map, defined in file.mimetypes.inc is quite big.
+ // We only load it when necessary.
+ include_once DRUPAL_ROOT . '/includes/file.mimetypes.inc';
+ $mapping = file_mimetype_mapping();
}
$extension = '';