42 $this->mExists = $exists;
53 $data =
$repo->fetchImageQuery( [
55 'iiprop' => self::getProps(),
56 'prop' =>
'imageinfo',
57 'iimetadataversion' => MediaHandler::getMetadataVersion(),
60 'iiextmetadatamultilang' => 1,
63 $info =
$repo->getImageInfo( $data );
66 $lastRedirect = count( $data[
'query'][
'redirects'] ?? [] ) - 1;
67 if ( $lastRedirect >= 0 ) {
69 $newtitle = Title::newFromText( $data[
'query'][
'redirects'][$lastRedirect][
'to'] );
70 $img =
new self( $newtitle,
$repo, $info, true );
87 return 'timestamp|user|comment|url|size|sha1|metadata|mime|mediatype|extmetadata';
103 return $this->mExists;
121 return parent::transform( $params, $flags );
126 $otherParams = $this->handler->makeParamString( $params );
127 $width = $params[
'width'] ?? -1;
128 $height = $params[
'height'] ?? -1;
131 if ( $width > 0 || $height > 0 ) {
133 $thumbUrl = $this->repo->getThumbUrlFromCache(
143 if ( $thumbUrl ===
false ) {
146 return $this->repo->getThumbError(
155 return $this->handler->getTransform( $this,
'bogus', $thumbUrl, $params );
165 return (
int)( $this->mInfo[
'width'] ?? 0 );
173 return (
int)( $this->mInfo[
'height'] ?? 0 );
180 if ( isset( $this->mInfo[
'metadata'] ) ) {
181 return serialize( self::parseMetadata( $this->mInfo[
'metadata'] ) );
188 if ( isset( $this->mInfo[
'metadata'] ) ) {
200 return $this->mInfo[
'extmetadata'] ??
null;
208 if ( !is_array( $metadata ) ) {
209 return [
'_error' => $metadata ];
211 '@phan-var array[] $metadata';
213 foreach ( $metadata as $meta ) {
214 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
224 private static function parseMetadataValue( $metadata ) {
225 if ( !is_array( $metadata ) ) {
228 '@phan-var array[] $metadata';
230 foreach ( $metadata as $meta ) {
231 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
241 return isset( $this->mInfo[
'size'] ) ? intval( $this->mInfo[
'size'] ) :
null;
248 return isset( $this->mInfo[
'url'] ) ? strval( $this->mInfo[
'url'] ) :
null;
259 if ( isset( $this->mInfo[
'descriptionshorturl'] ) ) {
260 return $this->mInfo[
'descriptionshorturl'];
261 } elseif ( isset( $this->mInfo[
'pageid'] ) ) {
262 $url = $this->repo->makeUrl( [
'curid' => $this->mInfo[
'pageid'] ] );
263 if (
$url !==
false ) {
271 if ( isset( $this->mInfo[
'user'] ) ) {
272 return UserIdentityValue::newExternal( $this->getRepoName(), $this->mInfo[
'user'] );
283 return isset( $this->mInfo[
'comment'] ) ? strval( $this->mInfo[
'comment'] ) :
null;
290 return isset( $this->mInfo[
'sha1'] )
291 ? \Wikimedia\base_convert( strval( $this->mInfo[
'sha1'] ), 16, 36, 31 )
300 isset( $this->mInfo[
'timestamp'] )
301 ? strval( $this->mInfo[
'timestamp'] )
310 if ( !isset( $this->mInfo[
'mime'] ) ) {
311 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
312 $this->mInfo[
'mime'] = $magic->getMimeTypeFromExtensionOrNull( $this->getExtension() );
315 return $this->mInfo[
'mime'];
322 if ( isset( $this->mInfo[
'mediatype'] ) ) {
323 return $this->mInfo[
'mediatype'];
325 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
327 return $magic->getMediaType(
null, $this->getMimeType() );
334 return $this->mInfo[
'descriptionurl'] ??
false;
343 if ( !$this->repo->canCacheThumbs() ) {
347 $path = $this->repo->getZonePath(
'thumb' ) .
'/' . $this->getHashPath();
349 $path .= $suffix .
'/';
358 $dir = $this->getThumbPath( $this->getName() );
359 $iter = $this->repo->getBackend()->getFileList( [
'dir' => $dir ] );
363 foreach ( $iter as $file ) {
373 $this->purgeThumbnails( $options );
374 $this->purgeDescriptionPage();
377 private function purgeDescriptionPage() {
378 $services = MediaWikiServices::getInstance();
379 $langCode = $services->getContentLanguageCode()->toString();
382 $key = $this->repo->getLocalCacheKey(
'file-remote-description', $langCode, md5( $this->getName() ) );
383 $services->getMainWANObjectCache()->delete( $key );
390 $key = $this->repo->getLocalCacheKey(
'file-thumb-url', sha1( $this->getName() ) );
391 MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
393 $files = $this->getThumbnails();
395 $handler = $this->getHandler();
397 $handler->filterThumbnailPurgeList( $files, $options );
400 $dir = $this->getThumbPath( $this->getName() );
402 foreach ( $files as $file ) {
403 $purgeList[] =
"{$dir}{$file}";
406 # Delete the thumbnails
407 $this->repo->quickPurgeBatch( $purgeList );
408 # Clear out the thumbnail directory if empty
409 $this->repo->quickCleanDir( $dir );
423class_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'))