3055382624f3e85ca68619a1f5684cad0541ad91
4 var $localRepo, $foreignRepos, $reposInitialised = false;
5 var $localInfo, $foreignInfo;
7 protected static $instance;
10 if ( self
::$instance ) {
11 return self
::$instance;
13 global $wgLocalFileRepo, $wgForeignFileRepos;
14 self
::$instance = new RepoGroup( $wgLocalFileRepo, $wgForeignFileRepos );
15 return self
::$instance;
19 * Construct a group of file repositories.
20 * @param array $data Array of repository info arrays.
21 * Each info array is an associative array with the 'class' member
22 * giving the class name. The entire array is passed to the repository
23 * constructor as the first parameter.
25 function __construct( $localInfo, $foreignInfo ) {
26 $this->localInfo
= $localInfo;
27 $this->foreignInfo
= $foreignInfo;
31 * Search repositories for an image.
32 * You can also use wfGetFile() to do this.
33 * @param mixed $title Title object or string
34 * @param mixed $time The 14-char timestamp before which the file should
35 * have been uploaded, or false for the current version
36 * @return File object or false if it is not found
38 function findFile( $title, $time = false ) {
39 if ( !$this->reposInitialised
) {
40 $this->initialiseRepos();
43 $image = $this->localRepo
->findFile( $title, $time );
47 foreach ( $this->foreignRepos
as $repo ) {
48 $image = $repo->findFile( $image, $time );
57 * Get the repo instance with a given key.
59 function getRepo( $index ) {
60 if ( !$this->reposInitialised
) {
61 $this->initialiseRepos();
63 if ( $index == 'local' ) {
64 return $this->localRepo
;
65 } elseif ( isset( $this->foreignRepos
[$index] ) ) {
66 return $this->foreignRepos
[$index];
72 function getLocalRepo() {
73 return $this->getRepo( 'local' );
77 * Initialise the $repos array
79 function initialiseRepos() {
80 if ( $this->reposInitialised
) {
83 $this->reposInitialised
= true;
85 $this->localRepo
= $this->newRepo( $this->localInfo
);
86 $this->foreignRepos
= array();
87 foreach ( $this->foreignInfo
as $key => $info ) {
88 $this->foreignRepos
[$key] = $this->newRepo( $info );
92 function newRepo( $info ) {
93 $class = $info['class'];
94 return new $class( $info );