17use Wikimedia\Timestamp\TimestampFormat as TS;
43 $this->mExists = $exists;
54 $data =
$repo->fetchImageQuery( [
56 'iiprop' => self::getProps(),
57 'prop' =>
'imageinfo',
58 'iimetadataversion' => MediaHandler::getMetadataVersion(),
61 'iiextmetadatamultilang' => 1,
64 $info =
$repo->getImageInfo( $data );
67 $lastRedirect = count( $data[
'query'][
'redirects'] ?? [] ) - 1;
68 if ( $lastRedirect >= 0 ) {
70 $newtitle = Title::newFromText( $data[
'query'][
'redirects'][$lastRedirect][
'to'] );
71 $img =
new self( $newtitle,
$repo, $info, true );
88 return 'timestamp|user|comment|url|size|sha1|metadata|mime|mediatype|extmetadata';
104 return $this->mExists;
122 return parent::transform( $params, $flags );
127 $otherParams = $this->handler->makeParamString( $params );
128 $width = $params[
'width'] ?? -1;
129 $height = $params[
'height'] ?? -1;
132 if ( $width > 0 || $height > 0 ) {
134 $thumbUrl = $this->repo->getThumbUrlFromCache(
144 if ( $thumbUrl ===
false ) {
147 return $this->repo->getThumbError(
156 return $this->handler->getTransform( $this,
'bogus', $thumbUrl, $params );
166 return (
int)( $this->mInfo[
'width'] ?? 0 );
174 return (
int)( $this->mInfo[
'height'] ?? 0 );
181 if ( isset( $this->mInfo[
'metadata'] ) ) {
182 return serialize( self::parseMetadata( $this->mInfo[
'metadata'] ) );
189 if ( isset( $this->mInfo[
'metadata'] ) ) {
201 return $this->mInfo[
'extmetadata'] ??
null;
209 if ( !is_array( $metadata ) ) {
210 return [
'_error' => $metadata ];
212 '@phan-var array[] $metadata';
214 foreach ( $metadata as $meta ) {
215 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
225 private static function parseMetadataValue( $metadata ) {
226 if ( !is_array( $metadata ) ) {
229 '@phan-var array[] $metadata';
231 foreach ( $metadata as $meta ) {
232 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
242 return isset( $this->mInfo[
'size'] ) ? intval( $this->mInfo[
'size'] ) :
null;
249 return isset( $this->mInfo[
'url'] ) ? strval( $this->mInfo[
'url'] ) :
null;
260 if ( isset( $this->mInfo[
'descriptionshorturl'] ) ) {
261 return $this->mInfo[
'descriptionshorturl'];
262 } elseif ( isset( $this->mInfo[
'pageid'] ) ) {
263 $url = $this->repo->makeUrl( [
'curid' => $this->mInfo[
'pageid'] ] );
264 if (
$url !==
false ) {
272 if ( isset( $this->mInfo[
'user'] ) ) {
273 return UserIdentityValue::newExternal( $this->getRepoName(), $this->mInfo[
'user'] );
284 return isset( $this->mInfo[
'comment'] ) ? strval( $this->mInfo[
'comment'] ) :
null;
291 return isset( $this->mInfo[
'sha1'] )
292 ? \Wikimedia\base_convert( strval( $this->mInfo[
'sha1'] ), 16, 36, 31 )
301 isset( $this->mInfo[
'timestamp'] )
302 ? strval( $this->mInfo[
'timestamp'] )
311 if ( !isset( $this->mInfo[
'mime'] ) ) {
312 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
313 $this->mInfo[
'mime'] = $magic->getMimeTypeFromExtensionOrNull( $this->getExtension() ) ??
'unknown/unknown';
316 return $this->mInfo[
'mime'];
323 if ( isset( $this->mInfo[
'mediatype'] ) ) {
324 return $this->mInfo[
'mediatype'];
326 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
328 return $magic->getMediaType(
null, $this->getMimeType() );
335 return $this->mInfo[
'descriptionurl'] ??
false;
344 if ( !$this->repo->canCacheThumbs() ) {
348 $path = $this->repo->getZonePath(
'thumb' ) .
'/' . $this->getHashPath();
350 $path .= $suffix .
'/';
359 $dir = $this->getThumbPath( $this->getName() );
360 $iter = $this->repo->getBackend()->getFileList( [
'dir' => $dir ] );
364 foreach ( $iter as $file ) {
374 $this->purgeThumbnails( $options );
375 $this->purgeDescriptionPage();
378 private function purgeDescriptionPage() {
379 $services = MediaWikiServices::getInstance();
380 $langCode = $services->getContentLanguageCode()->toString();
383 $key = $this->repo->getLocalCacheKey(
'file-remote-description', $langCode, md5( $this->getName() ) );
384 $services->getMainWANObjectCache()->delete( $key );
391 $key = $this->repo->getLocalCacheKey(
'file-thumb-url', sha1( $this->getName() ) );
392 MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
394 $files = $this->getThumbnails();
396 $handler = $this->getHandler();
398 $handler->filterThumbnailPurgeList( $files, $options );
401 $dir = $this->getThumbPath( $this->getName() );
403 foreach ( $files as $file ) {
404 $purgeList[] =
"{$dir}{$file}";
407 # Delete the thumbnails
408 $this->repo->quickPurgeBatch( $purgeList );
409 # Clear out the thumbnail directory if empty
410 $this->repo->quickCleanDir( $dir );
424class_alias( ForeignAPIFile::class,
'ForeignAPIFile' );
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
if(!defined('MW_SETUP_CALLBACK'))