51 $this->mExists = $exists;
62 $data =
$repo->fetchImageQuery( [
64 'iiprop' => self::getProps(),
65 'prop' =>
'imageinfo',
66 'iimetadataversion' => MediaHandler::getMetadataVersion(),
69 'iiextmetadatamultilang' => 1,
72 $info =
$repo->getImageInfo( $data );
75 $lastRedirect = count( $data[
'query'][
'redirects'] ?? [] ) - 1;
76 if ( $lastRedirect >= 0 ) {
78 $newtitle = Title::newFromText( $data[
'query'][
'redirects'][$lastRedirect][
'to'] );
79 $img =
new self( $newtitle,
$repo, $info, true );
96 return 'timestamp|user|comment|url|size|sha1|metadata|mime|mediatype|extmetadata';
112 return $this->mExists;
130 return parent::transform(
$params, $flags );
135 $otherParams = $this->handler->makeParamString(
$params );
136 $width =
$params[
'width'] ?? -1;
137 $height =
$params[
'height'] ?? -1;
140 if ( $width > 0 || $height > 0 ) {
142 $thumbUrl = $this->repo->getThumbUrlFromCache(
152 if ( $thumbUrl ===
false ) {
155 return $this->repo->getThumbError(
164 return $this->handler->getTransform( $this,
'bogus', $thumbUrl,
$params );
174 return (
int)( $this->mInfo[
'width'] ?? 0 );
182 return (
int)( $this->mInfo[
'height'] ?? 0 );
189 if ( isset( $this->mInfo[
'metadata'] ) ) {
190 return serialize( self::parseMetadata( $this->mInfo[
'metadata'] ) );
197 if ( isset( $this->mInfo[
'metadata'] ) ) {
209 return $this->mInfo[
'extmetadata'] ??
null;
217 if ( !is_array( $metadata ) ) {
218 return [
'_error' => $metadata ];
220 '@phan-var array[] $metadata';
222 foreach ( $metadata as $meta ) {
223 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
233 private static function parseMetadataValue( $metadata ) {
234 if ( !is_array( $metadata ) ) {
237 '@phan-var array[] $metadata';
239 foreach ( $metadata as $meta ) {
240 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
250 return isset( $this->mInfo[
'size'] ) ? intval( $this->mInfo[
'size'] ) :
null;
257 return isset( $this->mInfo[
'url'] ) ? strval( $this->mInfo[
'url'] ) :
null;
268 if ( isset( $this->mInfo[
'descriptionshorturl'] ) ) {
269 return $this->mInfo[
'descriptionshorturl'];
270 } elseif ( isset( $this->mInfo[
'pageid'] ) ) {
271 $url = $this->repo->makeUrl( [
'curid' => $this->mInfo[
'pageid'] ] );
272 if (
$url !==
false ) {
280 if ( isset( $this->mInfo[
'user'] ) ) {
281 return UserIdentityValue::newExternal( $this->getRepoName(), $this->mInfo[
'user'] );
292 return isset( $this->mInfo[
'comment'] ) ? strval( $this->mInfo[
'comment'] ) :
null;
299 return isset( $this->mInfo[
'sha1'] )
300 ? Wikimedia\base_convert( strval( $this->mInfo[
'sha1'] ), 16, 36, 31 )
309 isset( $this->mInfo[
'timestamp'] )
310 ? strval( $this->mInfo[
'timestamp'] )
319 if ( !isset( $this->mInfo[
'mime'] ) ) {
320 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
321 $this->mInfo[
'mime'] = $magic->getMimeTypeFromExtensionOrNull( $this->getExtension() );
324 return $this->mInfo[
'mime'];
331 if ( isset( $this->mInfo[
'mediatype'] ) ) {
332 return $this->mInfo[
'mediatype'];
334 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
336 return $magic->getMediaType(
null, $this->getMimeType() );
343 return $this->mInfo[
'descriptionurl'] ??
false;
352 if ( !$this->repo->canCacheThumbs() ) {
356 $path = $this->repo->getZonePath(
'thumb' ) .
'/' . $this->getHashPath();
358 $path .= $suffix .
'/';
367 $dir = $this->getThumbPath( $this->getName() );
368 $iter = $this->repo->getBackend()->getFileList( [
'dir' => $dir ] );
372 foreach ( $iter as $file ) {
381 $this->purgeThumbnails( $options );
382 $this->purgeDescriptionPage();
385 private function purgeDescriptionPage() {
386 $services = MediaWikiServices::getInstance();
387 $langCode = $services->getContentLanguageCode()->toString();
390 $key = $this->repo->getLocalCacheKey(
'file-remote-description', $langCode, md5( $this->getName() ) );
391 $services->getMainWANObjectCache()->delete( $key );
398 $key = $this->repo->getLocalCacheKey(
'file-thumb-url', sha1( $this->getName() ) );
399 MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
401 $files = $this->getThumbnails();
403 $handler = $this->getHandler();
405 $handler->filterThumbnailPurgeList( $files, $options );
408 $dir = $this->getThumbPath( $this->getName() );
410 foreach ( $files as $file ) {
411 $purgeList[] =
"{$dir}{$file}";
414 # Delete the thumbnails
415 $this->repo->quickPurgeBatch( $purgeList );
416 # Clear out the thumbnail directory if empty
417 $this->repo->quickCleanDir( $dir );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
array $params
The job parameters.
if(!defined('MW_SETUP_CALLBACK'))
Implements some public methods and some protected utility functions which are required by multiple ch...
assertRepoDefined()
Assert that $this->repo is set to a valid FileRepo instance.
getName()
Return the name of this file.
FileRepo LocalRepo ForeignAPIRepo false $repo
Some member variables can be lazy-initialised using __get().
canRender()
Checks if the output of transform() for this file is likely to be valid.
Title string false $title
Foreign file accessible through api.php requests.
getThumbPath( $suffix='')
Only useful if we're locally caching thumbs anyway...
__construct( $title, $repo, $info, $exists=false)
purgeCache( $options=[])
Purge shared caches such as thumbnails and DB data caching STUB Overridden by LocalFile.
isTransformedLocally()
The thumbnail is created on the foreign server and fetched over internet.
static parseMetadata( $metadata)
getMetadataArray()
Get the unserialized handler-specific metadata STUB.
static newFromTitle(Title $title, $repo)
purgeThumbnails( $options=[])
getUploader(int $audience=self::FOR_PUBLIC, ?Authority $performer=null)
Get the identity of the file uploader.
transform( $params, $flags=0)
getDescription( $audience=self::FOR_PUBLIC, ?Authority $performer=null)
getDescriptionShortUrl()
Get short description URL for a file based on the foreign API response, or if unavailable,...
static getProps()
Get the property string for iiprop and aiprop.