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'] ) );
200 if ( isset( $this->mInfo[
'metadata'] ) ) {
212 return $this->mInfo[
'extmetadata'] ??
null;
220 if ( !is_array( $metadata ) ) {
221 return [
'_error' => $metadata ];
223 '@phan-var array[] $metadata';
225 foreach ( $metadata as $meta ) {
226 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
236 private static function parseMetadataValue( $metadata ) {
237 if ( !is_array( $metadata ) ) {
240 '@phan-var array[] $metadata';
242 foreach ( $metadata as $meta ) {
243 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
253 return isset( $this->mInfo[
'size'] ) ? intval( $this->mInfo[
'size'] ) :
null;
260 return isset( $this->mInfo[
'url'] ) ? strval( $this->mInfo[
'url'] ) :
null;
271 if ( isset( $this->mInfo[
'descriptionshorturl'] ) ) {
272 return $this->mInfo[
'descriptionshorturl'];
273 } elseif ( isset( $this->mInfo[
'pageid'] ) ) {
274 $url = $this->repo->makeUrl( [
'curid' => $this->mInfo[
'pageid'] ] );
275 if (
$url !==
false ) {
283 if ( isset( $this->mInfo[
'user'] ) ) {
284 return UserIdentityValue::newExternal( $this->getRepoName(), $this->mInfo[
'user'] );
295 return isset( $this->mInfo[
'comment'] ) ? strval( $this->mInfo[
'comment'] ) :
null;
302 return isset( $this->mInfo[
'sha1'] )
303 ? Wikimedia\base_convert( strval( $this->mInfo[
'sha1'] ), 16, 36, 31 )
312 isset( $this->mInfo[
'timestamp'] )
313 ? strval( $this->mInfo[
'timestamp'] )
322 if ( !isset( $this->mInfo[
'mime'] ) ) {
323 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
324 $this->mInfo[
'mime'] = $magic->getMimeTypeFromExtensionOrNull( $this->getExtension() );
327 return $this->mInfo[
'mime'];
334 if ( isset( $this->mInfo[
'mediatype'] ) ) {
335 return $this->mInfo[
'mediatype'];
337 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
339 return $magic->getMediaType(
null, $this->getMimeType() );
346 return $this->mInfo[
'descriptionurl'] ??
false;
355 if ( !$this->repo->canCacheThumbs() ) {
359 $path = $this->repo->getZonePath(
'thumb' ) .
'/' . $this->getHashPath();
361 $path .= $suffix .
'/';
370 $dir = $this->getThumbPath( $this->getName() );
371 $iter = $this->repo->getBackend()->getFileList( [
'dir' => $dir ] );
375 foreach ( $iter as $file ) {
384 $this->purgeThumbnails( $options );
385 $this->purgeDescriptionPage();
388 private function purgeDescriptionPage() {
389 $services = MediaWikiServices::getInstance();
390 $langCode = $services->getContentLanguageCode()->toString();
393 $key = $this->repo->getLocalCacheKey(
'file-remote-description', $langCode, md5( $this->getName() ) );
394 $services->getMainWANObjectCache()->delete( $key );
401 $key = $this->repo->getLocalCacheKey(
'file-thumb-url', sha1( $this->getName() ) );
402 MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
404 $files = $this->getThumbnails();
406 $handler = $this->getHandler();
408 $handler->filterThumbnailPurgeList( $files, $options );
411 $dir = $this->getThumbPath( $this->getName() );
413 foreach ( $files as $file ) {
414 $purgeList[] =
"{$dir}{$file}";
417 # Delete the thumbnails
418 $this->repo->quickPurgeBatch( $purgeList );
419 # Clear out the thumbnail directory if empty
420 $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)
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.