var $pathDisclosureProtection = 'simple'; // 'paranoid'
var $descriptionCacheExpiry, $url, $thumbUrl;
var $hashLevels, $deletedHashLevels;
+ protected $abbrvThreshold;
/**
* Factory functions for creating new files
? $info['deletedHashLevels']
: $this->hashLevels;
$this->transformVia404 = !empty( $info['transformVia404'] );
+ $this->abbrvThreshold = isset( $info['abbrvThreshold'] )
+ ? $info['abbrvThreshold']
+ : 255;
$this->isPrivate = !empty( $info['isPrivate'] );
// Give defaults for the basic zones...
$this->zones = isset( $info['zones'] ) ? $info['zones'] : array();
/**
* Store a file to a given destination.
*
- * @param $srcPath String: source FS path, storage path, or virtual URL
+ * @param $srcPath String: source file system path, storage path, or virtual URL
* @param $dstZone String: destination zone
* @param $dstRel String: destination relative path
* @param $flags Integer: bitwise combination of the following flags:
* This function can be used to write to otherwise read-only foreign repos.
* This is intended for copying generated thumbnails into the repo.
*
- * @param $src string File system path
+ * @param $src string Source file system path, storage path, or virtual URL
* @param $dst string Virtual URL or storage path
+ * @param $disposition string|null Content-Disposition if given and supported
* @return FileRepoStatus
*/
- final public function quickImport( $src, $dst ) {
- return $this->quickImportBatch( array( array( $src, $dst ) ) );
+ final public function quickImport( $src, $dst, $disposition = null ) {
+ return $this->quickImportBatch( array( array( $src, $dst, $disposition ) ) );
}
/**
* This function can be used to write to otherwise read-only foreign repos.
* This is intended for copying generated thumbnails into the repo.
*
- * @param $pairs Array List of tuples (file system path, virtual URL or storage path)
+ * All path parameters may be a file system path, storage path, or virtual URL.
+ * When "dispositions" are given they are used as Content-Disposition if supported.
+ *
+ * @param $triples Array List of (source path, destination path, disposition)
* @return FileRepoStatus
*/
- public function quickImportBatch( array $pairs ) {
+ public function quickImportBatch( array $triples ) {
$status = $this->newGood();
$operations = array();
- foreach ( $pairs as $pair ) {
- list ( $src, $dst ) = $pair;
+ foreach ( $triples as $triple ) {
+ list( $src, $dst ) = $triple;
+ $src = $this->resolveToStoragePath( $src );
$dst = $this->resolveToStoragePath( $dst );
$operations[] = array(
- 'op' => 'store',
- 'src' => $src,
- 'dst' => $dst
+ 'op' => FileBackend::isStoragePath( $src ) ? 'copy' : 'store',
+ 'src' => $src,
+ 'dst' => $dst,
+ 'disposition' => isset( $triple[2] ) ? $triple[2] : null
);
$status->merge( $this->initDirectory( dirname( $dst ) ) );
}
/**
* Copy or move a file either from a storage path, virtual URL,
- * or FS path, into this repository at the specified destination location.
+ * or file system path, into this repository at the specified destination location.
*
* Returns a FileRepoStatus object. On success, the value contains "new" or
* "archived", to indicate whether the file was new with that name.
*
- * @param $srcPath String: the source FS path, storage path, or URL
+ * @param $srcPath String: the source file system path, storage path, or URL
* @param $dstRel String: the destination relative path
* @param $archiveRel String: the relative path where the existing file is to
* be archived, if there is one. Relative to the public zone root.
* @return string
*/
public function getDeletedHashPath( $key ) {
+ if ( strlen( $key ) < 31 ) {
+ throw new MWException( "Invalid storage key '$key'." );
+ }
$path = '';
for ( $i = 0; $i < $this->deletedHashLevels; $i++ ) {
$path .= $key[$i] . '/';
return wfMessageFallback( 'shared-repo-name-' . $this->name, 'shared-repo' )->text();
}
+ /**
+ * Get the portion of the file that contains the origin file name.
+ * If that name is too long, then the name "thumbnail.<ext>" will be given.
+ *
+ * @param $name string
+ * @return string
+ */
+ public function nameForThumb( $name ) {
+ if ( strlen( $name ) > $this->abbrvThreshold ) {
+ $ext = FileBackend::extensionFromPath( $name );
+ $name = ( $ext == '' ) ? 'thumbnail' : "thumbnail.$ext";
+ }
+ return $name;
+ }
+
/**
* Returns true if this the local file repository.
*