12use Wikimedia\Timestamp\ConvertibleTimestamp;
13use Wikimedia\Timestamp\TimestampFormat as TS;
51 return is_file( $this->path );
61 return @filesize( $this->path );
71 $timestamp = @filemtime( $this->path );
72 if ( $timestamp !==
false ) {
73 $timestamp = ConvertibleTimestamp::convert( TS::MW, $timestamp );
98 $info[
'fileExists'] = $this->
exists();
100 if ( $info[
'fileExists'] ) {
101 $info[
'size'] = $this->
getSize();
104 $mime = mime_content_type( $this->path );
105 # MIME type according to file contents
106 $info[
'file-mime'] = ( $mime === false ) ?
'unknown/unknown' : $mime;
108 $info[
'mime'] = $mime;
110 if ( str_contains( $mime,
'/' ) ) {
111 [ $info[
'major_mime'], $info[
'minor_mime'] ] = explode(
'/', $mime, 2 );
113 [ $info[
'major_mime'], $info[
'minor_mime'] ] = [ $mime,
'unknown' ];
136 'fileExists' =>
false,
139 'major_mime' =>
null,
140 'minor_mime' =>
null,
157 if ( $this->sha1Base36 !==
null && !$recache ) {
162 $this->sha1Base36 = @sha1_file( $this->path );
164 if ( $this->sha1Base36 !==
false ) {
165 $this->sha1Base36 = \Wikimedia\base_convert( $this->sha1Base36, 16, 36, 31 );
178 $i = strrpos(
$path,
'.' );
180 return strtolower( $i ? substr(
$path, $i + 1 ) :
'' );
192 $fsFile =
new self(
$path );
194 return $fsFile->getProps( $ext );
208 $fsFile =
new self(
$path );
210 return $fsFile->getSha1Base36();
215class_alias( FSFile::class,
'FSFile' );