53 parent::__construct(
'UploadStash',
'upload' );
69 $this->stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $this->
getUser() );
72 if ( $subPage ===
null || $subPage ===
'' ) {
92 if ( $params[
'type'] ===
'thumb' ) {
100 $message = $e->getMessage();
103 $message = $e->getMessage();
106 $message = $e->getMessage();
109 $message = $e->getMessage();
110 }
catch ( Exception $e ) {
112 $message = $e->getMessage();
128 $type = strtok( $key,
'/' );
130 if (
$type !==
'file' &&
$type !==
'thumb' ) {
132 $this->
msg(
'uploadstash-bad-path-unknown-type',
$type )
135 $fileName = strtok(
'/' );
136 $thumbPart = strtok(
'/' );
137 $file = $this->stash->getFile( $fileName );
138 if (
$type ===
'thumb' ) {
139 $srcNamePos = strrpos( $thumbPart, $fileName );
140 if ( $srcNamePos ===
false || $srcNamePos < 1 ) {
142 $this->
msg(
'uploadstash-bad-path-unrecognized-thumb-name' )
145 $paramString = substr( $thumbPart, 0, $srcNamePos - 1 );
147 $handler =
$file->getHandler();
149 $params = $handler->parseParamString( $paramString );
151 return [
'file' =>
$file,
'type' =>
$type,
'params' => $params ];
154 $this->
msg(
'uploadstash-bad-path-no-handler',
$file->getMimeType(),
$file->getPath() )
175 if ( $this->
getConfig()->
get(
'UploadStashScalerBaseUrl' ) ) {
194 $flags |= File::RENDER_NOW;
196 $thumbnailImage =
$file->transform( $params, $flags );
197 if ( !$thumbnailImage ) {
199 $this->
msg(
'uploadstash-file-not-found-no-thumb' )
204 if ( !$thumbnailImage->getStoragePath() ) {
206 $this->
msg(
'uploadstash-file-not-found-no-local-path' )
213 $this->stash->repo, $thumbnailImage->getStoragePath(),
false );
216 $this->
msg(
'uploadstash-file-not-found-no-object' )
245 $scalerBaseUrl = $this->
getConfig()->get(
'UploadStashScalerBaseUrl' );
247 if ( preg_match(
'/^\/\//', $scalerBaseUrl ) ) {
257 $scalerThumbName =
$file->generateThumbName(
$file->getName(), $params );
258 $scalerThumbUrl = $scalerBaseUrl .
'/' .
$file->getUrlRel() .
259 '/' . rawurlencode( $scalerThumbName );
263 $thumbProxyUrl =
$file->getRepo()->getThumbProxyUrl();
265 if ( strlen( $thumbProxyUrl ) ) {
266 $scalerThumbUrl = $thumbProxyUrl .
'temp/' .
$file->getUrlRel() .
267 '/' . rawurlencode( $scalerThumbName );
276 $req = MWHttpRequest::factory( $scalerThumbUrl, $httpOptions, __METHOD__ );
278 $secret =
$file->getRepo()->getThumbProxySecret();
281 if ( strlen( $secret ) ) {
282 $req->setHeader(
'X-Swift-Secret', $secret );
285 $status = $req->execute();
286 if ( !$status->isOK() ) {
287 $errors = $status->getErrorsArray();
290 'uploadstash-file-not-found-no-remote-thumb',
291 print_r( $errors, 1 ),
296 $contentType = $req->getResponseHeader(
"content-type" );
297 if ( !$contentType ) {
299 $this->
msg(
'uploadstash-file-not-found-missing-content-type' )
315 if (
$file->getSize() > self::MAX_SERVE_BYTES ) {
317 $this->
msg(
'uploadstash-file-too-large', self::MAX_SERVE_BYTES )
321 $file->getRepo()->streamFileWithStatus(
$file->getPath(),
322 [
'Content-Transfer-Encoding: binary',
323 'Expires: Sun, 17-Jan-2038 19:14:07 GMT' ]
336 if ( $size > self::MAX_SERVE_BYTES ) {
338 $this->
msg(
'uploadstash-file-too-large', self::MAX_SERVE_BYTES )
357 header(
"Content-Type: $contentType",
true );
358 header(
'Content-Transfer-Encoding: binary',
true );
359 header(
'Expires: Sun, 17-Jan-2038 19:14:07 GMT',
true );
361 header(
'Cache-Control: private' );
362 header(
"Content-Length: $size",
true );
375 if ( isset( $formData[
'Clear'] ) ) {
376 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $form->getUser() );
377 wfDebug(
'stash has: ' . print_r(
$stash->listFiles(),
true ) .
"\n" );
380 return Status::newFatal(
'uploadstash-errclear' );
384 return Status::newGood();
401 $form = HTMLForm::factory(
'ooui', [
407 ],
$context,
'clearStashedUploads' );
408 $form->setSubmitDestructive();
409 $form->setSubmitCallback( [ __CLASS__,
'tryClearStashedUploads' ] );
410 $form->setSubmitTextMsg(
'uploadstash-clear' );
412 $form->prepareForm();
413 $formResult = $form->tryAuthorizedSubmit();
416 $refreshHtml = Html::element(
'a',
418 $this->
msg(
'uploadstash-refresh' )->text() );
419 $files = $this->stash->listFiles();
420 if ( $files && count( $files ) ) {
422 $fileListItemsHtml =
'';
424 foreach ( $files as
$file ) {
430 $fileObj = $this->stash->getFile(
$file );
431 $thumb = $fileObj->generateThumbName(
$file, [
'width' => 220 ] );
433 $this->
msg(
'word-separator' )->escaped() .
434 $this->
msg(
'parentheses' )->rawParams(
436 $this->getPageTitle(
"thumb/$file/$thumb" ),
437 $this->msg(
'uploadstash-thumbnail' )->text()
440 }
catch ( Exception $e ) {
442 $fileListItemsHtml .= Html::rawElement(
'li', [], $itemHtml );
444 $this->
getOutput()->addHTML( Html::rawElement(
'ul', [], $fileListItemsHtml ) );
445 $form->displayForm( $formResult );
446 $this->
getOutput()->addHTML( Html::rawElement(
'p', [], $refreshHtml ) );
448 $this->
getOutput()->addHTML( Html::rawElement(
'p', [],
449 Html::element(
'span', [], $this->
msg(
'uploadstash-nofiles' )->text() )
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfResetOutputBuffers( $resetGzipEncoding=true)
Clear away any user-level output buffers, discarding contents.
An IContextSource implementation which will inherit context from another source but allow individual ...
Implements some public methods and some protected utility functions which are required by multiple ch...
Show an error that looks like an HTTP server error.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getPageTitle( $subpage=false)
Get a self-referential title object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
MediaWiki Linker LinkRenderer null $linkRenderer
Web access for files temporarily stored by UploadStash.
static outputFileHeaders( $contentType, $size)
Output headers for streaming.
outputLocalFile(File $file)
Output HTTP response for file Side effect: writes HTTP response to STDOUT.
outputThumbFromStash( $file, $params)
Get a thumbnail for file, either generated locally or remotely, and stream it out.
showUploads()
Default action when we don't have a subpage – just show links to the uploads we have,...
parseKey( $key)
Parse the key passed to the SpecialPage.
showUpload( $key)
If file available in stash, cats it out to the client as a simple HTTP response.
outputRemoteScaledThumb( $file, $params, $flags)
Scale a file with a remote "scaler", as exists on the Wikimedia Foundation cluster,...
const MAX_SERVE_BYTES
Since we are directly writing the file to STDOUT, we should not be reading in really big files and se...
execute( $subPage)
Execute page – can output a file directly or show a listing of them.
doesWrites()
Indicates whether this special page may perform database writes.
static tryClearStashedUploads( $formData, $form)
Static callback for the HTMLForm in showUploads, to process Note the stash has to be recreated since ...
outputLocallyScaledThumb( $file, $params, $flags)
Scale a file (probably with a locally installed imagemagick, or similar) and output it to STDOUT.
outputContents( $content, $contentType)
Output HTTP response of raw content Side effect: writes HTTP response to STDOUT.
Shortcut to construct a special page which is unlisted by default.
A file object referring to either a standalone local file, or a file in a local repository with no da...
while(( $__line=Maintenance::readconsole()) !==false) print
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.