MediaWiki master
MediaWiki\FileRepo\ForeignAPIRepo Class Reference

A foreign repository for a remote MediaWiki accessible through api.php requests. More...

Inherits MediaWiki\FileRepo\FileRepo, and MediaWiki\FileRepo\IForeignRepoWithMWApi.

Collaboration diagram for MediaWiki\FileRepo\ForeignAPIRepo:

Public Member Functions

 __construct ( $info)
 
 canCacheThumbs ()
 Are we locally caching the thumbnails?
 
 enumFiles ( $callback)
 
 fetchImageQuery ( $query)
 Make an API query in the foreign repo, caching results.
 
 fileExistsBatch (array $files)
 
 findBySha1 ( $hash)
 
 getFileProps ( $virtualUrl)
 
 getImageInfo ( $data)
 
 getInfo ()
 Get information about the repo - overrides/extends the parent class's information.
 
 getThumbError ( $name, $width=-1, $height=-1, $otherParams='', $lang=null)
 
 getThumbUrlFromCache ( $name, $width, $height, $params="")
 Return the imageurl from cache if possible.
 
 getZonePath ( $zone)
 Get the local directory corresponding to one of the basic zones.
 
 getZoneUrl ( $zone, $ext=null)
 
 httpGetCached ( $attribute, $query, $cacheTTL=3600)
 HTTP GET request to a mediawiki API (with caching)
 
 newFile ( $title, $time=false)
 Per docs in FileRepo, this needs to return false if we don't support versioned files.
 
