X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMimeMagic.php;h=24d803b39e31565adf697a3d02fbabe51ebcaff9;hb=f7c5ef1307141bdd9bdcc96496fd61ab269e65be;hp=68b6f6a011fde9b17560317df8afe0ddeca4d964;hpb=fac1ec45f1201c913f4dc1dc7a2a31d21f77993c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php index 68b6f6a011..24d803b39e 100644 --- a/includes/MimeMagic.php +++ b/includes/MimeMagic.php @@ -39,7 +39,7 @@ * appending MM_WELL_KNOWN_MIME_TYPES behind $wgMimeTypeFile, but who knows * what will break? In practice this probably isn't a problem anyway -- Bryan) */ -define('MM_WELL_KNOWN_MIME_TYPES', <<doGuessMimeType( $file, $ext ); - if( !$mime ) { + if ( !$mime ) { wfDebug( __METHOD__ . ": internal type detection failed for $file (.$ext)...\n" ); $mime = $this->detectMimeType( $file, $ext ); } @@ -587,7 +587,7 @@ class MimeMagic { $f = fopen( $file, 'rt' ); wfRestoreWarnings(); - if( !$f ) { + if ( !$f ) { return 'unknown/unknown'; } $head = fread( $f, 1024 ); @@ -628,7 +628,7 @@ class MimeMagic { $doctype = strpos( $head, "\x42\x82" ); if ( $doctype ) { // Next byte is datasize, then data (sizes larger than 1 byte are very stupid muxers) - $data = substr( $head, $doctype+3, 8 ); + $data = substr( $head, $doctype + 3, 8 ); if ( strncmp( $data, "matroska", 8 ) == 0 ) { wfDebug( __METHOD__ . ": recognized file as video/x-matroska\n" ); return "video/x-matroska"; @@ -689,11 +689,11 @@ class MimeMagic { $script_type = null; # detect by shebang - if ( substr( $head, 0, 2) == "#!" ) { + if ( substr( $head, 0, 2 ) == "#!" ) { $script_type = "ASCII"; - } elseif ( substr( $head, 0, 5) == "\xef\xbb\xbf#!" ) { + } elseif ( substr( $head, 0, 5 ) == "\xef\xbb\xbf#!" ) { $script_type = "UTF-8"; - } elseif ( substr( $head, 0, 7) == "\xfe\xff\x00#\x00!" ) { + } elseif ( substr( $head, 0, 7 ) == "\xfe\xff\x00#\x00!" ) { $script_type = "UTF-16BE"; } elseif ( substr( $head, 0, 7 ) == "\xff\xfe#\x00!" ) { $script_type = "UTF-16LE"; @@ -705,8 +705,8 @@ class MimeMagic { $pack = array( 'UTF-16BE' => 'n*', 'UTF-16LE' => 'v*' ); $chars = unpack( $pack[$script_type], substr( $head, 2 ) ); $head = ''; - foreach( $chars as $codepoint ) { - if( $codepoint < 128 ) { + foreach ( $chars as $codepoint ) { + if ( $codepoint < 128 ) { $head .= chr( $codepoint ); } else { $head .= '?'; @@ -733,7 +733,7 @@ class MimeMagic { $gis = getimagesize( $file ); wfRestoreWarnings(); - if( $gis && isset( $gis['mime'] ) ) { + if ( $gis && isset( $gis['mime'] ) ) { $mime = $gis['mime']; wfDebug( __METHOD__ . ": getimagesize detected $file as $mime\n" ); return $mime; @@ -741,7 +741,7 @@ class MimeMagic { // Also test DjVu $deja = new DjVuImage( $file ); - if( $deja->isValid() ) { + if ( $deja->isValid() ) { wfDebug( __METHOD__ . ": detected $file as image/vnd.djvu\n" ); return 'image/vnd.djvu'; } @@ -763,7 +763,7 @@ class MimeMagic { * @return string */ function detectZipType( $header, $tail = null, $ext = false ) { - if( $ext ) { # TODO: remove $ext param + if ( $ext ) { # TODO: remove $ext param wfDebug( __METHOD__ . ": WARNING: use of the \$ext parameter is deprecated. " . "Use improveTypeFromExtension(\$mime, \$ext) instead.\n" ); } @@ -804,7 +804,7 @@ class MimeMagic { * These mime's are stored in the database, where we don't really want * x-opc+zip, because we use it only for internal purposes */ - if ( $this->isMatchingExtension( $ext, $mime) ) { + if ( $this->isMatchingExtension( $ext, $mime ) ) { /* A known file extension for an OPC file, * find the proper mime type for that file extension */ @@ -817,10 +817,10 @@ class MimeMagic { } elseif ( substr( $header, 0, 8 ) == "\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1" && ($headerpos = strpos( $tail, "PK\x03\x04" ) ) !== false && preg_match( $openxmlRegex, substr( $tail, $headerpos + 30 ) ) ) { - if ( substr( $header, 512, 4) == "\xEC\xA5\xC1\x00" ) { + if ( substr( $header, 512, 4 ) == "\xEC\xA5\xC1\x00" ) { $mime = "application/msword"; } - switch( substr( $header, 512, 6) ) { + switch( substr( $header, 512, 6 ) ) { case "\xEC\xA5\xC1\x00\x0E\x00": case "\xEC\xA5\xC1\x00\x1C\x00": case "\xEC\xA5\xC1\x00\x43\x00": @@ -853,7 +853,7 @@ class MimeMagic { * Internal mime type detection. 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 + * are available. If the detections 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 @@ -897,14 +897,14 @@ class MimeMagic { $m = finfo_file( $mime_magic_resource, $file ); finfo_close( $mime_magic_resource ); } else { - wfDebug( __METHOD__ . ": finfo_open failed on ".FILEINFO_MIME."!\n" ); + wfDebug( __METHOD__ . ": finfo_open failed on " . FILEINFO_MIME . "!\n" ); } } elseif ( function_exists( "mime_content_type" ) ) { # NOTE: this function is available since PHP 4.3.0, but only if # PHP was compiled with --with-mime-magic or, before 4.3.2, with --enable-mime-magic. # - # On Windows, you must set mime_magic.magicfile in php.ini to point to the mime.magic file bundeled with PHP; + # On Windows, you must set mime_magic.magicfile in php.ini to point to the mime.magic file bundled with PHP; # sometimes, this may even be needed under linus/unix. # # Also note that this has been DEPRECATED in favor of the fileinfo extension by PECL, see above. @@ -935,7 +935,7 @@ class MimeMagic { $ext = strtolower( $i ? substr( $file, $i + 1 ) : '' ); } if ( $ext ) { - if( $this->isRecognizableExtension( $ext ) ) { + if ( $this->isRecognizableExtension( $ext ) ) { wfDebug( __METHOD__ . ": refusing to guess mime type for .$ext file, we should have recognized it\n" ); } else { $m = $this->guessTypesForExtension( $ext ); @@ -968,12 +968,12 @@ class MimeMagic { * @return (int?string?) a value to be used with the MEDIATYPE_xxx constants. */ function getMediaType( $path = null, $mime = null ) { - if( !$mime && !$path ) { + if ( !$mime && !$path ) { return MEDIATYPE_UNKNOWN; } // If mime type is unknown, guess it - if( !$mime ) { + if ( !$mime ) { $mime = $this->guessMimeType( $path, false ); } @@ -983,22 +983,30 @@ class MimeMagic { // Read a chunk of the file $f = fopen( $path, "rt" ); - if ( !$f ) return MEDIATYPE_UNKNOWN; + if ( !$f ) { + return MEDIATYPE_UNKNOWN; + } $head = fread( $f, 256 ); fclose( $f ); $head = strtolower( $head ); // This is an UGLY HACK, file should be parsed correctly - if ( strpos( $head, 'theora' ) !== false ) return MEDIATYPE_VIDEO; - elseif ( strpos( $head, 'vorbis' ) !== false ) return MEDIATYPE_AUDIO; - elseif ( strpos( $head, 'flac' ) !== false ) return MEDIATYPE_AUDIO; - elseif ( strpos( $head, 'speex' ) !== false ) return MEDIATYPE_AUDIO; - else return MEDIATYPE_MULTIMEDIA; + if ( strpos( $head, 'theora' ) !== false ) { + return MEDIATYPE_VIDEO; + } elseif ( strpos( $head, 'vorbis' ) !== false ) { + return MEDIATYPE_AUDIO; + } elseif ( strpos( $head, 'flac' ) !== false ) { + return MEDIATYPE_AUDIO; + } elseif ( strpos( $head, 'speex' ) !== false ) { + return MEDIATYPE_AUDIO; + } else { + return MEDIATYPE_MULTIMEDIA; + } } // Check for entry for full mime type - if( $mime ) { + if ( $mime ) { $type = $this->findMediaType( $mime ); if ( $type !== MEDIATYPE_UNKNOWN ) { return $type; @@ -1029,7 +1037,7 @@ class MimeMagic { } } - if( !$type ) { + if ( !$type ) { $type = MEDIATYPE_UNKNOWN; } @@ -1041,7 +1049,7 @@ class MimeMagic { * 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 + * This function relies on the mapping defined by $this->mMediaTypes * @access private * @return int|string */