12use Wikimedia\AtEase\AtEase;
13use Wikimedia\Timestamp\ConvertibleTimestamp;
14use Wikimedia\Timestamp\TimestampFormat as TS;
52 return is_file( $this->path );
61 AtEase::suppressWarnings();
62 $size = filesize( $this->path );
63 AtEase::restoreWarnings();
74 AtEase::suppressWarnings();
75 $timestamp = filemtime( $this->path );
76 AtEase::restoreWarnings();
77 if ( $timestamp !==
false ) {
78 $timestamp = ConvertibleTimestamp::convert( TS::MW, $timestamp );
103 $info[
'fileExists'] = $this->
exists();
105 if ( $info[
'fileExists'] ) {
106 $info[
'size'] = $this->
getSize();
109 $mime = mime_content_type( $this->path );
110 # MIME type according to file contents
111 $info[
'file-mime'] = ( $mime === false ) ?
'unknown/unknown' : $mime;
113 $info[
'mime'] = $mime;
115 if ( str_contains( $mime,
'/' ) ) {
116 [ $info[
'major_mime'], $info[
'minor_mime'] ] = explode(
'/', $mime, 2 );
118 [ $info[
'major_mime'], $info[
'minor_mime'] ] = [ $mime,
'unknown' ];
141 'fileExists' =>
false,
144 'major_mime' =>
null,
145 'minor_mime' =>
null,
162 if ( $this->sha1Base36 !==
null && !$recache ) {
166 AtEase::suppressWarnings();
167 $this->sha1Base36 = sha1_file( $this->path );
168 AtEase::restoreWarnings();
170 if ( $this->sha1Base36 !==
false ) {
171 $this->sha1Base36 = \Wikimedia\base_convert( $this->sha1Base36, 16, 36, 31 );
184 $i = strrpos(
$path,
'.' );
186 return strtolower( $i ? substr(
$path, $i + 1 ) :
'' );
198 $fsFile =
new self(
$path );
200 return $fsFile->getProps( $ext );
214 $fsFile =
new self(
$path );
216 return $fsFile->getSha1Base36();
221class_alias( FSFile::class,
'FSFile' );