public function __construct() {
parent::__construct( 'UploadStash', 'upload' );
- try {
- $this->stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
- } catch ( UploadStashNotAvailableException $e ) {
- }
}
/**
* @return bool Success
*/
public function execute( $subPage ) {
+ $this->stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $this->getUser() );
$this->checkPermissions();
if ( $subPage === null || $subPage === '' ) {
* @return bool Success
*/
private function outputThumbFromStash( $file, $params ) {
- // this global, if it exists, points to a "scaler", as you might find in
+ $flags = 0;
+ // this config option, if it exists, points to a "scaler", as you might find in
// the Wikimedia Foundation cluster. See outputRemoteScaledThumb(). This
// is part of our horrible NFS-based system, we create a file on a mount
// point here, but fetch the scaled file from somewhere else that
// happens to share it over NFS.
- global $wgUploadStashScalerBaseUrl;
-
- $flags = 0;
- if ( $wgUploadStashScalerBaseUrl ) {
+ if ( $this->getConfig()->get( 'UploadStashScalerBaseUrl' ) ) {
$this->outputRemoteScaledThumb( $file, $params, $flags );
} else {
$this->outputLocallyScaledThumb( $file, $params, $flags );
throw new UploadStashFileNotFoundException( "no local path for scaled item" );
}
- // now we should construct a File, so we can get mime and other such info in a standard way
- // n.b. mimetype may be different from original (ogx original -> jpeg thumb)
+ // now we should construct a File, so we can get MIME and other such info in a standard way
+ // n.b. MIME type may be different from original (ogx original -> jpeg thumb)
$thumbFile = new UnregisteredLocalFile( false,
$this->stash->repo, $thumbnailImage->getStoragePath(), false );
if ( !$thumbFile ) {
* @return bool Success
*/
private function outputRemoteScaledThumb( $file, $params, $flags ) {
- // This global probably looks something like
- // 'http://upload.wikimedia.org/wikipedia/test/thumb/temp'. Do not use
+ // This option probably looks something like
+ // '//upload.wikimedia.org/wikipedia/test/thumb/temp'. Do not use
// trailing slash.
- global $wgUploadStashScalerBaseUrl;
- $scalerBaseUrl = $wgUploadStashScalerBaseUrl;
+ $scalerBaseUrl = $this->getConfig()->get( 'UploadStashScalerBaseUrl' );
if ( preg_match( '/^\/\//', $scalerBaseUrl ) ) {
// this is apparently a protocol-relative URL, which makes no sense in this context,
// make a curl call to the scaler to create a thumbnail
$httpOptions = array(
'method' => 'GET',
- 'timeout' => 'default'
+ 'timeout' => 5 // T90599 attempt to time out cleanly
);
- $req = MWHttpRequest::factory( $scalerThumbUrl, $httpOptions );
+ $req = MWHttpRequest::factory( $scalerThumbUrl, $httpOptions, __METHOD__ );
$status = $req->execute();
if ( !$status->isOK() ) {
$errors = $status->getErrorsArray();
* Output HTTP response of raw content
* Side effect: writes HTTP response to STDOUT.
* @param string $content Content
- * @param string $contentType Mime type
+ * @param string $contentType MIME type
* @throws SpecialUploadStashTooLargeException
* @return bool
*/
/**
* Output headers for streaming
* @todo Unsure about encoding as binary; if we received from HTTP perhaps
- * we should use that encoding, concatted with semicolon to mimeType as it
+ * we should use that encoding, concatenated with semicolon to `$contentType` as it
* usually is.
* Side effect: preps PHP to write headers to STDOUT.
* @param string $contentType String suitable for content-type header
* This works, because there really is only one stash per logged-in user, despite appearances.
*
* @param array $formData
+ * @param HTMLForm $form
* @return Status
*/
- public static function tryClearStashedUploads( $formData ) {
+ public static function tryClearStashedUploads( $formData, $form ) {
if ( isset( $formData['Clear'] ) ) {
- $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
+ $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $form->getUser() );
wfDebug( 'stash has: ' . print_r( $stash->listFiles(), true ) . "\n" );
if ( !$stash->clear() ) {