55 parent::__construct(
'UploadStash',
'upload' );
71 $this->stash = MediaWikiServices::getInstance()->getRepoGroup()
72 ->getLocalRepo()->getUploadStash( $this->
getUser() );
75 if ( $subPage ===
null || $subPage ===
'' ) {
95 if ( $params[
'type'] ===
'thumb' ) {
103 $message = $e->getMessage();
104 }
catch ( Exception $e ) {
106 $message = $e->getMessage();
122 $type = strtok( $key,
'/' );
124 if (
$type !==
'file' &&
$type !==
'thumb' ) {
126 $this->
msg(
'uploadstash-bad-path-unknown-type',
$type )
129 $fileName = strtok(
'/' );
130 $thumbPart = strtok(
'/' );
131 $file = $this->stash->getFile( $fileName );
132 if (
$type ===
'thumb' ) {
133 $srcNamePos = strrpos( $thumbPart, $fileName );
134 if ( $srcNamePos ===
false || $srcNamePos < 1 ) {
136 $this->
msg(
'uploadstash-bad-path-unrecognized-thumb-name' )
139 $paramString = substr( $thumbPart, 0, $srcNamePos - 1 );
141 $handler =
$file->getHandler();
143 $params = $handler->parseParamString( $paramString );
145 return [
'file' =>
$file,
'type' =>
$type,
'params' => $params ];
148 $this->
msg(
'uploadstash-bad-path-no-handler',
$file->getMimeType(),
$file->getPath() )
169 if ( $this->
getConfig()->
get(
'UploadStashScalerBaseUrl' ) ) {
188 $flags |= File::RENDER_NOW;
190 $thumbnailImage =
$file->transform( $params, $flags );
191 if ( !$thumbnailImage ) {
193 $this->
msg(
'uploadstash-file-not-found-no-thumb' )
198 if ( !$thumbnailImage->getStoragePath() ) {
200 $this->
msg(
'uploadstash-file-not-found-no-local-path' )
207 $this->stash->repo, $thumbnailImage->getStoragePath(),
false );
234 $scalerBaseUrl = $this->
getConfig()->get(
'UploadStashScalerBaseUrl' );
236 if ( preg_match(
'/^\/\//', $scalerBaseUrl ) ) {
246 $scalerThumbName =
$file->generateThumbName(
$file->getName(), $params );
247 $scalerThumbUrl = $scalerBaseUrl .
'/' .
$file->getUrlRel() .
248 '/' . rawurlencode( $scalerThumbName );
252 $thumbProxyUrl =
$file->getRepo()->getThumbProxyUrl();
254 if ( strlen( $thumbProxyUrl ) ) {
255 $scalerThumbUrl = $thumbProxyUrl .
'temp/' .
$file->getUrlRel() .
256 '/' . rawurlencode( $scalerThumbName );
265 $req = MWHttpRequest::factory( $scalerThumbUrl, $httpOptions, __METHOD__ );
267 $secret =
$file->getRepo()->getThumbProxySecret();
270 if ( strlen( $secret ) ) {
271 $req->setHeader(
'X-Swift-Secret', $secret );
274 $status = $req->execute();
275 if ( !$status->isOK() ) {
276 $errors = $status->getErrorsArray();
279 'uploadstash-file-not-found-no-remote-thumb',
280 print_r( $errors, 1 ),
285 $contentType = $req->getResponseHeader(
"content-type" );
286 if ( !$contentType ) {
288 $this->
msg(
'uploadstash-file-not-found-missing-content-type' )
304 if (
$file->getSize() > self::MAX_SERVE_BYTES ) {
306 $this->
msg(
'uploadstash-file-too-large', self::MAX_SERVE_BYTES )
310 $file->getRepo()->streamFileWithStatus(
$file->getPath(),
311 [
'Content-Transfer-Encoding: binary',
312 'Expires: Sun, 17-Jan-2038 19:14:07 GMT' ]
325 if ( $size > self::MAX_SERVE_BYTES ) {
327 $this->
msg(
'uploadstash-file-too-large', self::MAX_SERVE_BYTES )
346 header(
"Content-Type: $contentType",
true );
347 header(
'Content-Transfer-Encoding: binary',
true );
348 header(
'Expires: Sun, 17-Jan-2038 19:14:07 GMT',
true );
350 header(
'Cache-Control: private' );
351 header(
"Content-Length: $size",
true );
364 if ( isset( $formData[
'Clear'] ) ) {
365 $stash = MediaWikiServices::getInstance()->getRepoGroup()
366 ->getLocalRepo()->getUploadStash( $form->getUser() );
367 wfDebug(
'stash has: ' . print_r(
$stash->listFiles(),
true ) );
370 return Status::newFatal(
'uploadstash-errclear' );
374 return Status::newGood();
391 $form = HTMLForm::factory(
'ooui', [
397 ], $context,
'clearStashedUploads' );
398 $form->setSubmitDestructive();
399 $form->setSubmitCallback( [ __CLASS__,
'tryClearStashedUploads' ] );
400 $form->setSubmitTextMsg(
'uploadstash-clear' );
402 $form->prepareForm();
403 $formResult = $form->tryAuthorizedSubmit();
406 $refreshHtml = Html::element(
'a',
408 $this->
msg(
'uploadstash-refresh' )->text() );
409 $files = $this->stash->listFiles();
410 if ( $files && count( $files ) ) {
412 $fileListItemsHtml =
'';
414 foreach ( $files as
$file ) {
420 $fileObj = $this->stash->getFile(
$file );
421 $thumb = $fileObj->generateThumbName(
$file, [
'width' => 220 ] );
423 $this->
msg(
'word-separator' )->escaped() .
424 $this->
msg(
'parentheses' )->rawParams(
426 $this->getPageTitle(
"thumb/$file/$thumb" ),
427 $this->msg(
'uploadstash-thumbnail' )->text()
430 }
catch ( Exception $e ) {
432 $fileListItemsHtml .= Html::rawElement(
'li', [], $itemHtml );
434 $this->
getOutput()->addHTML( Html::rawElement(
'ul', [], $fileListItemsHtml ) );
435 $form->displayForm( $formResult );
436 $this->
getOutput()->addHTML( Html::rawElement(
'p', [], $refreshHtml ) );
438 $this->
getOutput()->addHTML( Html::rawElement(
'p', [],
439 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.