49 $this->mExists = $exists;
60 $data =
$repo->fetchImageQuery( [
62 'iiprop' => self::getProps(),
63 'prop' =>
'imageinfo',
67 'iiextmetadatamultilang' => 1,
70 $info =
$repo->getImageInfo( $data );
73 $lastRedirect = count( $data[
'query'][
'redirects'] ?? [] ) - 1;
74 if ( $lastRedirect >= 0 ) {
76 $newtitle = Title::newFromText( $data[
'query'][
'redirects'][$lastRedirect][
'to'] );
77 $img =
new self( $newtitle,
$repo, $info,
true );
94 return 'timestamp|user|comment|url|size|sha1|metadata|mime|mediatype|extmetadata';
110 return $this->mExists;
128 return parent::transform( $params, $flags );
133 $otherParams = $this->handler->makeParamString( $params );
134 $width = $params[
'width'] ?? -1;
135 $height = $params[
'height'] ?? -1;
138 if ( $width > 0 || $height > 0 ) {
140 $thumbUrl = $this->repo->getThumbUrlFromCache(
150 if ( $thumbUrl ===
false ) {
153 return $this->repo->getThumbError(
162 return $this->handler->getTransform( $this,
'bogus', $thumbUrl, $params );
172 return (
int)( $this->mInfo[
'width'] ?? 0 );
180 return (
int)( $this->mInfo[
'height'] ?? 0 );
187 if ( isset( $this->mInfo[
'metadata'] ) ) {
188 return serialize( self::parseMetadata( $this->mInfo[
'metadata'] ) );
198 if ( isset( $this->mInfo[
'metadata'] ) ) {
210 return $this->mInfo[
'extmetadata'] ??
null;
218 if ( !is_array( $metadata ) ) {
219 return [
'_error' => $metadata ];
221 '@phan-var array[] $metadata';
223 foreach ( $metadata as $meta ) {
224 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
234 private static function parseMetadataValue( $metadata ) {
235 if ( !is_array( $metadata ) ) {
238 '@phan-var array[] $metadata';
240 foreach ( $metadata as $meta ) {
241 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
251 return isset( $this->mInfo[
'size'] ) ? intval( $this->mInfo[
'size'] ) :
null;
258 return isset( $this->mInfo[
'url'] ) ? strval( $this->mInfo[
'url'] ) :
null;
269 if ( isset( $this->mInfo[
'descriptionshorturl'] ) ) {
270 return $this->mInfo[
'descriptionshorturl'];
271 } elseif ( isset( $this->mInfo[
'pageid'] ) ) {
272 $url = $this->repo->makeUrl( [
'curid' => $this->mInfo[
'pageid'] ] );
273 if ( $url !==
false ) {
281 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->getContentLanguage()->getCode();
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') &&! $wgCommandLineMode $wgLang
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
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.
canRender()
Checks if the output of transform() for this file is likely to be valid.
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
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.
Represents a title within MediaWiki.
getDBkey()
Get the main part with underscores.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.