From 87de57b3f240bc561214649abd593744fb6f43ee Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 28 Mar 2011 21:40:50 +0000 Subject: [PATCH] Reverted r84918 per CR --- includes/filerepo/FileRepo.php | 58 +++++++++++++++++++++++++++++++++ includes/filerepo/RepoGroup.php | 23 +++++++++++++ 2 files changed, 81 insertions(+) diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 8d862b0fcc..6e4d12f372 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -30,6 +30,7 @@ abstract class FileRepo { * Override these in the base class */ var $fileFactory = false, $oldFileFactory = false; + var $fileFactoryKey = false, $oldFileFactoryKey = false; function __construct( $info ) { // Required settings @@ -177,6 +178,63 @@ abstract class FileRepo { 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 { + if ( $this->fileFactoryKey ) { + return call_user_func( $this->fileFactoryKey, $sha1, $this ); + } + } + return false; + } + + /** + * 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; + + # First try the current version of the file to see if it precedes the timestamp + $img = $this->newFileFromKey( $sha1 ); + if ( !$img ) { + return false; + } + if ( $img->exists() && ( !$time || $img->getTimestamp() == $time ) ) { + return $img; + } + # Now try an old version of the file + if ( $time !== false ) { + $img = $this->newFileFromKey( $sha1, $time ); + if ( $img && $img->exists() ) { + if ( !$img->isDeleted(File::DELETED_FILE) ) { + return $img; + } else if ( !empty( $options['private'] ) && $img->userCan(File::DELETED_FILE) ) { + return $img; + } + } + } + return false; + } + /** * Get the URL of thumb.php */ diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 49e5023f6e..2d0b1ac84b 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -211,6 +211,29 @@ class RepoGroup { return false; } + /** + * Find an instance of the file with this key, created at the specified time + * Returns false if the file does not exist. + * + * @param $hash String base 36 SHA-1 hash + * @param $options Option array, same as findFile() + * @return File object or false if it is not found + */ + 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 ); + if ( $file ) break; + } + } + return $file; + } + /** * Find all instances of files with this key * -- 2.20.1