mime: Represent lists as arrays instead of space-delimited strings
Deprecate the interfaces in MimeAnalyzer that return lists as
space-separated strings in favor of replacement methods that return
arrays.
Deprecated:
- ::getExtensionsForType( $mime ) : string|null
- ::getTypesForExtension( $ext ) : string|null
- ::guessTypesForExtension( $ext ) : string|null
Added:
- ::getExtensionsFromMimeType( $mime ) : string[]
- ::getMimeTypesFromExtension( $ext ) : string[]
- ::getExtensionFromMimeTypeOrNull( $mime ) : string|null
- ::getMimeTypeFromExtensionOrNull( $ext ) : string|null
- "From" is clearer than "For"[1] and is neatly symmetrical with "To"
(viz. ::mExtToMime and ::mMimeToExt).
- "MimeType" is less ambiguous than "Type", which in this context may
refer either to media type or MIME type.
- "{..}OrNull" is better because it helps users remember to handle a null
return value. Putting the "OrNull" at the end (getXFromYOrNull) is
better than putting it in the middle (getXOrNullFromY) because it's
harder to ignore that way, at the cost of a very slight grammatical
ambiguity.
Usage in Core will updated in a separate commit.
Lastly, this change prepares for the deprecation of mutating the public
'mExtToMime' attribute as a means of registering extensions. It will be
formally deprecated in a follow-up change.
[1]: Positive signal: https://developer.android.com/reference/android/webkit/MimeTypeMap#getMimeTypeFromExtension(java.lang.String)
Bug: T252228
Change-Id: I93bd71ec18492722f05c66e0a2945d93281c3100
This commit is contained in:
parent
afcf9361d7
commit
7e01e86e09
6 changed files with 364 additions and 296 deletions
|
|
@ -794,6 +794,10 @@ because of Phabricator reports.
|
|||
ResourceLoaderFileModule::compileLessString() instead
|
||||
* The SquidPurgeClient and SquidPurgeClientPool classes have been deprecated.
|
||||
Use MultiHttpClient or HtmlCacheUpdater instead.
|
||||
* MimeAnalyzer::getExtensionsForType() and ::getTypesForExtensions() were
|
||||
deprecated in favor of MimeAnalyzer::getExtensionsFromMimeType() and
|
||||
::getMimeTypesFromExtension(), respectively. The new methods return arrays
|
||||
rather than strings.
|
||||
* Calling Action::factory and Action constructor with WikiPage has been
|
||||
hard deprecated. Caller must provide an Article instance.
|
||||
* ApiTestCase::doLogin, soft deprecated in 1.31, was hard deprecated.
|
||||
|
|
|
|||
|
|
@ -49,11 +49,13 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
protected $mediaTypes = null;
|
||||
/** @var array Map of MIME type aliases */
|
||||
protected $mimeTypeAliases = null;
|
||||
/** @var array Map of MIME types to file extensions (as a space separated list) */
|
||||
protected $mimeToExt = null;
|
||||
/** @var array<string,string[]> Map of MIME types to file extensions */
|
||||
protected $mimeToExts = [];
|
||||
/** @var array<string,string[]> Map of file extensions to MIME types */
|
||||
protected $extToMimes = [];
|
||||
|
||||
/** @var array Map of file extensions types to MIME types (as a space separated list) */
|
||||
public $mExtToMime = null; // legacy name; field accessed by hooks
|
||||
public $mExtToMime = []; // legacy name; field accessed by hooks
|
||||
|
||||
/** @var IEContentAnalyzer */
|
||||
protected $IEAnalyzer;
|
||||
|
|
@ -105,9 +107,9 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
|
||||
$rawTypes = $this->extraTypes;
|
||||
if ( $this->typeFile === self::USE_INTERNAL ) {
|
||||
$this->mimeToExt = MimeMap::MIME_EXTENSIONS;
|
||||
$this->mimeToExts = MimeMap::MIME_EXTENSIONS;
|
||||
} else {
|
||||
$this->mimeToExt = MimeMapMinimal::MIME_EXTENSIONS;
|
||||
$this->mimeToExts = MimeMapMinimal::MIME_EXTENSIONS;
|
||||
if ( $this->typeFile ) {
|
||||
$rawTypes = file_get_contents( $this->typeFile ) . "\n" . $this->extraTypes;
|
||||
}
|
||||
|
|
@ -117,13 +119,17 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
}
|
||||
|
||||
// Build the reverse mapping (extension => MIME type).
|
||||
foreach ( $this->mimeToExt as $mime => $exts ) {
|
||||
foreach ( explode( ' ', $exts ) as $ext ) {
|
||||
if ( isset( $this->mExtToMime[$ext] ) ) {
|
||||
$this->mExtToMime[$ext] .= " " . $mime;
|
||||
} else {
|
||||
$this->mExtToMime[$ext] = $mime;
|
||||
}
|
||||
foreach ( $this->mimeToExts as $mime => $exts ) {
|
||||
foreach ( $exts as $ext ) {
|
||||
$this->extToMimes[$ext][] = $mime;
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate items from the legacy $this->mExtToMime field.
|
||||
// TODO: Remove this when mExtToMime is finally removed.
|
||||
foreach ( $this->mExtToMime as $ext => $mimes ) {
|
||||
foreach ( explode( ' ', $mimes ) as $mime ) {
|
||||
$this->extToMimes[$ext][] = $mime;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,10 +177,11 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
continue;
|
||||
}
|
||||
|
||||
if ( !empty( $this->mimeToExt[$mime] ) ) {
|
||||
$this->mimeToExt[$mime] .= ' ' . $ext;
|
||||
} else {
|
||||
$this->mimeToExt[$mime] = $ext;
|
||||
$tokens = preg_split( '/\s+/', $s, -1, PREG_SPLIT_NO_EMPTY );
|
||||
if ( count( $tokens ) > 1 ) {
|
||||
$mime = array_shift( $tokens );
|
||||
$this->mimeToExts[$mime] = array_values( array_unique(
|
||||
array_merge( $this->mimeToExts[$mime] ?? [], $tokens ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -265,59 +272,95 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
* separated string or null if the MIME type was unrecognized. Resolves
|
||||
* MIME type aliases.
|
||||
*
|
||||
* @deprecated since 1.35 Use getExtensionsFromMimeType() instead.
|
||||
* @param string $mime
|
||||
* @return string|null
|
||||
*/
|
||||
public function getExtensionsForType( $mime ) {
|
||||
$exts = $this->getExtensionsFromMimeType( $mime );
|
||||
return $exts ? implode( ' ', $exts ) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of file extensions associated with a given MIME type.
|
||||
* The returned array is empty if the MIME type was unrecognized. Resolves
|
||||
* MIME type aliases.
|
||||
*
|
||||
* @since 1.35
|
||||
* @param string $mime
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensionsFromMimeType( $mime ) {
|
||||
$mime = strtolower( $mime );
|
||||
|
||||
// Check the mime-to-ext map
|
||||
if ( isset( $this->mimeToExt[$mime] ) ) {
|
||||
return $this->mimeToExt[$mime];
|
||||
}
|
||||
|
||||
// Resolve the MIME type to the canonical type
|
||||
if ( isset( $this->mimeTypeAliases[$mime] ) ) {
|
||||
if ( !isset( $this->mimeToExts[$mime] ) && isset( $this->mimeTypeAliases[$mime] ) ) {
|
||||
$mime = $this->mimeTypeAliases[$mime];
|
||||
if ( isset( $this->mimeToExt[$mime] ) ) {
|
||||
return $this->mimeToExt[$mime];
|
||||
}
|
||||
}
|
||||
return $this->mimeToExts[$mime] ?? [];
|
||||
}
|
||||
|
||||
return null;
|
||||
/**
|
||||
* Returns an array of MIME types associated with a given file extension.
|
||||
* The returned array is empty if the file extension is not associated with
|
||||
* any MIME types.
|
||||
*
|
||||
* @since 1.35
|
||||
* @param string $ext
|
||||
* @return array
|
||||
*/
|
||||
public function getMimeTypesFromExtension( $ext ) {
|
||||
$ext = strtolower( $ext );
|
||||
return $this->extToMimes[$ext] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single MIME type for a given file extension or null if unknown.
|
||||
* This is always the first type from the list returned by getMimeTypesFromExtension($ext).
|
||||
*
|
||||
* @since 1.35
|
||||
* @param string $ext
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMimeTypeFromExtensionOrNull( $ext ) {
|
||||
$types = $this->getMimeTypesFromExtension( $ext );
|
||||
return $types[0] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single file extension for a given MIME type or null if unknown.
|
||||
* This is always the first type from the list returned by getExtensionsFromMimeType($mime).
|
||||
*
|
||||
* @deprecated since 1.35 Use getMimeTypeFromExtensionOrNull() instead.
|
||||
* @param string $ext
|
||||
* @return string|null
|
||||
*/
|
||||
public function guessTypesForExtension( $ext ) {
|
||||
return $this->getMimeTypeFromExtensionOrNull( $ext );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of MIME types for a given file extension as a space
|
||||
* separated string or null if the extension was unrecognized.
|
||||
*
|
||||
* @deprecated since 1.35 Use getMimeTypesFromExtension() instead.
|
||||
* @param string $ext
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTypesForExtension( $ext ) {
|
||||
$ext = strtolower( $ext );
|
||||
|
||||
return $this->mExtToMime[$ext] ?? null;
|
||||
$types = $this->getMimeTypesFromExtension( $ext );
|
||||
return $types ? implode( ' ', $types ) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single MIME type for a given file extension or null if unknown.
|
||||
* This is always the first type from the list returned by getTypesForExtension($ext).
|
||||
* Returns a single file extension for a given MIME type or null if unknown.
|
||||
* This is always the first type from the list returned by getExtensionsFromMimeType($mime).
|
||||
*
|
||||
* @param string $ext
|
||||
* @since 1.35
|
||||
* @param string $mime
|
||||
* @return string|null
|
||||
*/
|
||||
public function guessTypesForExtension( $ext ) {
|
||||
$m = $this->getTypesForExtension( $ext );
|
||||
if ( $m === null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: Check if this is needed; strtok( $m, ' ' ) should be sufficient
|
||||
$m = trim( $m );
|
||||
$m = preg_replace( '/\s.*$/', '', $m );
|
||||
|
||||
return $m;
|
||||
public function getExtensionFromMimeTypeOrNull( $mime ) {
|
||||
$exts = $this->getExtensionsFromMimeType( $mime );
|
||||
return $exts[0] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -330,16 +373,13 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
* @return bool|null
|
||||
*/
|
||||
public function isMatchingExtension( $extension, $mime ) {
|
||||
$ext = $this->getExtensionsForType( $mime );
|
||||
$exts = $this->getExtensionsFromMimeType( $mime );
|
||||
|
||||
if ( !$ext ) {
|
||||
if ( !$exts ) {
|
||||
return null; // Unknown MIME type
|
||||
}
|
||||
|
||||
$ext = explode( ' ', $ext );
|
||||
|
||||
$extension = strtolower( $extension );
|
||||
return in_array( $extension, $ext );
|
||||
return in_array( strtolower( $extension ), $exts );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -421,13 +461,13 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
} else {
|
||||
// Not something we can detect, so simply
|
||||
// trust the file extension
|
||||
$mime = $this->guessTypesForExtension( $ext );
|
||||
$mime = $this->getMimeTypeFromExtensionOrNull( $ext );
|
||||
}
|
||||
} elseif ( $mime === 'application/x-opc+zip' ) {
|
||||
if ( $this->isMatchingExtension( $ext, $mime ) ) {
|
||||
// A known file extension for an OPC file,
|
||||
// find the proper MIME type for that file extension
|
||||
$mime = $this->guessTypesForExtension( $ext );
|
||||
$mime = $this->getMimeTypeFromExtensionOrNull( $ext );
|
||||
} else {
|
||||
$this->logger->info( __METHOD__ .
|
||||
": refusing to guess better type for $mime file, " .
|
||||
|
|
@ -439,7 +479,7 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
// If detected as text/plain, and has an extension which is textual
|
||||
// improve to the extension's type. For example, csv and json are often
|
||||
// misdetected as text/plain.
|
||||
$mime = $this->guessTypesForExtension( $ext );
|
||||
$mime = $this->getMimeTypeFromExtensionOrNull( $ext );
|
||||
}
|
||||
|
||||
# Media handling extensions can improve the MIME detected
|
||||
|
|
@ -799,7 +839,7 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
/* A known file extension for an OPC file,
|
||||
* find the proper mime type for that file extension
|
||||
*/
|
||||
$mime = $this->guessTypesForExtension( $ext );
|
||||
$mime = $this->getMimeTypeFromExtensionOrNull( $ext );
|
||||
} else {
|
||||
$mime = "application/zip";
|
||||
}
|
||||
|
|
@ -866,7 +906,7 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
* Internal MIME type detection. Detection is done using the fileinfo
|
||||
* extension if it is available. It can be overriden by callback, which could
|
||||
* use an external program, for example. If detection fails and $ext is not false,
|
||||
* the MIME type is guessed from the file extension, using guessTypesForExtension.
|
||||
* the MIME type is guessed from the file extension, using getMimeTypeFromExtensionOrNull.
|
||||
*
|
||||
* If the MIME type is still unknown, getimagesize is used to detect the
|
||||
* MIME type if the file is an image. If no MIME type can be determined,
|
||||
|
|
@ -919,7 +959,7 @@ class MimeAnalyzer implements LoggerAwareInterface {
|
|||
$this->logger->info( __METHOD__ . ": refusing to guess mime type for .$ext file, "
|
||||
. "we should have recognized it\n" );
|
||||
} else {
|
||||
$m = $this->guessTypesForExtension( $ext );
|
||||
$m = $this->getMimeTypeFromExtensionOrNull( $ext );
|
||||
if ( $m ) {
|
||||
$this->logger->info( __METHOD__ . ": extension mime type of $file: $m\n" );
|
||||
return $m;
|
||||
|
|
|
|||
|
|
@ -29,201 +29,203 @@ namespace Wikimedia\Mime;
|
|||
class MimeMap {
|
||||
/** @var array Map of MIME types to a string of space-separated file extensions */
|
||||
public const MIME_EXTENSIONS = [
|
||||
'application/ogg' => 'ogx ogg ogm ogv oga spx opus',
|
||||
'application/pdf' => 'pdf',
|
||||
'application/vnd.oasis.opendocument.chart' => 'odc',
|
||||
'application/vnd.oasis.opendocument.chart-template' => 'otc',
|
||||
'application/vnd.oasis.opendocument.database' => 'odb',
|
||||
'application/vnd.oasis.opendocument.formula' => 'odf',
|
||||
'application/vnd.oasis.opendocument.formula-template' => 'otf',
|
||||
'application/vnd.oasis.opendocument.graphics' => 'odg',
|
||||
'application/vnd.oasis.opendocument.graphics-template' => 'otg',
|
||||
'application/vnd.oasis.opendocument.image' => 'odi',
|
||||
'application/vnd.oasis.opendocument.image-template' => 'oti',
|
||||
'application/vnd.oasis.opendocument.presentation' => 'odp',
|
||||
'application/vnd.oasis.opendocument.presentation-template' => 'otp',
|
||||
'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
|
||||
'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots',
|
||||
'application/vnd.oasis.opendocument.text' => 'odt',
|
||||
'application/vnd.oasis.opendocument.text-master' => 'otm odm',
|
||||
'application/vnd.oasis.opendocument.text-template' => 'ott',
|
||||
'application/vnd.oasis.opendocument.text-web' => 'oth',
|
||||
'application/javascript' => 'js',
|
||||
'application/x-shockwave-flash' => 'swf',
|
||||
'audio/midi' => 'mid midi kar',
|
||||
'audio/mpeg' => 'mpga mpa mp2 mp3',
|
||||
'audio/x-aiff' => 'aif aiff aifc',
|
||||
'audio/x-wav' => 'wav',
|
||||
'audio/ogg' => 'oga spx ogg opus',
|
||||
'audio/opus' => 'opus ogg oga spx',
|
||||
'image/x-bmp' => 'bmp',
|
||||
'image/gif' => 'gif',
|
||||
'image/jpeg' => 'jpeg jpg jpe',
|
||||
'image/png' => 'png apng',
|
||||
'image/svg+xml' => 'svg',
|
||||
'image/svg' => 'svg',
|
||||
'image/tiff' => 'tiff tif',
|
||||
'image/vnd.djvu' => 'djvu djv',
|
||||
'image/x.djvu' => 'djvu',
|
||||
'image/x-djvu' => 'djvu',
|
||||
'image/x-portable-pixmap' => 'ppm',
|
||||
'image/x-xcf' => 'xcf',
|
||||
'text/plain' => 'txt',
|
||||
'text/html' => 'html htm',
|
||||
'video/ogg' => 'ogv ogm ogg',
|
||||
'video/mpeg' => 'mpg mpeg mpe',
|
||||
'application/acad' => 'dwg',
|
||||
'application/andrew-inset' => 'ez',
|
||||
'application/mac-binhex40' => 'hqx',
|
||||
'application/mac-compactpro' => 'cpt',
|
||||
'application/mathml+xml' => 'mathml',
|
||||
'application/msword' => 'doc dot',
|
||||
'application/octet-stream' => 'bin dms lha lzh exe class so dll',
|
||||
'application/oda' => 'oda',
|
||||
'application/postscript' => 'ai eps ps',
|
||||
'application/rdf+xml' => 'rdf',
|
||||
'application/smil' => 'smi smil',
|
||||
'application/srgs' => 'gram',
|
||||
'application/srgs+xml' => 'grxml',
|
||||
'application/vnd.mif' => 'mif',
|
||||
'application/vnd.ms-excel' => 'xls xlt xla',
|
||||
'application/vnd.ms-powerpoint' => 'ppt pot pps ppa',
|
||||
'application/vnd.wap.wbxml' => 'wbxml',
|
||||
'application/vnd.wap.wmlc' => 'wmlc',
|
||||
'application/vnd.wap.wmlscriptc' => 'wmlsc',
|
||||
'application/voicexml+xml' => 'vxml',
|
||||
'application/x-7z-compressed' => '7z',
|
||||
'application/x-bcpio' => 'bcpio',
|
||||
'application/x-bzip' => 'bz',
|
||||
'application/x-bzip2' => 'bz2',
|
||||
'application/x-cdlink' => 'vcd',
|
||||
'application/x-chess-pgn' => 'pgn',
|
||||
'application/x-cpio' => 'cpio',
|
||||
'application/x-csh' => 'csh',
|
||||
'application/x-dia-diagram' => 'dia',
|
||||
'application/x-director' => 'dcr dir dxr',
|
||||
'application/x-dvi' => 'dvi',
|
||||
'application/x-futuresplash' => 'spl',
|
||||
'application/x-gtar' => 'gtar tar',
|
||||
'application/x-gzip' => 'gz',
|
||||
'application/x-hdf' => 'hdf',
|
||||
'application/x-jar' => 'jar',
|
||||
'application/json' => 'json',
|
||||
'application/x-koan' => 'skp skd skt skm',
|
||||
'application/x-latex' => 'latex',
|
||||
'application/x-netcdf' => 'nc cdf',
|
||||
'application/x-sh' => 'sh',
|
||||
'application/x-shar' => 'shar',
|
||||
'application/x-stuffit' => 'sit',
|
||||
'application/x-sv4cpio' => 'sv4cpio',
|
||||
'application/x-sv4crc' => 'sv4crc',
|
||||
'application/x-tar' => 'tar',
|
||||
'application/x-tcl' => 'tcl',
|
||||
'application/x-tex' => 'tex',
|
||||
'application/x-texinfo' => 'texinfo texi',
|
||||
'application/x-troff' => 't tr roff',
|
||||
'application/x-troff-man' => 'man',
|
||||
'application/x-troff-me' => 'me',
|
||||
'application/x-troff-ms' => 'ms',
|
||||
'application/x-ustar' => 'ustar',
|
||||
'application/x-wais-source' => 'src',
|
||||
'application/x-xpinstall' => 'xpi',
|
||||
'application/xhtml+xml' => 'xhtml xht',
|
||||
'application/xslt+xml' => 'xslt',
|
||||
'application/xml' => 'xml xsl xsd kml',
|
||||
'application/xml-dtd' => 'dtd',
|
||||
'application/zip' => 'zip jar xpi sxc stc sxd std sxi sti sxm stm sxw stw',
|
||||
'application/x-rar' => 'rar',
|
||||
'application/font-woff' => 'woff',
|
||||
'application/font-woff2' => 'woff2',
|
||||
'application/vnd.ms-fontobject' => 'eot',
|
||||
'application/x-font-ttf' => 'ttf',
|
||||
'audio/basic' => 'au snd',
|
||||
'video/webm' => 'webm',
|
||||
'audio/webm' => 'webm',
|
||||
'audio/x-matroska' => 'mka mkv',
|
||||
'audio/x-mpegurl' => 'm3u',
|
||||
'audio/x-ogg' => 'oga ogg spx opus',
|
||||
'audio/x-pn-realaudio' => 'ram rm',
|
||||
'audio/x-pn-realaudio-plugin' => 'rpm',
|
||||
'audio/x-realaudio' => 'ra',
|
||||
'audio/wav' => 'wav',
|
||||
'audio/x-flac' => 'flac',
|
||||
'audio/flac' => 'flac',
|
||||
'chemical/x-pdb' => 'pdb',
|
||||
'chemical/x-xyz' => 'xyz',
|
||||
'image/bmp' => 'bmp',
|
||||
'image/cgm' => 'cgm',
|
||||
'image/ief' => 'ief',
|
||||
'image/jp2' => 'j2k jp2 jpg2',
|
||||
'image/vnd.microsoft.icon' => 'ico',
|
||||
'image/vnd.wap.wbmp' => 'wbmp',
|
||||
'image/webp' => 'webp',
|
||||
'image/x-cmu-raster' => 'ras',
|
||||
'image/x-icon' => 'ico',
|
||||
'image/x-ms-bmp' => 'bmp',
|
||||
'image/x-portable-anymap' => 'pnm',
|
||||
'image/x-portable-bitmap' => 'pbm',
|
||||
'image/x-portable-graymap' => 'pgm',
|
||||
'image/x-rgb' => 'rgb',
|
||||
'image/x-photoshop' => 'psd',
|
||||
'image/x-xbitmap' => 'xbm',
|
||||
'image/x-xpixmap' => 'xpm',
|
||||
'image/x-xwindowdump' => 'xwd',
|
||||
'model/iges' => 'igs iges',
|
||||
'model/mesh' => 'msh mesh silo',
|
||||
'model/vrml' => 'wrl vrml',
|
||||
'text/calendar' => 'ics ifb',
|
||||
'text/css' => 'css',
|
||||
'text/csv' => 'csv',
|
||||
'text/richtext' => 'rtx',
|
||||
'text/rtf' => 'rtf',
|
||||
'text/sgml' => 'sgml sgm',
|
||||
'text/tab-separated-values' => 'tsv',
|
||||
'text/vnd.wap.wml' => 'wml',
|
||||
'text/vnd.wap.wmlscript' => 'wmls',
|
||||
'text/xml' => 'xml xsl xslt rss rdf',
|
||||
'text/x-component' => 'htc',
|
||||
'text/x-setext' => 'etx',
|
||||
'text/x-sawfish' => 'jl',
|
||||
'video/mp4' => 'mp4 m4a m4p m4b m4r m4v',
|
||||
'audio/mp4' => 'm4a',
|
||||
'video/quicktime' => 'qt mov',
|
||||
'video/vnd.mpegurl' => 'mxu',
|
||||
'video/x-flv' => 'flv',
|
||||
'video/x-matroska' => 'mkv mka',
|
||||
'video/x-msvideo' => 'avi',
|
||||
'video/x-ogg' => 'ogv ogm ogg',
|
||||
'video/x-sgi-movie' => 'movie',
|
||||
'x-conference/x-cooltalk' => 'ice',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx',
|
||||
'application/vnd.ms-word.document.macroenabled.12' => 'docm',
|
||||
'application/vnd.ms-word.template.macroenabled.12' => 'dotm',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.template' => 'potx',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
|
||||
'application/vnd.ms-powerpoint.addin.macroenabled.12' => 'ppam',
|
||||
'application/vnd.ms-powerpoint.presentation.macroenabled.12' => 'pptm potm',
|
||||
'application/vnd.ms-powerpoint.slideshow.macroenabled.12' => 'ppsm',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'xltx',
|
||||
'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm',
|
||||
'application/vnd.ms-excel.template.macroenabled.12' => 'xltm',
|
||||
'application/vnd.ms-excel.addin.macroenabled.12' => 'xlam',
|
||||
'application/vnd.ms-excel.sheet.binary.macroenabled.12' => 'xlsb',
|
||||
'model/vnd.dwfx+xps' => 'dwfx',
|
||||
'application/vnd.ms-xpsdocument' => 'xps',
|
||||
'application/x-opc+zip' =>
|
||||
'docx dotx docm dotm potx ppsx pptx ppam pptm potm ppsm xlsx xltx xlsm xltm xlam xlsb dwfx xps',
|
||||
'chemical/x-mdl-molfile' => 'mol',
|
||||
'chemical/x-mdl-sdfile' => 'sdf',
|
||||
'chemical/x-mdl-rxnfile' => 'rxn',
|
||||
'chemical/x-mdl-rdfile' => 'rd',
|
||||
'chemical/x-mdl-rgfile' => 'rg',
|
||||
'application/x-amf' => 'amf',
|
||||
'application/sla' => 'stl',
|
||||
'application/wasm' => 'wasm',
|
||||
'application/ogg' => [ 'ogx', 'ogg', 'ogm', 'ogv', 'oga', 'spx', 'opus' ],
|
||||
'application/pdf' => [ 'pdf' ],
|
||||
'application/vnd.oasis.opendocument.chart' => [ 'odc' ],
|
||||
'application/vnd.oasis.opendocument.chart-template' => [ 'otc' ],
|
||||
'application/vnd.oasis.opendocument.database' => [ 'odb' ],
|
||||
'application/vnd.oasis.opendocument.formula' => [ 'odf' ],
|
||||
'application/vnd.oasis.opendocument.formula-template' => [ 'otf' ],
|
||||
'application/vnd.oasis.opendocument.graphics' => [ 'odg' ],
|
||||
'application/vnd.oasis.opendocument.graphics-template' => [ 'otg' ],
|
||||
'application/vnd.oasis.opendocument.image' => [ 'odi' ],
|
||||
'application/vnd.oasis.opendocument.image-template' => [ 'oti' ],
|
||||
'application/vnd.oasis.opendocument.presentation' => [ 'odp' ],
|
||||
'application/vnd.oasis.opendocument.presentation-template' => [ 'otp' ],
|
||||
'application/vnd.oasis.opendocument.spreadsheet' => [ 'ods' ],
|
||||
'application/vnd.oasis.opendocument.spreadsheet-template' => [ 'ots' ],
|
||||
'application/vnd.oasis.opendocument.text' => [ 'odt' ],
|
||||
'application/vnd.oasis.opendocument.text-master' => [ 'otm', 'odm' ],
|
||||
'application/vnd.oasis.opendocument.text-template' => [ 'ott' ],
|
||||
'application/vnd.oasis.opendocument.text-web' => [ 'oth' ],
|
||||
'application/javascript' => [ 'js' ],
|
||||
'application/x-shockwave-flash' => [ 'swf' ],
|
||||
'audio/midi' => [ 'mid', 'midi', 'kar' ],
|
||||
'audio/mpeg' => [ 'mpga', 'mpa', 'mp2', 'mp3' ],
|
||||
'audio/x-aiff' => [ 'aif', 'aiff', 'aifc' ],
|
||||
'audio/x-wav' => [ 'wav' ],
|
||||
'audio/ogg' => [ 'oga', 'spx', 'ogg', 'opus' ],
|
||||
'audio/opus' => [ 'opus', 'ogg', 'oga', 'spx' ],
|
||||
'image/x-bmp' => [ 'bmp' ],
|
||||
'image/gif' => [ 'gif' ],
|
||||
'image/jpeg' => [ 'jpeg', 'jpg', 'jpe' ],
|
||||
'image/png' => [ 'png', 'apng' ],
|
||||
'image/svg+xml' => [ 'svg' ],
|
||||
'image/svg' => [ 'svg' ],
|
||||
'image/tiff' => [ 'tiff', 'tif' ],
|
||||
'image/vnd.djvu' => [ 'djvu', 'djv' ],
|
||||
'image/x.djvu' => [ 'djvu' ],
|
||||
'image/x-djvu' => [ 'djvu' ],
|
||||
'image/x-portable-pixmap' => [ 'ppm' ],
|
||||
'image/x-xcf' => [ 'xcf' ],
|
||||
'text/plain' => [ 'txt' ],
|
||||
'text/html' => [ 'html', 'htm' ],
|
||||
'video/ogg' => [ 'ogv', 'ogm', 'ogg' ],
|
||||
'video/mpeg' => [ 'mpg', 'mpeg', 'mpe' ],
|
||||
'application/acad' => [ 'dwg' ],
|
||||
'application/andrew-inset' => [ 'ez' ],
|
||||
'application/mac-binhex40' => [ 'hqx' ],
|
||||
'application/mac-compactpro' => [ 'cpt' ],
|
||||
'application/mathml+xml' => [ 'mathml' ],
|
||||
'application/msword' => [ 'doc', 'dot' ],
|
||||
'application/octet-stream' => [ 'bin', 'dms', 'lha', 'lzh', 'exe', 'class', 'so', 'dll' ],
|
||||
'application/oda' => [ 'oda' ],
|
||||
'application/postscript' => [ 'ai', 'eps', 'ps' ],
|
||||
'application/rdf+xml' => [ 'rdf' ],
|
||||
'application/smil' => [ 'smi', 'smil' ],
|
||||
'application/srgs' => [ 'gram' ],
|
||||
'application/srgs+xml' => [ 'grxml' ],
|
||||
'application/vnd.mif' => [ 'mif' ],
|
||||
'application/vnd.ms-excel' => [ 'xls', 'xlt', 'xla' ],
|
||||
'application/vnd.ms-powerpoint' => [ 'ppt', 'pot', 'pps', 'ppa' ],
|
||||
'application/vnd.wap.wbxml' => [ 'wbxml' ],
|
||||
'application/vnd.wap.wmlc' => [ 'wmlc' ],
|
||||
'application/vnd.wap.wmlscriptc' => [ 'wmlsc' ],
|
||||
'application/voicexml+xml' => [ 'vxml' ],
|
||||
'application/x-7z-compressed' => [ '7z' ],
|
||||
'application/x-bcpio' => [ 'bcpio' ],
|
||||
'application/x-bzip' => [ 'bz' ],
|
||||
'application/x-bzip2' => [ 'bz2' ],
|
||||
'application/x-cdlink' => [ 'vcd' ],
|
||||
'application/x-chess-pgn' => [ 'pgn' ],
|
||||
'application/x-cpio' => [ 'cpio' ],
|
||||
'application/x-csh' => [ 'csh' ],
|
||||
'application/x-dia-diagram' => [ 'dia' ],
|
||||
'application/x-director' => [ 'dcr', 'dir', 'dxr' ],
|
||||
'application/x-dvi' => [ 'dvi' ],
|
||||
'application/x-futuresplash' => [ 'spl' ],
|
||||
'application/x-gtar' => [ 'gtar', 'tar' ],
|
||||
'application/x-gzip' => [ 'gz' ],
|
||||
'application/x-hdf' => [ 'hdf' ],
|
||||
'application/x-jar' => [ 'jar' ],
|
||||
'application/json' => [ 'json' ],
|
||||
'application/x-koan' => [ 'skp', 'skd', 'skt', 'skm' ],
|
||||
'application/x-latex' => [ 'latex' ],
|
||||
'application/x-netcdf' => [ 'nc', 'cdf' ],
|
||||
'application/x-sh' => [ 'sh' ],
|
||||
'application/x-shar' => [ 'shar' ],
|
||||
'application/x-stuffit' => [ 'sit' ],
|
||||
'application/x-sv4cpio' => [ 'sv4cpio' ],
|
||||
'application/x-sv4crc' => [ 'sv4crc' ],
|
||||
'application/x-tar' => [ 'tar' ],
|
||||
'application/x-tcl' => [ 'tcl' ],
|
||||
'application/x-tex' => [ 'tex' ],
|
||||
'application/x-texinfo' => [ 'texinfo', 'texi' ],
|
||||
'application/x-troff' => [ 't', 'tr', 'roff' ],
|
||||
'application/x-troff-man' => [ 'man' ],
|
||||
'application/x-troff-me' => [ 'me' ],
|
||||
'application/x-troff-ms' => [ 'ms' ],
|
||||
'application/x-ustar' => [ 'ustar' ],
|
||||
'application/x-wais-source' => [ 'src' ],
|
||||
'application/x-xpinstall' => [ 'xpi' ],
|
||||
'application/xhtml+xml' => [ 'xhtml', 'xht' ],
|
||||
'application/xslt+xml' => [ 'xslt' ],
|
||||
'application/xml' => [ 'xml', 'xsl', 'xsd', 'kml' ],
|
||||
'application/xml-dtd' => [ 'dtd' ],
|
||||
'application/zip' =>
|
||||
[ 'zip', 'jar', 'xpi', 'sxc', 'stc', 'sxd', 'std', 'sxi', 'sti', 'sxm', 'stm', 'sxw', 'stw' ],
|
||||
'application/x-rar' => [ 'rar' ],
|
||||
'application/font-woff' => [ 'woff' ],
|
||||
'application/font-woff2' => [ 'woff2' ],
|
||||
'application/vnd.ms-fontobject' => [ 'eot' ],
|
||||
'application/x-font-ttf' => [ 'ttf' ],
|
||||
'audio/basic' => [ 'au', 'snd' ],
|
||||
'video/webm' => [ 'webm' ],
|
||||
'audio/webm' => [ 'webm' ],
|
||||
'audio/x-matroska' => [ 'mka', 'mkv' ],
|
||||
'audio/x-mpegurl' => [ 'm3u' ],
|
||||
'audio/x-ogg' => [ 'oga', 'ogg', 'spx', 'opus' ],
|
||||
'audio/x-pn-realaudio' => [ 'ram', 'rm' ],
|
||||
'audio/x-pn-realaudio-plugin' => [ 'rpm' ],
|
||||
'audio/x-realaudio' => [ 'ra' ],
|
||||
'audio/wav' => [ 'wav' ],
|
||||
'audio/x-flac' => [ 'flac' ],
|
||||
'audio/flac' => [ 'flac' ],
|
||||
'chemical/x-pdb' => [ 'pdb' ],
|
||||
'chemical/x-xyz' => [ 'xyz' ],
|
||||
'image/bmp' => [ 'bmp' ],
|
||||
'image/cgm' => [ 'cgm' ],
|
||||
'image/ief' => [ 'ief' ],
|
||||
'image/jp2' => [ 'j2k', 'jp2', 'jpg2' ],
|
||||
'image/vnd.microsoft.icon' => [ 'ico' ],
|
||||
'image/vnd.wap.wbmp' => [ 'wbmp' ],
|
||||
'image/webp' => [ 'webp' ],
|
||||
'image/x-cmu-raster' => [ 'ras' ],
|
||||
'image/x-icon' => [ 'ico' ],
|
||||
'image/x-ms-bmp' => [ 'bmp' ],
|
||||
'image/x-portable-anymap' => [ 'pnm' ],
|
||||
'image/x-portable-bitmap' => [ 'pbm' ],
|
||||
'image/x-portable-graymap' => [ 'pgm' ],
|
||||
'image/x-rgb' => [ 'rgb' ],
|
||||
'image/x-photoshop' => [ 'psd' ],
|
||||
'image/x-xbitmap' => [ 'xbm' ],
|
||||
'image/x-xpixmap' => [ 'xpm' ],
|
||||
'image/x-xwindowdump' => [ 'xwd' ],
|
||||
'model/iges' => [ 'igs', 'iges' ],
|
||||
'model/mesh' => [ 'msh', 'mesh', 'silo' ],
|
||||
'model/vrml' => [ 'wrl', 'vrml' ],
|
||||
'text/calendar' => [ 'ics', 'ifb' ],
|
||||
'text/css' => [ 'css' ],
|
||||
'text/csv' => [ 'csv' ],
|
||||
'text/richtext' => [ 'rtx' ],
|
||||
'text/rtf' => [ 'rtf' ],
|
||||
'text/sgml' => [ 'sgml', 'sgm' ],
|
||||
'text/tab-separated-values' => [ 'tsv' ],
|
||||
'text/vnd.wap.wml' => [ 'wml' ],
|
||||
'text/vnd.wap.wmlscript' => [ 'wmls' ],
|
||||
'text/xml' => [ 'xml', 'xsl', 'xslt', 'rss', 'rdf' ],
|
||||
'text/x-component' => [ 'htc' ],
|
||||
'text/x-setext' => [ 'etx' ],
|
||||
'text/x-sawfish' => [ 'jl' ],
|
||||
'video/mp4' => [ 'mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v' ],
|
||||
'audio/mp4' => [ 'm4a' ],
|
||||
'video/quicktime' => [ 'qt', 'mov' ],
|
||||
'video/vnd.mpegurl' => [ 'mxu' ],
|
||||
'video/x-flv' => [ 'flv' ],
|
||||
'video/x-matroska' => [ 'mkv', 'mka' ],
|
||||
'video/x-msvideo' => [ 'avi' ],
|
||||
'video/x-ogg' => [ 'ogv', 'ogm', 'ogg' ],
|
||||
'video/x-sgi-movie' => [ 'movie' ],
|
||||
'x-conference/x-cooltalk' => [ 'ice' ],
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => [ 'docx' ],
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => [ 'dotx' ],
|
||||
'application/vnd.ms-word.document.macroenabled.12' => [ 'docm' ],
|
||||
'application/vnd.ms-word.template.macroenabled.12' => [ 'dotm' ],
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.template' => [ 'potx' ],
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => [ 'ppsx' ],
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => [ 'pptx' ],
|
||||
'application/vnd.ms-powerpoint.addin.macroenabled.12' => [ 'ppam' ],
|
||||
'application/vnd.ms-powerpoint.presentation.macroenabled.12' => [ 'pptm', 'potm' ],
|
||||
'application/vnd.ms-powerpoint.slideshow.macroenabled.12' => [ 'ppsm' ],
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => [ 'xlsx' ],
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => [ 'xltx' ],
|
||||
'application/vnd.ms-excel.sheet.macroenabled.12' => [ 'xlsm' ],
|
||||
'application/vnd.ms-excel.template.macroenabled.12' => [ 'xltm' ],
|
||||
'application/vnd.ms-excel.addin.macroenabled.12' => [ 'xlam' ],
|
||||
'application/vnd.ms-excel.sheet.binary.macroenabled.12' => [ 'xlsb' ],
|
||||
'model/vnd.dwfx+xps' => [ 'dwfx' ],
|
||||
'application/vnd.ms-xpsdocument' => [ 'xps' ],
|
||||
'application/x-opc+zip' => [
|
||||
'docx', 'dotx', 'docm', 'dotm', 'potx', 'ppsx', 'pptx', 'ppam', 'pptm', 'potm', 'ppsm',
|
||||
'xlsx', 'xltx', 'xlsm', 'xltm', 'xlam', 'xlsb', 'dwfx', 'xps' ],
|
||||
'chemical/x-mdl-molfile' => [ 'mol' ],
|
||||
'chemical/x-mdl-sdfile' => [ 'sdf' ],
|
||||
'chemical/x-mdl-rxnfile' => [ 'rxn' ],
|
||||
'chemical/x-mdl-rdfile' => [ 'rd' ],
|
||||
'chemical/x-mdl-rgfile' => [ 'rg' ],
|
||||
'application/x-amf' => [ 'amf' ],
|
||||
'application/sla' => [ 'stl' ],
|
||||
'application/wasm' => [ 'wasm' ],
|
||||
];
|
||||
|
||||
/** @var array Map of built-in media types and their associated MIME types */
|
||||
|
|
|
|||
|
|
@ -31,49 +31,49 @@ namespace Wikimedia\Mime;
|
|||
*/
|
||||
class MimeMapMinimal {
|
||||
public const MIME_EXTENSIONS = [
|
||||
'application/ogg' => 'ogx ogg ogm ogv oga spx opus',
|
||||
'application/pdf' => 'pdf',
|
||||
'application/vnd.oasis.opendocument.chart' => 'odc',
|
||||
'application/vnd.oasis.opendocument.chart-template' => 'otc',
|
||||
'application/vnd.oasis.opendocument.database' => 'odb',
|
||||
'application/vnd.oasis.opendocument.formula' => 'odf',
|
||||
'application/vnd.oasis.opendocument.formula-template' => 'otf',
|
||||
'application/vnd.oasis.opendocument.graphics' => 'odg',
|
||||
'application/vnd.oasis.opendocument.graphics-template' => 'otg',
|
||||
'application/vnd.oasis.opendocument.image' => 'odi',
|
||||
'application/vnd.oasis.opendocument.image-template' => 'oti',
|
||||
'application/vnd.oasis.opendocument.presentation' => 'odp',
|
||||
'application/vnd.oasis.opendocument.presentation-template' => 'otp',
|
||||
'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
|
||||
'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots',
|
||||
'application/vnd.oasis.opendocument.text' => 'odt',
|
||||
'application/vnd.oasis.opendocument.text-master' => 'otm',
|
||||
'application/vnd.oasis.opendocument.text-template' => 'ott',
|
||||
'application/vnd.oasis.opendocument.text-web' => 'oth',
|
||||
'application/javascript' => 'js',
|
||||
'application/x-shockwave-flash' => 'swf',
|
||||
'audio/midi' => 'mid midi kar',
|
||||
'audio/mpeg' => 'mpga mpa mp2 mp3',
|
||||
'audio/x-aiff' => 'aif aiff aifc',
|
||||
'audio/x-wav' => 'wav',
|
||||
'audio/ogg' => 'oga spx ogg opus',
|
||||
'audio/opus' => 'opus ogg oga spx',
|
||||
'image/x-bmp' => 'bmp',
|
||||
'image/gif' => 'gif',
|
||||
'image/jpeg' => 'jpeg jpg jpe',
|
||||
'image/png' => 'png',
|
||||
'image/svg+xml' => 'svg',
|
||||
'image/svg' => 'svg',
|
||||
'image/tiff' => 'tiff tif',
|
||||
'image/vnd.djvu' => 'djvu',
|
||||
'image/x.djvu' => 'djvu',
|
||||
'image/x-djvu' => 'djvu',
|
||||
'image/x-portable-pixmap' => 'ppm',
|
||||
'image/x-xcf' => 'xcf',
|
||||
'text/plain' => 'txt',
|
||||
'text/html' => 'html htm',
|
||||
'video/ogg' => 'ogv ogm ogg',
|
||||
'video/mpeg' => 'mpg mpeg',
|
||||
'application/ogg' => [ 'ogx', 'ogg', 'ogm', 'ogv', 'oga', 'spx', 'opus' ],
|
||||
'application/pdf' => [ 'pdf' ],
|
||||
'application/vnd.oasis.opendocument.chart' => [ 'odc' ],
|
||||
'application/vnd.oasis.opendocument.chart-template' => [ 'otc' ],
|
||||
'application/vnd.oasis.opendocument.database' => [ 'odb' ],
|
||||
'application/vnd.oasis.opendocument.formula' => [ 'odf' ],
|
||||
'application/vnd.oasis.opendocument.formula-template' => [ 'otf' ],
|
||||
'application/vnd.oasis.opendocument.graphics' => [ 'odg' ],
|
||||
'application/vnd.oasis.opendocument.graphics-template' => [ 'otg' ],
|
||||
'application/vnd.oasis.opendocument.image' => [ 'odi' ],
|
||||
'application/vnd.oasis.opendocument.image-template' => [ 'oti' ],
|
||||
'application/vnd.oasis.opendocument.presentation' => [ 'odp' ],
|
||||
'application/vnd.oasis.opendocument.presentation-template' => [ 'otp' ],
|
||||
'application/vnd.oasis.opendocument.spreadsheet' => [ 'ods' ],
|
||||
'application/vnd.oasis.opendocument.spreadsheet-template' => [ 'ots' ],
|
||||
'application/vnd.oasis.opendocument.text' => [ 'odt' ],
|
||||
'application/vnd.oasis.opendocument.text-master' => [ 'otm' ],
|
||||
'application/vnd.oasis.opendocument.text-template' => [ 'ott' ],
|
||||
'application/vnd.oasis.opendocument.text-web' => [ 'oth' ],
|
||||
'application/javascript' => [ 'js' ],
|
||||
'application/x-shockwave-flash' => [ 'swf' ],
|
||||
'audio/midi' => [ 'mid', 'midi', 'kar' ],
|
||||
'audio/mpeg' => [ 'mpga', 'mpa', 'mp2', 'mp3' ],
|
||||
'audio/x-aiff' => [ 'aif', 'aiff', 'aifc' ],
|
||||
'audio/x-wav' => [ 'wav' ],
|
||||
'audio/ogg' => [ 'oga', 'spx', 'ogg', 'opus' ],
|
||||
'audio/opus' => [ 'opus', 'ogg', 'oga', 'spx' ],
|
||||
'image/x-bmp' => [ 'bmp' ],
|
||||
'image/gif' => [ 'gif' ],
|
||||
'image/jpeg' => [ 'jpeg', 'jpg', 'jpe' ],
|
||||
'image/png' => [ 'png' ],
|
||||
'image/svg+xml' => [ 'svg' ],
|
||||
'image/svg' => [ 'svg' ],
|
||||
'image/tiff' => [ 'tiff', 'tif' ],
|
||||
'image/vnd.djvu' => [ 'djvu' ],
|
||||
'image/x.djvu' => [ 'djvu' ],
|
||||
'image/x-djvu' => [ 'djvu' ],
|
||||
'image/x-portable-pixmap' => [ 'ppm' ],
|
||||
'image/x-xcf' => [ 'xcf' ],
|
||||
'text/plain' => [ 'txt' ],
|
||||
'text/html' => [ 'html', 'htm' ],
|
||||
'video/ogg' => [ 'ogv', 'ogm', 'ogg' ],
|
||||
'video/mpeg' => [ 'mpg', 'mpeg' ],
|
||||
];
|
||||
|
||||
public const MEDIA_TYPES = [
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ if ( $ext == 'php' ) {
|
|||
$mime = 'text/plain';
|
||||
// Borrow from MimeAnalyzer
|
||||
foreach ( \Wikimedia\Mime\MimeMap::MIME_EXTENSIONS as $type => $exts ) {
|
||||
if ( in_array( $ext, explode( ' ', $exts ) ) ) {
|
||||
if ( in_array( $ext, $exts ) ) {
|
||||
$mime = $type;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,4 +229,26 @@ class MimeAnalyzerTest extends PHPUnit\Framework\TestCase {
|
|||
$this->assertSame( MEDIATYPE_OFFICE, $mimeAnalyzer->findMediaType( '.fake_extension' ) );
|
||||
$this->assertSame( 'fake/mime', $mimeAnalyzer->getTypesForExtension( 'no_such_extension' ) );
|
||||
}
|
||||
|
||||
public function testGetMimeTypesFromExtension() {
|
||||
$this->assertSame(
|
||||
[ 'video/webm', 'audio/webm' ], $this->mimeAnalyzer->getMimeTypesFromExtension( 'webm' ) );
|
||||
$this->assertSame( [], $this->mimeAnalyzer->getMimeTypesFromExtension( 'no_such_extension' ) );
|
||||
}
|
||||
|
||||
public function testGetMimeTypeFromExtensionOrNull() {
|
||||
$this->assertSame( 'video/webm', $this->mimeAnalyzer->getMimeTypeFromExtensionOrNull( 'webm' ) );
|
||||
$this->assertNull( $this->mimeAnalyzer->getMimeTypeFromExtensionOrNull( 'no_such_extension' ) );
|
||||
}
|
||||
|
||||
public function testGetExtensionsFromMimeType() {
|
||||
$this->assertSame(
|
||||
[ 'sgml', 'sgm' ], $this->mimeAnalyzer->getExtensionsFromMimeType( 'text/sgml' ) );
|
||||
$this->assertSame( [], $this->mimeAnalyzer->getExtensionsFromMimeType( 'fake/mime' ) );
|
||||
}
|
||||
|
||||
public function testGetExtensionFromMimeTypeOrNull() {
|
||||
$this->assertSame( 'sgml', $this->mimeAnalyzer->getExtensionFromMimeTypeOrNull( 'text/sgml' ) );
|
||||
$this->assertNull( $this->mimeAnalyzer->getExtensionFromMimeTypeOrNull( 'fake/mime' ) );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue