2007-05-30 21:02:32 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
2012-05-07 07:11:33 +00:00
|
|
|
* Prioritized list of file repositories.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup FileRepo
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2010-09-04 18:13:18 +00:00
|
|
|
/**
|
2007-05-31 01:43:41 +00:00
|
|
|
* Prioritized list of file repositories
|
2010-09-04 18:13:18 +00:00
|
|
|
*
|
|
|
|
|
* @ingroup FileRepo
|
2007-05-31 01:43:41 +00:00
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
class RepoGroup {
|
2013-11-24 09:44:10 +00:00
|
|
|
/** @var LocalRepo */
|
|
|
|
|
protected $localRepo;
|
2011-02-18 23:56:08 +00:00
|
|
|
|
2013-12-05 09:13:28 +00:00
|
|
|
/** @var FileRepo[] */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $foreignRepos;
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2013-11-24 09:44:10 +00:00
|
|
|
/** @var bool */
|
|
|
|
|
protected $reposInitialised = false;
|
|
|
|
|
|
2013-12-04 16:18:05 +00:00
|
|
|
/** @var array */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $localInfo;
|
2013-12-04 16:18:05 +00:00
|
|
|
|
|
|
|
|
/** @var array */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $foreignInfo;
|
|
|
|
|
|
2014-02-05 11:02:29 +00:00
|
|
|
/** @var ProcessCacheLRU */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $cache;
|
|
|
|
|
|
|
|
|
|
/** @var RepoGroup */
|
2007-05-30 21:02:32 +00:00
|
|
|
protected static $instance;
|
2013-11-24 09:44:10 +00:00
|
|
|
|
|
|
|
|
/** Maximum number of cache items */
|
2012-04-06 17:38:38 +00:00
|
|
|
const MAX_CACHE_SIZE = 500;
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2007-05-31 01:43:41 +00:00
|
|
|
/**
|
|
|
|
|
* Get a RepoGroup instance. At present only one instance of RepoGroup is
|
|
|
|
|
* needed in a MediaWiki invocation, this may change in the future.
|
2011-01-12 00:29:17 +00:00
|
|
|
* @return RepoGroup
|
2007-05-31 01:43:41 +00:00
|
|
|
*/
|
2007-06-03 09:05:29 +00:00
|
|
|
static function singleton() {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( self::$instance ) {
|
|
|
|
|
return self::$instance;
|
|
|
|
|
}
|
|
|
|
|
global $wgLocalFileRepo, $wgForeignFileRepos;
|
|
|
|
|
self::$instance = new RepoGroup( $wgLocalFileRepo, $wgForeignFileRepos );
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return self::$instance;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-03 09:05:29 +00:00
|
|
|
/**
|
|
|
|
|
* Destroy the singleton instance, so that a new one will be created next
|
|
|
|
|
* time singleton() is called.
|
|
|
|
|
*/
|
|
|
|
|
static function destroySingleton() {
|
|
|
|
|
self::$instance = null;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-09 00:21:16 +00:00
|
|
|
/**
|
|
|
|
|
* Set the singleton instance to a given object
|
2011-10-11 19:49:29 +00:00
|
|
|
* 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()
|
2011-05-28 18:59:42 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param RepoGroup $instance
|
2008-01-09 00:21:16 +00:00
|
|
|
*/
|
|
|
|
|
static function setSingleton( $instance ) {
|
|
|
|
|
self::$instance = $instance;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Construct a group of file repositories.
|
2010-03-26 21:55:13 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $localInfo Associative array for local repo's info
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param array $foreignInfo Array of repository info arrays.
|
2013-12-04 16:18:05 +00:00
|
|
|
* 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.
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function __construct( $localInfo, $foreignInfo ) {
|
|
|
|
|
$this->localInfo = $localInfo;
|
|
|
|
|
$this->foreignInfo = $foreignInfo;
|
2013-12-03 20:24:50 +00:00
|
|
|
$this->cache = new ProcessCacheLRU( self::MAX_CACHE_SIZE );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Search repositories for an image.
|
2010-01-23 14:25:10 +00:00
|
|
|
* You can also use wfFindFile() to do this.
|
2010-03-26 21:55:13 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param Title|string $title Title object or string
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $options Associative array of options:
|
2013-12-04 16:18:05 +00:00
|
|
|
* 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 true, return restricted (deleted) files if the current
|
|
|
|
|
* user is allowed to view them. Otherwise, such files will not
|
|
|
|
|
* be found.
|
|
|
|
|
* bypassCache: If true, do not use the process-local cache of File objects
|
|
|
|
|
* @return File|bool False if title is not found
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2009-08-15 09:59:59 +00:00
|
|
|
function findFile( $title, $options = array() ) {
|
|
|
|
|
if ( !is_array( $options ) ) {
|
|
|
|
|
// MW 1.15 compat
|
|
|
|
|
$options = array( 'time' => $options );
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !$this->reposInitialised ) {
|
|
|
|
|
$this->initialiseRepos();
|
|
|
|
|
}
|
2011-11-04 23:49:03 +00:00
|
|
|
$title = File::normalizeTitle( $title );
|
|
|
|
|
if ( !$title ) {
|
|
|
|
|
return false;
|
2010-11-10 09:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-15 09:59:59 +00:00
|
|
|
# Check the cache
|
2010-01-22 03:14:52 +00:00
|
|
|
if ( empty( $options['ignoreRedirect'] )
|
|
|
|
|
&& empty( $options['private'] )
|
2013-11-23 20:00:11 +00:00
|
|
|
&& empty( $options['bypassCache'] )
|
|
|
|
|
) {
|
2009-08-15 09:59:59 +00:00
|
|
|
$time = isset( $options['time'] ) ? $options['time'] : '';
|
|
|
|
|
$dbkey = $title->getDBkey();
|
2013-12-03 20:24:50 +00:00
|
|
|
if ( $this->cache->has( $dbkey, $time, 60 ) ) {
|
|
|
|
|
return $this->cache->get( $dbkey, $time );
|
2009-08-15 09:59:59 +00:00
|
|
|
}
|
2012-04-06 17:38:38 +00:00
|
|
|
$useCache = true;
|
2009-08-15 09:59:59 +00:00
|
|
|
} else {
|
|
|
|
|
$useCache = false;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2009-08-15 09:59:59 +00:00
|
|
|
# Check the local repo
|
|
|
|
|
$image = $this->localRepo->findFile( $title, $options );
|
|
|
|
|
|
|
|
|
|
# Check the foreign repos
|
2012-04-06 17:38:38 +00:00
|
|
|
if ( !$image ) {
|
|
|
|
|
foreach ( $this->foreignRepos as $repo ) {
|
|
|
|
|
$image = $repo->findFile( $title, $options );
|
|
|
|
|
if ( $image ) {
|
|
|
|
|
break;
|
2009-08-15 09:59:59 +00:00
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-04-06 17:38:38 +00:00
|
|
|
|
|
|
|
|
$image = $image ? $image : false; // type sanity
|
|
|
|
|
# Cache file existence or non-existence
|
|
|
|
|
if ( $useCache && ( !$image || $image->isCacheable() ) ) {
|
2013-12-03 20:24:50 +00:00
|
|
|
$this->cache->set( $dbkey, $time, $image );
|
2012-04-06 17:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $image;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2009-08-15 09:59:59 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2013-12-09 20:24:32 +00:00
|
|
|
* Search repositories for many files at once.
|
|
|
|
|
*
|
|
|
|
|
* @param array $items An array of titles, or an array of findFile() options with
|
|
|
|
|
* the "title" option giving the title. Example:
|
|
|
|
|
*
|
|
|
|
|
* $findItem = array( 'title' => $title, 'private' => true );
|
|
|
|
|
* $findBatch = array( $findItem );
|
|
|
|
|
* $repo->findFiles( $findBatch );
|
|
|
|
|
*
|
|
|
|
|
* No title should appear in $items twice, as the result use titles as keys
|
|
|
|
|
* @param int $flags Supports:
|
|
|
|
|
* - 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.
|
|
|
|
|
* @return array Map of (file name => File objects) for matches
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param array $inputItems
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param int $flags
|
2012-05-18 02:58:15 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2013-12-09 20:24:32 +00:00
|
|
|
function findFiles( array $inputItems, $flags = 0 ) {
|
2008-05-20 17:05:57 +00:00
|
|
|
if ( !$this->reposInitialised ) {
|
|
|
|
|
$this->initialiseRepos();
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-15 09:59:59 +00:00
|
|
|
$items = array();
|
|
|
|
|
foreach ( $inputItems as $item ) {
|
|
|
|
|
if ( !is_array( $item ) ) {
|
|
|
|
|
$item = array( 'title' => $item );
|
|
|
|
|
}
|
2011-11-11 22:14:21 +00:00
|
|
|
$item['title'] = File::normalizeTitle( $item['title'] );
|
|
|
|
|
if ( $item['title'] ) {
|
2009-08-15 09:59:59 +00:00
|
|
|
$items[$item['title']->getDBkey()] = $item;
|
2011-11-11 22:14:21 +00:00
|
|
|
}
|
2008-05-30 13:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-09 20:24:32 +00:00
|
|
|
$images = $this->localRepo->findFiles( $items, $flags );
|
2008-05-20 17:05:57 +00:00
|
|
|
|
|
|
|
|
foreach ( $this->foreignRepos as $repo ) {
|
2009-08-15 09:59:59 +00:00
|
|
|
// Remove found files from $items
|
|
|
|
|
foreach ( $images as $name => $image ) {
|
|
|
|
|
unset( $items[$name] );
|
|
|
|
|
}
|
2010-01-22 03:14:52 +00:00
|
|
|
|
2013-12-09 20:24:32 +00:00
|
|
|
$images = array_merge( $images, $repo->findFiles( $items, $flags ) );
|
2008-05-20 17:05:57 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-05-20 17:05:57 +00:00
|
|
|
return $images;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2008-01-16 18:27:43 +00:00
|
|
|
/**
|
|
|
|
|
* Interface for FileRepo::checkRedirect()
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param Title $title
|
2014-07-08 21:40:06 +00:00
|
|
|
* @return bool|Title
|
2008-01-16 18:27:43 +00:00
|
|
|
*/
|
2011-11-04 23:49:03 +00:00
|
|
|
function checkRedirect( Title $title ) {
|
2008-01-16 18:27:43 +00:00
|
|
|
if ( !$this->reposInitialised ) {
|
|
|
|
|
$this->initialiseRepos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$redir = $this->localRepo->checkRedirect( $title );
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( $redir ) {
|
2008-01-16 18:27:43 +00:00
|
|
|
return $redir;
|
|
|
|
|
}
|
2013-12-05 09:13:28 +00:00
|
|
|
|
2008-01-16 18:27:43 +00:00
|
|
|
foreach ( $this->foreignRepos as $repo ) {
|
|
|
|
|
$redir = $repo->checkRedirect( $title );
|
|
|
|
|
if ( $redir ) {
|
|
|
|
|
return $redir;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-01-16 18:27:43 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-01-22 03:14:52 +00:00
|
|
|
|
2011-03-28 21:40:50 +00:00
|
|
|
/**
|
|
|
|
|
* Find an instance of the file with this key, created at the specified time
|
|
|
|
|
* Returns false if the file does not exist.
|
|
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param string $hash Base 36 SHA-1 hash
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $options Option array, same as findFile()
|
2014-04-19 15:19:17 +00:00
|
|
|
* @return File|bool File object or false if it is not found
|
2011-03-28 21:40:50 +00:00
|
|
|
*/
|
|
|
|
|
function findFileFromKey( $hash, $options = array() ) {
|
|
|
|
|
if ( !$this->reposInitialised ) {
|
|
|
|
|
$this->initialiseRepos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$file = $this->localRepo->findFileFromKey( $hash, $options );
|
|
|
|
|
if ( !$file ) {
|
|
|
|
|
foreach ( $this->foreignRepos as $repo ) {
|
|
|
|
|
$file = $repo->findFileFromKey( $hash, $options );
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( $file ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-28 21:40:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-03-28 21:40:50 +00:00
|
|
|
return $file;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-20 20:34:03 +00:00
|
|
|
/**
|
|
|
|
|
* Find all instances of files with this key
|
|
|
|
|
*
|
2014-07-24 17:43:03 +00:00
|
|
|
* @param string $hash Base 36 SHA-1 hash
|
2014-07-08 21:40:06 +00:00
|
|
|
* @return File[]
|
2011-03-20 20:34:03 +00:00
|
|
|
*/
|
2008-05-14 15:11:48 +00:00
|
|
|
function findBySha1( $hash ) {
|
|
|
|
|
if ( !$this->reposInitialised ) {
|
|
|
|
|
$this->initialiseRepos();
|
|
|
|
|
}
|
2010-01-22 03:14:52 +00:00
|
|
|
|
2008-05-14 15:11:48 +00:00
|
|
|
$result = $this->localRepo->findBySha1( $hash );
|
2011-03-20 20:34:03 +00:00
|
|
|
foreach ( $this->foreignRepos as $repo ) {
|
2008-05-14 15:11:48 +00:00
|
|
|
$result = array_merge( $result, $repo->findBySha1( $hash ) );
|
2011-03-20 20:34:03 +00:00
|
|
|
}
|
2012-07-08 08:45:21 +00:00
|
|
|
usort( $result, 'File::compare' );
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2010-01-22 03:14:52 +00:00
|
|
|
return $result;
|
2008-05-14 15:11:48 +00:00
|
|
|
}
|
2008-01-16 18:27:43 +00:00
|
|
|
|
2012-07-23 16:45:38 +00:00
|
|
|
/**
|
|
|
|
|
* Find all instances of files with this keys
|
|
|
|
|
*
|
2014-07-24 17:43:03 +00:00
|
|
|
* @param array $hashes Base 36 SHA-1 hashes
|
2014-04-19 15:19:17 +00:00
|
|
|
* @return array Array of array of File objects
|
2012-07-23 16:45:38 +00:00
|
|
|
*/
|
|
|
|
|
function findBySha1s( array $hashes ) {
|
|
|
|
|
if ( !$this->reposInitialised ) {
|
|
|
|
|
$this->initialiseRepos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $this->localRepo->findBySha1s( $hashes );
|
|
|
|
|
foreach ( $this->foreignRepos as $repo ) {
|
|
|
|
|
$result = array_merge_recursive( $result, $repo->findBySha1s( $hashes ) );
|
|
|
|
|
}
|
|
|
|
|
//sort the merged (and presorted) sublist of each hash
|
2013-04-20 17:18:13 +00:00
|
|
|
foreach ( $result as $hash => $files ) {
|
2012-07-23 16:45:38 +00:00
|
|
|
usort( $result[$hash], 'File::compare' );
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2012-07-23 16:45:38 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Get the repo instance with a given key.
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param string|int $index
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool|LocalRepo
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getRepo( $index ) {
|
|
|
|
|
if ( !$this->reposInitialised ) {
|
|
|
|
|
$this->initialiseRepos();
|
|
|
|
|
}
|
2007-11-19 09:43:47 +00:00
|
|
|
if ( $index === 'local' ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->localRepo;
|
|
|
|
|
} elseif ( isset( $this->foreignRepos[$index] ) ) {
|
|
|
|
|
return $this->foreignRepos[$index];
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-18 02:58:15 +00:00
|
|
|
|
2008-02-09 13:40:16 +00:00
|
|
|
/**
|
|
|
|
|
* Get the repo instance by its name
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param string $name
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool
|
2008-02-09 13:40:16 +00:00
|
|
|
*/
|
|
|
|
|
function getRepoByName( $name ) {
|
|
|
|
|
if ( !$this->reposInitialised ) {
|
|
|
|
|
$this->initialiseRepos();
|
|
|
|
|
}
|
2010-10-14 20:53:04 +00:00
|
|
|
foreach ( $this->foreignRepos as $repo ) {
|
2012-05-18 02:58:15 +00:00
|
|
|
if ( $repo->name == $name ) {
|
2008-02-09 13:40:16 +00:00
|
|
|
return $repo;
|
2012-05-18 02:58:15 +00:00
|
|
|
}
|
2008-02-09 13:40:16 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-02-09 13:40:16 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2007-05-31 01:43:41 +00:00
|
|
|
/**
|
|
|
|
|
* Get the local repository, i.e. the one corresponding to the local image
|
|
|
|
|
* table. Files are typically uploaded to the local repository.
|
2011-07-01 02:25:19 +00:00
|
|
|
*
|
|
|
|
|
* @return LocalRepo
|
2007-05-31 01:43:41 +00:00
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getLocalRepo() {
|
|
|
|
|
return $this->getRepo( 'local' );
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-03 13:50:37 +00:00
|
|
|
/**
|
2010-01-22 03:14:52 +00:00
|
|
|
* Call a function for each foreign repo, with the repo object as the
|
2008-09-16 06:13:31 +00:00
|
|
|
* first parameter.
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param callable $callback The function to call
|
|
|
|
|
* @param array $params Optional additional parameters to pass to the function
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool
|
2008-09-03 13:50:37 +00:00
|
|
|
*/
|
2008-05-01 22:16:23 +00:00
|
|
|
function forEachForeignRepo( $callback, $params = array() ) {
|
2014-07-03 06:12:27 +00:00
|
|
|
if ( !$this->reposInitialised ) {
|
|
|
|
|
$this->initialiseRepos();
|
|
|
|
|
}
|
2013-04-20 17:18:13 +00:00
|
|
|
foreach ( $this->foreignRepos as $repo ) {
|
2008-05-01 22:16:23 +00:00
|
|
|
$args = array_merge( array( $repo ), $params );
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( call_user_func_array( $callback, $args ) ) {
|
2008-05-01 22:16:23 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-05-01 22:16:23 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-03 13:50:37 +00:00
|
|
|
/**
|
2008-09-16 06:13:31 +00:00
|
|
|
* Does the installation have any foreign repos set up?
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return bool
|
2008-09-03 13:50:37 +00:00
|
|
|
*/
|
2008-05-01 22:16:23 +00:00
|
|
|
function hasForeignRepos() {
|
2014-07-03 06:12:27 +00:00
|
|
|
if ( !$this->reposInitialised ) {
|
|
|
|
|
$this->initialiseRepos();
|
|
|
|
|
}
|
2008-09-16 06:13:31 +00:00
|
|
|
return (bool)$this->foreignRepos;
|
2008-05-01 22:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Initialise the $repos array
|
|
|
|
|
*/
|
|
|
|
|
function initialiseRepos() {
|
|
|
|
|
if ( $this->reposInitialised ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->reposInitialised = true;
|
|
|
|
|
|
|
|
|
|
$this->localRepo = $this->newRepo( $this->localInfo );
|
|
|
|
|
$this->foreignRepos = array();
|
|
|
|
|
foreach ( $this->foreignInfo as $key => $info ) {
|
|
|
|
|
$this->foreignRepos[$key] = $this->newRepo( $info );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-31 01:43:41 +00:00
|
|
|
/**
|
|
|
|
|
* Create a repo class based on an info structure
|
|
|
|
|
*/
|
|
|
|
|
protected function newRepo( $info ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$class = $info['class'];
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return new $class( $info );
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Split a virtual URL into repo, zone and rel parts
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param string $url
|
2012-05-18 02:58:15 +00:00
|
|
|
* @throws MWException
|
2014-07-24 17:43:03 +00:00
|
|
|
* @return array Containing repo, zone and rel
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
|
|
|
|
function splitVirtualUrl( $url ) {
|
|
|
|
|
if ( substr( $url, 0, 9 ) != 'mwrepo://' ) {
|
2013-02-03 19:42:08 +00:00
|
|
|
throw new MWException( __METHOD__ . ': unknown protocol' );
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$bits = explode( '/', substr( $url, 9 ), 3 );
|
|
|
|
|
if ( count( $bits ) != 3 ) {
|
2013-02-03 19:42:08 +00:00
|
|
|
throw new MWException( __METHOD__ . ": invalid mwrepo URL: $url" );
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
return $bits;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param string $fileName
|
2012-05-18 02:58:15 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2007-06-16 02:55:25 +00:00
|
|
|
function getFileProps( $fileName ) {
|
|
|
|
|
if ( FileRepo::isVirtualUrl( $fileName ) ) {
|
2007-08-21 03:57:54 +00:00
|
|
|
list( $repoName, /* $zone */, /* $rel */ ) = $this->splitVirtualUrl( $fileName );
|
2007-06-16 02:55:25 +00:00
|
|
|
if ( $repoName === '' ) {
|
|
|
|
|
$repoName = 'local';
|
|
|
|
|
}
|
|
|
|
|
$repo = $this->getRepo( $repoName );
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
return $repo->getFileProps( $fileName );
|
|
|
|
|
} else {
|
2011-12-20 03:52:06 +00:00
|
|
|
return FSFile::getPropsFromPath( $fileName );
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-15 09:59:59 +00:00
|
|
|
|
2011-09-21 21:32:24 +00:00
|
|
|
/**
|
|
|
|
|
* Clear RepoGroup process cache used for finding a file
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param Title|null $title Title of the file or null to clear all files
|
2011-09-21 21:32:24 +00:00
|
|
|
*/
|
|
|
|
|
public function clearCache( Title $title = null ) {
|
|
|
|
|
if ( $title == null ) {
|
2013-12-03 20:24:50 +00:00
|
|
|
$this->cache->clear();
|
2011-09-21 21:32:24 +00:00
|
|
|
} else {
|
2013-12-03 20:24:50 +00:00
|
|
|
$this->cache->clear( $title->getDBkey() );
|
2011-09-21 21:32:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|