//
// This service is really for thumbnails and other such previews while
// uploading.
- const MAX_SERVE_BYTES = 262144; // 256K
+ const MAX_SERVE_BYTES = 1048576; // 1MB
public function __construct() {
parent::__construct( 'UploadStash', 'upload' );
* @return Boolean: success
*/
public function execute( $subPage ) {
- global $wgUser;
-
- if ( !$this->userCanExecute( $wgUser ) ) {
+ if ( !$this->userCanExecute( $this->getUser() ) ) {
$this->displayRestrictionError();
return;
}
- if ( !isset( $subPage ) || $subPage === '' ) {
+ if ( $subPage === null || $subPage === '' ) {
return $this->showUploads();
+ } else {
+ return $this->showUpload( $subPage );
}
-
- return $this->showUpload( $subPage );
}
* @param $key String: the key of a particular requested file
*/
public function showUpload( $key ) {
- global $wgOut;
-
// prevent callers from doing standard HTML output -- we'll take it from here
- $wgOut->disable();
+ $this->getOutput()->disable();
try {
$params = $this->parseKey( $key );
$message = $e->getMessage();
}
- wfHttpError( $code, OutputPage::getStatusMessage( $code ), $message );
- return false;
+ throw new HttpError( $code, $message );
}
/**
return array( 'file' => $file, 'type' => $type );
}
-
-
-
/**
* Get a thumbnail for file, either generated locally or remotely, and stream it out
- * @param String $key: key for the file in the stash
- * @param int $width: width of desired thumbnail
+ *
+ * @param $file
+ * @param $params array
+ *
* @return boolean success
*/
private function outputThumbFromStash( $file, $params ) {
} else {
$this->outputLocallyScaledThumb( $file, $params, $flags );
}
-
-
}
-
/**
* Scale a file (probably with a locally installed imagemagick, or similar) and output it to STDOUT.
* @param $file: File object
// this global probably looks something like 'http://upload.wikimedia.org/wikipedia/test/thumb/temp'
// do not use trailing slash
global $wgUploadStashScalerBaseUrl;
+ $scalerBaseUrl = $wgUploadStashScalerBaseUrl;
+
+ if( preg_match( '/^\/\//', $scalerBaseUrl ) ) {
+ // this is apparently a protocol-relative URL, which makes no sense in this context,
+ // since this is used for communication that's internal to the application.
+ // default to http.
+ $scalerBaseUrl = wfExpandUrl( $scalerBaseUrl, PROTO_CANONICAL );
+ }
// We need to use generateThumbName() instead of thumbName(), because
// the suffix needs to match the file name for the remote thumbnailer
// to work
$scalerThumbName = $file->generateThumbName( $file->getName(), $params );
- $scalerThumbUrl = $wgUploadStashScalerBaseUrl . '/' . $file->getUrlRel() .
+ $scalerThumbUrl = $scalerBaseUrl . '/' . $file->getUrlRel() .
'/' . rawurlencode( $scalerThumbName );
// make a curl call to the scaler to create a thumbnail
$req = MWHttpRequest::factory( $scalerThumbUrl, $httpOptions );
$status = $req->execute();
if ( ! $status->isOK() ) {
- $errors = $status->getWikiTextArray( $status->getErrorsArray() );
- throw new MWException( "Fetching thumbnail failed: " . join( ", ", $errors ) );
+ $errors = $status->getErrorsArray();
+ $errorStr = "Fetching thumbnail failed: " . print_r( $errors, 1 );
+ $errorStr .= "\nurl = $scalerThumbUrl\n";
+ throw new MWException( $errorStr );
}
$contentType = $req->getResponseHeader( "content-type" );
if ( ! $contentType ) {
* @param Status : $status - the result of processRequest
*/
private function showUploads( $status = null ) {
- global $wgOut;
if ( $status === null ) {
$status = Status::newGood();
}
$this->setHeaders();
$this->outputHeader();
-
// create the form, which will also be used to execute a callback to process incoming form data
// this design is extremely dubious, but supposedly HTMLForm is our standard now?
'default' => true,
'name' => 'clear',
)
- ), 'clearStashedUploads' );
+ ), $this->getContext(), 'clearStashedUploads' );
$form->setSubmitCallback( array( __CLASS__ , 'tryClearStashedUploads' ) );
$form->setTitle( $this->getTitle() );
$form->setSubmitText( wfMsg( 'uploadstash-clear' ) );
$form->prepareForm();
$formResult = $form->tryAuthorizedSubmit();
-
// show the files + form, if there are any, or just say there are none
$refreshHtml = Html::element( 'a',
array( 'href' => $this->getTitle()->getLocalURL() ),
wfMsg( 'uploadstash-refresh' ) );
$files = $this->stash->listFiles();
- if ( count( $files ) ) {
+ if ( $files && count( $files ) ) {
sort( $files );
$fileListItemsHtml = '';
foreach ( $files as $file ) {
$this->getTitle( "file/$file" )->getLocalURL() ), $file )
);
}
- $wgOut->addHtml( Html::rawElement( 'ul', array(), $fileListItemsHtml ) );
+ $this->getOutput()->addHtml( Html::rawElement( 'ul', array(), $fileListItemsHtml ) );
$form->displayForm( $formResult );
- $wgOut->addHtml( Html::rawElement( 'p', array(), $refreshHtml ) );
+ $this->getOutput()->addHtml( Html::rawElement( 'p', array(), $refreshHtml ) );
} else {
- $wgOut->addHtml( Html::rawElement( 'p', array(),
+ $this->getOutput()->addHtml( Html::rawElement( 'p', array(),
Html::element( 'span', array(), wfMsg( 'uploadstash-nofiles' ) )
. ' '
. $refreshHtml