* Get a relative path including trailing slash, e.g. f/fa/
* If the repo is not hashed, returns an empty string
*
- * @param $name string
+ * @param $name string Name of file
* @return string
*/
public function getHashPath( $name ) {
return self::getHashPathForLevel( $name, $this->hashLevels );
}
+ /**
+ * Get a relative path including trailing slash, e.g. f/fa/
+ * If the repo is not hashed, returns an empty string
+ *
+ * @param $suffix string Basename of file from FileRepo::storeTemp()
+ * @return string
+ */
+ public function getTempHashPath( $suffix ) {
+ $parts = explode( '!', $suffix, 2 ); // format is <timestamp>!<name> or just <name>
+ $name = isset( $parts[1] ) ? $parts[1] : $suffix; // hash path is not based on timestamp
+ return self::getHashPathForLevel( $name, $this->hashLevels );
+ }
+
/**
* @param $name
* @param $levels
return call_user_func_array( 'wfMemcKey', $args );
}
+ /**
+ * Get an temporary FileRepo associated with this repo.
+ * Files will be created in the temp zone of this repo and
+ * thumbnails in a /temp subdirectory in thumb zone of this repo.
+ * It will have the same backend as this repo.
+ *
+ * @return TempFileRepo
+ */
+ public function getTempRepo() {
+ return new TempFileRepo( array(
+ 'name' => "{$this->name}-temp",
+ 'backend' => $this->backend,
+ 'zones' => array(
+ 'public' => array(
+ 'container' => $this->zones['temp']['container'],
+ 'directory' => $this->zones['temp']['directory']
+ ),
+ 'thumb' => array(
+ 'container' => $this->zones['thumb']['container'],
+ 'directory' => ( $this->zones['thumb']['directory'] == '' )
+ ? 'temp'
+ : $this->zones['thumb']['directory'] . '/temp'
+ )
+ ),
+ 'url' => $this->getZoneUrl( 'temp' ),
+ 'thumbUrl' => $this->getZoneUrl( 'thumb' ) . '/temp',
+ 'hashLevels' => $this->hashLevels // performance
+ ) );
+ }
+
/**
* Get an UploadStash associated with this repo.
*
*/
protected function assertWritableRepo() {}
}
+
+/**
+ * FileRepo for temporary files created via FileRepo::getTempRepo()
+ */
+class TempFileRepo extends FileRepo {
+ public function getTempRepo() {
+ throw new MWException( "Cannot get a temp repo from a temp repo." );
+ }
+}
// Is this a thumb of an archived file?
$isOld = ( isset( $params['archived'] ) && $params['archived'] );
- unset( $params['archived'] );
+ unset( $params['archived'] ); // handlers don't care
+
+ // Is this a thumb of a temp file?
+ $isTemp = ( isset( $params['temp'] ) && $params['temp'] );
+ unset( $params['temp'] ); // handlers don't care
// Some basic input validation
$fileName = strtr( $fileName, '\\/', '__' );
return;
}
$img = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $title, $fileName );
+ } elseif ( $isTemp ) {
+ $repo = RepoGroup::singleton()->getLocalRepo()->getTempRepo();
+ // Format is <timestamp>!<name> or just <name>
+ $bits = explode( '!', $fileName, 2 );
+ // Get the name without the timestamp so hash paths are correctly computed
+ $title = Title::makeTitleSafe( NS_FILE, isset( $bits[1] ) ? $bits[1] : $fileName );
+ if ( !$title ) {
+ wfThumbError( 404, wfMsg( 'badtitletext' ) );
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+ $img = new UnregisteredLocalFile( $title, $repo,
+ $repo->getZonePath( 'public' ) . '/' . $repo->getTempHashPath( $fileName ) . $fileName
+ );
} else {
$img = wfLocalFile( $fileName );
}
// Check that the zone relative path matches up so squid caches won't pick
// up thumbs that would not be purged on source file deletion (bug 34231).
if ( isset( $params['rel404'] ) // thumbnail was handled via 404
- && urldecode( $params['rel404'] ) !== $img->getThumbRel( $thumbName ) )
+ && urldecode( $params['rel404'] ) !== $img->getThumbRel( $thumbName ) )
{
wfThumbError( 404, 'The source file for the specified thumbnail does not exist.' );
wfProfileOut( __METHOD__ );