MediaWiki  master
RepoGroup Class Reference

Prioritized list of file repositories. More...

Collaboration diagram for RepoGroup:

Public Member Functions

 __construct ( $localInfo, $foreignInfo, $wanCache)
 Construct a group of file repositories. More...
 
 checkRedirect ( $title)
 Interface for FileRepo::checkRedirect() More...
 
 clearCache ( $title=null)
 Clear RepoGroup process cache used for finding a file. More...
 
 findBySha1 ( $hash)
 Find all instances of files with this key. More...
 
 findBySha1s (array $hashes)
 Find all instances of files with this keys. More...
 
 findFile ( $title, $options=[])
 Search repositories for an image. More...
 
 findFileFromKey ( $hash, $options=[])
 Find an instance of the file with this key, created at the specified time Returns false if the file does not exist. More...
 
 findFiles (array $inputItems, $flags=0)
 Search repositories for many files at once. More...
 
 forEachForeignRepo ( $callback, $params=[])
 Call a function for each foreign repo, with the repo object as the first parameter. More...
 
 getFileProps ( $fileName)
 
 getLocalRepo ()
 Get the local repository, i.e. More...
 
 getRepo ( $index)
 Get the repo instance with a given key. More...
 
 getRepoByName ( $name)
 Get the repo instance by its name. More...
 
 hasForeignRepos ()
 Does the installation have any foreign repos set up? More...
 
 initialiseRepos ()
 Initialise the $repos array. More...
 
 newCustomLocalRepo ( $info=[])
 Create a local repo with the specified option overrides. More...
 

Static Public Member Functions

static destroySingleton ()
 
static setSingleton ( $instance)
 
static singleton ()
 

Protected Member Functions

 newRepo ( $info)
 Create a repo class based on an info structure. More...
 

Protected Attributes

MapCacheLRU $cache
 
array $foreignInfo
 
FileRepo[] $foreignRepos
 
array $localInfo
 
LocalRepo $localRepo
 
bool $reposInitialised = false
 
WANObjectCache $wanCache
 

Private Member Functions

 splitVirtualUrl ( $url)
 Split a virtual URL into repo, zone and rel parts. More...
 

Private Attributes

const MAX_CACHE_SIZE = 500
 Maximum number of cache items. More...
 

Detailed Description

Prioritized list of file repositories.

Definition at line 33 of file RepoGroup.php.

Constructor & Destructor Documentation

◆ __construct()

RepoGroup::__construct (   $localInfo,
  $foreignInfo,
  $wanCache 
)

Construct a group of file repositories.

Do not call this – use MediaWikiServices::getRepoGroup.

Parameters
array$localInfoAssociative array for local repo's info
array$foreignInfoArray of repository info arrays. Each info array is an associative array with the 'class' member giving the class name. The entire array is passed to the repository constructor as the first parameter.
WANObjectCache$wanCache

Definition at line 107 of file RepoGroup.php.

References $foreignInfo, $localInfo, and $wanCache.

Member Function Documentation

◆ checkRedirect()

RepoGroup::checkRedirect (   $title)

Interface for FileRepo::checkRedirect()

Parameters
PageIdentity | LinkTarget | string$title
Returns
bool|Title

Definition at line 240 of file RepoGroup.php.

References $title, initialiseRepos(), and File\normalizeTitle().

◆ clearCache()

RepoGroup::clearCache (   $title = null)

Clear RepoGroup process cache used for finding a file.

Parameters
PageIdentity | string | null$titleFile page or file name, or null to clear all files

Definition at line 491 of file RepoGroup.php.

References $title.

◆ destroySingleton()

static RepoGroup::destroySingleton ( )
static
Deprecated:
since 1.34, hard deprecated since 1.37 Use MediaWikiTestCase::overrideMwServices() or similar. This will cause bugs if you don't reset all other services that depend on this one at the same time.

Definition at line 74 of file RepoGroup.php.

References wfDeprecated().

◆ findBySha1()

RepoGroup::findBySha1 (   $hash)

Find all instances of files with this key.

Parameters
string$hashBase 36 SHA-1 hash
Returns
File[]

Definition at line 294 of file RepoGroup.php.

References initialiseRepos().

◆ findBySha1s()

RepoGroup::findBySha1s ( array  $hashes)

Find all instances of files with this keys.

Parameters
array$hashesBase 36 SHA-1 hashes
Returns
File[][]

Definition at line 314 of file RepoGroup.php.

References $hashes, and initialiseRepos().

◆ findFile()

RepoGroup::findFile (   $title,
  $options = [] 
)

Search repositories for an image.

Parameters
PageIdentity | LinkTarget | string$titleThe file to find
array$optionsAssociative array of options: time: requested time for an archived image, or false for the current version. An image object will be returned which was created at the specified time. ignoreRedirect: If true, do not follow file redirects private: If Authority object, return restricted (deleted) files if the performer is allowed to view them. Otherwise, such files will not be found. Authority is only accepted since 1.37, User was required before. latest: If true, load from the latest available data into File objects @phpcs:ignore Generic.Files.LineLength
Returns
File|bool False if title is not found

Definition at line 132 of file RepoGroup.php.

References $title, initialiseRepos(), and File\normalizeTitle().

◆ findFileFromKey()

RepoGroup::findFileFromKey (   $hash,
  $options = [] 
)

Find an instance of the file with this key, created at the specified time Returns false if the file does not exist.

