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'] ) ) {
283 return UserIdentityValue::newExternal( $this->getRepoName(), $this->mInfo[
'user'] );
294 return isset( $this->mInfo[
'comment'] ) ? strval( $this->mInfo[
'comment'] ) :
null;
301 return isset( $this->mInfo[
'sha1'] )
302 ? Wikimedia\base_convert( strval( $this->mInfo[
'sha1'] ), 16, 36, 31 )
311 isset( $this->mInfo[
'timestamp'] )
312 ? strval( $this->mInfo[
'timestamp'] )
321 if ( !isset( $this->mInfo[
'mime'] ) ) {
322 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
323 $this->mInfo[
'mime'] = $magic->getMimeTypeFromExtensionOrNull( $this->getExtension() );
326 return $this->mInfo[
'mime'];
333 if ( isset( $this->mInfo[
'mediatype'] ) ) {
334 return $this->mInfo[
'mediatype'];
336 $magic = MediaWikiServices::getInstance()->getMimeAnalyzer();
338 return $magic->getMediaType(
null, $this->getMimeType() );
345 return $this->mInfo[
'descriptionurl'] ??
false;
354 if ( !$this->repo->canCacheThumbs() ) {
358 $path = $this->repo->getZonePath(
'thumb' ) .
'/' . $this->getHashPath();
360 $path .= $suffix .
'/';
369 $dir = $this->getThumbPath( $this->getName() );
370 $iter = $this->repo->getBackend()->getFileList( [
'dir' => $dir ] );
374 foreach ( $iter as $file ) {
383 $this->purgeThumbnails( $options );
384 $this->purgeDescriptionPage();
387 private function purgeDescriptionPage() {
388 $services = MediaWikiServices::getInstance();
389 $langCode = $services->getContentLanguage()->getCode();
392 $key = $this->repo->getLocalCacheKey(
'file-remote-description', $langCode, md5( $this->getName() ) );
393 $services->getMainWANObjectCache()->delete( $key );
400 $key = $this->repo->getLocalCacheKey(
'file-thumb-url', sha1( $this->getName() ) );
401 MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
403 $files = $this->getThumbnails();
405 $handler = $this->getHandler();
407 $handler->filterThumbnailPurgeList( $files, $options );
410 $dir = $this->getThumbPath( $this->getName() );
412 foreach ( $files as $file ) {
413 $purgeList[] =
"{$dir}{$file}";
416 # Delete the thumbnails
417 $this->repo->quickPurgeBatch( $purgeList );
418 # Clear out the thumbnail directory if empty
419 $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.