Merge "Adds the SidebarBeforeOutput hook"
[lhc/web/wiklou.git] / includes / upload / UploadFromChunks.php
index b572499..6f90280 100644 (file)
@@ -36,9 +36,9 @@ class UploadFromChunks extends UploadFromFile {
        /**
         * Setup local pointers to stash, repo and user (similar to UploadFromStash)
         *
-        * @param $user User|null Default: null
-        * @param $stash UploadStash|bool Default: false
-        * @param $repo FileRepo|bool Default: false
+        * @param User|null $user Default: null
+        * @param UploadStash|bool $stash Default: false
+        * @param FileRepo|bool $repo Default: false
         */
        public function __construct( $user = null, $stash = false, $repo = false ) {
                // user object. sometimes this won't exist, as when running from cron.
@@ -67,6 +67,7 @@ class UploadFromChunks extends UploadFromFile {
        /**
         * Calls the parent stashFile and updates the uploadsession table to handle "chunks"
         *
+        * @param User|null $user
         * @return UploadStashFile stashed file
         */
        public function stashFile( User $user = null ) {
@@ -86,11 +87,16 @@ class UploadFromChunks extends UploadFromFile {
 
                // Update db table to reflect initial "chunk" state
                $this->updateChunkStatus();
+
                return $this->mLocalFile;
        }
 
        /**
         * Continue chunk uploading
+        *
+        * @param string $name
+        * @param string $key
+        * @param WebRequestUpload $webRequestUpload
         */
        public function continueChunks( $name, $key, $webRequestUpload ) {
                $this->mFileKey = $key;
@@ -139,7 +145,7 @@ class UploadFromChunks extends UploadFromFile {
                if ( !$status->isOk() ) {
                        return $status;
                }
-               wfDebugLog( 'fileconcatenate', "Combined $i chunks in $tAmount seconds.\n" );
+               wfDebugLog( 'fileconcatenate', "Combined $i chunks in $tAmount seconds." );
 
                // File system path
                $this->mTempPath = $tmpPath;
@@ -149,6 +155,7 @@ class UploadFromChunks extends UploadFromFile {
                if ( $ret['status'] !== UploadBase::OK ) {
                        wfDebugLog( 'fileconcatenate', "Verification failed for chunked upload" );
                        $status->fatal( $this->getVerificationErrorCode( $ret['status'] ) );
+
                        return $status;
                }
 
@@ -158,36 +165,37 @@ class UploadFromChunks extends UploadFromFile {
                $this->mLocalFile = parent::stashFile( $this->user );
                $tAmount = microtime( true ) - $tStart;
                $this->mLocalFile->setLocalReference( $tmpFile ); // reuse (e.g. for getImageInfo())
-               wfDebugLog( 'fileconcatenate', "Stashed combined file ($i chunks) in $tAmount seconds.\n" );
+               wfDebugLog( 'fileconcatenate', "Stashed combined file ($i chunks) in $tAmount seconds." );
 
                return $status;
        }
 
        /**
         * Perform the upload, then remove the temp copy afterward
-        * @param $comment string
-        * @param $pageText string
-        * @param $watch bool
-        * @param $user User
+        * @param string $comment
+        * @param string $pageText
+        * @param bool $watch
+        * @param User $user
         * @return Status
         */
        public function performUpload( $comment, $pageText, $watch, $user ) {
                $rv = parent::performUpload( $comment, $pageText, $watch, $user );
+
                return $rv;
        }
 
        /**
         * Returns the virtual chunk location:
-        * @param $index
+        * @param int $index
         * @return string
         */
        function getVirtualChunkLocation( $index ) {
                return $this->repo->getVirtualUrl( 'temp' ) .
-                               '/' .
-                               $this->repo->getHashPath(
-                                       $this->getChunkFileKey( $index )
-                               ) .
-                               $this->getChunkFileKey( $index );
+                       '/' .
+                       $this->repo->getHashPath(
+                               $this->getChunkFileKey( $index )
+                       ) .
+                       $this->getChunkFileKey( $index );
        }
 
        /**
@@ -229,6 +237,7 @@ class UploadFromChunks extends UploadFromFile {
                                $status = Status::newFatal( 'invalid-chunk-offset' );
                        }
                }
+
                return $status;
        }
 
@@ -237,7 +246,7 @@ class UploadFromChunks extends UploadFromFile {
         */
        private function updateChunkStatus() {
                wfDebug( __METHOD__ . " update chunk status for {$this->mFileKey} offset:" .
-                                       $this->getOffset() . ' inx:' . $this->getChunkIndex() . "\n" );
+                       $this->getOffset() . ' inx:' . $this->getChunkIndex() . "\n" );
 
                $dbw = $this->repo->getMasterDb();
                // Use a quick transaction since we will upload the full temp file into shared
@@ -283,30 +292,32 @@ class UploadFromChunks extends UploadFromFile {
 
        /**
         * Get the current Chunk index
-        * @return Integer index of the current chunk
+        * @return int Index of the current chunk
         */
        private function getChunkIndex() {
                if ( $this->mChunkIndex !== null ) {
                        return $this->mChunkIndex;
                }
+
                return 0;
        }
 
        /**
         * Gets the current offset in fromt the stashedupload table
-        * @return Integer current byte offset of the chunk file set
+        * @return int Current byte offset of the chunk file set
         */
        private function getOffset() {
                if ( $this->mOffset !== null ) {
                        return $this->mOffset;
                }
+
                return 0;
        }
 
        /**
         * Output the chunk to disk
         *
-        * @param $chunkPath string
+        * @param string $chunkPath
         * @throws UploadChunkFileException
         * @return FileRepoStatus
         */
@@ -320,19 +331,20 @@ class UploadFromChunks extends UploadFromFile {
                        $this->repo->getZonePath( 'temp' ) . "/{$hashPath}{$fileKey}" );
 
                // Check for error in stashing the chunk:
-               if ( ! $storeStatus->isOK() ) {
+               if ( !$storeStatus->isOK() ) {
                        $error = $storeStatus->getErrorsArray();
                        $error = reset( $error );
-                       if ( ! count( $error ) ) {
+                       if ( !count( $error ) ) {
                                $error = $storeStatus->getWarningsArray();
                                $error = reset( $error );
-                               if ( ! count( $error ) ) {
+                               if ( !count( $error ) ) {
                                        $error = array( 'unknown', 'no error recorded' );
                                }
                        }
                        throw new UploadChunkFileException( "Error storing file in '$chunkPath': " .
                                implode( '; ', $error ) );
                }
+
                return $storeStatus;
        }
 
@@ -340,6 +352,7 @@ class UploadFromChunks extends UploadFromFile {
                if ( $index === null ) {
                        $index = $this->getChunkIndex();
                }
+
                return $this->mFileKey . '.' . $index;
        }