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'] ) );
195 return $this->mInfo[
'extmetadata'] ??
null;
203 if ( !is_array( $metadata ) ) {
206 '@phan-var array[] $metadata';
208 foreach ( $metadata as $meta ) {
219 return isset( $this->mInfo[
'size'] ) ? intval( $this->mInfo[
'size'] ) :
null;
226 return isset( $this->mInfo[
'url'] ) ? strval( $this->mInfo[
'url'] ) :
null;
237 if ( isset( $this->mInfo[
'descriptionshorturl'] ) ) {
238 return $this->mInfo[
'descriptionshorturl'];
239 } elseif ( isset( $this->mInfo[
'pageid'] ) ) {
240 $url = $this->repo->makeUrl( [
'curid' => $this->mInfo[
'pageid'] ] );
241 if (
$url !==
false ) {
253 if (
$type ==
'text' ) {
254 return isset( $this->mInfo[
'user'] ) ? strval( $this->mInfo[
'user'] ) :
null;
266 return isset( $this->mInfo[
'comment'] ) ? strval( $this->mInfo[
'comment'] ) :
null;
273 return isset( $this->mInfo[
'sha1'] )
274 ? Wikimedia\base_convert( strval( $this->mInfo[
'sha1'] ), 16, 36, 31 )
283 isset( $this->mInfo[
'timestamp'] )
284 ? strval( $this->mInfo[
'timestamp'] )
293 if ( !isset( $this->mInfo[
'mime'] ) ) {
294 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
295 $this->mInfo[
'mime'] = $magic->getMimeTypeFromExtensionOrNull( $this->
getExtension() );
298 return $this->mInfo[
'mime'];
305 if ( isset( $this->mInfo[
'mediatype'] ) ) {
306 return $this->mInfo[
'mediatype'];
308 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
310 return $magic->getMediaType(
null, $this->
getMimeType() );
317 return $this->mInfo[
'descriptionurl'] ??
false;
326 if ( !$this->repo->canCacheThumbs() ) {
332 $path .= $suffix .
'/';
342 $iter = $this->repo->getBackend()->getFileList( [
'dir' => $dir ] );
346 foreach ( $iter as
$file ) {
360 $services = MediaWikiServices::getInstance();
361 $url = $this->repo->getDescriptionRenderUrl(
362 $this->
getName(), $services->getContentLanguage()->getCode() );
363 $key = $this->repo->getLocalCacheKey(
'RemoteFileDescription',
'url', md5(
$url ) );
365 $services->getMainWANObjectCache()->delete( $key );
372 $key = $this->repo->getLocalCacheKey(
'ForeignAPIRepo',
'ThumbUrl', $this->
getName() );
373 MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
384 foreach ( $files as
$file ) {
385 $purgeList[] =
"{$dir}{$file}";
388 # Delete the thumbnails
389 $this->repo->quickPurgeBatch( $purgeList );
390 # Clear out the thumbnail directory if empty
391 $this->repo->quickCleanDir( $dir );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Implements some public methods and some protected utility functions which are required by multiple ch...
string $url
The URL corresponding to one of the four basic zones.
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.
getExtension()
Get the file extension, e.g.
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
string $path
The storage path corresponding to one of the zones.
getHandler()
Get a MediaHandler instance for this file.
getHashPath()
Get the filename hash component of the directory including trailing slash, e.g.
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 Stable to ove...
isTransformedLocally()
The thumbnail is created on the foreign server and fetched over internet.
static parseMetadata( $metadata)
static newFromTitle(Title $title, $repo)
purgeThumbnails( $options=[])
getDescription( $audience=self::FOR_PUBLIC, User $user=null)
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.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.