Parameters
string$hashBase 36 SHA-1 hash
array$optionsOption array, same as findFile()
Returns
File|bool File object or false if it is not found

Definition at line 270 of file RepoGroup.php.

References $file, and initialiseRepos().

◆ findFiles()

RepoGroup::findFiles ( array  $inputItems,
  $flags = 0 
)

Search repositories for many files at once.

Parameters
array$inputItemsAn 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 );

No title should appear in $items twice, as the result use titles as keys

Parameters
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

Definition at line 205 of file RepoGroup.php.

References initialiseRepos(), and File\normalizeTitle().

◆ forEachForeignRepo()

RepoGroup::forEachForeignRepo (   $callback,
  $params = [] 
)

Call a function for each foreign repo, with the repo object as the first parameter.

Parameters
callable$callbackThe function to call
array$paramsOptional additional parameters to pass to the function
Returns
bool

Definition at line 385 of file RepoGroup.php.

References initialiseRepos().

◆ getFileProps()

RepoGroup::getFileProps (   $fileName)
Parameters
string$fileName
Returns
array

Definition at line 471 of file RepoGroup.php.

References getRepo(), FileRepo\isVirtualUrl(), and splitVirtualUrl().

◆ getLocalRepo()

RepoGroup::getLocalRepo ( )

Get the local repository, i.e.

the one corresponding to the local image table. Files are typically uploaded to the local repository.

Returns
LocalRepo

Definition at line 370 of file RepoGroup.php.

References getRepo().

Referenced by ApiQueryAllImages\__construct(), ImageListPager\__construct(), SpecialUndelete\__construct(), and SpecialUploadStash\__construct().

◆ getRepo()

RepoGroup::getRepo (   $index)

Get the repo instance with a given key.

Parameters
string | int$index
Returns
bool|FileRepo

Definition at line 336 of file RepoGroup.php.

References $localRepo, and initialiseRepos().

Referenced by getFileProps(), and getLocalRepo().

◆ getRepoByName()

RepoGroup::getRepoByName (   $name)

Get the repo instance by its name.

Parameters
string$name
Returns
FileRepo|bool

Definition at line 351 of file RepoGroup.php.

References initialiseRepos().

◆ hasForeignRepos()

RepoGroup::hasForeignRepos ( )

Does the installation have any foreign repos set up?

Returns
bool

Definition at line 402 of file RepoGroup.php.

References $foreignRepos, and initialiseRepos().

◆ initialiseRepos()

RepoGroup::initialiseRepos ( )

Initialise the $repos array.

Definition at line 412 of file RepoGroup.php.

References newRepo().

Referenced by checkRedirect(), findBySha1(), findBySha1s(), findFile(), findFileFromKey(), findFiles(), forEachForeignRepo(), getRepo(), getRepoByName(), and hasForeignRepos().

◆ newCustomLocalRepo()

RepoGroup::newCustomLocalRepo (   $info = [])

Create a local repo with the specified option overrides.

Parameters
array$info
Returns
FileRepo

Definition at line 431 of file RepoGroup.php.

References newRepo().

◆ newRepo()

RepoGroup::newRepo (   $info)
protected

Create a repo class based on an info structure.

Parameters
array$info
Returns
FileRepo

Definition at line 440 of file RepoGroup.php.

References $wanCache.

Referenced by initialiseRepos(), and newCustomLocalRepo().

◆ setSingleton()

static RepoGroup::setSingleton (   $instance)
static
Deprecated:
since 1.34, hard deprecated since 1.37 Use MediaWikiTestCase::setService, this can mess up state of other tests
Parameters
RepoGroup$instance

Definition at line 85 of file RepoGroup.php.

References wfDeprecated().

◆ singleton()

static RepoGroup::singleton ( )
static
Deprecated:
since 1.34, hard deprecated since 1.37 Use MediaWikiServices::getRepoGroup instead
Returns
RepoGroup

Definition at line 64 of file RepoGroup.php.

References wfDeprecated().

◆ splitVirtualUrl()

RepoGroup::splitVirtualUrl (   $url)
private

Split a virtual URL into repo, zone and rel parts.

Parameters
string$url
Exceptions
MWException
Returns
string[] Containing repo, zone and rel

Definition at line 454 of file RepoGroup.php.

Referenced by getFileProps().

Member Data Documentation

◆ $cache

MapCacheLRU RepoGroup::$cache
protected

Definition at line 53 of file RepoGroup.php.

◆ $foreignInfo

array RepoGroup::$foreignInfo
protected

Definition at line 50 of file RepoGroup.php.

Referenced by __construct().

◆ $foreignRepos

FileRepo [] RepoGroup::$foreignRepos
protected

Definition at line 38 of file RepoGroup.php.

Referenced by hasForeignRepos().

◆ $localInfo

array RepoGroup::$localInfo
protected

Definition at line 47 of file RepoGroup.php.

Referenced by __construct().

◆ $localRepo

LocalRepo RepoGroup::$localRepo
protected

Definition at line 35 of file RepoGroup.php.

Referenced by getRepo().

◆ $reposInitialised

bool RepoGroup::$reposInitialised = false
protected

Definition at line 44 of file RepoGroup.php.

◆ $wanCache

WANObjectCache RepoGroup::$wanCache
protected

Definition at line 41 of file RepoGroup.php.

Referenced by __construct(), and newRepo().

◆ MAX_CACHE_SIZE

const RepoGroup::MAX_CACHE_SIZE = 500
private

Maximum number of cache items.

Definition at line 56 of file RepoGroup.php.


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