Use local context to get message instead of relying on global variables
[lhc/web/wiklou.git] / includes / specials / SpecialUploadStash.php
index 9dd78ef..121b6a4 100644 (file)
@@ -35,7 +35,6 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                try {
                        $this->stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
                } catch ( UploadStashNotAvailableException $e ) {
-                       return null;
                }
        }
 
@@ -46,19 +45,14 @@ class SpecialUploadStash extends UnlistedSpecialPage {
         * @return Boolean: success
         */
        public function execute( $subPage ) {
-               if ( !$this->userCanExecute( $this->getUser() ) ) {
-                       $this->displayRestrictionError();
-                       return;
-               }
+               $this->checkPermissions();
 
                if ( $subPage === null || $subPage === '' ) {
                        return $this->showUploads();
-               } else {
-                       return $this->showUpload( $subPage );
                }
+               return $this->showUpload( $subPage );
        }
 
-
        /**
         * If file available in stash, cats it out to the client as a simple HTTP response.
         * n.b. Most sanity checking done in UploadStashLocalFile, so this is straightforward.
@@ -172,14 +166,15 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                }
 
                // we should have just generated it locally
-               if ( ! $thumbnailImage->getPath() ) {
+               if ( !$thumbnailImage->getStoragePath() ) {
                        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)
-               $thumbFile = new UnregisteredLocalFile( false, $this->stash->repo, $thumbnailImage->getPath(), false );
-               if ( ! $thumbFile ) {
+               $thumbFile = new UnregisteredLocalFile( false, 
+                       $this->stash->repo, $thumbnailImage->getStoragePath(), false );
+               if ( !$thumbFile ) {
                        throw new UploadStashFileNotFoundException( "couldn't create local file object for thumbnail" );
                }
 
@@ -206,7 +201,7 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                // 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.
@@ -244,18 +239,17 @@ class SpecialUploadStash extends UnlistedSpecialPage {
        /**
         * Output HTTP response for file
         * Side effect: writes HTTP response to STDOUT.
-        * XXX could use wfStreamfile (in includes/Streamfile.php), but for consistency with outputContents() doing it this way.
-        * XXX is mimeType really enough, or do we need encoding for full Content-Type header?
         *
         * @param $file File object with a local path (e.g. UnregisteredLocalFile, LocalFile. Oddly these don't share an ancestor!)
         */
-       private function outputLocalFile( $file ) {
+       private function outputLocalFile( File $file ) {
                if ( $file->getSize() > self::MAX_SERVE_BYTES ) {
                        throw new SpecialUploadStashTooLargeException();
                }
-               self::outputFileHeaders( $file->getMimeType(), $file->getSize() );
-               readfile( $file->getPath() );
-               return true;
+               return $file->getRepo()->streamFile( $file->getPath(),
+                       array( 'Content-Transfer-Encoding: binary',
+                               'Expires: Sun, 17-Jan-2038 19:14:07 GMT' )
+               );
        }
 
        /**