* Override these in the base class
*/
var $fileFactory = false, $oldFileFactory = false;
+ var $fileFactoryKey = false, $oldFileFactoryKey = false;
function __construct( $info ) {
// Required settings
}
# Now try redirects
- if ( $flags & FileRepo::FIND_IGNORE_REDIRECT ) return false;
+ if ( $flags & FileRepo::FIND_IGNORE_REDIRECT ) {
+ return false;
+ }
$redir = $this->checkRedirect( $title );
if( $redir && $redir->getNamespace() == NS_IMAGE) {
$img = $this->newFile( $redir );
}
return false;
}
+
+ /**
+ * Create a new File object from the local repository
+ * @param mixed $sha1 SHA-1 key
+ * @param mixed $time 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.
+ */
+ 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
+ * version control should return false if the time is specified.
+ *
+ * @param string $sha1 string
+ * @param mixed $time 14-character timestamp, or false for the current version
+ */
+ function findFileFromKey( $sha1, $time = false, $flags = 0 ) {
+ # 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->exists() ) {
+ if ( !$img->isDeleted(File::DELETED_FILE) ) {
+ return $img;
+ } else if ( ($flags & FileRepo::FIND_PRIVATE) && $img->userCan(File::DELETED_FILE) ) {
+ return $img;
+ }
+ }
+ }
+ return false;
+ }
/**
* Get the URL of thumb.php
return $file;
}
+ /**
+ * Create a LocalFile from a SHA-1 key
+ * Do not call this except from inside a repo class.
+ */
+ static function newFromKey( $sha1, $repo, $timestamp = false ) {
+ # Polymorphic function name to distinguish foreign and local fetches
+ $fname = get_class( $this ) . '::' . __FUNCTION__;
+
+ $conds = array( 'img_sha1' => $sha1 );
+ if( $timestamp ) {
+ $conds['img_timestamp'] = $timestamp;
+ }
+ $row = $dbr->selectRow( 'image', $this->getCacheFields( 'img_' ), $conds, $fname );
+ if( $row ) {
+ return self::newFromRow( $row, $repo );
+ } else {
+ return false;
+ }
+ }
+
/**
* Fields in the image table
*/
$file->loadFromRow( $row, 'oi_' );
return $file;
}
+
+ static function newFromKey( $sha1, $repo, $timestamp = false ) {
+ # Polymorphic function name to distinguish foreign and local fetches
+ $fname = get_class( $this ) . '::' . __FUNCTION__;
+
+ $conds = array( 'oi_sha1' => $sha1 );
+ if( $timestamp ) {
+ $conds['oi_timestamp'] = $timestamp;
+ }
+ $row = $dbr->selectRow( 'oldimage', $this->getCacheFields( 'oi_' ), $conds, $fname );
+ if( $row ) {
+ return self::newFromRow( $row, $repo );
+ } else {
+ return false;
+ }
+ }
/**
* @param Title $title