50 $this->mExists = $exists;
61 $data =
$repo->fetchImageQuery( [
63 'iiprop' => self::getProps(),
64 'prop' =>
'imageinfo',
68 'iiextmetadatamultilang' => 1,
71 $info =
$repo->getImageInfo( $data );
74 $lastRedirect = isset( $data[
'query'][
'redirects'] )
75 ? count( $data[
'query'][
'redirects'] ) - 1
77 if ( $lastRedirect >= 0 ) {
79 $newtitle = Title::newFromText( $data[
'query'][
'redirects'][$lastRedirect][
'to'] );
80 $img =
new self( $newtitle,
$repo, $info,
true );
97 return 'timestamp|user|comment|url|size|sha1|metadata|mime|mediatype|extmetadata';
131 return parent::transform( $params, $flags );
136 $otherParams = $this->handler->makeParamString( $params );
137 $width = $params[
'width'] ?? -1;
138 $height = $params[
'height'] ?? -1;
140 $thumbUrl = $this->repo->getThumbUrlFromCache(
146 if ( $thumbUrl ===
false ) {
149 return $this->repo->getThumbError(
158 return $this->handler->getTransform( $this,
'bogus', $thumbUrl, $params );
168 return isset( $this->mInfo[
'width'] ) ? intval( $this->mInfo[
'width'] ) : 0;
176 return isset( $this->mInfo[
'height'] ) ? intval( $this->mInfo[
'height'] ) : 0;
183 if ( isset( $this->mInfo[
'metadata'] ) ) {
184 return serialize( self::parseMetadata( $this->mInfo[
'metadata'] ) );
194 if ( isset( $this->mInfo[
'metadata'] ) ) {
206 return $this->mInfo[
'extmetadata'] ??
null;
214 if ( !is_array( $metadata ) ) {
215 return [
'_error' => $metadata ];
217 '@phan-var array[] $metadata';
219 foreach ( $metadata as $meta ) {
220 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
231 if ( !is_array( $metadata ) ) {
234 '@phan-var array[] $metadata';
236 foreach ( $metadata as $meta ) {
237 $ret[$meta[
'name']] = self::parseMetadataValue( $meta[
'value'] );
247 return isset( $this->mInfo[
'size'] ) ? intval( $this->mInfo[
'size'] ) :
null;
254 return isset( $this->mInfo[
'url'] ) ? strval( $this->mInfo[
'url'] ) :
null;
265 if ( isset( $this->mInfo[
'descriptionshorturl'] ) ) {
266 return $this->mInfo[
'descriptionshorturl'];
267 } elseif ( isset( $this->mInfo[
'pageid'] ) ) {
268 $url = $this->repo->makeUrl( [
'curid' => $this->mInfo[
'pageid'] ] );
269 if ( $url !==
false ) {
277 if ( isset( $this->mInfo[
'user'] ) ) {
280 return UserIdentityValue::newExternal( $this->getRepoName(), $this->mInfo[
'user'] );
291 return isset( $this->mInfo[
'comment'] ) ? strval( $this->mInfo[
'comment'] ) :
null;
298 return isset( $this->mInfo[
'sha1'] )
299 ? Wikimedia\base_convert( strval( $this->mInfo[
'sha1'] ), 16, 36, 31 )
308 isset( $this->mInfo[
'timestamp'] )
309 ? strval( $this->mInfo[
'timestamp'] )
318 if ( !isset( $this->mInfo[
'mime'] ) ) {
319 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
320 $this->mInfo[
'mime'] = $magic->getMimeTypeFromExtensionOrNull( $this->getExtension() );
323 return $this->mInfo[
'mime'];
330 if ( isset( $this->mInfo[
'mediatype'] ) ) {
331 return $this->mInfo[
'mediatype'];
333 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
335 return $magic->getMediaType(
null, $this->getMimeType() );
342 return $this->mInfo[
'descriptionurl'] ??
false;
351 if ( !$this->repo->canCacheThumbs() ) {
355 $path = $this->repo->getZonePath(
'thumb' ) .
'/' . $this->getHashPath();
357 $path .= $suffix .
'/';
366 $dir = $this->getThumbPath( $this->getName() );
367 $iter = $this->repo->getBackend()->getFileList( [
'dir' => $dir ] );
371 foreach ( $iter as
$file ) {
380 $this->purgeThumbnails( $options );
381 $this->purgeDescriptionPage();
385 $services = MediaWikiServices::getInstance();
386 $url = $this->repo->getDescriptionRenderUrl(
388 $services->getContentLanguage()->getCode()
391 $key = $this->repo->getLocalCacheKey(
'file-remote-description', md5( $url ) );
392 $services->getMainWANObjectCache()->delete( $key );
399 $key = $this->repo->getLocalCacheKey(
'file-thumb-url', sha1( $this->getName() ) );
400 MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
402 $files = $this->getThumbnails();
404 $handler = $this->getHandler();
406 $handler->filterThumbnailPurgeList( $files, $options );
409 $dir = $this->getThumbPath( $this->getName() );
411 foreach ( $files as
$file ) {
412 $purgeList[] =
"{$dir}{$file}";
415 # Delete the thumbnails
416 $this->repo->quickPurgeBatch( $purgeList );
417 # Clear out the thumbnail directory if empty
418 $this->repo->quickCleanDir( $dir );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
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.
static parseMetadataValue( $metadata)
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.