X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FMimeMagic.php;h=44fafcaf15a1dd874b318c7be3997123b1b18a1b;hb=59404fb12ee50a52925709a389f9c263f3e332a2;hp=11fc5741476394c292fc46d7c170b4ac6b766488;hpb=15abcf71ca7ec185b475e47ef0fe43884e764239;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php index 11fc574147..44fafcaf15 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 ); @@ -642,7 +642,7 @@ class MimeMagic { } /* Look for WebP */ - if ( strncmp( $head, "RIFF", 4 ) == 0 && strncmp( substr( $head, 8, 8), "WEBPVP8 ", 8 ) == 0 ) { + if ( strncmp( $head, "RIFF", 4 ) == 0 && strncmp( substr( $head, 8, 8 ), "WEBPVP8 ", 8 ) == 0 ) { wfDebug( __METHOD__ . ": recognized file as image/webp\n" ); return "image/webp"; } @@ -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" ); } @@ -815,12 +815,12 @@ class MimeMagic { } wfDebug( __METHOD__ . ": detected an Open Packaging Conventions archive: $mime\n" ); } elseif ( substr( $header, 0, 8 ) == "\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1" && - ($headerpos = strpos( $tail, "PK\x03\x04" ) ) !== false && + ( $headerpos = strpos( $tail, "PK\x03\x04" ) ) !== false && preg_match( $openxmlRegex, substr( $tail, $headerpos + 30 ) ) ) { 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": @@ -876,9 +876,8 @@ class MimeMagic { $m = null; if ( $wgMimeDetectorCommand ) { - // @todo FIXME: Use wfShellExec - $fn = wfEscapeShellArg( $file ); - $m = `$wgMimeDetectorCommand $fn`; + $args = wfEscapeShellArg( $file ); + $m = wfShellExec( "$wgMimeDetectorCommand $args" ); } elseif ( function_exists( "finfo_open" ) && function_exists( "finfo_file" ) ) { # This required the fileinfo extension by PECL, @@ -935,7 +934,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 +967,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 +982,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 +1036,7 @@ class MimeMagic { } } - if( !$type ) { + if ( !$type ) { $type = MEDIATYPE_UNKNOWN; }