50 $this->mExists = $exists;
61 $data =
$repo->fetchImageQuery( [
63 'iiprop' => self::getProps(),
64 'prop' =>
'imageinfo',
65 'iimetadataversion' => MediaHandler::getMetadataVersion(),
68 'iiextmetadatamultilang' => 1,
71 $info =
$repo->getImageInfo( $data );
74 $lastRedirect = count( $data[
'query'][
'redirects'] ?? [] ) - 1;
75 if ( $lastRedirect >= 0 ) {
77 $newtitle = Title::newFromText( $data[
'query'][
'redirects'][$lastRedirect][
'to'] );
78 $img =
new self( $newtitle,
$repo, $info, true );
95 return 'timestamp|user|comment|url|size|sha1|metadata|mime|mediatype|extmetadata';
111 return $this->mExists;
129 return parent::transform(
$params, $flags );
134 $otherParams = $this->handler->makeParamString(
$params );
135 $width =
$params[
'width'] ?? -1;
136 $height =
$params[
'height'] ?? -1;
139 if ( $width > 0 || $height > 0 ) {
141 $thumbUrl = $this->repo->getThumbUrlFromCache(
151 if ( $thumbUrl ===
false ) {
154 return $this->repo->getThumbError(
163 return $this->handler->getTransform( $this,
'bogus', $thumbUrl,
$params );
173 return (
int)( $this->mInfo[
'width'] ?? 0 );
181 return (
int)( $this->mInfo[
'height'] ?? 0 );
188 if ( isset( $this->mInfo[
'metadata'] ) ) {
189 return serialize( self::parseMetadata( $this->mInfo[
'metadata'] ) );
199 if ( isset( $this->mInfo[
'metadata'] ) ) {
211 return $this->mInfo[
'extmetadata'] ??
null;
219 if ( !is_array( $metadata ) ) {
220 return [
'_error' => $metadata ];
222 '@phan-var array[] $metadata';
224 foreach ( $metadata as $meta ) {
225 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
235 private static function parseMetadataValue( $metadata ) {
236 if ( !is_array( $metadata ) ) {
239 '@phan-var array[] $metadata';
241 foreach ( $metadata as $meta ) {
242 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
252 return isset( $this->mInfo[
'size'] ) ? intval( $this->mInfo[
'size'] ) :
null;
259 return isset( $this->mInfo[
'url'] ) ? strval( $this->mInfo[
'url'] ) :
null;
270 if ( isset( $this->mInfo[
'descriptionshorturl'] ) ) {
271 return $this->mInfo[
'descriptionshorturl'];
272 } elseif ( isset( $this->mInfo[
'pageid'] ) ) {
273 $url = $this->repo->makeUrl( [
'curid' => $this->mInfo[
'pageid'] ] );
274 if ( $url !==
false ) {
282 if ( isset( $this->mInfo[
'user'] ) ) {
285 return UserIdentityValue::newExternal( $this->getRepoName(), $this->mInfo[
'user'] );
296 return isset( $this->mInfo[
'comment'] ) ? strval( $this->mInfo[
'comment'] ) :
null;
303 return isset( $this->mInfo[
'sha1'] )
304 ? Wikimedia\base_convert( strval( $this->mInfo[
'sha1'] ), 16, 36, 31 )
313 isset( $this->mInfo[
'timestamp'] )
314 ? strval( $this->mInfo[
'timestamp'] )
323 if ( !isset( $this->mInfo[
'mime'] ) ) {
324 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
325 $this->mInfo[
'mime'] = $magic->getMimeTypeFromExtensionOrNull( $this->getExtension() );
328 return $this->mInfo[
'mime'];
335 if ( isset( $this->mInfo[
'mediatype'] ) ) {
336 return $this->mInfo[
'mediatype'];
338 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
340 return $magic->getMediaType(
null, $this->getMimeType() );
347 return $this->mInfo[
'descriptionurl'] ??
false;
356 if ( !$this->repo->canCacheThumbs() ) {
360 $path = $this->repo->getZonePath(
'thumb' ) .
'/' . $this->getHashPath();
362 $path .= $suffix .
'/';
371 $dir = $this->getThumbPath( $this->getName() );
372 $iter = $this->repo->getBackend()->getFileList( [
'dir' => $dir ] );
376 foreach ( $iter as $file ) {
385 $this->purgeThumbnails( $options );
386 $this->purgeDescriptionPage();
389 private function purgeDescriptionPage() {
390 $services = MediaWikiServices::getInstance();
391 $langCode = $services->getContentLanguage()->getCode();
394 $key = $this->repo->getLocalCacheKey(
'file-remote-description', $langCode, md5( $this->getName() ) );
395 $services->getMainWANObjectCache()->delete( $key );
402 $key = $this->repo->getLocalCacheKey(
'file-thumb-url', sha1( $this->getName() ) );
403 MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
405 $files = $this->getThumbnails();
407 $handler = $this->getHandler();
409 $handler->filterThumbnailPurgeList( $files, $options );
412 $dir = $this->getThumbPath( $this->getName() );
414 foreach ( $files as $file ) {
415 $purgeList[] =
"{$dir}{$file}";
418 # Delete the thumbnails
419 $this->repo->quickPurgeBatch( $purgeList );
420 # Clear out the thumbnail directory if empty
421 $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...
getDescription( $audience=self::FOR_PUBLIC, Authority $performer=null)
__construct( $title, $repo, $info, $exists=false)
getUploader(int $audience=self::FOR_PUBLIC, Authority $performer=null)
Get the identity of the file uploader.
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)
static newFromTitle(Title $title, $repo)
purgeThumbnails( $options=[])
transform( $params, $flags=0)
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.