8use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
10use Wikimedia\AtEase\AtEase;
64 use ProtectedHookAccessorTrait;
201 if ( $ret instanceof
Title ) {
202 # Normalize NS_MEDIA -> NS_FILE
203 if ( $ret->getNamespace() ==
NS_MEDIA ) {
204 $ret = Title::makeTitleSafe(
NS_FILE, $ret->getDBkey() );
205 # Sanity check the title namespace
206 } elseif ( $ret->getNamespace() !==
NS_FILE ) {
210 # Convert strings to Title objects
211 $ret = Title::makeTitleSafe(
NS_FILE, (
string)$ret );
213 if ( !$ret && $exception !==
false ) {
214 throw new MWException(
"`$title` is not a valid file title." );
221 $function = [ $this,
'get' . ucfirst(
$name ) ];
222 if ( !is_callable( $function ) ) {
225 $this->
$name = $function();
247 if ( isset( $squish[$lower] ) ) {
248 return $squish[$lower];
249 } elseif ( preg_match(
'/^[0-9a-z]+$/', $lower ) ) {
266 $n = strrpos( $new,
'.' );
267 $newExt = self::normalizeExtension( $n ? substr( $new, $n + 1 ) :
'' );
268 $mimeMagic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
270 return $mimeMagic->isMatchingExtension( $newExt, $oldMime );
291 if ( strpos(
$mime,
'/' ) !==
false ) {
292 return explode(
'/',
$mime, 2 );
294 return [
$mime,
'unknown' ];
316 if ( $this->name ===
null ) {
318 $this->name = $this->repo->getNameFromTitle( $this->title );
331 if ( !isset( $this->extension ) ) {
332 $n = strrpos( $this->
getName(),
'.' );
333 $this->extension = self::normalizeExtension(
334 $n ? substr( $this->
getName(), $n + 1 ) :
'' );
337 return $this->extension;
355 if ( $this->redirected ) {
369 if ( !isset( $this->url ) ) {
372 $this->url = $this->repo->getZoneUrl(
'public',
$ext ) .
'/' . $this->
getUrlRel();
417 wfDebug( __METHOD__ .
': supposed to render ' . $this->
getName() .
420 return $this->
getUrl(); # hm...
return NULL?
442 if ( !isset( $this->path ) ) {
444 $this->path = $this->repo->getZonePath(
'public' ) .
'/' . $this->
getRel();
459 if ( !isset( $this->fsFile ) ) {
460 $starttime = microtime(
true );
461 $this->fsFile = $this->repo->getLocalReference( $this->
getPath() );
463 $statTiming = microtime(
true ) - $starttime;
464 MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
465 'media.thumbnail.generate.fetchoriginal', 1000 * $statTiming );
467 if ( !$this->fsFile ) {
468 $this->fsFile =
false;
472 return ( $this->fsFile )
473 ? $this->fsFile->getPath()
519 $imageWidth = $this->
getWidth( $page );
521 if ( $imageWidth ===
false ) {
525 if ( $desiredWidth > $imageWidth ) {
535 sort( $sortedBuckets );
537 foreach ( $sortedBuckets as $bucket ) {
538 if ( $bucket >= $imageWidth ) {
562 if ( !$maxWidth || !$maxHeight ) {
564 throw new MWException(
'Using a choice from $wgImageLimits that is 0x0' );
569 if ( !$width || !$height ) {
574 if ( $width <= $maxWidth && $height <= $maxHeight ) {
576 } elseif ( $width / $height >= $maxWidth / $maxHeight ) {
577 # The limiting factor is the width, not the height.
578 $height = round( $height * $maxWidth / $width );
582 $newwidth = floor( $width * $maxHeight / $height );
583 $height = round( $height * $newwidth / $width );
588 return [ $width, $height ];
663 $userPreferredLanguage,
752 if ( !is_array( $metadata ) ) {
794 return 'unknown/unknown';
826 return $this->canRender;
849 return $this->
getHandler() && $this->handler->mustRender( $this );
879 return $this->isSafeFile;
910 return false; # unknown type, not trusted
916 if (
$mime ===
"unknown/unknown" ) {
917 return false; # unknown type, not trusted
940 # this could be implemented to check a flag in the database,
941 # look for signatures, etc
955 public function load( $flags = 0 ) {
967 return $this->
getPath() && $this->repo->fileExists( $this->path );
985 if ( !isset( $this->transformScript ) ) {
986 $this->transformScript =
false;
988 $script = $this->repo->getThumbScriptUrl();
995 return $this->transformScript;
1006 $hp =& $handlerParams;
1007 $page = $hp[
'page'] ??
false;
1012 $hp[
'width'] = $width;
1014 unset( $hp[
'height'] );
1030 $name = ( $this->repo && !( $flags & self::THUMB_FULL_NAME ) )
1031 ? $this->repo->nameForThumb( $this->
getName() )
1050 list( $thumbExt, ) = $this->
getHandler()->getThumbType(
1052 $thumbName = $this->
getHandler()->makeParamString( $params );
1054 if ( $this->repo->supportsSha1URLs() ) {
1055 $thumbName .=
'-' . $this->
getSha1() .
'.' . $thumbExt;
1057 $thumbName .=
'-' .
$name;
1060 $thumbName .=
".$thumbExt";
1085 $params = [
'width' => $width ];
1086 if ( $height != -1 ) {
1087 $params[
'height'] = $height;
1090 if ( !$thumb || $thumb->isError() ) {
1094 return $thumb->getUrl();
1114 $params[
'width'], 0,
wfMessage(
'thumbnail-dest-create' ) );
1138 if ( $descriptionUrl ) {
1144 if ( $script && !( $flags & self::RENDER_NOW ) ) {
1152 $normalisedParams = $params;
1155 $thumbName = $this->
thumbName( $normalisedParams );
1159 if ( $this->repo ) {
1161 if ( $this->repo->canTransformVia404() && !( $flags & self::RENDER_NOW ) ) {
1169 wfDebug( __METHOD__ .
": Doing stat for $thumbPath" );
1170 if ( !( $flags & self::RENDER_FORCE ) && $this->repo->fileExists( $thumbPath ) ) {
1171 $timestamp = $this->repo->getFileTimestamp( $thumbPath );
1177 $thumb->setStoragePath( $thumbPath );
1180 } elseif ( $flags & self::RENDER_FORCE ) {
1181 wfDebug( __METHOD__ .
" forcing rendering per flag File::RENDER_FORCE" );
1186 if ( $this->repo->getReadOnlyReason() !==
false ) {
1201 return is_object( $thumb ) ? $thumb :
false;
1214 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
1218 $normalisedParams = $transformParams;
1221 $thumbName = $this->
thumbName( $normalisedParams );
1225 $tmpThumbPath = $tmpFile->getPath();
1231 $starttime = microtime(
true );
1235 $tmpFile->bind( $thumb );
1237 $statTiming = microtime(
true ) - $starttime;
1238 $stats->timing(
'media.thumbnail.generate.transform', 1000 * $statTiming );
1242 } elseif ( $thumb->isError() ) {
1244 '@phan-var MediaTransformError $thumb';
1245 $this->lastError = $thumb->toText();
1250 } elseif ( $this->repo && $thumb->hasFile() && !$thumb->fileIsSource() ) {
1253 $starttime = microtime(
true );
1256 $status = $this->repo->quickImport( $tmpThumbPath, $thumbPath, $disposition );
1257 if ( $status->isOK() ) {
1258 $thumb->setStoragePath( $thumbPath );
1263 $statTiming = microtime(
true ) - $starttime;
1264 $stats->timing(
'media.thumbnail.generate.store', 1000 * $statTiming );
1267 $this->getHookRunner()->onFileTransformed( $this, $thumb, $tmpThumbPath, $thumbPath );
1281 || !isset( $params[
'physicalWidth'] )
1282 || !isset( $params[
'physicalHeight'] )
1289 if ( !$bucket || $bucket == $params[
'physicalWidth'] ) {
1295 if ( $this->repo->fileExists( $bucketPath ) ) {
1299 $starttime = microtime(
true );
1301 $params[
'physicalWidth'] = $bucket;
1302 $params[
'width'] = $bucket;
1304 $params = $this->
getHandler()->sanitizeParamsForBucketing( $params );
1314 $buckettime = microtime(
true ) - $starttime;
1316 if ( !$thumb || $thumb->isError() ) {
1320 $this->tmpBucketedThumbCache[$bucket] = $tmpFile->getPath();
1323 $tmpFile->bind( $this );
1325 MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
1326 'media.thumbnail.generate.bucket', 1000 * $buckettime );
1339 && isset( $params[
'physicalWidth'] )
1349 if ( isset( $this->tmpBucketedThumbCache[$bucket] ) ) {
1350 $tmpPath = $this->tmpBucketedThumbCache[$bucket];
1352 if ( file_exists( $tmpPath ) ) {
1356 'height' => $bucketHeight
1363 if ( $this->repo->fileExists( $bucketPath ) ) {
1364 $fsFile = $this->repo->getLocalReference( $bucketPath );
1370 'height' => $bucketHeight
1378 if ( $this->
getSize() >= 1e7 ) {
1381 'doWork' =>
function () {
1415 return $this->
thumbName( [
'physicalWidth' => $bucket ] );
1425 return MediaWikiServices::getInstance()->getTempFSFileFactory()
1426 ->newTempFSFile(
'transform_', $thumbExt );
1435 $fileName = $this->name;
1437 if ( $thumbExt !=
'' && $thumbExt !== $this->
getExtension() ) {
1438 $fileName .=
".$thumbExt";
1460 if ( !isset( $this->handler ) ) {
1464 return $this->handler;
1474 $assetsPath =
"$wgResourceBasePath/resources/assets/file-type-icons/";
1475 $assetsDirectory =
"$IP/resources/assets/file-type-icons/";
1477 $try = [
'fileicon-' . $this->
getExtension() .
'.png',
'fileicon.png' ];
1478 foreach ( $try as $icon ) {
1479 if ( file_exists( $assetsDirectory . $icon ) ) {
1480 $params = [
'width' => 120,
'height' => 120 ];
1482 return new ThumbnailImage( $this, $assetsPath . $icon,
false, $params );
1495 return $this->lastError;
1528 $title->invalidateCache();
1529 $hcu = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
1530 $hcu->purgeTitleUrls(
$title, $hcu::PURGE_INTENT_TXROUND_REFLECTED );
1548 [
'causeAction' =>
'file-purge' ]
1550 JobQueueGroup::singleton()->lazyPush(
$job );
1566 public function getHistory( $limit =
null, $start =
null, $end =
null, $inc =
true ) {
1602 if ( $this->hashPath ===
null ) {
1604 $this->hashPath = $this->repo->getHashPath( $this->
getName() );
1607 return $this->hashPath;
1631 if ( $suffix ===
false ) {
1650 if ( $suffix !==
false ) {
1651 $path .=
'/' . $suffix;
1678 if ( $suffix !==
false ) {
1679 $path .=
'/' . $suffix;
1694 return $this->repo->getZonePath(
'public' ) .
'/' . $this->
getArchiveRel( $suffix );
1707 return $this->repo->getZonePath(
'thumb' ) .
'/' .
1721 return $this->repo->getZonePath(
'thumb' ) .
'/' . $this->
getThumbRel( $suffix );
1733 return $this->repo->getZonePath(
'transcoded' ) .
'/' . $this->
getThumbRel( $suffix );
1747 if ( $suffix ===
false ) {
1750 $path .= rawurlencode( $suffix );
1767 $path = $this->repo->getZoneUrl(
'thumb',
$ext ) .
'/archive/' .
1768 $this->
getHashPath() . rawurlencode( $archiveName );
1769 if ( $suffix !==
false ) {
1770 $path .=
'/' . rawurlencode( $suffix );
1787 if ( $suffix !==
false ) {
1788 $path .=
'/' . rawurlencode( $suffix );
1802 return $this->
getZoneUrl(
'thumb', $suffix );
1812 return $this->
getZoneUrl(
'transcoded', $suffix );
1824 $path = $this->repo->getVirtualUrl() .
'/public/' . $this->
getUrlRel();
1825 if ( $suffix !==
false ) {
1826 $path .=
'/' . rawurlencode( $suffix );
1841 $path = $this->repo->getVirtualUrl() .
'/public/archive/' . $this->
getHashPath();
1842 if ( $suffix ===
false ) {
1845 $path .= rawurlencode( $suffix );
1860 $path = $this->repo->getVirtualUrl() .
'/thumb/' . $this->
getUrlRel();
1861 if ( $suffix !==
false ) {
1862 $path .=
'/' . rawurlencode( $suffix );
1874 return (
bool)$this->repo->getHashLevels();
1881 throw new MWException( static::class .
': write operations are not supported' );
1902 $watch =
false, $timestamp =
false,
User $user =
null
1930 public function publish( $src, $flags = 0, array $options = [] ) {
1943 return $this->
getHandler()->formatMetadata( $this, $context );
1952 return $this->repo && $this->repo->isLocal();
1961 return $this->repo ? $this->repo->getName() :
'unknown';
2053 public function delete( $reason, $suppress =
false, $user = null ) {
2094 public function restore( $versions = [], $unsuppress =
false ) {
2107 return $this->
getHandler() && $this->handler->isMultiPage( $this );
2119 if ( $this->
getHandler() && $this->handler->isMultiPage( $this ) ) {
2120 $this->
pageCount = $this->handler->pageCount( $this );
2126 return $this->pageCount;
2138 public static function scaleHeight( $srcWidth, $srcHeight, $dstWidth ) {
2140 if ( $srcWidth == 0 ) {
2143 return (
int)round( $srcHeight * $dstWidth / $srcWidth );
2163 return $this->
getHandler()->getImageSize( $this, $filePath );
2174 if ( $this->repo ) {
2175 return $this->repo->getDescriptionUrl( $this->
getName() );
2191 if ( !$this->repo || !$this->repo->fetchDescription ) {
2197 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->
getName(),
$lang->getCode() );
2199 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
2200 $key = $this->repo->getLocalCacheKey(
2201 'RemoteFileDescription',
2205 $fname = __METHOD__;
2207 return $cache->getWithSetCallback(
2209 $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
2210 function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
2211 wfDebug(
"Fetching shared description from $renderUrl" );
2212 $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
2213 get( $renderUrl, [], $fname );
2215 $ttl = WANObjectCache::TTL_UNCACHEABLE;
2252 return $this->repo->getFileTimestamp( $this->
getPath() );
2276 return $this->repo->getFileSha1( $this->
getPath() );
2290 $dotExt =
$ext ===
'' ?
'' :
".$ext";
2292 return $hash . $dotExt;
2306 wfDeprecated( __METHOD__ .
' without passing a $user parameter',
'1.35' );
2320 if ( is_string( $metadata ) ) {
2321 $metadata = AtEase::quietCall(
'unserialize', $metadata );
2324 if ( !is_array( $metadata ) ) {
2374 return $this->redirected;
2381 if ( $this->redirected ) {
2382 if ( !$this->redirectTitle ) {
2383 $this->redirectTitle = Title::makeTitle(
NS_FILE, $this->redirected );
2386 return $this->redirectTitle;
2397 $this->redirected = $from;
2422 if ( !( $this->repo instanceof $this->repoClass ) ) {
2423 throw new MWException(
"A {$this->repoClass} object is not set for this File.\n" );
2432 if ( !( $this->title instanceof
Title ) ) {
2433 throw new MWException(
"A Title object is not set for this File.\n" );
unserialize( $serialized)
$wgIgnoreImageErrors
If set, inline scaled images will still produce "<img>" tags ready for output instead of showing an e...
$wgThumbnailBuckets
When defined, is an array of image widths used as buckets for thumbnail generation.
$wgThumbnailMinimumBucketDistance
When using thumbnail buckets as defined above, this sets the minimum distance to the bucket above the...
$wgResourceBasePath
The default 'remoteBasePath' value for instances of ResourceLoaderFileModule.
$wgThumbnailEpoch
If rendered thumbnail files are older than this timestamp, they will be rerendered on demand as if th...
$wgTrustedMediaFormats
list of trusted media-types and MIME types.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Class representing a non-directory file on the file system.
getPath()
Returns the file system path.
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
static makeContentDisposition( $type, $filename='')
Build a Content-Disposition header value per RFC 6266.
Base class for file repositories.
Implements some public methods and some protected utility functions which are required by multiple ch...
getStorageKey()
Get the deletion archive key, "<sha1>.<ext>".
string $url
The URL corresponding to one of the four basic zones.
getVisibility()
Return the deletion bitfield STUB Stable to override.
isVectorized()
Return true if the file is vectorized.
recordUpload( $oldver, $desc, $license='', $copyStatus='', $source='', $watch=false, $timestamp=false, User $user=null)
Record a file upload in the upload log and the image table Stable to override STUB Overridden by Loca...
restore( $versions=[], $unsuppress=false)
Restore all or specified deleted revisions to the given file.
isExpensiveToThumbnail()
True if creating thumbnails from the file is large or otherwise resource-intensive.
isLocal()
Returns true if the file comes from the local file repository.
getThumbRel( $suffix=false)
Get the path, relative to the thumbnail zone root, of the thumbnail directory or a particular file if...
getLastError()
Get last thumbnailing error.
generateAndSaveThumb( $tmpFile, $transformParams, $flags)
Generates a thumbnail according to the given parameters and saves it to storage.
purgeDescription()
Purge the file description page, but don't go after pages using the file.
__construct( $title, $repo)
Call this constructor from child classes.
getIsSafeFileUncached()
Uncached accessor.
getArchivePath( $suffix=false)
Get the path of the archived file.
getBucketThumbName( $bucket)
Returns the name of the thumb for a given bucket.
FSFile bool $fsFile
False if undefined.
const RENDER_NOW
Force rendering in the current process.
getPath()
Return the storage path to the file.
getThumbPath( $suffix=false)
Get the path of the thumbnail directory, or a particular file if $suffix is specified Stable to overr...
getThumbVirtualUrl( $suffix=false)
Get the virtual URL for a thumbnail file or directory Stable to override.
getIsSafeFile()
Accessor for __get()
getDescriptionTouched()
Returns the timestamp (in TS_MW format) of the last change of the description page.
transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags)
Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors)
getDisplayWidthHeight( $maxWidth, $maxHeight, $page=1)
Get the width and height to display image at.
array $tmpBucketedThumbCache
Cache of tmp filepaths pointing to generated bucket thumbnails, keyed by width.
getMimeType()
Returns the MIME type of the file.
getSize()
Return the size of the image file, in bytes Overridden by LocalFile, UnregisteredLocalFile STUB Stabl...
string $extension
File extension.
pageCount()
Returns the number of pages of a multipage document, or false for documents which aren't multipage do...
getMediaType()
Return the type of the media in the file.
string $redirected
Main part of the title, with underscores (Title::getDBkey)
getTranscodedUrl( $suffix=false)
Get the URL of the transcoded directory, or a particular file if $suffix is specified.
bool $isSafeFile
Whether this media file is in a format that is unlikely to contain viruses or malicious content.
getRel()
Get the path of the file relative to the public zone root.
getLength()
Get the duration of a media file in seconds.
static normalizeTitle( $title, $exception=false)
Given a string or Title object return either a valid Title object with namespace NS_FILE or null.
getTimestamp()
Get the 14-character timestamp of the file upload.
assertRepoDefined()
Assert that $this->repo is set to a valid FileRepo instance.
getName()
Return the name of this file.
resetHistory()
Reset the history pointer to the first element of the history.
canAnimateThumbIfAppropriate()
Will the thumbnail be animated if one would expect it to be.
getWidth( $page=1)
Return the width of the image.
getLocalRefPath()
Get an FS copy or original of this file and return the path.
exists()
Returns true if file exists in the repository.
getMatchedLanguage( $userPreferredLanguage)
Get the language code from the available languages for this file that matches the language requested ...
getThumbUrl( $suffix=false)
Get the URL of the thumbnail directory, or a particular file if $suffix is specified Stable to overri...
allowInlineDisplay()
Alias for canRender()
mustRender()
Return true if the file is of a type that can't be directly rendered by typical browsers and needs to...
getVirtualUrl( $suffix=false)
Get the public zone virtual URL for a current version source file Stable to override.
isTrustedFile()
Returns true if the file is flagged as trusted.
getHistory( $limit=null, $start=null, $end=null, $inc=true)
Return a fragment of the history of file.
isCacheable()
Check if this file object is small and can be cached Stable to override.
isMissing()
Stable to override.
isVisible()
Returns true if file exists in the repository and can be included in a page.
iconThumb()
Get a ThumbnailImage representing a file type icon.
getRepo()
Returns the repository Stable to override.
getZoneUrl( $zone, $suffix=false)
Get the URL of the zone directory, or a particular file if $suffix is specified.
upgradeRow()
Upgrade the database row if there is one Called by ImagePage STUB.
convertMetadataVersion( $metadata, $version)
get versioned metadata
getCanRender()
Accessor for __get()
getDescriptionText(Language $lang=null)
Get the HTML text of the description page, if available Stable to override.
getArchiveVirtualUrl( $suffix=false)
Get the public zone virtual URL for an archived version source file Stable to override.
assertTitleDefined()
Assert that $this->title is set to a Title.
getArchiveThumbPath( $archiveName, $suffix=false)
Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified.
getHeight( $page=1)
Return the height of the image.
getThumbnailSource( $params)
Returns the most appropriate source image for the thumbnail, given a target thumbnail size.
getArchiveThumbRel( $archiveName, $suffix=false)
Get the path, relative to the thumbnail zone root, for an archived file's thumbs directory or a speci...
getUser( $type='text')
Returns ID or name of user who uploaded the file STUB.
makeTransformTmpFile( $thumbPath)
Creates a temp FS file with the same extension and the thumbnail.
int false $pageCount
Number of pages of a multipage document, or false for documents which aren't multipage documents.
getBitDepth()
Return the bit depth of the file Overridden by LocalFile STUB Stable to override.
publish( $src, $flags=0, array $options=[])
Move or copy a file to its public location.
isOld()
Returns true if the image is an old version STUB.
getTitle()
Return the associated title object.
getDescriptionShortUrl()
Get short description URL for a files based on the page ID Stable to override.
canRender()
Checks if the output of transform() for this file is likely to be valid.
getAvailableLanguages()
Gives a (possibly empty) list of languages to render the file in.
getCommonMetaArray()
Like getMetadata but returns a handler independent array of common values.
getOriginalTitle()
Return the title used to find this file.
getRepoName()
Returns the name of the repository.
getDefaultRenderLanguage()
In files that support multiple language, what is the default language to use if none specified.
migrateThumbFile( $thumbName)
Hook into transform() to allow migration of thumbnail files STUB Stable to override.
static compare(File $a, File $b)
Callback for usort() to do file sorts by name.
getCanonicalUrl()
Stable to override.
isMultipage()
Returns 'true' if this file is a type which supports multiple pages, e.g.
isSafeFile()
Determines if this media file is in a format that is unlikely to contain viruses or malicious content...
getThumbnails()
Get all thumbnail names previously generated for this file STUB Overridden by LocalFile Stable to ove...
createThumb( $width, $height=-1)
Create a thumbnail of the image having the specified width/height.
string $name
The name of a file from its title object.
getTranscodedPath( $suffix=false)
Get the path of the transcoded directory, or a particular file if $suffix is specified.
load( $flags=0)
Load any lazy-loaded file object fields from source.
getExtension()
Get the file extension, e.g.
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
transform( $params, $flags=0)
Transform a media file Stable to override.
getImageSize( $filePath)
Get an image size array like that returned by getImageSize(), or false if it can't be determined.
nextHistoryLine()
Return the history of this file, line by line.
purgeEverything()
Purge metadata and all affected pages when the file is created, deleted, or majorly updated.
string $path
The storage path corresponding to one of the zones.
static normalizeExtension( $extension)
Normalize a file extension to the common form, making it lowercase and checking some synonyms,...
static splitMime( $mime)
Split an internet media type into its two components; if not a two-part name, set the minor type to '...
getUrl()
Return the URL of the file Stable to override.
wasDeleted()
Was this file ever deleted from the wiki?
string $transformScript
URL of transformscript (for example thumb.php)
string $repoClass
Required Repository class type.
thumbName( $params, $flags=0)
Return the file name of a thumbnail with the specified parameters.
getArchiveUrl( $suffix=false)
Get the URL of the archive directory, or a particular file if $suffix is specified Stable to override...
getSha1()
Get the SHA-1 base 36 hash of the file.
formatMetadata( $context=false)
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this file, if it's marked as d...
isTransformedLocally()
Whether the thumbnails created on the same server as this code is running.
getHandler()
Get a MediaHandler instance for this file.
getDescriptionUrl()
Get the URL of the image description page.
string $hashPath
Relative path including trailing slash.
getBucketThumbPath( $bucket)
Returns the repo path of the thumb for a given bucket.
purgeCache( $options=[])
Purge shared caches such as thumbnails and DB data caching STUB Overridden by LocalFile Stable to ove...
getThumbnailBucket( $desiredWidth, $page=1)
Return the smallest bucket from $wgThumbnailBuckets which is at least $wgThumbnailMinimumBucketDistan...
getUnscaledThumb( $handlerParams=[])
Get a ThumbnailImage which is the same size as the source.
getArchiveRel( $suffix=false)
Get the path of an archived file relative to the public zone root Stable to override.
getUrlRel()
Get urlencoded path of the file relative to the public zone root.
getThumbDisposition( $thumbName, $dispositionType='inline')
move( $target)
Move file to the new title.
generateBucketsIfNeeded( $params, $flags=0)
Generates chained bucketed thumbnails if needed.
static scaleHeight( $srcWidth, $srcHeight, $dstWidth)
Calculate the height of a thumbnail using the source and destination width.
isDeleted( $field)
Is this file a "deleted" file in a private archive? STUB.
getArchiveThumbUrl( $archiveName, $suffix=false)
Get the URL of the archived file's thumbs, or a particular thumb if $suffix is specified Stable to ov...
getDescription( $audience=self::FOR_PUBLIC, User $user=null)
Get description of file revision STUB.
getMetadata()
Get handler-specific metadata Overridden by LocalFile, UnregisteredLocalFile STUB Stable to override.
deleteFile( $reason, User $user, $suppress=false)
Delete all versions of the file.
generateThumbName( $name, $params)
Generate a thumbnail file name from a name and specified parameters Stable to override.
bool $canRender
Whether the output of transform() for this file is likely to be valid.
getFullUrl()
Return a fully-qualified URL to the file.
const RENDER_FORCE
Force rendering even if thumbnail already exist and using RENDER_NOW I.e.
static checkExtensionCompatibility(File $old, $new)
Checks if file extensions are compatible.
getHashPath()
Get the filename hash component of the directory including trailing slash, e.g.
string $lastError
Text of last error.
A foreign repository with a remote MediaWiki with an API thingy.
static newForBacklinks(Title $title, $table, $params=[])
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Convenience class for dealing with PoolCounters using callbacks.
execute( $skipcache=false)
Get the result of the work (whatever it is), or the result of the error() function.
Media transform output for images.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Interface for database access objects.
if(count( $args)< 1) $job
if(!is_readable( $file)) $ext
if(!isset( $args[0])) $lang