Public Member Functions | |
__construct () | |
Initializes the MimeMagic object. | |
getExtensionsForType ($mime) | |
returns a list of file extensions for a given mime type as a space separated string. | |
getTypesForExtension ($ext) | |
returns a list of mime types for a given file extension as a space separated string. | |
guessTypesForExtension ($ext) | |
returns a single mime type for a given file extension. | |
isMatchingExtension ($extension, $mime) | |
tests if the extension matches the given mime type. | |
isPHPImageType ($mime) | |
returns true if the mime type is known to represent an image format supported by the PHP GD library. | |
isRecognizableExtension ($extension) | |
Returns true if the extension represents a type which can be reliably detected from its content. | |
guessMimeType ($file, $ext=true) | |
mime type detection. | |
doGuessMimeType ($file, $ext=true) | |
detectZipType ($header) | |
Detect application-specific file type of a given ZIP file from its header data. | |
detectMimeType ($file, $ext=true) | |
Internal mime type detection, please use guessMimeType() for application code instead. | |
getMediaType ($path=NULL, $mime=NULL) | |
Determine the media type code for a file, using its mime type, name and possibly its contents. | |
findMediaType ($extMime) | |
returns a media code matching the given mime type or file extension. | |
getIEMimeTypes ($fileName, $chunk, $proposed) | |
Get the MIME types that various versions of Internet Explorer would detect from a chunk of the content. | |
Static Public Member Functions | |
static & | singleton () |
Get an instance of this class. | |
Public Attributes | |
$mMediaTypes = NULL | |
Mapping of media types to arrays of mime types. | |
$mMimeTypeAliases = NULL | |
Map of mime type aliases. | |
$mMimeToExt = NULL | |
map of mime types to file extensions (as a space seprarated list) | |
$mExtToMime = NULL | |
map of file extensions types to mime types (as a space seprarated list) | |
$mIEAnalyzer | |
IEContentAnalyzer instance. | |
Protected Member Functions | |
getIEContentAnalyzer () | |
Get a cached instance of IEContentAnalyzer. | |
Static Private Attributes | |
static | $instance |
The singleton instance. |
Instances of this class are stateles, there only needs to be one global instance of MimeMagic. Please use MimeMagic::singleton() to get that instance.
Definition at line 115 of file MimeMagic.php.
MimeMagic::__construct | ( | ) |
Initializes the MimeMagic object.
This is called by MimeMagic::singleton().
This constructor parses the mime.types and mime.info files and build internal mappings.
Definition at line 147 of file MimeMagic.php.
References $ext, $i, $IP, $s, $wgMimeInfoFile, $wgMimeTypeFile, and wfDebug().
MimeMagic::detectMimeType | ( | $ | file, | |
$ | ext = true | |||
) |
Internal mime type detection, please use guessMimeType() for application code instead.
Detection is done using an external program, if $wgMimeDetectorCommand is set. Otherwise, the fileinfo extension and mime_content_type are tried (in this order), if they are available. If the dections fails and $ext is not false, the mime type is guessed from the file extension, using guessTypesForExtension. 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, this function returns "unknown/unknown".
string | $file The file to check | |
mixed | $ext The file extension, or true to extract it from the filename. Set it to false to ignore the extension. |
Definition at line 629 of file MimeMagic.php.
References $ext, $file, $i, $wgMimeDetectorCommand, guessTypesForExtension(), isRecognizableExtension(), wfDebug(), and wfEscapeShellArg().
Referenced by guessMimeType().
MimeMagic::detectZipType | ( | $ | header | ) |
Detect application-specific file type of a given ZIP file from its header data.
Currently works for OpenDocument types... If can't tell, returns 'application/zip'.
string | $header Some reasonably-sized chunk of file header |
Definition at line 580 of file MimeMagic.php.
References wfDebug().
Referenced by doGuessMimeType().
MimeMagic::doGuessMimeType | ( | $ | file, | |
$ | ext = true | |||
) |
Definition at line 434 of file MimeMagic.php.
References $file, $wgXMLMimeTypes, detectZipType(), wfDebug(), wfRestoreWarnings(), and wfSuppressWarnings().
Referenced by guessMimeType().
MimeMagic::findMediaType | ( | $ | extMime | ) |
returns a media code matching the given mime type or file extension.
File extensions are represented by a string starting with a dot (.) to distinguish them from mime types.
This funktion relies on the mapping defined by $this->mMediaTypes private
Definition at line 790 of file MimeMagic.php.
Referenced by getMediaType().
MimeMagic::getExtensionsForType | ( | $ | mime | ) |
returns a list of file extensions for a given mime type as a space separated string.
Definition at line 303 of file MimeMagic.php.
Referenced by isMatchingExtension().
MimeMagic::getIEContentAnalyzer | ( | ) | [protected] |
MimeMagic::getIEMimeTypes | ( | $ | fileName, | |
$ | chunk, | |||
$ | proposed | |||
) |
Get the MIME types that various versions of Internet Explorer would detect from a chunk of the content.
string | $fileName The file name (unused at present) | |
string | $chunk The first 256 bytes of the file | |
string | $proposed The MIME type proposed by the server |
Definition at line 824 of file MimeMagic.php.
MimeMagic::getMediaType | ( | $ | path = NULL , |
|
$ | 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.
look at multiple extension, separately and together.
string | $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 | $mime mime type. If null it will be guessed using guessMimeType. |
Definition at line 724 of file MimeMagic.php.
References $i, $path, $type, findMediaType(), and guessMimeType().
MimeMagic::getTypesForExtension | ( | $ | ext | ) |
returns a list of mime types for a given file extension as a space separated string.
Definition at line 319 of file MimeMagic.php.
References $ext.
Referenced by guessTypesForExtension().
MimeMagic::guessMimeType | ( | $ | 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 misinterpreter by the default mime detection (namely xml based formats like XHTML or SVG).
string | $file The file to check | |
mixed | $ext The file extension, or true to extract it from the filename. Set it to false to ignore the extension. |
Definition at line 418 of file MimeMagic.php.
References $ext, $file, detectMimeType(), doGuessMimeType(), and wfDebug().
Referenced by getMediaType().
MimeMagic::guessTypesForExtension | ( | $ | ext | ) |
returns a single mime type for a given file extension.
This is always the first type from the list returned by getTypesForExtension($ext).
Definition at line 329 of file MimeMagic.php.
References $ext, and getTypesForExtension().
Referenced by detectMimeType().
MimeMagic::isMatchingExtension | ( | $ | extension, | |
$ | 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.
Definition at line 344 of file MimeMagic.php.
References $ext, and getExtensionsForType().
MimeMagic::isPHPImageType | ( | $ | mime | ) |
returns true if the mime type is known to represent an image format supported by the PHP GD library.
Definition at line 364 of file MimeMagic.php.
MimeMagic::isRecognizableExtension | ( | $ | 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.
Definition at line 390 of file MimeMagic.php.
Referenced by detectMimeType().
static& MimeMagic::singleton | ( | ) | [static] |
Get an instance of this class.
Definition at line 293 of file MimeMagic.php.
Referenced by File::checkExtensionCompatibility(), ForeignAPIFile::getMediaType(), UnregisteredLocalFile::getMimeType(), ForeignAPIFile::getMimeType(), File::getPropsFromPath(), DjVuHandler::getThumbType(), UploadForm::verify(), UploadForm::verifyExtension(), wfGetMimeMagic(), and wfGetType().
MimeMagic::$instance [static, private] |
MimeMagic::$mExtToMime = NULL |
map of file extensions types to mime types (as a space seprarated list)
Definition at line 133 of file MimeMagic.php.
MimeMagic::$mIEAnalyzer |
MimeMagic::$mMediaTypes = NULL |
Mapping of media types to arrays of mime types.
This is used by findMediaType and getMediaType, respectively
Definition at line 121 of file MimeMagic.php.
MimeMagic::$mMimeToExt = NULL |
map of mime types to file extensions (as a space seprarated list)
Definition at line 129 of file MimeMagic.php.
MimeMagic::$mMimeTypeAliases = NULL |