*
* - articleUrl Equivalent to $wgArticlePath, e.g. http://en.wikipedia.org/wiki/$1
* - fetchDescription Fetch the text of the remote file description page. Equivalent to
- * $wgFetchCommonsDescriptions.
+ * $wgFetchCommonsDescriptions.
+ * - abbrvThreshold File names over this size will use the short form of thumbnail names.
+ * Short thumbnail names only have the width, parameters, and the extension.
*
* ForeignDBRepo:
* - dbType, dbServer, dbUser, dbPassword, dbName, dbFlags
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();
*
* @param $src string File system path
* @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)
+ * When "dispositions" are given they are used as Content-Disposition if supported.
+ *
+ * @param $pairs Array List of tuples (file system path, virtual URL/storage path, disposition)
* @return FileRepoStatus
*/
public function quickImportBatch( array $pairs ) {
list ( $src, $dst ) = $pair;
$dst = $this->resolveToStoragePath( $dst );
$operations[] = array(
- 'op' => 'store',
- 'src' => $src,
- 'dst' => $dst
+ 'op' => 'store',
+ 'src' => $src,
+ 'dst' => $dst,
+ 'disposition' => isset( $pair[2] ) ? $pair[2] : null
);
$status->merge( $this->initDirectory( dirname( $dst ) ) );
}
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.
*
* @return string
*/
function thumbName( $params ) {
- return $this->generateThumbName( $this->getName(), $params );
+ $name = $this->repo ? $this->repo->nameForThumb( $this->getName() ) : $this->getName();
+ return $this->generateThumbName( $name, $params );
}
/**
}
} elseif ( $this->repo && $thumb->hasFile() && !$thumb->fileIsSource() ) {
// Copy the thumbnail from the file system into storage...
- $status = $this->repo->quickImport( $tmpThumbPath, $thumbPath );
+ $disposition = FileBackend::makeContentDisposition( 'inline', $this->name );
+ $status = $this->repo->quickImport( $tmpThumbPath, $thumbPath, $disposition );
if ( $status->isOK() ) {
$thumb->setStoragePath( $thumbPath );
} else {