- Public Member Functions inherited from MediaWiki\FileRepo\FileRepo
 __construct (?array $info=null)
 
 addShellboxInputFile (BoxedCommand $command, string $boxedName, string $virtualUrl)
 Add a file to a Shellbox command as an input file.
 
 backendSupportsUnicodePaths ()
 
 canTransformLocally ()
 Returns true if the repository can transform files locally.
 
 canTransformVia404 ()
 Returns true if the repository can transform files via a 404 handler.
 
 checkRedirect ( $title)
 Checks if there is a redirect named as $title.
 
 cleanDir ( $dir)
 Deletes a directory if empty.
 
 cleanupBatch (array $files, $flags=0)
 Deletes a batch of files.
 
 cleanupDeletedBatch (array $storageKeys)
 Delete files in the deleted directory if they are not referenced in the filearchive table.
 
 concatenate (array $srcPaths, $dstPath, $flags=0)
 Concatenate a list of temporary files into a target file location.
 
 delete ( $srcRel, $archiveRel)
 Move a file to the deletion archive.
 
 deleteBatch (array $sourceDestPairs)
 Move a group of files to the deletion archive.
 
 fileExists ( $file)
 Checks existence of a file.
 
 findBySha1s (array $hashes)
 Get an array of arrays or iterators of file objects for files that have the given SHA-1 content hashes.
 
 findFile ( $title, $options=[])
 Find an instance of the named file created at the specified time Returns false if the file does not exist.
 
 findFileFromKey ( $sha1, $options=[])
 Find an instance of the file with this key, created at the specified time Returns false if the file does not exist.
 
 findFiles (array $items, $flags=0)
 Find many files at once.
 
 findFilesByPrefix ( $prefix, $limit)
 Return an array of files where the name starts with $prefix.
 
 freeTemp ( $virtualUrl)
 Remove a temporary file or mark it for garbage collection.
 
 getBackend ()
 Get the file backend instance.
 
 getDeletedHashPath ( $key)
 Get a relative path for a deletion archive key, e.g.
 
 getDescriptionRenderUrl ( $name, $lang=null)
 Get the URL of the content-only fragment of the description page.
 
 getDescriptionStylesheetUrl ()
 Get the URL of the stylesheet to apply to description pages.
 
 getDescriptionUrl ( $name)
 Get the URL of an image description page.
 
 getDisplayName ()
 Get the human-readable name of the repo.
 
 getFileSha1 ( $virtualUrl)
 Get the sha1 (base 36) of a file with a given virtual URL/storage path.
 
 getFileSize ( $virtualUrl)
 Get the size of a file with a given virtual URL/storage path.
 
 getFileTimestamp ( $virtualUrl)
 Get the timestamp of a file with a given virtual URL/storage path.
 
 getHashLevels ()
 Get the number of hash directory levels.
 
 getHashPath ( $name)
 Get a relative path including trailing slash, e.g.
 
 getLocalCacheKey ( $kClassSuffix,... $components)
 Get a site-local, repository-qualified, WAN cache key.
 
 getLocalCopy ( $virtualUrl)
 Get a local FS copy of a file with a given virtual URL/storage path.
 
 getLocalReference ( $virtualUrl)
 Get a local FS file with a given virtual URL/storage path.
 
 getName ()
 Get the name of this repository, as specified by $info['name]' to the constructor.
 
 getNameFromTitle ( $title)
 Get the name of a file from its title.
 
 getReadOnlyReason ()
 Get an explanatory message if this repo is read-only.
 
 getRootDirectory ()
 Get the public zone root storage directory of the repository.
 
 getSharedCacheKey ( $kClassSuffix,... $components)
 Get a global, repository-qualified, WAN cache key.
 
 getTempHashPath ( $suffix)
 Get a relative path including trailing slash, e.g.
 
 getTempRepo ()
 Get a temporary private FileRepo associated with this repo.
 
 getThumbProxySecret ()
 Get the secret key for the proxied thumb service.
 
 getThumbProxyUrl ()
 Get the URL thumb.php requests are being proxied to.
 
 getThumbScriptUrl ()
 Get the URL of thumb.php.
 
 getUploadStash (?UserIdentity $user=null)
 Get an UploadStash associated with this repo.
 
 getVirtualUrl ( $suffix=false)
 Get a URL referring to this repository, with the private mwrepo protocol.
 
 hasSha1Storage ()
 Returns whether or not storage is SHA-1 based.
 
 invalidateImageRedirect ( $title)
 Invalidates image redirect cache related to that image Doesn't do anything for repositories that don't support image redirects.
 
 isLocal ()
 Returns true if this the local file repository.
 
 makeUrl ( $query='', $entry='index')
 Make an url to this repo.
 
 nameForThumb ( $name)
 Get the portion of the file that contains the origin file name.
 
 newFatal ( $message,... $parameters)
 Create a new fatal error.
 
 newGood ( $value=null)
 Create a new good result.
 
 paranoidClean ( $param)
 Path disclosure protection function.
 
 passThrough ( $param)
 Path disclosure protection function.
 
 publish ( $src, $dstRel, $archiveRel, $flags=0, array $options=[])
 Copy or move a file either from a storage path, virtual URL, or file system path, into this repository at the specified destination location.
 
 publishBatch (array $ntuples, $flags=0)
 Publish a batch of files.
 
 quickCleanDir ( $dir)
 Deletes a directory if empty.
 
 quickImport ( $src, $dst, $options=null)
 Import a file from the local file system into the repo.
 
 quickImportBatch (array $triples)
 Import a batch of files from the local file system into the repo.
 
 quickPurge ( $path)
 Purge a file from the repo.
 
 quickPurgeBatch (array $paths)
 Purge a batch of files from the repo.
 
 resolveVirtualUrl ( $url)
 Get the backend storage path corresponding to a virtual URL.
 
 store ( $srcPath, $dstZone, $dstRel, $flags=0)
 Store a file to a given destination.
 
 storeBatch (array $triplets, $flags=0)
 Store a batch of files.
 
 storeTemp ( $originalName, $srcPath)
 Pick a random name in the temp zone and store a file to it.
 
 streamFileWithStatus ( $virtualUrl, $headers=[], $optHeaders=[])
 Attempt to stream a file with the given virtual URL/storage path.
 
 supportsSha1URLs ()
 Returns whether or not repo supports having originals SHA-1s in the thumb URLs.
 
 validateFilename ( $filename)
 Determine if a relative path is valid, i.e.
 

Static Public Member Functions

static getUserAgent ()
 The user agent the ForeignAPIRepo will use.
 
static httpGet ( $url, $timeout='default', $options=[], &$mtime=false)
 
- Static Public Member Functions inherited from MediaWiki\FileRepo\FileRepo
static isVirtualUrl ( $url)
 Determine if a string is an mwrepo:// URL.
 

Protected Member Functions

 assertWritableRepo ()
 
- Protected Member Functions inherited from MediaWiki\FileRepo\FileRepo
 enumFilesInStorage ( $callback)
 Call a callback function for every public file in the repository.
 
 getZoneLocation ( $zone)
 The storage container and base path of a zone.
 
 initDirectory ( $dir)
 Creates a directory with the appropriate zone permissions.
 
 initZones ( $doZones=[])
 Ensure that a single zone or list of zones is defined for usage.
 
 resolveToStoragePathIfVirtual ( $path)
 If a path is a virtual URL, resolve it to a storage path.
 

Static Protected Member Functions

static getIIProps ()
 
- Static Protected Member Functions inherited from MediaWiki\FileRepo\FileRepo
static getHashPathForLevel ( $name, $levels)
 

Protected Attributes

int $apiMetadataExpiry = 4 * 3600
 API metadata cache time.
 
int $apiThumbCacheExpiry = 24 * 3600
 Check back with Commons after this expiry.
 
int $fileCacheExpiry = 30 * 24 * 3600
 Redownload thumbnail files after this expiry.
 
callable $fileFactory = [ ForeignAPIFile::class, 'newFromTitle' ]
 
array $mFileExists = []
 
- Protected Attributes inherited from MediaWiki\FileRepo\FileRepo
int $abbrvThreshold
 File names over this size will use the short form of thumbnail names.
 
string null $articleUrl
 Equivalent to $wgArticlePath, e.g.
 
FileBackend $backend
 
int $deletedHashLevels
 The number of directory levels for hash-based division of deleted files.
 
string null $descBaseUrl
 URL of image description pages, e.g.
 
bool $disableLocalTransform = false
 Disable local image scaling.
 
null string $favicon = null
 The URL to a favicon (optional, may be a server-local path URL).
 
callable $fileFactory = [ UnregisteredLocalFile::class, 'newFromTitle' ]
 Override these in the base class.
 
callable false $fileFactoryKey = false
 Override these in the base class.
 
int $hashLevels
 The number of directory levels for hash-based division of files.
 
bool $hasSha1Storage = false
 
bool $initialCapital
 Equivalent to $wgCapitalLinks (or $wgCapitalLinkOverrides[NS_FILE], determines whether filenames implicitly start with a capital letter.
 
bool $isPrivate
 Whether all zones should be private (e.g.
 
callable false $oldFileFactory = false
 Override these in the base class.
 
callable false $oldFileFactoryKey = false
 Override these in the base class.
 
string $pathDisclosureProtection = 'simple'
 May be 'paranoid' to remove all parameters from error messages, 'none' to leave the paths in unchanged, or 'simple' to replace paths with placeholders.
 
string null $scriptDirUrl
 URL of the MediaWiki installation, equivalent to $wgScriptPath, e.g.
 
bool $supportsSha1URLs = false
 
string $thumbProxySecret
 Secret key to pass as an X-Swift-Secret header to the proxied thumb service.
 
string $thumbProxyUrl
 URL of where to proxy thumb.php requests to.
 
string $thumbScriptUrl
 URL of thumb.php.
 
string false $thumbUrl
 The base thumbnail URL.
 
bool $transformVia404
 Whether to skip media file transformation on parse and rely on a 404 handler instead.
 
string false $url
 Public zone URL.
 
WANObjectCache $wanCache
 
array $zones = []
 Map of zones to config.
 

Additional Inherited Members

- Public Attributes inherited from MediaWiki\FileRepo\FileRepo
int $descriptionCacheExpiry
 
bool $fetchDescription
 Whether to fetch commons image description pages and display them on the local wiki.
 
string $name
 
const DELETE_SOURCE = 1
 
const NAME_AND_TIME_ONLY = 1
 
const OVERWRITE = 2
 
const OVERWRITE_SAME = 4
 
const SKIP_LOCKING = 8
 

Detailed Description

A foreign repository for a remote MediaWiki accessible through api.php requests.

Example config:
'class' => ForeignAPIRepo::class,
'name' => 'shared',
'apibase' => 'https://en.wikipedia.org/w/api.php',
'fetchDescription' => true, // Optional
'descriptionCacheExpiry' => 3600,
];
$wgForeignFileRepos
Config variable stub for the ForeignFileRepos setting, for use by phpdoc and IDEs.

Definition at line 54 of file ForeignAPIRepo.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\FileRepo\ForeignAPIRepo::__construct ( $info)

Member Function Documentation

◆ assertWritableRepo()

MediaWiki\FileRepo\ForeignAPIRepo::assertWritableRepo ( )
protected
Returns
never

Reimplemented from MediaWiki\FileRepo\FileRepo.

Definition at line 636 of file ForeignAPIRepo.php.

◆ canCacheThumbs()

MediaWiki\FileRepo\ForeignAPIRepo::canCacheThumbs ( )

Are we locally caching the thumbnails?

Returns
bool

Definition at line 489 of file ForeignAPIRepo.php.

Referenced by MediaWiki\FileRepo\ForeignAPIRepo\__construct(), and MediaWiki\FileRepo\ForeignAPIRepo\getThumbUrlFromCache().

◆ enumFiles()

MediaWiki\FileRepo\ForeignAPIRepo::enumFiles ( $callback)
Parameters
callable$callback
Returns
never

Reimplemented from MediaWiki\FileRepo\FileRepo.

Definition at line 629 of file ForeignAPIRepo.php.

◆ fetchImageQuery()

MediaWiki\FileRepo\ForeignAPIRepo::fetchImageQuery ( $query)

◆ fileExistsBatch()

MediaWiki\FileRepo\ForeignAPIRepo::fileExistsBatch ( array $files)
Parameters
string[]$files
Returns
array

Reimplemented from MediaWiki\FileRepo\FileRepo.

Definition at line 148 of file ForeignAPIRepo.php.

References MediaWiki\FileRepo\ForeignAPIRepo\fetchImageQuery(), Wikimedia\FileBackend\FileBackend\isStoragePath(), and wfWarn().

◆ findBySha1()

MediaWiki\FileRepo\ForeignAPIRepo::findBySha1 ( $hash)
Parameters
string$hash
Returns
ForeignAPIFile[]

Reimplemented from MediaWiki\FileRepo\FileRepo.

Definition at line 261 of file ForeignAPIRepo.php.

References MediaWiki\FileRepo\ForeignAPIRepo\fetchImageQuery(), MediaWiki\FileRepo\File\ForeignAPIFile\getProps(), and NS_FILE.

◆ getFileProps()

MediaWiki\FileRepo\ForeignAPIRepo::getFileProps ( $virtualUrl)
Parameters
string$virtualUrl
Returns
array

Reimplemented from MediaWiki\FileRepo\FileRepo.

Definition at line 203 of file ForeignAPIRepo.php.

◆ getIIProps()

static MediaWiki\FileRepo\ForeignAPIRepo::getIIProps ( )
staticprotected
Returns
string
Since
1.23

Definition at line 584 of file ForeignAPIRepo.php.

◆ getImageInfo()

MediaWiki\FileRepo\ForeignAPIRepo::getImageInfo ( $data)
Parameters
array$data
Returns
array|false

Definition at line 241 of file ForeignAPIRepo.php.

Referenced by MediaWiki\FileRepo\ForeignAPIRepo\getThumbError().

◆ getInfo()

MediaWiki\FileRepo\ForeignAPIRepo::getInfo ( )

Get information about the repo - overrides/extends the parent class's information.

Returns
array
Since
1.22

Reimplemented from MediaWiki\FileRepo\FileRepo.

Definition at line 508 of file ForeignAPIRepo.php.

References MediaWiki\FileRepo\ForeignAPIRepo\httpGetCached().

◆ getThumbError()

MediaWiki\FileRepo\ForeignAPIRepo::getThumbError ( $name,
$width = -1,
$height = -1,
$otherParams = '',
$lang = null )
Parameters
string$name
int$width
int$height
string$otherParams
string | null$langLanguage code for language of error
Returns
MediaTransformError|false
Since
1.22

Definition at line 321 of file ForeignAPIRepo.php.

References MediaWiki\FileRepo\FileRepo\$name, MediaWiki\FileRepo\ForeignAPIRepo\fetchImageQuery(), MediaWiki\FileRepo\FileRepo\getDisplayName(), MediaWiki\FileRepo\ForeignAPIRepo\getImageInfo(), and wfDebug().

◆ getThumbUrlFromCache()

MediaWiki\FileRepo\ForeignAPIRepo::getThumbUrlFromCache ( $name,
$width,
$height,
$params = "" )

◆ getUserAgent()

static MediaWiki\FileRepo\ForeignAPIRepo::getUserAgent ( )
static

The user agent the ForeignAPIRepo will use.

Returns
string

Definition at line 497 of file ForeignAPIRepo.php.

References MediaWiki\MediaWikiServices\getInstance().

Referenced by MediaWiki\FileRepo\ForeignAPIRepo\httpGet().

◆ getZonePath()

MediaWiki\FileRepo\ForeignAPIRepo::getZonePath ( $zone)

Get the local directory corresponding to one of the basic zones.

Parameters
string$zone
Returns
null|string|false

Reimplemented from MediaWiki\FileRepo\FileRepo.

Definition at line 476 of file ForeignAPIRepo.php.

Referenced by MediaWiki\FileRepo\ForeignAPIRepo\getThumbUrlFromCache().

◆ getZoneUrl()

MediaWiki\FileRepo\ForeignAPIRepo::getZoneUrl ( $zone,
$ext = null )
See also
FileRepo::getZoneUrl()
Parameters
string$zone
string | null$extOptional file extension
Returns
string

Reimplemented from MediaWiki\FileRepo\FileRepo.

Definition at line 460 of file ForeignAPIRepo.php.

References MediaWiki\FileRepo\FileRepo\$thumbUrl, and MediaWiki\FileRepo\FileRepo\$url.

Referenced by MediaWiki\FileRepo\ForeignAPIRepo\getThumbUrlFromCache().

◆ httpGet()

static MediaWiki\FileRepo\ForeignAPIRepo::httpGet ( $url,
$timeout = 'default',
$options = [],
& $mtime = false )
static
Parameters
string$url
string$timeout
array$options
int | false&$mtimeResulting Last-Modified UNIX timestamp if received
Returns
string|false

Definition at line 542 of file ForeignAPIRepo.php.

References MediaWiki\FileRepo\FileRepo\$url, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\FileRepo\ForeignAPIRepo\getUserAgent(), PROTO_HTTP, wfDebug(), and wfTimestamp().

Referenced by MediaWiki\FileRepo\ForeignAPIRepo\getThumbUrlFromCache(), and MediaWiki\FileRepo\ForeignAPIRepo\httpGetCached().

◆ httpGetCached()

MediaWiki\FileRepo\ForeignAPIRepo::httpGetCached ( $attribute,
$query,
$cacheTTL = 3600 )

HTTP GET request to a mediawiki API (with caching)

Parameters
string$attributeUsed in cache key creation, mostly
array$queryThe query parameters for the API request
int$cacheTTLTime to live for the memcached caching
Returns
string|null

Definition at line 595 of file ForeignAPIRepo.php.

References MediaWiki\FileRepo\FileRepo\$url, MediaWiki\FileRepo\ForeignAPIRepo\httpGet(), MediaWiki\FileRepo\FileRepo\makeUrl(), and wfAppendQuery().

Referenced by MediaWiki\FileRepo\ForeignAPIRepo\fetchImageQuery(), and MediaWiki\FileRepo\ForeignAPIRepo\getInfo().

◆ newFile()

MediaWiki\FileRepo\ForeignAPIRepo::newFile ( $title,
$time = false )

Per docs in FileRepo, this needs to return false if we don't support versioned files.

Well, we don't.

Parameters
PageIdentity | LinkTarget | string$title
string | false$time
Returns
File|false

Reimplemented from MediaWiki\FileRepo\FileRepo.

Definition at line 136 of file ForeignAPIRepo.php.

Member Data Documentation

◆ $apiMetadataExpiry

int MediaWiki\FileRepo\ForeignAPIRepo::$apiMetadataExpiry = 4 * 3600
protected

API metadata cache time.

Since
1.38

This is often the performance bottleneck for ForeignAPIRepo. For each file used, we must fetch file metadata for it and every high-DPI variant, in serial, during the parse. This is slow if a page has many files, with RTT of the handshake often being significant. The metadata rarely changes, but if a new version of the file was uploaded, it might be displayed incorrectly until its metadata entry falls out of cache.

Definition at line 87 of file ForeignAPIRepo.php.

◆ $apiThumbCacheExpiry

int MediaWiki\FileRepo\ForeignAPIRepo::$apiThumbCacheExpiry = 24 * 3600
protected

Check back with Commons after this expiry.

Definition at line 71 of file ForeignAPIRepo.php.

Referenced by MediaWiki\FileRepo\ForeignAPIRepo\getThumbUrlFromCache().

◆ $fileCacheExpiry

int MediaWiki\FileRepo\ForeignAPIRepo::$fileCacheExpiry = 30 * 24 * 3600
protected

Redownload thumbnail files after this expiry.

Definition at line 74 of file ForeignAPIRepo.php.

◆ $fileFactory

callable MediaWiki\FileRepo\ForeignAPIRepo::$fileFactory = [ ForeignAPIFile::class, 'newFromTitle' ]
protected

Definition at line 69 of file ForeignAPIRepo.php.

◆ $mFileExists

array MediaWiki\FileRepo\ForeignAPIRepo::$mFileExists = []
protected

Definition at line 90 of file ForeignAPIRepo.php.


The documentation for this class was generated from the following file: