Index: trunk/phase3/includes/filerepo/FileRepo.php |
— | — | @@ -30,6 +30,7 @@ |
31 | 31 | * Override these in the base class |
32 | 32 | */ |
33 | 33 | var $fileFactory = false, $oldFileFactory = false; |
| 34 | + var $fileFactoryKey = false, $oldFileFactoryKey = false; |
34 | 35 | |
35 | 36 | function __construct( $info ) { |
36 | 37 | // Required settings |
— | — | @@ -178,6 +179,63 @@ |
179 | 180 | } |
180 | 181 | |
181 | 182 | /** |
| 183 | + * Create a new File object from the local repository |
| 184 | + * @param $sha1 Mixed: base 36 SHA-1 hash |
| 185 | + * @param $time Mixed: time at which the image was uploaded. |
| 186 | + * If this is specified, the returned object will be an |
| 187 | + * of the repository's old file class instead of a current |
| 188 | + * file. Repositories not supporting version control should |
| 189 | + * return false if this parameter is set. |
| 190 | + * |
| 191 | + * @return File |
| 192 | + */ |
| 193 | + function newFileFromKey( $sha1, $time = false ) { |
| 194 | + if ( $time ) { |
| 195 | + if ( $this->oldFileFactoryKey ) { |
| 196 | + return call_user_func( $this->oldFileFactoryKey, $sha1, $this, $time ); |
| 197 | + } |
| 198 | + } else { |
| 199 | + if ( $this->fileFactoryKey ) { |
| 200 | + return call_user_func( $this->fileFactoryKey, $sha1, $this ); |
| 201 | + } |
| 202 | + } |
| 203 | + return false; |
| 204 | + } |
| 205 | + |
| 206 | + /** |
| 207 | + * Find an instance of the file with this key, created at the specified time |
| 208 | + * Returns false if the file does not exist. Repositories not supporting |
| 209 | + * version control should return false if the time is specified. |
| 210 | + * |
| 211 | + * @param $sha1 String base 36 SHA-1 hash |
| 212 | + * @param $options Option array, same as findFile(). |
| 213 | + */ |
| 214 | + function findFileFromKey( $sha1, $options = array() ) { |
| 215 | + $time = isset( $options['time'] ) ? $options['time'] : false; |
| 216 | + |
| 217 | + # First try the current version of the file to see if it precedes the timestamp |
| 218 | + $img = $this->newFileFromKey( $sha1 ); |
| 219 | + if ( !$img ) { |
| 220 | + return false; |
| 221 | + } |
| 222 | + if ( $img->exists() && ( !$time || $img->getTimestamp() == $time ) ) { |
| 223 | + return $img; |
| 224 | + } |
| 225 | + # Now try an old version of the file |
| 226 | + if ( $time !== false ) { |
| 227 | + $img = $this->newFileFromKey( $sha1, $time ); |
| 228 | + if ( $img && $img->exists() ) { |
| 229 | + if ( !$img->isDeleted(File::DELETED_FILE) ) { |
| 230 | + return $img; |
| 231 | + } else if ( !empty( $options['private'] ) && $img->userCan(File::DELETED_FILE) ) { |
| 232 | + return $img; |
| 233 | + } |
| 234 | + } |
| 235 | + } |
| 236 | + return false; |
| 237 | + } |
| 238 | + |
| 239 | + /** |
182 | 240 | * Get the URL of thumb.php |
183 | 241 | */ |
184 | 242 | function getThumbScriptUrl() { |
Index: trunk/phase3/includes/filerepo/RepoGroup.php |
— | — | @@ -212,6 +212,29 @@ |
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
| 216 | + * Find an instance of the file with this key, created at the specified time |
| 217 | + * Returns false if the file does not exist. |
| 218 | + * |
| 219 | + * @param $hash String base 36 SHA-1 hash |
| 220 | + * @param $options Option array, same as findFile() |
| 221 | + * @return File object or false if it is not found |
| 222 | + */ |
| 223 | + function findFileFromKey( $hash, $options = array() ) { |
| 224 | + if ( !$this->reposInitialised ) { |
| 225 | + $this->initialiseRepos(); |
| 226 | + } |
| 227 | + |
| 228 | + $file = $this->localRepo->findFileFromKey( $hash, $options ); |
| 229 | + if ( !$file ) { |
| 230 | + foreach ( $this->foreignRepos as $repo ) { |
| 231 | + $file = $repo->findFileFromKey( $hash, $options ); |
| 232 | + if ( $file ) break; |
| 233 | + } |
| 234 | + } |
| 235 | + return $file; |
| 236 | + } |
| 237 | + |
| 238 | + /** |
216 | 239 | * Find all instances of files with this key |
217 | 240 | * |
218 | 241 | * @param $hash String base 36 SHA-1 hash |