50 $this->mExists = $exists;
61 $data =
$repo->fetchImageQuery( [
62 'titles' =>
'File:' . $title->
getDBkey(),
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 ) {
80 $img =
new self( $newtitle,
$repo, $info,
true );
81 $img->redirectedFrom( $title->
getDBkey() );
97 return 'timestamp|user|comment|url|size|sha1|metadata|mime|mediatype|extmetadata';
124 return parent::transform( $params, $flags );
129 $otherParams = $this->handler->makeParamString( $params );
130 $width = $params[
'width'] ?? -1;
131 $height = $params[
'height'] ?? -1;
133 $thumbUrl = $this->repo->getThumbUrlFromCache(
139 if ( $thumbUrl ===
false ) {
142 return $this->repo->getThumbError(
151 return $this->handler->getTransform( $this,
'bogus', $thumbUrl, $params );
161 return isset( $this->mInfo[
'width'] ) ? intval( $this->mInfo[
'width'] ) : 0;
169 return isset( $this->mInfo[
'height'] ) ? intval( $this->mInfo[
'height'] ) : 0;
176 if ( isset( $this->mInfo[
'metadata'] ) ) {
177 return serialize( self::parseMetadata( $this->mInfo[
'metadata'] ) );
188 return $this->mInfo[
'extmetadata'] ?? null;
196 if ( !is_array( $metadata ) ) {
199 '@phan-var array[] $metadata';
201 foreach ( $metadata as $meta ) {
202 $ret[$meta[
'name']] = self::parseMetadata( $meta[
'value'] );
212 return isset( $this->mInfo[
'size'] ) ? intval( $this->mInfo[
'size'] ) : null;
219 return isset( $this->mInfo[
'url'] ) ? strval( $this->mInfo[
'url'] ) : null;
230 if ( isset( $this->mInfo[
'descriptionshorturl'] ) ) {
231 return $this->mInfo[
'descriptionshorturl'];
232 } elseif ( isset( $this->mInfo[
'pageid'] ) ) {
233 $url = $this->repo->makeUrl( [
'curid' => $this->mInfo[
'pageid'] ] );
234 if (
$url !==
false ) {
246 if (
$type ==
'text' ) {
247 return isset( $this->mInfo[
'user'] ) ? strval( $this->mInfo[
'user'] ) : null;
259 return isset( $this->mInfo[
'comment'] ) ? strval( $this->mInfo[
'comment'] ) : null;
266 return isset( $this->mInfo[
'sha1'] )
267 ? Wikimedia\base_convert( strval( $this->mInfo[
'sha1'] ), 16, 36, 31 )
276 isset( $this->mInfo[
'timestamp'] )
277 ? strval( $this->mInfo[
'timestamp'] )
286 if ( !isset( $this->mInfo[
'mime'] ) ) {
288 $this->mInfo[
'mime'] = $magic->guessTypesForExtension( $this->
getExtension() );
291 return $this->mInfo[
'mime'];
298 if ( isset( $this->mInfo[
'mediatype'] ) ) {
299 return $this->mInfo[
'mediatype'];
303 return $magic->getMediaType( null, $this->
getMimeType() );
310 return $this->mInfo[
'descriptionurl'] ??
false;
319 if ( !$this->repo->canCacheThumbs() ) {
325 $path .= $suffix .
'/';
335 $iter = $this->repo->getBackend()->getFileList( [
'dir' => $dir ] );
339 foreach ( $iter as
$file ) {
353 $services = MediaWikiServices::getInstance();
354 $url = $this->repo->getDescriptionRenderUrl(
355 $this->
getName(), $services->getContentLanguage()->getCode() );
356 $key = $this->repo->getLocalCacheKey(
'RemoteFileDescription',
'url', md5(
$url ) );
358 $services->getMainWANObjectCache()->delete( $key );
365 $key = $this->repo->getLocalCacheKey(
'ForeignAPIRepo',
'ThumbUrl', $this->
getName() );
366 MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
377 foreach ( $files as
$file ) {
378 $purgeList[] =
"{$dir}{$file}";
381 # Delete the thumbnails 382 $this->repo->quickPurgeBatch( $purgeList );
383 # Clear out the thumbnail directory if empty 384 $this->repo->quickCleanDir( $dir );
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
purgeThumbnails( $options=[])
getDescription( $audience=self::FOR_PUBLIC, User $user=null)
getDescriptionShortUrl()
Get short description URL for a file based on the foreign API response, or if unavailable, the short URL is constructed from the foreign page ID.
canRender()
Checks if the output of transform() for this file is likely to be valid.
assertRepoDefined()
Assert that $this->repo is set to a valid FileRepo instance.
getName()
Return the name of this file.
getHashPath()
Get the filename hash component of the directory including trailing slash, e.g.
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Foreign file accessible through api.php requests.
static parseMetadata( $metadata)
getThumbPath( $suffix='')
Only useful if we're locally caching thumbs anyway...
getDBkey()
Get the main part with underscores.
isTransformedLocally()
The thumbnail is created on the foreign server and fetched over internet.
getHandler()
Get a MediaHandler instance for this file.
static newFromTitle(Title $title, $repo)
static getProps()
Get the property string for iiprop and aiprop.
getExtension()
Get the file extension, e.g.
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
string $url
The URL corresponding to one of the four basic zones.
__construct( $title, $repo, $info, $exists=false)
string $path
The storage path corresponding to one of the zones.
Implements some public methods and some protected utility functions which are required by multiple ch...
transform( $params, $flags=0)
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.