26use Wikimedia\AtEase\AtEase;
27use Wikimedia\Timestamp\ConvertibleTimestamp;
65 return is_file( $this->path );
74 AtEase::suppressWarnings();
75 $size = filesize( $this->path );
76 AtEase::restoreWarnings();
87 AtEase::suppressWarnings();
88 $timestamp = filemtime( $this->path );
89 AtEase::restoreWarnings();
90 if ( $timestamp !==
false ) {
91 $timestamp = ConvertibleTimestamp::convert( TS_MW, $timestamp );
116 $info[
'fileExists'] = $this->
exists();
118 if ( $info[
'fileExists'] ) {
119 $info[
'size'] = $this->
getSize();
122 $mime = mime_content_type( $this->path );
123 # MIME type according to file contents
124 $info[
'file-mime'] = ( $mime === false ) ?
'unknown/unknown' : $mime;
126 $info[
'mime'] = $mime;
128 if ( strpos( $mime,
'/' ) !==
false ) {
129 [ $info[
'major_mime'], $info[
'minor_mime'] ] = explode(
'/', $mime, 2 );
131 [ $info[
'major_mime'], $info[
'minor_mime'] ] = [ $mime,
'unknown' ];
154 $info[
'fileExists'] =
false;
156 $info[
'file-mime'] =
null;
157 $info[
'major_mime'] =
null;
158 $info[
'minor_mime'] =
null;
159 $info[
'mime'] =
null;
176 if ( $this->sha1Base36 !==
null && !$recache ) {
180 AtEase::suppressWarnings();
181 $this->sha1Base36 = sha1_file( $this->path );
182 AtEase::restoreWarnings();
184 if ( $this->sha1Base36 !==
false ) {
185 $this->sha1Base36 = \Wikimedia\base_convert( $this->sha1Base36, 16, 36, 31 );
198 $i = strrpos(
$path,
'.' );
200 return strtolower( $i ? substr(
$path, $i + 1 ) :
'' );
212 $fsFile =
new self(
$path );
214 return $fsFile->getProps( $ext );
228 $fsFile =
new self(
$path );
230 return $fsFile->getSha1Base36();
235class_alias( FSFile::class,
'FSFile' );