$this->initialCapital = MWNamespace::isCapitalized( NS_FILE );
foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription',
'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection',
- 'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl', 'scriptExtension' )
+ 'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl', 'scriptExtension' )
as $var )
{
if ( isset( $info[$var] ) ) {
/**
* Determine if a string is an mwrepo:// URL
+ *
+ * @param $url string
+ *
+ * @return bool
*/
static function isVirtualUrl( $url ) {
return substr( $url, 0, 9 ) == 'mwrepo://';
* current file. Repositories not supporting version control
* should return false if this parameter is set.
*
- * @return File
+ * @return File|null A File, or null if passed an invalid Title
*/
function newFile( $title, $time = false ) {
- if ( !($title instanceof Title) ) {
- $title = Title::makeTitleSafe( NS_FILE, $title );
- if ( !is_object( $title ) ) {
- return null;
- }
+ $title = File::normalizeTitle( $title );
+ if ( !$title ) {
+ return null;
}
if ( $time ) {
if ( $this->oldFileFactory ) {
* version control should return false if the time is specified.
*
* @param $title Mixed: Title object or string
- * @param $options Associative array of options:
+ * @param $options array Associative array of options:
* 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.
* private: If true, return restricted (deleted) files if the current
* user is allowed to view them. Otherwise, such files will not
* be found.
+ *
+ * @return File|false
*/
function findFile( $title, $options = array() ) {
- if ( !is_array( $options ) ) {
- // MW 1.15 compat
- $time = $options;
- $options = array();
- } else {
- $time = isset( $options['time'] ) ? $options['time'] : false;
- }
- if ( !($title instanceof Title) ) {
- $title = Title::makeTitleSafe( NS_FILE, $title );
- if ( !is_object( $title ) ) {
- return false;
- }
+ $title = File::normalizeTitle( $title );
+ if ( !$title ) {
+ return false;
}
+ $time = isset( $options['time'] ) ? $options['time'] : false;
# First try the current version of the file to see if it precedes the timestamp
$img = $this->newFile( $title );
if ( !$img ) {
if ( $time !== false ) {
$img = $this->newFile( $title, $time );
if ( $img && $img->exists() ) {
- if ( !$img->isDeleted(File::DELETED_FILE) ) {
- return $img;
- } else if ( !empty( $options['private'] ) && $img->userCan(File::DELETED_FILE) ) {
+ if ( !$img->isDeleted( File::DELETED_FILE ) ) {
+ return $img; // always OK
+ } elseif ( !empty( $options['private'] ) && $img->userCan( File::DELETED_FILE ) ) {
return $img;
}
}
return false;
}
- /*
+ /**
* Find many files at once.
* @param $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 );
+ *
+ * @return array
*/
function findFiles( $items ) {
$result = array();
return $result;
}
- /**
- * Create a new File object from the local repository
- * @param $sha1 Mixed: base 36 SHA-1 hash
- * @param $time Mixed: time at which the image was uploaded.
- * If this is specified, the returned object will be an
- * 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.
- *
- * @return File
- */
- function newFileFromKey( $sha1, $time = false ) {
- if ( $time ) {
- if ( $this->oldFileFactoryKey ) {
- return call_user_func( $this->oldFileFactoryKey, $sha1, $this, $time );
- } else {
- return false;
- }
- } else {
- return call_user_func( $this->fileFactoryKey, $sha1, $this );
- }
- }
-
/**
* 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
* @param $options Option array, same as findFile().
*/
function findFileFromKey( $sha1, $options = array() ) {
- if ( !is_array( $options ) ) {
- # MW 1.15 compat
- $time = $options;
- $options = array();
- } else {
- $time = isset( $options['time'] ) ? $options['time'] : false;
- }
+ $time = isset( $options['time'] ) ? $options['time'] : false;
- # First try the current version of the file to see if it precedes the timestamp
- $img = $this->newFileFromKey( $sha1 );
- if ( !$img ) {
- return false;
+ # 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
}
- if ( $img->exists() && ( !$time || $img->getTimestamp() == $time ) ) {
+ if ( $img && $img->exists() ) {
return $img;
}
- # Now try an old version of the file
- if ( $time !== false ) {
- $img = $this->newFileFromKey( $sha1, $time );
- if ( $img->exists() ) {
- if ( !$img->isDeleted(File::DELETED_FILE) ) {
- return $img;
- } else if ( !empty( $options['private'] ) && $img->userCan(File::DELETED_FILE) ) {
+ # 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 );
+ if ( $img && $img->exists() ) {
+ if ( !$img->isDeleted( File::DELETED_FILE ) ) {
+ return $img; // always OK
+ } elseif ( !empty( $options['private'] ) && $img->userCan( File::DELETED_FILE ) ) {
return $img;
}
}
/**
* Returns true if the repository can transform files via a 404 handler
+ *
+ * @return bool
*/
function canTransformVia404() {
return $this->transformVia404;
* Get the name of an image from its title object
* @param $title Title
*/
- function getNameFromTitle( $title ) {
+ function getNameFromTitle( Title $title ) {
if ( $this->initialCapital != MWNamespace::isCapitalized( NS_FILE ) ) {
global $wgContLang;
$name = $title->getUserCaseDBKey();
return $name;
}
+ /**
+ * @param $name
+ * @param $levels
+ * @return string
+ */
static function getHashPathForLevel( $name, $levels ) {
if ( $levels == 0 ) {
return '';
}
}
+ /**
+ * Get the number of hash directory levels
+ *
+ * @return integer
+ */
+ function getHashLevels() {
+ return $this->hashLevels;
+ }
+
/**
* Get a relative path including trailing slash, e.g. f/fa/
* If the repo is not hashed, returns an empty string
+ *
+ * @param $name string
+ *
+ * @return string
*/
function getHashPath( $name ) {
return self::getHashPathForLevel( $name, $this->hashLevels );
function getName() {
return $this->name;
}
-
+
/**
* Make an url to this repo
- *
+ *
* @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';
- return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}{$ext}", $query );
- }
+ return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}{$ext}", $query );
+ }
/**
* Get the URL of an image description page. May return false if it is
$query .= '&uselang=' . $lang;
}
if ( isset( $this->scriptDirUrl ) ) {
- return $this->makeUrl(
+ return $this->makeUrl(
'title=' .
wfUrlencode( 'Image:' . $name ) .
"&$query" );
}
}
}
-
+
/**
* Get the URL of the stylesheet to apply to description pages
* @return string
/**
- * Append the contents of the source path to the given file.
+ * 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 );
+
+ /**
+ * Append the contents of the source path to the given file, OR queue
+ * the appending operation in anticipation of a later appendFinish() call.
* @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
*/
abstract function append( $srcPath, $toAppendPath, $flags = 0 );
+ /**
+ * Finish the append operation.
+ * @param $toAppendPath String: path to append to.
+ * @return mixed Status or false
+ */
+ abstract function appendFinish( $toAppendPath );
+
/**
* Remove a temporary file or mark it for garbage collection
* @param $virtualUrl String: the virtual URL returned by storeTemp
*
* @param $srcPath String: the source path or URL
* @param $dstRel String: the destination relative path
- * @param $archiveRel String: rhe relative path where the existing file is to
+ * @param $archiveRel String: the relative path where the existing file is to
* be archived, if there is one. Relative to the public zone root.
* @param $flags Integer: bitfield, may be FileRepo::DELETE_SOURCE to indicate
* that the source file should be deleted if possible
*/
abstract function publishBatch( $triplets, $flags = 0 );
+ /**
+ * @param $file
+ * @param int $flags
+ * @return bool
+ */
function fileExists( $file, $flags = 0 ) {
$result = $this->fileExistsBatch( array( $file ), $flags );
return $result[0];
* 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()
+ *
+ * @param $virtualUrl string
*/
abstract function getFileProps( $virtualUrl );
/**
* Determine if a relative path is valid, i.e. not blank or involving directory traveral
+ *
+ * @param $filename string
+ *
+ * @return bool
*/
function validateFilename( $filename ) {
if ( strval( $filename ) == '' ) {
* Use the same traversal protection as Title::secureAndSplit()
*/
if ( strpos( $filename, '.' ) !== false &&
- ( $filename === '.' || $filename === '..' ||
- strpos( $filename, './' ) === 0 ||
- strpos( $filename, '../' ) === 0 ||
- strpos( $filename, '/./' ) !== false ||
- strpos( $filename, '/../' ) !== false ) )
+ ( $filename === '.' || $filename === '..' ||
+ strpos( $filename, './' ) === 0 ||
+ strpos( $filename, '../' ) === 0 ||
+ strpos( $filename, '/./' ) !== false ||
+ strpos( $filename, '/../' ) !== false ) )
{
return false;
} else {
* Path disclosure protection functions
*/
function paranoidClean( $param ) { return '[hidden]'; }
+
+ /**
+ * @param $param
+ * @return
+ */
function passThrough( $param ) { return $param; }
/**
function newFatal( $message /*, parameters...*/ ) {
$params = func_get_args();
array_unshift( $params, $this );
- return call_user_func_array( array( 'FileRepoStatus', 'newFatal' ), $params );
+ return MWInit::callStaticMethod( 'FileRepoStatus', 'newFatal', $params );
}
/**
* Create a new good result
+ *
+ * @return FileRepoStatus
*/
function newGood( $value = null ) {
return FileRepoStatus::newGood( $this, $value );
* @param $title Title of image
* @return Bool
*/
- function checkRedirect( $title ) {
+ function checkRedirect( Title $title ) {
return false;
}
* STUB
* @param $title Title of image
*/
- function invalidateImageRedirect( $title ) {}
+ function invalidateImageRedirect( Title $title ) {}
/**
* Get an array or iterator of file objects for files that have a given
return $this->getName() == 'local';
}
-
/**
* Get a key on the primary cache for this repository.
* Returns false if the repository's cache is not accessible at this site.
array_unshift( $args, 'filerepo', $this->getName() );
return call_user_func_array( 'wfMemcKey', $args );
}
-
+
/**
* Get an UploadStash associated with this repo.
*