X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilerepo%2FRepoGroup.php;h=d685121a6c901e5738dd9d0813137d1b99154a62;hb=aed9d4b91218e361e9f6ff72886cd172147aadd3;hp=70dd6d87fd8fcd88cc9f0aaeeafab8cdc4fd07e4;hpb=85fa7504e68ea6a67cc7bb0b34de3dce2868f11f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 70dd6d87fd..d685121a6c 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -2,7 +2,7 @@ /** * Prioritized list of file repositories - * @addtogroup filerepo + * @addtogroup FileRepo */ class RepoGroup { var $localRepo, $foreignRepos, $reposInitialised = false; @@ -31,6 +31,13 @@ class RepoGroup { self::$instance = null; } + /** + * Set the singleton instance to a given object + */ + static function setSingleton( $instance ) { + self::$instance = $instance; + } + /** * Construct a group of file repositories. * @param array $data Array of repository info arrays. @@ -47,8 +54,8 @@ class RepoGroup { * Search repositories for an image. * You can also use wfGetFile() to do this. * @param mixed $title Title object or string - * @param mixed $time The 14-char timestamp before which the file should - * have been uploaded, or false for the current version + * @param mixed $time The 14-char timestamp the file should have + * been uploaded, or false for the current version * @return File object or false if it is not found */ function findFile( $title, $time = false ) { @@ -69,6 +76,27 @@ class RepoGroup { return false; } + /** + * Interface for FileRepo::checkRedirect() + */ + function checkRedirect( $title ) { + if ( !$this->reposInitialised ) { + $this->initialiseRepos(); + } + + $redir = $this->localRepo->checkRedirect( $title ); + if( $redir ) { + return $redir; + } + foreach ( $this->foreignRepos as $repo ) { + $redir = $repo->checkRedirect( $title ); + if ( $redir ) { + return $redir; + } + } + return false; + } + /** * Get the repo instance with a given key. */ @@ -76,7 +104,7 @@ class RepoGroup { if ( !$this->reposInitialised ) { $this->initialiseRepos(); } - if ( $index == 'local' ) { + if ( $index === 'local' ) { return $this->localRepo; } elseif ( isset( $this->foreignRepos[$index] ) ) { return $this->foreignRepos[$index]; @@ -84,6 +112,19 @@ class RepoGroup { return false; } } + /** + * Get the repo instance by its name + */ + function getRepoByName( $name ) { + if ( !$this->reposInitialised ) { + $this->initialiseRepos(); + } + foreach ( $this->foreignRepos as $key => $repo ) { + if ( $repo->name == $name) + return $repo; + } + return false; + } /** * Get the local repository, i.e. the one corresponding to the local image @@ -135,7 +176,7 @@ class RepoGroup { function getFileProps( $fileName ) { if ( FileRepo::isVirtualUrl( $fileName ) ) { - list( $repoName, $zone, $rel ) = $this->splitVirtualUrl( $fileName ); + list( $repoName, /* $zone */, /* $rel */ ) = $this->splitVirtualUrl( $fileName ); if ( $repoName === '' ) { $repoName = 'local'; } @@ -147,4 +188,4 @@ class RepoGroup { } } -?> +