26use InvalidArgumentException;
39 private const UNKNOWN_CONTENT_TYPE =
'unknown/unknown';
61 throw new InvalidArgumentException( __FUNCTION__ .
" given storage path '$fname'." );
67 'obResetFunc' =>
'wfResetOutputBuffers',
68 'streamMimeFunc' => [ __CLASS__,
'contentTypeFromPath' ],
69 'headerFunc' => [ __CLASS__,
'setHeader' ],
73 return $streamer->stream( $headers, $sendErrors, $optHeaders, $flags );
82 RequestContext::getMain()->getRequest()->response()->header(
$header );
99 $ext = strrchr( $filename,
'.' );
100 $ext = $ext ? strtolower( substr( $ext, 1 ) ) :
'';
102 # trivial detection by file extension,
103 # used for thumbnails (thumb.php)
104 if ( $trivialMimeDetection ) {
117 return self::UNKNOWN_CONTENT_TYPE;
124 $type = $magic->getMimeTypeFromExtensionOrNull( $ext );
138 [ , $extList ] = UploadBase::splitExtensions( $filename );
139 if ( UploadBase::checkFileExtensionList( $extList, $prohibitedFileExtensions ) ) {
140 return self::UNKNOWN_CONTENT_TYPE;
143 $checkFileExtensions &&
144 $strictFileExtensions &&
145 !UploadBase::checkFileExtensionList( $extList, $fileExtensions )
147 return self::UNKNOWN_CONTENT_TYPE;
149 if ( $verifyMimeType && $type !==
null && in_array( strtolower( $type ), $mimeTypeExclusions ) ) {
150 return self::UNKNOWN_CONTENT_TYPE;
158class_alias( StreamFile::class,
'StreamFile' );
Group all the pieces relevant to the context of a request into one instance.
A class containing constants representing the names of configuration variables.
const MimeTypeExclusions
Name constant for the MimeTypeExclusions setting, for use with Config::get()
const ProhibitedFileExtensions
Name constant for the ProhibitedFileExtensions setting, for use with Config::get()
const TrivialMimeDetection
Name constant for the TrivialMimeDetection setting, for use with Config::get()
const VerifyMimeType
Name constant for the VerifyMimeType setting, for use with Config::get()
const StrictFileExtensions
Name constant for the StrictFileExtensions setting, for use with Config::get()
const FileExtensions
Name constant for the FileExtensions setting, for use with Config::get()
const CheckFileExtensions
Name constant for the CheckFileExtensions setting, for use with Config::get()
UploadBase and subclasses are the backend of MediaWiki's file uploads.