00001 <?php
00011 define('MM_WELL_KNOWN_MIME_TYPES',<<<END_STRING
00012 application/ogg ogg ogm ogv
00013 application/pdf pdf
00014 application/vnd.oasis.opendocument.chart odc
00015 application/vnd.oasis.opendocument.chart-template otc
00016 application/vnd.oasis.opendocument.formula odf
00017 application/vnd.oasis.opendocument.formula-template otf
00018 application/vnd.oasis.opendocument.graphics odg
00019 application/vnd.oasis.opendocument.graphics-template otg
00020 application/vnd.oasis.opendocument.image odi
00021 application/vnd.oasis.opendocument.image-template oti
00022 application/vnd.oasis.opendocument.presentation odp
00023 application/vnd.oasis.opendocument.presentation-template otp
00024 application/vnd.oasis.opendocument.spreadsheet ods
00025 application/vnd.oasis.opendocument.spreadsheet-template ots
00026 application/vnd.oasis.opendocument.text odt
00027 application/vnd.oasis.opendocument.text-template ott
00028 application/vnd.oasis.opendocument.text-master otm
00029 application/vnd.oasis.opendocument.text-web oth
00030 application/x-javascript js
00031 application/x-shockwave-flash swf
00032 audio/midi mid midi kar
00033 audio/mpeg mpga mpa mp2 mp3
00034 audio/x-aiff aif aiff aifc
00035 audio/x-wav wav
00036 audio/ogg ogg
00037 image/x-bmp bmp
00038 image/gif gif
00039 image/jpeg jpeg jpg jpe
00040 image/png png
00041 image/svg+xml image/svg svg
00042 image/tiff tiff tif
00043 image/vnd.djvu image/x.djvu image/x-djvu djvu
00044 image/x-portable-pixmap ppm
00045 image/x-xcf xcf
00046 text/plain txt
00047 text/html html htm
00048 video/ogg ogm ogg ogv
00049 video/mpeg mpg mpeg
00050 END_STRING
00051 );
00052
00058 define('MM_WELL_KNOWN_MIME_INFO', <<<END_STRING
00059 application/pdf [OFFICE]
00060 application/vnd.oasis.opendocument.chart [OFFICE]
00061 application/vnd.oasis.opendocument.chart-template [OFFICE]
00062 application/vnd.oasis.opendocument.formula [OFFICE]
00063 application/vnd.oasis.opendocument.formula-template [OFFICE]
00064 application/vnd.oasis.opendocument.graphics [OFFICE]
00065 application/vnd.oasis.opendocument.graphics-template [OFFICE]
00066 application/vnd.oasis.opendocument.image [OFFICE]
00067 application/vnd.oasis.opendocument.image-template [OFFICE]
00068 application/vnd.oasis.opendocument.presentation [OFFICE]
00069 application/vnd.oasis.opendocument.presentation-template [OFFICE]
00070 application/vnd.oasis.opendocument.spreadsheet [OFFICE]
00071 application/vnd.oasis.opendocument.spreadsheet-template [OFFICE]
00072 application/vnd.oasis.opendocument.text [OFFICE]
00073 application/vnd.oasis.opendocument.text-template [OFFICE]
00074 application/vnd.oasis.opendocument.text-master [OFFICE]
00075 application/vnd.oasis.opendocument.text-web [OFFICE]
00076 text/javascript application/x-javascript [EXECUTABLE]
00077 application/x-shockwave-flash [MULTIMEDIA]
00078 audio/midi [AUDIO]
00079 audio/x-aiff [AUDIO]
00080 audio/x-wav [AUDIO]
00081 audio/mp3 audio/mpeg [AUDIO]
00082 application/ogg audio/ogg video/ogg [MULTIMEDIA]
00083 image/x-bmp image/bmp [BITMAP]
00084 image/gif [BITMAP]
00085 image/jpeg [BITMAP]
00086 image/png [BITMAP]
00087 image/svg+xml [DRAWING]
00088 image/tiff [BITMAP]
00089 image/vnd.djvu [BITMAP]
00090 image/x-xcf [BITMAP]
00091 image/x-portable-pixmap [BITMAP]
00092 text/plain [TEXT]
00093 text/html [TEXT]
00094 video/ogg [VIDEO]
00095 video/mpeg [VIDEO]
00096 unknown/unknown application/octet-stream application/x-empty [UNKNOWN]
00097 END_STRING
00098 );
00099
00100 #note: because this file is possibly included by a function,
00101 #we need to access the global scope explicitely!
00102 global $wgLoadFileinfoExtension;
00103
00104 if ($wgLoadFileinfoExtension) {
00105 if(!extension_loaded('fileinfo')) dl('fileinfo.' . PHP_SHLIB_SUFFIX);
00106 }
00107
00115 class MimeMagic {
00116
00121 var $mMediaTypes= null;
00122
00125 var $mMimeTypeAliases= null;
00126
00129 var $mMimeToExt= null;
00130
00133 var $mExtToMime= null;
00134
00137 var $mIEAnalyzer;
00138
00141 private static $instance;
00142
00147 function __construct() {
00148
00149
00150
00151
00152 global $wgMimeTypeFile, $IP;
00153
00154 $types = MM_WELL_KNOWN_MIME_TYPES;
00155
00156 if ( $wgMimeTypeFile == 'includes/mime.types' ) {
00157 $wgMimeTypeFile = "$IP/$wgMimeTypeFile";
00158 }
00159
00160 if ( $wgMimeTypeFile ) {
00161 if ( is_file( $wgMimeTypeFile ) and is_readable( $wgMimeTypeFile ) ) {
00162 wfDebug( __METHOD__.": loading mime types from $wgMimeTypeFile\n" );
00163 $types .= "\n";
00164 $types .= file_get_contents( $wgMimeTypeFile );
00165 } else {
00166 wfDebug( __METHOD__.": can't load mime types from $wgMimeTypeFile\n" );
00167 }
00168 } else {
00169 wfDebug( __METHOD__.": no mime types file defined, using build-ins only.\n" );
00170 }
00171
00172 $types = str_replace( array( "\r\n", "\n\r", "\n\n", "\r\r", "\r" ), "\n", $types );
00173 $types = str_replace( "\t", " ", $types );
00174
00175 $this->mMimeToExt = array();
00176 $this->mToMime = array();
00177
00178 $lines = explode( "\n",$types );
00179 foreach ( $lines as $s ) {
00180 $s = trim( $s );
00181 if ( empty( $s ) ) continue;
00182 if ( strpos( $s, '#' ) === 0 ) continue;
00183
00184 $s = strtolower( $s );
00185 $i = strpos( $s, ' ' );
00186
00187 if ( $i === false ) continue;
00188
00189 #print "processing MIME line $s<br>";
00190
00191 $mime = substr( $s, 0, $i );
00192 $ext = trim( substr($s, $i+1 ) );
00193
00194 if ( empty( $ext ) ) continue;
00195
00196 if ( !empty( $this->mMimeToExt[$mime] ) ) {
00197 $this->mMimeToExt[$mime] .= ' ' . $ext;
00198 } else {
00199 $this->mMimeToExt[$mime] = $ext;
00200 }
00201
00202 $extensions = explode( ' ', $ext );
00203
00204 foreach ( $extensions as $e ) {
00205 $e = trim( $e );
00206 if ( empty( $e ) ) continue;
00207
00208 if ( !empty( $this->mExtToMime[$e] ) ) {
00209 $this->mExtToMime[$e] .= ' ' . $mime;
00210 } else {
00211 $this->mExtToMime[$e] = $mime;
00212 }
00213 }
00214 }
00215
00216
00217
00218
00219
00220 global $wgMimeInfoFile;
00221 if ( $wgMimeInfoFile == 'includes/mime.info' ) {
00222 $wgMimeInfoFile = "$IP/$wgMimeInfoFile";
00223 }
00224
00225 $info = MM_WELL_KNOWN_MIME_INFO;
00226
00227 if ( $wgMimeInfoFile ) {
00228 if ( is_file( $wgMimeInfoFile ) and is_readable( $wgMimeInfoFile ) ) {
00229 wfDebug( __METHOD__.": loading mime info from $wgMimeInfoFile\n" );
00230 $info .= "\n";
00231 $info .= file_get_contents( $wgMimeInfoFile );
00232 } else {
00233 wfDebug(__METHOD__.": can't load mime info from $wgMimeInfoFile\n");
00234 }
00235 } else {
00236 wfDebug(__METHOD__.": no mime info file defined, using build-ins only.\n");
00237 }
00238
00239 $info = str_replace( array( "\r\n", "\n\r", "\n\n", "\r\r", "\r" ), "\n", $info);
00240 $info = str_replace( "\t", " ", $info );
00241
00242 $this->mMimeTypeAliases = array();
00243 $this->mMediaTypes = array();
00244
00245 $lines = explode( "\n", $info );
00246 foreach ( $lines as $s ) {
00247 $s = trim( $s );
00248 if ( empty( $s ) ) continue;
00249 if ( strpos( $s, '#' ) === 0 ) continue;
00250
00251 $s = strtolower( $s );
00252 $i = strpos( $s, ' ' );
00253
00254 if ( $i === false ) continue;
00255
00256 #print "processing MIME INFO line $s<br>";
00257
00258 $match = array();
00259 if ( preg_match( '!\[\s*(\w+)\s*\]!', $s, $match ) ) {
00260 $s = preg_replace( '!\[\s*(\w+)\s*\]!', '', $s );
00261 $mtype = trim( strtoupper( $match[1] ) );
00262 } else {
00263 $mtype = MEDIATYPE_UNKNOWN;
00264 }
00265
00266 $m = explode( ' ', $s );
00267
00268 if ( !isset( $this->mMediaTypes[$mtype] ) ) {
00269 $this->mMediaTypes[$mtype] = array();
00270 }
00271
00272 foreach ( $m as $mime ) {
00273 $mime = trim( $mime );
00274 if ( empty( $mime ) ) continue;
00275
00276 $this->mMediaTypes[$mtype][] = $mime;
00277 }
00278
00279 if ( sizeof( $m ) > 1 ) {
00280 $main = $m[0];
00281 for ( $i=1; $i<sizeof($m); $i += 1 ) {
00282 $mime = $m[$i];
00283 $this->mMimeTypeAliases[$mime] = $main;
00284 }
00285 }
00286 }
00287
00288 }
00289
00293 static function &singleton() {
00294 if ( !isset( self::$instance ) ) {
00295 self::$instance = new MimeMagic;
00296 }
00297 return self::$instance;
00298 }
00299
00303 function getExtensionsForType( $mime ) {
00304 $mime = strtolower( $mime );
00305
00306 $r = @$this->mMimeToExt[$mime];
00307
00308 if ( @!$r and isset( $this->mMimeTypeAliases[$mime] ) ) {
00309 $mime = $this->mMimeTypeAliases[$mime];
00310 $r = @$this->mMimeToExt[$mime];
00311 }
00312
00313 return $r;
00314 }
00315
00319 function getTypesForExtension( $ext ) {
00320 $ext = strtolower( $ext );
00321
00322 $r = isset( $this->mExtToMime[$ext] ) ? $this->mExtToMime[$ext] : null;
00323 return $r;
00324 }
00325
00329 function guessTypesForExtension( $ext ) {
00330 $m = $this->getTypesForExtension( $ext );
00331 if ( is_null( $m ) ) return null;
00332
00333 $m = trim( $m );
00334 $m = preg_replace( '/\s.*$/', '', $m );
00335
00336 return $m;
00337 }
00338
00339
00344 function isMatchingExtension( $extension, $mime ) {
00345 $ext = $this->getExtensionsForType( $mime );
00346
00347 if ( !$ext ) {
00348 return null;
00349 }
00350
00351 $ext = explode( ' ', $ext );
00352
00353 $extension = strtolower( $extension );
00354 if ( in_array( $extension, $ext ) ) {
00355 return true;
00356 }
00357
00358 return false;
00359 }
00360
00364 function isPHPImageType( $mime ) {
00365 #as defined by imagegetsize and image_type_to_mime
00366 static $types = array(
00367 'image/gif', 'image/jpeg', 'image/png',
00368 'image/x-bmp', 'image/xbm', 'image/tiff',
00369 'image/jp2', 'image/jpeg2000', 'image/iff',
00370 'image/xbm', 'image/x-xbitmap',
00371 'image/vnd.wap.wbmp', 'image/vnd.xiff',
00372 'image/x-photoshop',
00373 'application/x-shockwave-flash',
00374 );
00375
00376 return in_array( $mime, $types );
00377 }
00378
00390 function isRecognizableExtension( $extension ) {
00391 static $types = array(
00392
00393 'gif', 'jpeg', 'jpg', 'png', 'swf', 'psd',
00394 'bmp', 'tiff', 'tif', 'jpc', 'jp2',
00395 'jpx', 'jb2', 'swc', 'iff', 'wbmp',
00396 'xbm',
00397
00398
00399 'djvu', 'ogg', 'ogv', 'mid', 'pdf', 'wmf', 'xcf',
00400
00401
00402 'svg',
00403 );
00404 return in_array( strtolower( $extension ), $types );
00405 }
00406
00407
00418 function guessMimeType( $file, $ext = true ) {
00419 $mime = $this->doGuessMimeType( $file, $ext );
00420
00421 if( !$mime ) {
00422 wfDebug( __METHOD__.": internal type detection failed for $file (.$ext)...\n" );
00423 $mime = $this->detectMimeType( $file, $ext );
00424 }
00425
00426 if ( isset( $this->mMimeTypeAliases[$mime] ) ) {
00427 $mime = $this->mMimeTypeAliases[$mime];
00428 }
00429
00430 wfDebug(__METHOD__.": final mime type of $file: $mime\n");
00431 return $mime;
00432 }
00433
00434 function doGuessMimeType( $file, $ext = true ) {
00435
00436 wfSuppressWarnings();
00437 $f = fopen( $file, "rt" );
00438 wfRestoreWarnings();
00439 if( !$f ) return "unknown/unknown";
00440 $head = fread( $f, 1024 );
00441 fseek( $f, -65558, SEEK_END );
00442 $tail = fread( $f, 65558 );
00443 fclose( $f );
00444
00445
00446 $headers = array(
00447
00448 'MThd' => 'audio/midi',
00449 'OggS' => 'application/ogg',
00450
00451
00452
00453 "\x01\x00\x09\x00" => 'application/x-msmetafile',
00454 "\xd7\xcd\xc6\x9a" => 'application/x-msmetafile',
00455 '%PDF' => 'application/pdf',
00456 'gimp xcf' => 'image/x-xcf',
00457
00458
00459 'MZ' => 'application/octet-stream',
00460 "\xca\xfe\xba\xbe" => 'application/octet-stream',
00461 "\x7fELF" => 'application/octet-stream',
00462 );
00463
00464 foreach( $headers as $magic => $candidate ) {
00465 if( strncmp( $head, $magic, strlen( $magic ) ) == 0 ) {
00466 wfDebug( __METHOD__ . ": magic header in $file recognized as $candidate\n" );
00467 return $candidate;
00468 }
00469 }
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483 if( ( strpos( $head, '<?php' ) !== false ) ||
00484
00485 ( strpos( $head, "<\x00?\x00p\x00h\x00p" ) !== false ) ||
00486 ( strpos( $head, "<\x00?\x00 " ) !== false ) ||
00487 ( strpos( $head, "<\x00?\x00\n" ) !== false ) ||
00488 ( strpos( $head, "<\x00?\x00\t" ) !== false ) ||
00489 ( strpos( $head, "<\x00?\x00=" ) !== false ) ) {
00490
00491 wfDebug( __METHOD__ . ": recognized $file as application/x-php\n" );
00492 return "application/x-php";
00493 }
00494
00495
00496
00497
00498 $xml = new XmlTypeCheck( $file );
00499 if( $xml->wellFormed ) {
00500 global $wgXMLMimeTypes;
00501 if( isset( $wgXMLMimeTypes[$xml->getRootElement()] ) ) {
00502 return $wgXMLMimeTypes[$xml->getRootElement()];
00503 } else {
00504 return 'application/xml';
00505 }
00506 }
00507
00508
00509
00510
00511 $script_type = null;
00512
00513 # detect by shebang
00514 if ( substr( $head, 0, 2) == "#!" ) {
00515 $script_type = "ASCII";
00516 } elseif ( substr( $head, 0, 5) == "\xef\xbb\xbf#!" ) {
00517 $script_type = "UTF-8";
00518 } elseif ( substr( $head, 0, 7) == "\xfe\xff\x00#\x00!" ) {
00519 $script_type = "UTF-16BE";
00520 } elseif ( substr( $head, 0, 7 ) == "\xff\xfe#\x00!" ) {
00521 $script_type= "UTF-16LE";
00522 }
00523
00524 if ( $script_type ) {
00525 if ( $script_type !== "UTF-8" && $script_type !== "ASCII") {
00526
00527 $pack = array( 'UTF-16BE' => 'n*', 'UTF-16LE' => 'v*' );
00528 $chars = unpack( $pack[$script_type], substr( $head, 2 ) );
00529 $head = '';
00530 foreach( $chars as $codepoint ) {
00531 if( $codepoint < 128 ) {
00532 $head .= chr( $codepoint );
00533 } else {
00534 $head .= '?';
00535 }
00536 }
00537 }
00538
00539 $match = array();
00540
00541 if ( preg_match( '%/?([^\s]+/)(\w+)%', $head, $match ) ) {
00542 $mime = "application/x-{$match[2]}";
00543 wfDebug( __METHOD__.": shell script recognized as $mime\n" );
00544 return $mime;
00545 }
00546 }
00547
00548
00549 if ( strpos( $tail, "PK\x05\x06" ) !== false ) {
00550 wfDebug( __METHOD__.": ZIP header present at end of $file\n" );
00551 return $this->detectZipType( $head );
00552 }
00553
00554 wfSuppressWarnings();
00555 $gis = getimagesize( $file );
00556 wfRestoreWarnings();
00557
00558 if( $gis && isset( $gis['mime'] ) ) {
00559 $mime = $gis['mime'];
00560 wfDebug( __METHOD__.": getimagesize detected $file as $mime\n" );
00561 return $mime;
00562 }
00563
00564
00565 $deja = new DjVuImage( $file );
00566 if( $deja->isValid() ) {
00567 wfDebug( __METHOD__.": detected $file as image/vnd.djvu\n" );
00568 return 'image/vnd.djvu';
00569 }
00570
00571 return false;
00572 }
00573
00582 function detectZipType( $header ) {
00583 $opendocTypes = array(
00584 'chart-template',
00585 'chart',
00586 'formula-template',
00587 'formula',
00588 'graphics-template',
00589 'graphics',
00590 'image-template',
00591 'image',
00592 'presentation-template',
00593 'presentation',
00594 'spreadsheet-template',
00595 'spreadsheet',
00596 'text-template',
00597 'text-master',
00598 'text-web',
00599 'text' );
00600
00601
00602 $types = '(?:' . implode( '|', $opendocTypes ) . ')';
00603 $opendocRegex = "/^mimetype(application\/vnd\.oasis\.opendocument\.$types)/";
00604 wfDebug( __METHOD__.": $opendocRegex\n" );
00605
00606 if( preg_match( $opendocRegex, substr( $header, 30 ), $matches ) ) {
00607 $mime = $matches[1];
00608 wfDebug( __METHOD__.": detected $mime from ZIP archive\n" );
00609 return $mime;
00610 } else {
00611 wfDebug( __METHOD__.": unable to identify type of ZIP archive\n" );
00612 return 'application/zip';
00613 }
00614 }
00615
00631 function detectMimeType( $file, $ext = true ) {
00632 global $wgMimeDetectorCommand;
00633
00634 $m = null;
00635 if ( $wgMimeDetectorCommand ) {
00636 $fn = wfEscapeShellArg( $file );
00637 $m = `$wgMimeDetectorCommand $fn`;
00638 } elseif ( function_exists( "finfo_open" ) && function_exists( "finfo_file" ) ) {
00639
00640 # This required the fileinfo extension by PECL,
00641 # see http://pecl.php.net/package/fileinfo
00642 # This must be compiled into PHP
00643 #
00644 # finfo is the official replacement for the deprecated
00645 # mime_content_type function, see below.
00646 #
00647 # If you may need to load the fileinfo extension at runtime, set
00648 # $wgLoadFileinfoExtension in LocalSettings.php
00649
00650 $mime_magic_resource = finfo_open(FILEINFO_MIME);
00651
00652 if ($mime_magic_resource) {
00653 $m = finfo_file( $mime_magic_resource, $file );
00654 finfo_close( $mime_magic_resource );
00655 } else {
00656 wfDebug( __METHOD__.": finfo_open failed on ".FILEINFO_MIME."!\n" );
00657 }
00658 } elseif ( function_exists( "mime_content_type" ) ) {
00659
00660 # NOTE: this function is available since PHP 4.3.0, but only if
00661 # PHP was compiled with --with-mime-magic or, before 4.3.2, with --enable-mime-magic.
00662 #
00663 # On Windows, you must set mime_magic.magicfile in php.ini to point to the mime.magic file bundeled with PHP;
00664 # sometimes, this may even be needed under linus/unix.
00665 #
00666 # Also note that this has been DEPRECATED in favor of the fileinfo extension by PECL, see above.
00667 # see http://www.php.net/manual/en/ref.mime-magic.php for details.
00668
00669 $m = mime_content_type($file);
00670 } else {
00671 wfDebug( __METHOD__.": no magic mime detector found!\n" );
00672 }
00673
00674 if ( $m ) {
00675 # normalize
00676 $m = preg_replace( '![;, ].*$!', '', $m ); #strip charset, etc
00677 $m = trim( $m );
00678 $m = strtolower( $m );
00679
00680 if ( strpos( $m, 'unknown' ) !== false ) {
00681 $m = null;
00682 } else {
00683 wfDebug( __METHOD__.": magic mime type of $file: $m\n" );
00684 return $m;
00685 }
00686 }
00687
00688 # if desired, look at extension as a fallback.
00689 if ( $ext === true ) {
00690 $i = strrpos( $file, '.' );
00691 $ext = strtolower( $i ? substr( $file, $i + 1 ) : '' );
00692 }
00693 if ( $ext ) {
00694 if( $this->isRecognizableExtension( $ext ) ) {
00695 wfDebug( __METHOD__. ": refusing to guess mime type for .$ext file, we should have recognized it\n" );
00696 } else {
00697 $m = $this->guessTypesForExtension( $ext );
00698 if ( $m ) {
00699 wfDebug( __METHOD__.": extension mime type of $file: $m\n" );
00700 return $m;
00701 }
00702 }
00703 }
00704
00705 #unknown type
00706 wfDebug( __METHOD__.": failed to guess mime type for $file!\n" );
00707 return "unknown/unknown";
00708 }
00709
00726 function getMediaType( $path = null, $mime = null ) {
00727 if( !$mime && !$path ) return MEDIATYPE_UNKNOWN;
00728
00729 # If mime type is unknown, guess it
00730 if( !$mime ) $mime = $this->guessMimeType( $path, false );
00731
00732 # Special code for ogg - detect if it's video (theora),
00733 # else label it as sound.
00734 if( $mime == "application/ogg" && file_exists( $path ) ) {
00735
00736
00737 $f = fopen( $path, "rt" );
00738 if ( !$f ) return MEDIATYPE_UNKNOWN;
00739 $head = fread( $f, 256 );
00740 fclose( $f );
00741
00742 $head = strtolower( $head );
00743
00744 # This is an UGLY HACK, file should be parsed correctly
00745 if ( strpos( $head, 'theora' ) !== false ) return MEDIATYPE_VIDEO;
00746 elseif ( strpos( $head, 'vorbis' ) !== false ) return MEDIATYPE_AUDIO;
00747 elseif ( strpos( $head, 'flac' ) !== false ) return MEDIATYPE_AUDIO;
00748 elseif ( strpos( $head, 'speex' ) !== false ) return MEDIATYPE_AUDIO;
00749 else return MEDIATYPE_MULTIMEDIA;
00750 }
00751
00752 # check for entry for full mime type
00753 if( $mime ) {
00754 $type = $this->findMediaType( $mime );
00755 if( $type !== MEDIATYPE_UNKNOWN ) return $type;
00756 }
00757
00758 # Check for entry for file extension
00759 $e = null;
00760 if ( $path ) {
00761 $i = strrpos( $path, '.' );
00762 $e = strtolower( $i ? substr( $path, $i + 1 ) : '' );
00763
00764 # TODO: look at multi-extension if this fails, parse from full path
00765
00766 $type = $this->findMediaType( '.' . $e );
00767 if ( $type !== MEDIATYPE_UNKNOWN ) return $type;
00768 }
00769
00770 # Check major mime type
00771 if( $mime ) {
00772 $i = strpos( $mime, '/' );
00773 if( $i !== false ) {
00774 $major = substr( $mime, 0, $i );
00775 $type = $this->findMediaType( $major );
00776 if( $type !== MEDIATYPE_UNKNOWN ) return $type;
00777 }
00778 }
00779
00780 if( !$type ) $type = MEDIATYPE_UNKNOWN;
00781
00782 return $type;
00783 }
00784
00792 function findMediaType( $extMime ) {
00793 if ( strpos( $extMime, '.' ) === 0 ) { #if it's an extension, look up the mime types
00794 $m = $this->getTypesForExtension( substr( $extMime, 1 ) );
00795 if ( !$m ) return MEDIATYPE_UNKNOWN;
00796
00797 $m = explode( ' ', $m );
00798 } else {
00799 # Normalize mime type
00800 if ( isset( $this->mMimeTypeAliases[$extMime] ) ) {
00801 $extMime = $this->mMimeTypeAliases[$extMime];
00802 }
00803
00804 $m = array($extMime);
00805 }
00806
00807 foreach ( $m as $mime ) {
00808 foreach ( $this->mMediaTypes as $type => $codes ) {
00809 if ( in_array($mime, $codes, true ) ) {
00810 return $type;
00811 }
00812 }
00813 }
00814
00815 return MEDIATYPE_UNKNOWN;
00816 }
00817
00826 public function getIEMimeTypes( $fileName, $chunk, $proposed ) {
00827 $ca = $this->getIEContentAnalyzer();
00828 return $ca->getRealMimesFromData( $fileName, $chunk, $proposed );
00829 }
00830
00834 protected function getIEContentAnalyzer() {
00835 if ( is_null( $this->mIEAnalyzer ) ) {
00836 $this->mIEAnalyzer = new IEContentAnalyzer;
00837 }
00838 return $this->mIEAnalyzer;
00839 }
00840 }