$this->dieWithError( [ 'apierror-bad-badfilecontexttitle', $p ], 'invalid-title' );
}
} else {
- $badFileContextTitle = false;
+ $badFileContextTitle = null;
}
$pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
$vals = [
ApiResult::META_TYPE => 'assoc',
];
+
+ // Some information will be unavailable if the file does not exist. T221812
+ $exists = $file->exists();
+
// Timestamp is shown even if the file is revdelete'd in interface
// so do same here.
- if ( isset( $prop['timestamp'] ) ) {
+ if ( isset( $prop['timestamp'] ) && $exists ) {
$vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
}
$user = isset( $prop['user'] );
$userid = isset( $prop['userid'] );
- if ( $user || $userid ) {
+ if ( ( $user || $userid ) && $exists ) {
if ( $file->isDeleted( File::DELETED_USER ) ) {
$vals['userhidden'] = true;
$anyHidden = true;
// This is shown even if the file is revdelete'd in interface
// so do same here.
- if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) {
+ if ( ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) && $exists ) {
$vals['size'] = (int)$file->getSize();
$vals['width'] = (int)$file->getWidth();
$vals['height'] = (int)$file->getHeight();
$pcomment = isset( $prop['parsedcomment'] );
$comment = isset( $prop['comment'] );
- if ( $pcomment || $comment ) {
+ if ( ( $pcomment || $comment ) && $exists ) {
if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
$vals['commenthidden'] = true;
$anyHidden = true;
}
if ( $url ) {
- if ( $file->exists() ) {
+ if ( $exists ) {
if ( !is_null( $thumbParams ) ) {
$mto = $file->transform( $thumbParams );
self::$transformCount++;
$vals['thumbmime'] = $mime;
}
} elseif ( $mto && $mto->isError() ) {
+ /** @var MediaTransformError $mto */
+ '@phan-var MediaTransformError $mto';
$vals['thumberror'] = $mto->toText();
}
}
$vals['url'] = wfExpandUrl( $file->getFullUrl(), PROTO_CURRENT );
- } else {
- $vals['filemissing'] = true;
}
$vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
}
}
- if ( $sha1 ) {
+ if ( !$exists ) {
+ $vals['filemissing'] = true;
+ }
+
+ if ( $sha1 && $exists ) {
$vals['sha1'] = Wikimedia\base_convert( $file->getSha1(), 36, 16, 40 );
}
- if ( $meta ) {
+ if ( $meta && $exists ) {
Wikimedia\suppressWarnings();
$metadata = unserialize( $file->getMetadata() );
Wikimedia\restoreWarnings();
}
$vals['metadata'] = $metadata ? static::processMetaData( $metadata, $result ) : null;
}
- if ( $commonmeta ) {
+ if ( $commonmeta && $exists ) {
$metaArray = $file->getCommonMetaArray();
$vals['commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
}
- if ( $extmetadata ) {
+ if ( $extmetadata && $exists ) {
// Note, this should return an array where all the keys
// start with a letter, and all the values are strings.
// Thus there should be no issue with format=xml.
$format = new FormatMetadata;
$format->setSingleLanguage( !$opts['multilang'] );
+ // @phan-suppress-next-line PhanUndeclaredMethod
$format->getContext()->setLanguage( $opts['language'] );
$extmetaArray = $format->fetchExtendedMetadata( $file );
if ( $opts['extmetadatafilter'] ) {
$vals['extmetadata'] = $extmetaArray;
}
- if ( $mime ) {
+ if ( $mime && $exists ) {
$vals['mime'] = $file->getMimeType();
}
- if ( $mediatype ) {
+ if ( $mediatype && $exists ) {
$vals['mediatype'] = $file->getMediaType();
}
if ( $archive && $file->isOld() ) {
+ /** @var OldLocalFile $file */
+ '@phan-var OldLocalFile $file';
$vals['archivename'] = $file->getArchiveName();
}
- if ( $bitdepth ) {
+ if ( $bitdepth && $exists ) {
$vals['bitdepth'] = $file->getBitDepth();
}