MediaWiki master
MediaWiki\FileRepo\ForeignDBRepo Class Reference

A foreign repository with an accessible MediaWiki database. More...

Inherits MediaWiki\FileRepo\LocalRepo, and MediaWiki\FileRepo\IForeignRepoWithDB.

Collaboration diagram for MediaWiki\FileRepo\ForeignDBRepo:

Public Member Functions

 __construct ( $info)
 getBlobStore ()
 Get a BlobStore for storing and retrieving large metadata, or null if that can't be done.
 getPrimaryDB ()
 Get a connection to the primary DB.
Returns
IDatabase
Since
1.37

 getReplicaDB ()
 Get a connection to the replica DB.
Returns
IReadableDatabase

Public Member Functions inherited from MediaWiki\FileRepo\LocalRepo
 __construct (?array $info=null)
 checkRedirect ( $title)
 Checks if there is a redirect named as $title.
 cleanupDeletedBatch (array $storageKeys)
 Delete files in the deleted directory if they are not referenced in the filearchive table.
 findBySha1 ( $hash)
 Get an array or iterator of file objects for files that have a given SHA-1 content hash.
 findBySha1s (array $hashes)
 Get an array of arrays or iterators of file objects for files that have the given SHA-1 content hashes.
 findFiles (array $items, $flags=0)
 Find many files at once.
Parameters
array$itemsAn array of titles, or an array of findFile() options with the "title" option giving the title. Example:
$findItem = [ 'title' => $title, 'private' => true ];
$findBatch = [ $findItem ];
$repo->findFiles( $findBatch );
LocalRepo $repo
Repository that this uses to store temp files.
No title should appear in $items twice, as the result use titles as keys
int$flagsSupports:
  • FileRepo\NAME_AND_TIME_ONLY : return a (search title => (title,timestamp)) map. The search title uses the input titles; the other is the final post-redirect title. All titles are returned as string DB keys and the inner array is associative.
Returns
array Map of (file name => File objects) for matches or (search title => (title,timestamp))

 findFilesByPrefix ( $prefix, $limit)
 Return an array of files where the name starts with $prefix.
 getDbDomain ()
 Get the database domain ID for this repository.
 getSharedCacheKey ( $kClassSuffix,... $components)
 Get a global, repository-qualified, WAN cache key.This might be called from either the site context of the wiki that owns the repo or the site context of another wiki that simply has access to the repo. This returns false if the repository's cache is not accessible from the current site context.
Parameters
string$kClassSuffixKey collection name suffix (added to this repo class)
mixed...$components Additional key components
Returns
string|false

 getSplitMetadataThreshold ()
 Get the threshold above which metadata items should be split into separate storage, or null if no splitting should be done.
 getUploadStash (?UserIdentity $user=null)
 Get an UploadStash associated with this repo.
 invalidateImageRedirect ( $title)
 Invalidates image redirect cache related to that image.
 isJsonMetadataEnabled ()
 Returns true if files should store metadata in JSON format.
 isMetadataReserializeEnabled ()
 isMetadataUpdateEnabled ()
 isSplitMetadataEnabled ()
 Returns true if files should split up large metadata, storing parts of it in the BlobStore.
 newFileFromRow ( $row)
 newFromArchiveName ( $title, $archiveName)
Public Member Functions inherited from MediaWiki\FileRepo\FileRepo
 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.
 cleanDir ( $dir)
 Deletes a directory if empty.
 cleanupBatch (array $files, $flags=0)
 Deletes a batch of files.
 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.
 enumFiles ( $callback)
 Call a callback function for every public regular file in the repository.
 fileExists ( $file)
 Checks existence of a file.
 fileExistsBatch (array $files)
 Checks existence of an array of files.
 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.
 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.
 getFileProps ( $virtualUrl)
 Get properties of a file with a given virtual URL/storage path.
 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.
 getInfo ()
 Return information about the repository.
 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.
 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.
 getVirtualUrl ( $suffix=false)
 Get a URL referring to this repository, with the private mwrepo protocol.
 getZonePath ( $zone)
 Get the storage path corresponding to one of the zones.
 getZoneUrl ( $zone, $ext=null)
 Get the URL corresponding to one of the four basic zones.
 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.
 newFile ( $title, $time=false)
 Create a new File object from the local repository.
 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.

Protected Member Functions

 assertWritableRepo ()
 Throw an exception if this repo is read-only by design.
 getDBFactory ()
Protected Member Functions inherited from MediaWiki\FileRepo\LocalRepo
 deletedFileHasKey ( $key, $lock=null)
 Check if a deleted (filearchive) file has this sha1 key.
 getBackendOperationOptions ()
 FileRepo is responsible for locking since there can be both file objects and metadata.
 hasAccessibleSharedCache ()
 Check whether the repo has a shared cache, accessible from the current site context.
 hiddenFileHasKey ( $key, $lock=null)
 Check if a hidden (revision delete) file has this sha1 key.
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.

Protected Attributes

IDatabase $dbConn
string $dbFlags
string $dbName
string $dbPassword
string null $dbSchema
string $dbServer
string $dbType
string $dbUser
callable $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ]
callable $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ]
string $tablePrefix
Protected Attributes inherited from MediaWiki\FileRepo\LocalRepo
BlobStore $blobStore
string $dbDomain
 DB domain of the repo wiki.
