'wfResetOutputBuffers', 'streamMimeFunc' => [ __CLASS__, 'contentTypeFromPath' ] ] ); return $streamer->stream( $headers, $sendErrors, $optHeaders, $flags ); } /** * Send out a standard 404 message for a file * * @param string $fname Full name and path of the file to stream * @param int $flags Bitfield of STREAM_* constants * @since 1.24 */ public static function send404Message( $fname, $flags = 0 ) { HTTPFileStreamer::send404Message( $fname, $flags ); } /** * Convert a Range header value to an absolute (start, end) range tuple * * @param string $range Range header value * @param int $size File size * @return array|string Returns error string on failure (start, end, length) * @since 1.24 */ public static function parseRange( $range, $size ) { return HTTPFileStreamer::parseRange( $range, $size ); } /** * Determine the file type of a file based on the path * * @param string $filename Storage path or file system path * @param bool $safe Whether to do retroactive upload blacklist checks * @return null|string */ public static function contentTypeFromPath( $filename, $safe = true ) { global $wgTrivialMimeDetection; $ext = strrchr( $filename, '.' ); $ext = $ext === false ? '' : strtolower( substr( $ext, 1 ) ); # trivial detection by file extension, # used for thumbnails (thumb.php) if ( $wgTrivialMimeDetection ) { switch ( $ext ) { case 'gif': return 'image/gif'; case 'png': return 'image/png'; case 'jpg': return 'image/jpeg'; case 'jpeg': return 'image/jpeg'; } return 'unknown/unknown'; } $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); // Use the extension only, rather than magic numbers, to avoid opening // up vulnerabilities due to uploads of files with allowed extensions // but disallowed types. $type = $magic->guessTypesForExtension( $ext ); /** * Double-check some security settings that were done on upload but might * have changed since. */ if ( $safe ) { global $wgFileBlacklist, $wgCheckFileExtensions, $wgStrictFileExtensions, $wgFileExtensions, $wgVerifyMimeType, $wgMimeTypeBlacklist; list( , $extList ) = UploadBase::splitExtensions( $filename ); if ( UploadBase::checkFileExtensionList( $extList, $wgFileBlacklist ) ) { return 'unknown/unknown'; } if ( $wgCheckFileExtensions && $wgStrictFileExtensions && !UploadBase::checkFileExtensionList( $extList, $wgFileExtensions ) ) { return 'unknown/unknown'; } if ( $wgVerifyMimeType && in_array( strtolower( $type ), $wgMimeTypeBlacklist ) ) { return 'unknown/unknown'; } } return $type; } }