MediaWiki
master
|
Implements functions related to MIME types such as detection and mapping to file extension. More...
Public Member Functions | |
__construct (array $params) | |
addExtraInfo (string $info) | |
Adds to the list mapping MIME to media type. More... | |
addExtraTypes (string $types) | |
Adds to the list mapping MIME to file extensions. More... | |
detectZipTypeFromFile ( $handle) | |
Detect application-specific file type of a given ZIP file. More... | |
getExtensionFromMimeTypeOrNull (string $mime) | |
Returns a single file extension for a given MIME type or null if unknown. More... | |
getExtensionsForType ( $mime) | |
Returns a list of file extensions for a given MIME type as a space separated string or null if the MIME type was unrecognized. More... | |
getExtensionsFromMimeType (string $mime) | |
Returns an array of file extensions associated with a given MIME type. More... | |
getMediaType (string $path=null, string $mime=null) | |
Determine the media type code for a file, using its MIME type, name and possibly its contents. More... | |
getMediaTypes () | |
Returns an array of media types (MEDIATYPE_xxx constants) More... | |
getMimeTypeFromExtensionOrNull (string $ext) | |
Returns a single MIME type for a given file extension or null if unknown. More... | |
getMimeTypesFromExtension (string $ext) | |
Returns an array of MIME types associated with a given file extension. More... | |
getTypesForExtension ( $ext) | |
Returns a list of MIME types for a given file extension as a space separated string or null if the extension was unrecognized. More... | |
guessMimeType (string $file, $ext=true) | |
MIME type detection. More... | |
guessTypesForExtension ( $ext) | |
Returns a single file extension for a given MIME type or null if unknown. More... | |
improveTypeFromExtension (string $mime, string $ext) | |
Improves a MIME type using the file extension. More... | |
isMatchingExtension (string $extension, string $mime) | |
Tests if the extension matches the given MIME type. More... | |
isPHPImageType (string $mime) | |
Returns true if the MIME type is known to represent an image format supported by the PHP GD library. More... | |
isRecognizableExtension (string $extension) | |
Returns true if the extension represents a type which can be reliably detected from its content. More... | |
setLogger (LoggerInterface $logger) | |
Public Attributes | |
array | $mExtToMime = [] |
Map of file extensions types to MIME types (as a space separated list) More... | |
Protected Member Functions | |
loadFiles () | |
parseMimeInfo (string $rawMimeInfo) | |
parseMimeTypes (string $rawMimeTypes) | |
Protected Attributes | |
callable | $detectCallback |
callable | $extCallback |
array< string, string[]> | $extToMimes = [] |
Map of file extensions to MIME types. More... | |
callable | $guessCallback |
string | $infoFile |
callable | $initCallback |
array | $mediaTypes = null |
Mapping of media types to arrays of MIME types. More... | |
array< string, string[]> | $mimeToExts = [] |
Map of MIME types to file extensions. More... | |
array | $mimeTypeAliases = null |
Map of MIME type aliases. More... | |
string | $typeFile |
string | $xmlTypes |
Implements functions related to MIME types such as detection and mapping to file extension.
Definition at line 34 of file MimeAnalyzer.php.
MimeAnalyzer::__construct | ( | array | $params | ) |
array | $params | Configuration map, includes:
|
Definition at line 87 of file MimeAnalyzer.php.
References loadFiles().
MimeAnalyzer::addExtraInfo | ( | string | $info | ) |
Adds to the list mapping MIME to media type.
As an extension author, you are encouraged to submit patches to MediaWiki's core to add new MIME info to MimeMap.php.
string | $info |
Definition at line 261 of file MimeAnalyzer.php.
MimeAnalyzer::addExtraTypes | ( | string | $types | ) |
Adds to the list mapping MIME to file extensions.
As an extension author, you are encouraged to submit patches to MediaWiki's core to add new MIME types to MimeMap.php.
string | $types |
Definition at line 249 of file MimeAnalyzer.php.
MimeAnalyzer::detectZipTypeFromFile | ( | $handle | ) |
Detect application-specific file type of a given ZIP file.
If it can't tell, return 'application/zip'.
Definition at line 800 of file MimeAnalyzer.php.
References ZipDirectoryReader\readHandle().
MimeAnalyzer::getExtensionFromMimeTypeOrNull | ( | string | $mime | ) |
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).
string | $mime |
Definition at line 356 of file MimeAnalyzer.php.
MimeAnalyzer::getExtensionsForType | ( | $mime | ) |
Returns a list of file extensions for a given MIME type as a space separated string or null if the MIME type was unrecognized.
Resolves MIME type aliases.
string | $mime |
Definition at line 274 of file MimeAnalyzer.php.
References $mime.
MimeAnalyzer::getExtensionsFromMimeType | ( | string | $mime | ) |
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.
string | $mime |
Definition at line 288 of file MimeAnalyzer.php.
References $mime.
MimeAnalyzer::getMediaType | ( | string | $path = null , |
string | $mime = null |
||
) |
Determine the media type code for a file, using its MIME type, name and possibly its contents.
This function relies on the findMediaType(), mapping extensions and MIME types to media types.
analyse file if need be
look at multiple extension, separately and together.
string | null | $path | Full path to the image file, in case we have to look at the contents (if null, only the MIME type is used to determine the media type code). |
string | null | $mime | MIME type. If null it will be guessed using guessMimeType. |
Definition at line 947 of file MimeAnalyzer.php.
References MEDIATYPE_UNKNOWN.
MimeAnalyzer::getMediaTypes | ( | ) |
Returns an array of media types (MEDIATYPE_xxx constants)
Definition at line 1068 of file MimeAnalyzer.php.
Referenced by MediaWiki\Specials\SpecialNewFiles\__construct().
MimeAnalyzer::getMimeTypeFromExtensionOrNull | ( | string | $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).
string | $ext |
Definition at line 318 of file MimeAnalyzer.php.
MimeAnalyzer::getMimeTypesFromExtension | ( | string | $ext | ) |
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.
string | $ext |
Definition at line 305 of file MimeAnalyzer.php.
MimeAnalyzer::getTypesForExtension | ( | $ext | ) |
Returns a list of MIME types for a given file extension as a space separated string or null if the extension was unrecognized.
string | $ext |
Definition at line 343 of file MimeAnalyzer.php.
References $ext.
MimeAnalyzer::guessMimeType | ( | string | $file, |
$ext = true |
|||
) |
MIME type detection.
This uses detectMimeType to detect the MIME type of the file, but applies additional checks to determine some well known file formats that may be missed or misinterpreted by the default MIME detection (namely XML based formats like XHTML or SVG, as well as ZIP based formats like OPC/ODF files).
string | $file | The file to check |
string | bool | $ext | The file extension, or true (default) to extract it from the filename. Set it to false to ignore the extension. DEPRECATED! Set to false, use improveTypeFromExtension($mime, $ext) later to improve MIME type. |
Definition at line 509 of file MimeAnalyzer.php.
MimeAnalyzer::guessTypesForExtension | ( | $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).
string | $ext |
Definition at line 331 of file MimeAnalyzer.php.
References $ext.
MimeAnalyzer::improveTypeFromExtension | ( | string | $mime, |
string | $ext | ||
) |
Improves a MIME type using the file extension.
Some file formats are very generic, so their MIME type is not very meaningful. A more useful MIME type can be derived by looking at the file extension. Typically, this method would be called on the result of guessMimeType().
XXX: Null-returning behavior is probably an accident and definitely confusing (T253483).
string | $mime | The MIME type, typically guessed from a file's content. |
string | $ext | The file extension, as taken from the file name |
Definition at line 451 of file MimeAnalyzer.php.
MimeAnalyzer::isMatchingExtension | ( | string | $extension, |
string | $mime | ||
) |
Tests if the extension matches the given MIME type.
Returns true if a match was found, null if the MIME type is unknown, and false if the MIME type is known but no matches where found.
string | $extension | |
string | $mime |
Definition at line 370 of file MimeAnalyzer.php.
MimeAnalyzer::isPHPImageType | ( | string | $mime | ) |
Returns true if the MIME type is known to represent an image format supported by the PHP GD library.
string | $mime |
Definition at line 388 of file MimeAnalyzer.php.
MimeAnalyzer::isRecognizableExtension | ( | string | $extension | ) |
Returns true if the extension represents a type which can be reliably detected from its content.
Use this to determine whether strict content checks should be applied to reject invalid uploads; if we can't identify the type we won't be able to say if it's invalid.
string | $extension |
Definition at line 416 of file MimeAnalyzer.php.
|
protected |
Definition at line 100 of file MimeAnalyzer.php.
Referenced by __construct().
|
protected |
Definition at line 183 of file MimeAnalyzer.php.
|
protected |
Definition at line 150 of file MimeAnalyzer.php.
MimeAnalyzer::setLogger | ( | LoggerInterface | $logger | ) |
Definition at line 237 of file MimeAnalyzer.php.
|
protected |
Definition at line 44 of file MimeAnalyzer.php.
|
protected |
Definition at line 48 of file MimeAnalyzer.php.
|
protected |
Map of file extensions to MIME types.
Definition at line 56 of file MimeAnalyzer.php.
|
protected |
Definition at line 46 of file MimeAnalyzer.php.
|
protected |
Definition at line 38 of file MimeAnalyzer.php.
|
protected |
Definition at line 42 of file MimeAnalyzer.php.
|
protected |
Mapping of media types to arrays of MIME types.
Definition at line 50 of file MimeAnalyzer.php.
array MimeAnalyzer::$mExtToMime = [] |
Map of file extensions types to MIME types (as a space separated list)
Definition at line 59 of file MimeAnalyzer.php.
|
protected |
Map of MIME types to file extensions.
Definition at line 54 of file MimeAnalyzer.php.
|
protected |
Map of MIME type aliases.
Definition at line 52 of file MimeAnalyzer.php.
|
protected |
Definition at line 36 of file MimeAnalyzer.php.
|
protected |
Definition at line 40 of file MimeAnalyzer.php.