2007-06-16 02:55:25 +00:00
|
|
|
<?php
|
2010-09-04 18:13:18 +00:00
|
|
|
/**
|
|
|
|
|
* Base code for file repositories.
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup FileRepo
|
|
|
|
|
*/
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
/**
|
2010-09-04 18:13:18 +00:00
|
|
|
* Base class for file repositories.
|
2007-06-16 02:55:25 +00:00
|
|
|
* Do not instantiate, use a derived class.
|
2010-09-04 18:13:18 +00:00
|
|
|
*
|
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
|
|
|
* @ingroup FileRepo
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
|
|
|
|
abstract class FileRepo {
|
2009-03-29 13:42:29 +00:00
|
|
|
const FILES_ONLY = 1;
|
2007-06-16 02:55:25 +00:00
|
|
|
const DELETE_SOURCE = 1;
|
2007-07-22 14:45:12 +00:00
|
|
|
const OVERWRITE = 2;
|
|
|
|
|
const OVERWRITE_SAME = 4;
|
2011-02-04 20:54:11 +00:00
|
|
|
const SKIP_VALIDATION = 8;
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
var $thumbScriptUrl, $transformVia404;
|
2010-07-02 18:37:06 +00:00
|
|
|
var $descBaseUrl, $scriptDirUrl, $scriptExtension, $articleUrl;
|
|
|
|
|
var $fetchDescription, $initialCapital;
|
2007-07-22 14:45:12 +00:00
|
|
|
var $pathDisclosureProtection = 'paranoid';
|
2009-10-09 11:41:38 +00:00
|
|
|
var $descriptionCacheExpiry, $hashLevels, $url, $thumbUrl;
|
2007-06-16 02:55:25 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
/**
|
2007-06-16 02:55:25 +00:00
|
|
|
* Factory functions for creating new files
|
|
|
|
|
* Override these in the base class
|
|
|
|
|
*/
|
|
|
|
|
var $fileFactory = false, $oldFileFactory = false;
|
2011-03-28 21:40:50 +00:00
|
|
|
var $fileFactoryKey = false, $oldFileFactoryKey = false;
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
function __construct( $info ) {
|
|
|
|
|
// Required settings
|
|
|
|
|
$this->name = $info['name'];
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
// Optional settings
|
2009-10-09 12:52:16 +00:00
|
|
|
$this->initialCapital = MWNamespace::isCapitalized( NS_FILE );
|
2008-04-14 07:45:50 +00:00
|
|
|
foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription',
|
2010-02-10 10:36:11 +00:00
|
|
|
'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection',
|
2011-06-17 16:03:52 +00:00
|
|
|
'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl', 'scriptExtension' )
|
2010-07-02 18:37:06 +00:00
|
|
|
as $var )
|
2007-06-16 02:55:25 +00:00
|
|
|
{
|
|
|
|
|
if ( isset( $info[$var] ) ) {
|
|
|
|
|
$this->$var = $info[$var];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->transformVia404 = !empty( $info['transformVia404'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if a string is an mwrepo:// URL
|
2011-05-28 18:58:51 +00:00
|
|
|
*
|
|
|
|
|
* @param $url string
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
|
|
|
|
static function isVirtualUrl( $url ) {
|
|
|
|
|
return substr( $url, 0, 9 ) == 'mwrepo://';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new File object from the local repository
|
2010-03-26 21:55:13 +00:00
|
|
|
*
|
|
|
|
|
* @param $title Mixed: Title object or string
|
|
|
|
|
* @param $time Mixed: Time at which the image was uploaded.
|
|
|
|
|
* If this is specified, the returned object will be an
|
|
|
|
|
* instance of the repository's old file class instead of a
|
|
|
|
|
* current file. Repositories not supporting version control
|
|
|
|
|
* should return false if this parameter is set.
|
2011-02-18 23:56:08 +00:00
|
|
|
*
|
2011-11-11 22:14:21 +00:00
|
|
|
* @return File|null A File, or null if passed an invalid Title
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
|
|
|
|
function newFile( $title, $time = false ) {
|
2011-11-11 22:14:21 +00:00
|
|
|
$title = File::normalizeTitle( $title );
|
|
|
|
|
if ( !$title ) {
|
|
|
|
|
return null;
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
if ( $time ) {
|
|
|
|
|
if ( $this->oldFileFactory ) {
|
|
|
|
|
return call_user_func( $this->oldFileFactory, $title, $this, $time );
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return call_user_func( $this->fileFactory, $title, $this );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-05 15:38:08 +00:00
|
|
|
* Find an instance of the named file created at the specified time
|
2008-04-14 07:45:50 +00:00
|
|
|
* Returns false if the file does not exist. Repositories not supporting
|
2007-06-16 02:55:25 +00:00
|
|
|
* version control should return false if the time is specified.
|
|
|
|
|
*
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $title Mixed: Title object or string
|
2011-05-28 18:58:51 +00:00
|
|
|
* @param $options array Associative array of options:
|
2009-08-15 09:59:59 +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
|
|
|
|
|
*
|
2010-02-10 10:36:11 +00:00
|
|
|
* private: If true, return restricted (deleted) files if the current
|
2009-08-15 09:59:59 +00:00
|
|
|
* user is allowed to view them. Otherwise, such files will not
|
|
|
|
|
* be found.
|
2011-05-28 18:58:51 +00:00
|
|
|
*
|
|
|
|
|
* @return File|false
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
2009-08-15 09:59:59 +00:00
|
|
|
function findFile( $title, $options = array() ) {
|
2011-11-11 22:14:21 +00:00
|
|
|
$title = File::normalizeTitle( $title );
|
|
|
|
|
if ( !$title ) {
|
|
|
|
|
return false;
|
2008-04-06 10:18:47 +00:00
|
|
|
}
|
2011-11-11 22:14:21 +00:00
|
|
|
$time = isset( $options['time'] ) ? $options['time'] : false;
|
2007-06-16 02:55:25 +00:00
|
|
|
# First try the current version of the file to see if it precedes the timestamp
|
|
|
|
|
$img = $this->newFile( $title );
|
2007-10-01 19:50:25 +00:00
|
|
|
if ( !$img ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-02-04 08:18:55 +00:00
|
|
|
if ( $img->exists() && ( !$time || $img->getTimestamp() == $time ) ) {
|
2007-06-16 02:55:25 +00:00
|
|
|
return $img;
|
|
|
|
|
}
|
|
|
|
|
# Now try an old version of the file
|
2008-05-07 03:39:35 +00:00
|
|
|
if ( $time !== false ) {
|
|
|
|
|
$img = $this->newFile( $title, $time );
|
2008-09-07 00:38:57 +00:00
|
|
|
if ( $img && $img->exists() ) {
|
2011-10-19 04:06:16 +00:00
|
|
|
if ( !$img->isDeleted( File::DELETED_FILE ) ) {
|
|
|
|
|
return $img; // always OK
|
|
|
|
|
} elseif ( !empty( $options['private'] ) && $img->userCan( File::DELETED_FILE ) ) {
|
2008-05-07 03:39:35 +00:00
|
|
|
return $img;
|
|
|
|
|
}
|
2008-03-09 03:10:28 +00:00
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
2010-02-10 10:36:11 +00:00
|
|
|
|
2008-01-16 18:27:43 +00:00
|
|
|
# Now try redirects
|
2009-08-15 09:59:59 +00:00
|
|
|
if ( !empty( $options['ignoreRedirect'] ) ) {
|
2008-05-20 02:58:40 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-02-10 10:36:11 +00:00
|
|
|
$redir = $this->checkRedirect( $title );
|
2011-02-18 23:56:08 +00:00
|
|
|
if( $redir && $title->getNamespace() == NS_FILE) {
|
2008-01-16 18:27:43 +00:00
|
|
|
$img = $this->newFile( $redir );
|
|
|
|
|
if( !$img ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if( $img->exists() ) {
|
2008-05-08 20:55:13 +00:00
|
|
|
$img->redirectedFrom( $title->getDBkey() );
|
2008-01-16 18:27:43 +00:00
|
|
|
return $img;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-03-09 03:10:28 +00:00
|
|
|
return false;
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
2010-02-10 10:36:11 +00:00
|
|
|
|
2011-05-21 19:35:16 +00:00
|
|
|
/**
|
2010-02-10 10:36:11 +00:00
|
|
|
* Find many files at once.
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $items An array of titles, or an array of findFile() options with
|
2009-08-15 09:59:59 +00:00
|
|
|
* the "title" option giving the title. Example:
|
|
|
|
|
*
|
|
|
|
|
* $findItem = array( 'title' => $title, 'private' => true );
|
|
|
|
|
* $findBatch = array( $findItem );
|
|
|
|
|
* $repo->findFiles( $findBatch );
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2008-05-20 17:05:57 +00:00
|
|
|
*/
|
2009-08-15 09:59:59 +00:00
|
|
|
function findFiles( $items ) {
|
2008-05-20 17:05:57 +00:00
|
|
|
$result = array();
|
2010-10-12 22:48:22 +00:00
|
|
|
foreach ( $items as $item ) {
|
2009-08-15 09:59:59 +00:00
|
|
|
if ( is_array( $item ) ) {
|
|
|
|
|
$title = $item['title'];
|
|
|
|
|
$options = $item;
|
|
|
|
|
unset( $options['title'] );
|
|
|
|
|
} else {
|
|
|
|
|
$title = $item;
|
|
|
|
|
$options = array();
|
|
|
|
|
}
|
|
|
|
|
$file = $this->findFile( $title, $options );
|
2010-10-12 22:48:22 +00:00
|
|
|
if ( $file ) {
|
2008-05-20 17:05:57 +00:00
|
|
|
$result[$file->getTitle()->getDBkey()] = $file;
|
2010-10-12 22:48:22 +00:00
|
|
|
}
|
2008-05-20 17:05:57 +00:00
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2010-02-10 10:36:11 +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. Repositories not supporting
|
|
|
|
|
* version control should return false if the time is specified.
|
|
|
|
|
*
|
|
|
|
|
* @param $sha1 String base 36 SHA-1 hash
|
|
|
|
|
* @param $options Option array, same as findFile().
|
|
|
|
|
*/
|
|
|
|
|
function findFileFromKey( $sha1, $options = array() ) {
|
|
|
|
|
$time = isset( $options['time'] ) ? $options['time'] : false;
|
|
|
|
|
|
2011-10-19 04:06:16 +00:00
|
|
|
# First try to find a matching current version of a file...
|
|
|
|
|
if ( $this->fileFactoryKey ) {
|
|
|
|
|
$img = call_user_func( $this->fileFactoryKey, $sha1, $this, $time );
|
|
|
|
|
} else {
|
|
|
|
|
return false; // find-by-sha1 not supported
|
2011-03-28 21:40:50 +00:00
|
|
|
}
|
2011-10-19 04:06:16 +00:00
|
|
|
if ( $img && $img->exists() ) {
|
2011-03-28 21:40:50 +00:00
|
|
|
return $img;
|
|
|
|
|
}
|
2011-10-19 04:06:16 +00:00
|
|
|
# Now try to find a matching old version of a file...
|
|
|
|
|
if ( $time !== false && $this->oldFileFactoryKey ) { // find-by-sha1 supported?
|
|
|
|
|
$img = call_user_func( $this->oldFileFactoryKey, $sha1, $this, $time );
|
2011-03-28 21:40:50 +00:00
|
|
|
if ( $img && $img->exists() ) {
|
2011-10-19 04:06:16 +00:00
|
|
|
if ( !$img->isDeleted( File::DELETED_FILE ) ) {
|
|
|
|
|
return $img; // always OK
|
|
|
|
|
} elseif ( !empty( $options['private'] ) && $img->userCan( File::DELETED_FILE ) ) {
|
2011-03-28 21:40:50 +00:00
|
|
|
return $img;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
/**
|
|
|
|
|
* Get the URL of thumb.php
|
|
|
|
|
*/
|
|
|
|
|
function getThumbScriptUrl() {
|
|
|
|
|
return $this->thumbScriptUrl;
|
|
|
|
|
}
|
2010-02-10 10:36:11 +00:00
|
|
|
|
2009-10-09 11:41:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the URL corresponding to one of the four basic zones
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $zone String: one of: public, deleted, temp, thumb
|
2009-10-09 11:41:38 +00:00
|
|
|
* @return String or false
|
|
|
|
|
*/
|
|
|
|
|
function getZoneUrl( $zone ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the repository can transform files via a 404 handler
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
|
|
|
|
function canTransformVia404() {
|
|
|
|
|
return $this->transformVia404;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the name of an image from its title object
|
2011-02-18 23:56:08 +00:00
|
|
|
* @param $title Title
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
2011-11-04 23:33:53 +00:00
|
|
|
function getNameFromTitle( Title $title ) {
|
2009-10-09 12:52:16 +00:00
|
|
|
if ( $this->initialCapital != MWNamespace::isCapitalized( NS_FILE ) ) {
|
2007-06-16 02:55:25 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
$name = $title->getUserCaseDBKey();
|
|
|
|
|
if ( $this->initialCapital ) {
|
|
|
|
|
$name = $wgContLang->ucfirst( $name );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$name = $title->getDBkey();
|
|
|
|
|
}
|
|
|
|
|
return $name;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 12:00:58 +00:00
|
|
|
/**
|
|
|
|
|
* @param $name
|
|
|
|
|
* @param $levels
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-06-16 02:55:25 +00:00
|
|
|
static function getHashPathForLevel( $name, $levels ) {
|
|
|
|
|
if ( $levels == 0 ) {
|
|
|
|
|
return '';
|
|
|
|
|
} else {
|
|
|
|
|
$hash = md5( $name );
|
|
|
|
|
$path = '';
|
|
|
|
|
for ( $i = 1; $i <= $levels; $i++ ) {
|
|
|
|
|
$path .= substr( $hash, 0, $i ) . '/';
|
|
|
|
|
}
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-10 10:36:11 +00:00
|
|
|
|
2008-11-08 22:20:23 +00:00
|
|
|
/**
|
|
|
|
|
* Get a relative path including trailing slash, e.g. f/fa/
|
|
|
|
|
* If the repo is not hashed, returns an empty string
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @param $name string
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
2008-11-08 22:20:23 +00:00
|
|
|
*/
|
|
|
|
|
function getHashPath( $name ) {
|
|
|
|
|
return self::getHashPathForLevel( $name, $this->hashLevels );
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the name of this repository, as specified by $info['name]' to the constructor
|
|
|
|
|
*/
|
|
|
|
|
function getName() {
|
|
|
|
|
return $this->name;
|
|
|
|
|
}
|
2011-06-17 16:03:52 +00:00
|
|
|
|
2010-07-02 18:37:06 +00:00
|
|
|
/**
|
|
|
|
|
* Make an url to this repo
|
2011-06-17 16:03:52 +00:00
|
|
|
*
|
2010-07-02 18:37:06 +00:00
|
|
|
* @param $query mixed Query string to append
|
|
|
|
|
* @param $entry string Entry point; defaults to index
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function makeUrl( $query = '', $entry = 'index' ) {
|
|
|
|
|
$ext = isset( $this->scriptExtension ) ? $this->scriptExtension : '.php';
|
2011-06-17 16:03:52 +00:00
|
|
|
return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}{$ext}", $query );
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the URL of an image description page. May return false if it is
|
2008-04-14 07:45:50 +00:00
|
|
|
* unknown or not applicable. In general this should only be called by the
|
|
|
|
|
* File class, since it may return invalid results for certain kinds of
|
2007-06-16 02:55:25 +00:00
|
|
|
* repositories. Use File::getDescriptionUrl() in user code.
|
|
|
|
|
*
|
|
|
|
|
* In particular, it uses the article paths as specified to the repository
|
|
|
|
|
* constructor, whereas local repositories use the local Title functions.
|
|
|
|
|
*/
|
|
|
|
|
function getDescriptionUrl( $name ) {
|
2008-12-10 22:07:04 +00:00
|
|
|
$encName = wfUrlencode( $name );
|
|
|
|
|
if ( !is_null( $this->descBaseUrl ) ) {
|
|
|
|
|
# "http://example.com/wiki/Image:"
|
|
|
|
|
return $this->descBaseUrl . $encName;
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
2008-12-10 22:07:04 +00:00
|
|
|
if ( !is_null( $this->articleUrl ) ) {
|
|
|
|
|
# "http://example.com/wiki/$1"
|
|
|
|
|
#
|
|
|
|
|
# We use "Image:" as the canonical namespace for
|
|
|
|
|
# compatibility across all MediaWiki versions.
|
|
|
|
|
return str_replace( '$1',
|
|
|
|
|
"Image:$encName", $this->articleUrl );
|
|
|
|
|
}
|
|
|
|
|
if ( !is_null( $this->scriptDirUrl ) ) {
|
|
|
|
|
# "http://example.com/w"
|
|
|
|
|
#
|
|
|
|
|
# We use "Image:" as the canonical namespace for
|
|
|
|
|
# compatibility across all MediaWiki versions,
|
|
|
|
|
# and just sort of hope index.php is right. ;)
|
2010-07-02 18:37:06 +00:00
|
|
|
return $this->makeUrl( "title=Image:$encName" );
|
2008-12-10 22:07:04 +00:00
|
|
|
}
|
|
|
|
|
return false;
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Get the URL of the content-only fragment of the description page. For
|
|
|
|
|
* MediaWiki this means action=render. This should only be called by the
|
|
|
|
|
* repository's file class, since it may return invalid results. User code
|
2007-06-16 02:55:25 +00:00
|
|
|
* should use File::getDescriptionText().
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $name String: name of image to fetch
|
|
|
|
|
* @param $lang String: language to fetch it in, if any.
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
2009-01-27 19:34:21 +00:00
|
|
|
function getDescriptionRenderUrl( $name, $lang = null ) {
|
|
|
|
|
$query = 'action=render';
|
|
|
|
|
if ( !is_null( $lang ) ) {
|
|
|
|
|
$query .= '&uselang=' . $lang;
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
if ( isset( $this->scriptDirUrl ) ) {
|
2011-06-17 16:03:52 +00:00
|
|
|
return $this->makeUrl(
|
2010-07-02 18:37:06 +00:00
|
|
|
'title=' .
|
2008-12-04 18:23:52 +00:00
|
|
|
wfUrlencode( 'Image:' . $name ) .
|
2010-07-02 18:37:06 +00:00
|
|
|
"&$query" );
|
2007-06-16 02:55:25 +00:00
|
|
|
} else {
|
2008-12-10 22:07:04 +00:00
|
|
|
$descUrl = $this->getDescriptionUrl( $name );
|
|
|
|
|
if ( $descUrl ) {
|
2009-01-27 19:34:21 +00:00
|
|
|
return wfAppendQuery( $descUrl, $query );
|
2007-06-16 02:55:25 +00:00
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-17 16:03:52 +00:00
|
|
|
|
2010-07-02 19:54:46 +00:00
|
|
|
/**
|
|
|
|
|
* Get the URL of the stylesheet to apply to description pages
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function getDescriptionStylesheetUrl() {
|
|
|
|
|
if ( $this->scriptDirUrl ) {
|
2010-07-25 21:15:27 +00:00
|
|
|
return $this->makeUrl( 'title=MediaWiki:Filepage.css&' .
|
2010-07-02 19:54:46 +00:00
|
|
|
wfArrayToCGI( Skin::getDynamicStylesheetQuery() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a file to a given destination.
|
2007-07-22 14:45:12 +00:00
|
|
|
*
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $srcPath String: source path or virtual URL
|
|
|
|
|
* @param $dstZone String: destination zone
|
|
|
|
|
* @param $dstRel String: destination relative path
|
|
|
|
|
* @param $flags Integer: bitwise combination of the following flags:
|
2007-07-22 14:45:12 +00:00
|
|
|
* self::DELETE_SOURCE Delete the source file after upload
|
|
|
|
|
* self::OVERWRITE Overwrite an existing destination file instead of failing
|
2008-04-14 07:45:50 +00:00
|
|
|
* self::OVERWRITE_SAME Overwrite the file if the destination exists and has the
|
2007-07-22 14:45:12 +00:00
|
|
|
* same contents as the source
|
|
|
|
|
* @return FileRepoStatus
|
|
|
|
|
*/
|
|
|
|
|
function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
|
|
|
|
|
$status = $this->storeBatch( array( array( $srcPath, $dstZone, $dstRel ) ), $flags );
|
|
|
|
|
if ( $status->successCount == 0 ) {
|
|
|
|
|
$status->ok = false;
|
|
|
|
|
}
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a batch of files
|
|
|
|
|
*
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $triplets Array: (src,zone,dest) triplets as per store()
|
|
|
|
|
* @param $flags Integer: flags as per store
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
abstract function storeBatch( $triplets, $flags = 0 );
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Pick a random name in the temp zone and store a file to it.
|
2007-07-22 14:45:12 +00:00
|
|
|
* Returns a FileRepoStatus object with the URL in the value.
|
|
|
|
|
*
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $originalName String: the base name of the file as specified
|
2007-06-16 02:55:25 +00:00
|
|
|
* by the user. The file extension will be maintained.
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $srcPath String: the current location of the file.
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
|
|
|
|
abstract function storeTemp( $originalName, $srcPath );
|
|
|
|
|
|
2010-02-10 11:08:39 +00:00
|
|
|
|
2011-11-30 14:56:40 +00:00
|
|
|
/**
|
|
|
|
|
* Concatenate and array of file sources.
|
|
|
|
|
* @param $fileList Array of file sources
|
|
|
|
|
* @param $targetPath String target destination for file.
|
|
|
|
|
* @throws MWException
|
|
|
|
|
*/
|
|
|
|
|
abstract function concatenate( $fileList, $targetPath, $flags = 0 );
|
|
|
|
|
|
2010-02-10 11:08:39 +00:00
|
|
|
/**
|
2011-05-23 01:18:06 +00:00
|
|
|
* Append the contents of the source path to the given file, OR queue
|
|
|
|
|
* the appending operation in anticipation of a later appendFinish() call.
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $srcPath String: location of the source file
|
|
|
|
|
* @param $toAppendPath String: path to append to.
|
|
|
|
|
* @param $flags Integer: bitfield, may be FileRepo::DELETE_SOURCE to indicate
|
2010-02-22 02:15:30 +00:00
|
|
|
* that the source file should be deleted if possible
|
2010-02-10 11:08:39 +00:00
|
|
|
* @return mixed Status or false
|
|
|
|
|
*/
|
2010-02-22 12:24:50 +00:00
|
|
|
abstract function append( $srcPath, $toAppendPath, $flags = 0 );
|
2010-02-10 10:36:11 +00:00
|
|
|
|
2011-05-23 01:18:06 +00:00
|
|
|
/**
|
|
|
|
|
* Finish the append operation.
|
|
|
|
|
* @param $toAppendPath String: path to append to.
|
|
|
|
|
* @return mixed Status or false
|
|
|
|
|
*/
|
|
|
|
|
abstract function appendFinish( $toAppendPath );
|
|
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
/**
|
|
|
|
|
* Remove a temporary file or mark it for garbage collection
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $virtualUrl String: the virtual URL returned by storeTemp
|
|
|
|
|
* @return Boolean: true on success, false on failure
|
2007-06-16 02:55:25 +00:00
|
|
|
* STUB
|
|
|
|
|
*/
|
|
|
|
|
function freeTemp( $virtualUrl ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copy or move a file either from the local filesystem or from an mwrepo://
|
|
|
|
|
* virtual URL, into this repository at the specified destination location.
|
|
|
|
|
*
|
2007-07-22 14:45:12 +00:00
|
|
|
* Returns a FileRepoStatus object. On success, the value contains "new" or
|
2008-04-14 07:45:50 +00:00
|
|
|
* "archived", to indicate whether the file was new with that name.
|
2007-07-22 14:45:12 +00:00
|
|
|
*
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $srcPath String: the source path or URL
|
|
|
|
|
* @param $dstRel String: the destination relative path
|
2011-11-16 22:33:34 +00:00
|
|
|
* @param $archiveRel String: the relative path where the existing file is to
|
2007-06-16 02:55:25 +00:00
|
|
|
* be archived, if there is one. Relative to the public zone root.
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $flags Integer: bitfield, may be FileRepo::DELETE_SOURCE to indicate
|
2007-06-16 02:55:25 +00:00
|
|
|
* that the source file should be deleted if possible
|
|
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function publish( $srcPath, $dstRel, $archiveRel, $flags = 0 ) {
|
|
|
|
|
$status = $this->publishBatch( array( array( $srcPath, $dstRel, $archiveRel ) ), $flags );
|
|
|
|
|
if ( $status->successCount == 0 ) {
|
|
|
|
|
$status->ok = false;
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $status->value[0] ) ) {
|
|
|
|
|
$status->value = $status->value[0];
|
|
|
|
|
} else {
|
|
|
|
|
$status->value = false;
|
|
|
|
|
}
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Publish a batch of files
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $triplets Array: (source,dest,archive) triplets as per publish()
|
|
|
|
|
* @param $flags Integer: bitfield, may be FileRepo::DELETE_SOURCE to indicate
|
2007-07-22 14:45:12 +00:00
|
|
|
* that the source files should be deleted if possible
|
|
|
|
|
*/
|
|
|
|
|
abstract function publishBatch( $triplets, $flags = 0 );
|
|
|
|
|
|
2011-09-07 12:00:58 +00:00
|
|
|
/**
|
|
|
|
|
* @param $file
|
|
|
|
|
* @param int $flags
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2009-06-08 15:10:08 +00:00
|
|
|
function fileExists( $file, $flags = 0 ) {
|
|
|
|
|
$result = $this->fileExistsBatch( array( $file ), $flags );
|
2009-06-10 01:47:58 +00:00
|
|
|
return $result[0];
|
2009-06-08 15:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks existence of an array of files.
|
|
|
|
|
*
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $files Array: URLs (or paths) of files to check
|
|
|
|
|
* @param $flags Integer: bitwise combination of the following flags:
|
2009-06-08 15:10:08 +00:00
|
|
|
* self::FILES_ONLY Mark file as existing only if it is a file (not directory)
|
|
|
|
|
* @return Either array of files and existence flags, or false
|
|
|
|
|
*/
|
|
|
|
|
abstract function fileExistsBatch( $files, $flags = 0 );
|
|
|
|
|
|
2007-07-22 14:45:12 +00:00
|
|
|
/**
|
|
|
|
|
* Move a group of files to the deletion archive.
|
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* If no valid deletion archive is configured, this may either delete the
|
2007-07-22 14:45:12 +00:00
|
|
|
* file or throw an exception, depending on the preference of the repository.
|
|
|
|
|
*
|
|
|
|
|
* The overwrite policy is determined by the repository -- currently FSRepo
|
2008-04-14 07:45:50 +00:00
|
|
|
* assumes a naming scheme in the deleted zone based on content hash, as
|
2007-07-22 14:45:12 +00:00
|
|
|
* opposed to the public zone which is assumed to be unique.
|
|
|
|
|
*
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $sourceDestPairs Array of source/destination pairs. Each element
|
2007-07-22 14:45:12 +00:00
|
|
|
* is a two-element array containing the source file path relative to the
|
2008-04-14 07:45:50 +00:00
|
|
|
* public root in the first element, and the archive file path relative
|
2007-07-22 14:45:12 +00:00
|
|
|
* to the deleted zone root in the second element.
|
|
|
|
|
* @return FileRepoStatus
|
|
|
|
|
*/
|
|
|
|
|
abstract function deleteBatch( $sourceDestPairs );
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Move a file to the deletion archive.
|
2008-04-14 07:45:50 +00:00
|
|
|
* If no valid deletion archive exists, this may either delete the file
|
2007-07-22 14:45:12 +00:00
|
|
|
* or throw an exception, depending on the preference of the repository
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $srcRel Mixed: relative path for the file to be deleted
|
|
|
|
|
* @param $archiveRel Mixed: relative path for the archive location.
|
2007-07-22 14:45:12 +00:00
|
|
|
* Relative to a private archive directory.
|
2010-04-16 15:20:12 +00:00
|
|
|
* @return FileRepoStatus object
|
2007-07-22 14:45:12 +00:00
|
|
|
*/
|
|
|
|
|
function delete( $srcRel, $archiveRel ) {
|
|
|
|
|
return $this->deleteBatch( array( array( $srcRel, $archiveRel ) ) );
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get properties of a file with a given virtual URL
|
|
|
|
|
* The virtual URL must refer to this repo
|
|
|
|
|
* Properties should ultimately be obtained via File::getPropsFromPath()
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @param $virtualUrl string
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
|
|
|
|
abstract function getFileProps( $virtualUrl );
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call a callback function for every file in the repository
|
|
|
|
|
* May use either the database or the filesystem
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
|
|
|
|
function enumFiles( $callback ) {
|
|
|
|
|
throw new MWException( 'enumFiles is not supported by ' . get_class( $this ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if a relative path is valid, i.e. not blank or involving directory traveral
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @param $filename string
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-06-16 02:55:25 +00:00
|
|
|
*/
|
|
|
|
|
function validateFilename( $filename ) {
|
|
|
|
|
if ( strval( $filename ) == '' ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if ( wfIsWindows() ) {
|
|
|
|
|
$filename = strtr( $filename, '\\', '/' );
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Use the same traversal protection as Title::secureAndSplit()
|
|
|
|
|
*/
|
|
|
|
|
if ( strpos( $filename, '.' ) !== false &&
|
2011-09-07 12:00:58 +00:00
|
|
|
( $filename === '.' || $filename === '..' ||
|
|
|
|
|
strpos( $filename, './' ) === 0 ||
|
|
|
|
|
strpos( $filename, '../' ) === 0 ||
|
|
|
|
|
strpos( $filename, '/./' ) !== false ||
|
|
|
|
|
strpos( $filename, '/../' ) !== false ) )
|
2007-06-16 02:55:25 +00:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
|
|
|
|
|
/**#@+
|
|
|
|
|
* Path disclosure protection functions
|
|
|
|
|
*/
|
|
|
|
|
function paranoidClean( $param ) { return '[hidden]'; }
|
2011-09-07 12:00:58 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function passThrough( $param ) { return $param; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a callback function to use for cleaning error message parameters
|
|
|
|
|
*/
|
|
|
|
|
function getErrorCleanupFunction() {
|
|
|
|
|
switch ( $this->pathDisclosureProtection ) {
|
|
|
|
|
case 'none':
|
|
|
|
|
$callback = array( $this, 'passThrough' );
|
|
|
|
|
break;
|
|
|
|
|
default: // 'paranoid'
|
|
|
|
|
$callback = array( $this, 'paranoidClean' );
|
|
|
|
|
}
|
|
|
|
|
return $callback;
|
|
|
|
|
}
|
|
|
|
|
/**#@-*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new fatal error
|
|
|
|
|
*/
|
|
|
|
|
function newFatal( $message /*, parameters...*/ ) {
|
|
|
|
|
$params = func_get_args();
|
|
|
|
|
array_unshift( $params, $this );
|
2011-05-27 06:25:21 +00:00
|
|
|
return MWInit::callStaticMethod( 'FileRepoStatus', 'newFatal', $params );
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new good result
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
|
|
|
|
* @return FileRepoStatus
|
2007-07-22 14:45:12 +00:00
|
|
|
*/
|
|
|
|
|
function newGood( $value = null ) {
|
|
|
|
|
return FileRepoStatus::newGood( $this, $value );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete files in the deleted directory if they are not referenced in the filearchive table
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
|
|
|
|
function cleanupDeletedBatch( $storageKeys ) {}
|
2008-01-16 18:27:43 +00:00
|
|
|
|
|
|
|
|
/**
|
2009-04-20 03:06:49 +00:00
|
|
|
* Checks if there is a redirect named as $title. If there is, return the
|
|
|
|
|
* title object. If not, return false.
|
|
|
|
|
* STUB
|
2008-01-16 18:27:43 +00:00
|
|
|
*
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $title Title of image
|
2011-02-18 23:56:08 +00:00
|
|
|
* @return Bool
|
2008-01-16 18:27:43 +00:00
|
|
|
*/
|
2011-11-04 23:49:03 +00:00
|
|
|
function checkRedirect( Title $title ) {
|
2009-04-20 03:06:49 +00:00
|
|
|
return false;
|
2008-01-16 18:27:43 +00:00
|
|
|
}
|
2008-04-12 18:04:46 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Invalidates image redirect cache related to that image
|
2009-06-17 07:31:00 +00:00
|
|
|
* Doesn't do anything for repositories that don't support image redirects.
|
2010-02-10 10:36:11 +00:00
|
|
|
*
|
2009-06-17 07:31:00 +00:00
|
|
|
* STUB
|
2010-03-26 21:55:13 +00:00
|
|
|
* @param $title Title of image
|
2010-02-10 10:36:11 +00:00
|
|
|
*/
|
2011-11-05 09:19:35 +00:00
|
|
|
function invalidateImageRedirect( Title $title ) {}
|
2010-02-10 10:36:11 +00:00
|
|
|
|
2009-06-17 07:31:00 +00:00
|
|
|
/**
|
2010-02-10 10:36:11 +00:00
|
|
|
* Get an array or iterator of file objects for files that have a given
|
2009-06-17 07:31:00 +00:00
|
|
|
* SHA-1 content hash.
|
|
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
2008-05-14 15:11:48 +00:00
|
|
|
function findBySha1( $hash ) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2010-02-10 10:36:11 +00:00
|
|
|
|
2009-02-17 22:27:10 +00:00
|
|
|
/**
|
2010-02-10 10:36:11 +00:00
|
|
|
* Get the human-readable name of the repo.
|
2009-02-17 22:27:10 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getDisplayName() {
|
|
|
|
|
// We don't name our own repo, return nothing
|
2010-06-18 20:00:27 +00:00
|
|
|
if ( $this->isLocal() ) {
|
2009-02-17 22:27:10 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
2010-03-06 16:06:43 +00:00
|
|
|
// 'shared-repo-name-wikimediacommons' is used when $wgUseInstantCommons = true
|
2011-01-14 10:51:05 +00:00
|
|
|
return wfMessageFallback( 'shared-repo-name-' . $this->name, 'shared-repo' )->text();
|
2009-02-17 22:27:10 +00:00
|
|
|
}
|
2010-02-10 10:36:11 +00:00
|
|
|
|
2010-06-18 20:00:27 +00:00
|
|
|
/**
|
|
|
|
|
* Returns true if this the local file repository.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function isLocal() {
|
|
|
|
|
return $this->getName() == 'local';
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-17 07:31:00 +00:00
|
|
|
/**
|
|
|
|
|
* Get a key on the primary cache for this repository.
|
2010-02-10 10:36:11 +00:00
|
|
|
* Returns false if the repository's cache is not accessible at this site.
|
2009-06-17 07:31:00 +00:00
|
|
|
* The parameters are the parts of the key, as for wfMemcKey().
|
|
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
|
|
|
|
function getSharedCacheKey( /*...*/ ) {
|
|
|
|
|
return false;
|
2009-03-18 05:17:49 +00:00
|
|
|
}
|
2009-04-16 20:16:21 +00:00
|
|
|
|
2009-06-17 07:31:00 +00:00
|
|
|
/**
|
2010-02-10 10:36:11 +00:00
|
|
|
* Get a key for this repo in the local cache domain. These cache keys are
|
2009-06-17 07:31:00 +00:00
|
|
|
* not shared with remote instances of the repo.
|
|
|
|
|
* The parameters are the parts of the key, as for wfMemcKey().
|
|
|
|
|
*/
|
|
|
|
|
function getLocalCacheKey( /*...*/ ) {
|
|
|
|
|
$args = func_get_args();
|
|
|
|
|
array_unshift( $args, 'filerepo', $this->getName() );
|
|
|
|
|
return call_user_func_array( 'wfMemcKey', $args );
|
2009-04-16 20:16:21 +00:00
|
|
|
}
|
2011-06-17 16:03:52 +00:00
|
|
|
|
2011-01-25 21:26:53 +00:00
|
|
|
/**
|
|
|
|
|
* Get an UploadStash associated with this repo.
|
2011-02-27 21:11:45 +00:00
|
|
|
*
|
|
|
|
|
* @return UploadStash
|
2011-01-25 21:26:53 +00:00
|
|
|
*/
|
|
|
|
|
function getUploadStash() {
|
|
|
|
|
return new UploadStash( $this );
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|