IConnectionProvider $dbProvider
callable $fileFactory = [ LocalFile::class, 'newFromTitle' ]
callable $fileFactoryKey = [ LocalFile::class, 'newFromKey' ]
callable $fileFromRowFactory = [ LocalFile::class, 'newFromRow' ]
bool $hasAccessibleSharedCache
 Whether shared cache keys are exposed/accessible.
callable $oldFileFactory = [ OldLocalFile::class, 'newFromTitle' ]
callable $oldFileFactoryKey = [ OldLocalFile::class, 'newFromKey' ]
callable $oldFileFromRowFactory = [ OldLocalFile::class, 'newFromRow' ]
bool $reserializeMetadata = false
int null $splitMetadataThreshold = 1000
bool $updateCompatibleMetadata = false
bool $useJsonMetadata = true
bool $useSplitMetadata = false
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 $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

Static Public Member Functions inherited from MediaWiki\FileRepo\LocalRepo
static getHashFromKey ( $key)
 Gets the SHA1 hash from a storage key.
Static Public Member Functions inherited from MediaWiki\FileRepo\FileRepo
static isVirtualUrl ( $url)
 Determine if a string is an mwrepo:// URL.
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
Static Protected Member Functions inherited from MediaWiki\FileRepo\FileRepo
static getHashPathForLevel ( $name, $levels)

Detailed Description

A foreign repository with an accessible MediaWiki database.

Definition at line 25 of file ForeignDBRepo.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\FileRepo\ForeignDBRepo::__construct ( $info)
Parameters
array | null$info

Definition at line 61 of file ForeignDBRepo.php.

References MediaWiki\FileRepo\LocalRepo\$dbDomain, and MediaWiki\FileRepo\LocalRepo\hasAccessibleSharedCache().

Member Function Documentation

◆ assertWritableRepo()

MediaWiki\FileRepo\ForeignDBRepo::assertWritableRepo ( )
protected

Throw an exception if this repo is read-only by design.

This does not and should not check getReadOnlyReason().

Exceptions
LogicException

Reimplemented from MediaWiki\FileRepo\FileRepo.

Definition at line 115 of file ForeignDBRepo.php.

◆ getBlobStore()

MediaWiki\FileRepo\ForeignDBRepo::getBlobStore ( )

Get a BlobStore for storing and retrieving large metadata, or null if that can't be done.

Reimplemented from MediaWiki\FileRepo\LocalRepo.

Definition at line 119 of file ForeignDBRepo.php.

References return.

◆ getDBFactory()

MediaWiki\FileRepo\ForeignDBRepo::getDBFactory ( )
protected

◆ getPrimaryDB()

MediaWiki\FileRepo\ForeignDBRepo::getPrimaryDB ( )

Get a connection to the primary DB.

Returns
IDatabase
Since
1.37

Reimplemented from MediaWiki\FileRepo\LocalRepo.

Definition at line 80 of file ForeignDBRepo.php.

References $dbConn, DB_PRIMARY, and getDBFactory().

Referenced by getReplicaDB().

◆ getReplicaDB()

MediaWiki\FileRepo\ForeignDBRepo::getReplicaDB ( )

Get a connection to the replica DB.

Returns
IReadableDatabase

Reimplemented from MediaWiki\FileRepo\LocalRepo.

Definition at line 90 of file ForeignDBRepo.php.

References getPrimaryDB().

Member Data Documentation

◆ $dbConn

IDatabase MediaWiki\FileRepo\ForeignDBRepo::$dbConn
protected

Definition at line 51 of file ForeignDBRepo.php.

Referenced by getPrimaryDB().

◆ $dbFlags

string MediaWiki\FileRepo\ForeignDBRepo::$dbFlags
protected

Definition at line 42 of file ForeignDBRepo.php.

Referenced by getDBFactory().

◆ $dbName

string MediaWiki\FileRepo\ForeignDBRepo::$dbName
protected

Definition at line 39 of file ForeignDBRepo.php.

Referenced by getDBFactory().

◆ $dbPassword

string MediaWiki\FileRepo\ForeignDBRepo::$dbPassword
protected

Definition at line 36 of file ForeignDBRepo.php.

Referenced by getDBFactory().

◆ $dbSchema

string null MediaWiki\FileRepo\ForeignDBRepo::$dbSchema
protected

Definition at line 48 of file ForeignDBRepo.php.

Referenced by getDBFactory().

◆ $dbServer

string MediaWiki\FileRepo\ForeignDBRepo::$dbServer
protected

Definition at line 30 of file ForeignDBRepo.php.

Referenced by getDBFactory().

◆ $dbType

string MediaWiki\FileRepo\ForeignDBRepo::$dbType
protected

Definition at line 27 of file ForeignDBRepo.php.

Referenced by getDBFactory().

◆ $dbUser

string MediaWiki\FileRepo\ForeignDBRepo::$dbUser
protected

Definition at line 33 of file ForeignDBRepo.php.

Referenced by getDBFactory().

◆ $fileFactory

callable MediaWiki\FileRepo\ForeignDBRepo::$fileFactory = [ ForeignDBFile::class, 'newFromTitle' ]
protected

Definition at line 54 of file ForeignDBRepo.php.

◆ $fileFromRowFactory

callable MediaWiki\FileRepo\ForeignDBRepo::$fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ]
protected

Definition at line 56 of file ForeignDBRepo.php.

◆ $tablePrefix

string MediaWiki\FileRepo\ForeignDBRepo::$tablePrefix
protected

Definition at line 45 of file ForeignDBRepo.php.

Referenced by getDBFactory().


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