summaryrefslogtreecommitdiff
path: root/includes/filerepo/RepoGroup.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/filerepo/RepoGroup.php')
-rw-r--r--includes/filerepo/RepoGroup.php49
1 files changed, 28 insertions, 21 deletions
diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php
index d4875908..334ef2b8 100644
--- a/includes/filerepo/RepoGroup.php
+++ b/includes/filerepo/RepoGroup.php
@@ -7,10 +7,6 @@
*/
/**
- * @defgroup FileRepo FileRepo
- */
-
-/**
* Prioritized list of file repositories
*
* @ingroup FileRepo
@@ -56,6 +52,9 @@ class RepoGroup {
/**
* Set the singleton instance to a given object
+ * Used by extensions which hook into the Repo chain.
+ * It's not enough to just create a superclass ... you have
+ * to get people to call into it even though all they know is RepoGroup::singleton()
*
* @param $instance RepoGroup
*/
@@ -105,22 +104,15 @@ class RepoGroup {
if ( !$this->reposInitialised ) {
$this->initialiseRepos();
}
- if ( !($title instanceof Title) ) {
- $title = Title::makeTitleSafe( NS_FILE, $title );
- if ( !is_object( $title ) ) {
- return false;
- }
- }
-
- if ( $title->getNamespace() != NS_MEDIA && $title->getNamespace() != NS_FILE ) {
- throw new MWException( __METHOD__ . ' received an Title object with incorrect namespace' );
+ $title = File::normalizeTitle( $title );
+ if ( !$title ) {
+ return false;
}
# Check the cache
if ( empty( $options['ignoreRedirect'] )
&& empty( $options['private'] )
- && empty( $options['bypassCache'] )
- && $title->getNamespace() == NS_FILE )
+ && empty( $options['bypassCache'] ) )
{
$useCache = true;
$time = isset( $options['time'] ) ? $options['time'] : '';
@@ -176,10 +168,10 @@ class RepoGroup {
if ( !is_array( $item ) ) {
$item = array( 'title' => $item );
}
- if ( !( $item['title'] instanceof Title ) )
- $item['title'] = Title::makeTitleSafe( NS_FILE, $item['title'] );
- if ( $item['title'] )
+ $item['title'] = File::normalizeTitle( $item['title'] );
+ if ( $item['title'] ) {
$items[$item['title']->getDBkey()] = $item;
+ }
}
$images = $this->localRepo->findFiles( $items );
@@ -198,7 +190,7 @@ class RepoGroup {
/**
* Interface for FileRepo::checkRedirect()
*/
- function checkRedirect( $title ) {
+ function checkRedirect( Title $title ) {
if ( !$this->reposInitialised ) {
$this->initialiseRepos();
}
@@ -370,14 +362,14 @@ class RepoGroup {
$repo = $this->getRepo( $repoName );
return $repo->getFileProps( $fileName );
} else {
- return File::getPropsFromPath( $fileName );
+ return FSFile::getPropsFromPath( $fileName );
}
}
/**
* Limit cache memory
*/
- function trimCache() {
+ protected function trimCache() {
while ( count( $this->cache ) >= self::MAX_CACHE_SIZE ) {
reset( $this->cache );
$key = key( $this->cache );
@@ -385,4 +377,19 @@ class RepoGroup {
unset( $this->cache[$key] );
}
}
+
+ /**
+ * Clear RepoGroup process cache used for finding a file
+ * @param $title Title|null Title of the file or null to clear all files
+ */
+ public function clearCache( Title $title = null ) {
+ if ( $title == null ) {
+ $this->cache = array();
+ } else {
+ $dbKey = $title->getDBkey();
+ if ( isset( $this->cache[$dbKey] ) ) {
+ unset( $this->cache[$dbKey] );
+ }
+ }
+ }
}