* ( bug 21089 ) fixes js2 upload stash support.
[lhc/web/wiklou.git] / includes / upload / UploadFromChunks.php
index 3ac5401..6a8478a 100644 (file)
@@ -2,9 +2,9 @@
 /**
  * @file
  * @ingroup upload
- * 
+ *
  * @author Michael Dale
- * 
+ *
  * first destination checks are made (if ignorewarnings is not checked) errors / warning is returned.
  *
  * we return the uploadUrl
@@ -22,8 +22,10 @@ class UploadFromChunks extends UploadBase {
        const INIT      = 1;
        const CHUNK = 2;
        const DONE      = 3;
-
-       function initializeFromParams( $param, &$request ) {
+       public function initializeFromRequest( &$request ){
+               //should merge initializeFromParams (but just needs to be working atm)
+       }
+       public function initializeFromParams( $param, &$request ) {
                $this->initFromSessionKey( $param['chunksessionkey'], $request );
                // set the chunk mode:
                if( !$this->mSessionKey && !$param['done'] ){
@@ -46,7 +48,6 @@ class UploadFromChunks extends UploadBase {
 
                return $this->status;
        }
-
        static function isValidRequest( $request ) {
                $sessionData = $request->getSessionData( 'wsUploadData' );
                if( !self::isValidSessionKey(
@@ -56,13 +57,14 @@ class UploadFromChunks extends UploadBase {
                // check for the file:
                return (bool)$request->getFileTempName( 'file' );
        }
-
        /* check warnings depending on chunk_mode */
        function checkWarnings(){
-               $warning = array();
-               return $warning;
+               if( $this->chunk_mode == UploadFromChunks::DONE ){
+                       return parent::checkWarnings();
+               }else{
+                       return array();
+               }
        }
-
        function isEmptyFile(){
                // does not apply to chunk init
                if( $this->chunk_mode == UploadFromChunks::INIT ){
@@ -71,20 +73,17 @@ class UploadFromChunks extends UploadBase {
                        return parent::isEmptyFile();
                }
        }
-
        /**
         * Verify whether the upload is sane.
         * Returns self::OK or else an array with error information
         */
        function verifyUpload() {
-               // no checks on chunk upload mode:
-               if( $this->chunk_mode ==  UploadFromChunks::INIT )
-                       return self::OK;
-
-               // verify on init and last chunk request
-               if(     $this->chunk_mode == UploadFromChunks::CHUNK ||
-                       $this->chunk_mode == UploadFromChunks::DONE )
+               // verify once DONE uploading chunks
+               if(     $this->chunk_mode == UploadFromChunks::DONE ){
                        return parent::verifyUpload();
+               }else{
+                       return array( 'status' => self::OK );
+               }
        }
 
        // only run verifyFile on completed uploaded chunks
@@ -105,13 +104,6 @@ class UploadFromChunks extends UploadBase {
                }
        }
 
-       function getRealPath( $srcPath ){
-               $repo = RepoGroup::singleton()->getLocalRepo();
-               if ( $repo->isVirtualUrl( $srcPath ) ) {
-                       return $repo->resolveVirtualUrl( $srcPath );
-               }
-       }
-
        // pretty ugly inter-mixing of mParam and local vars
        function setupChunkSession( $summary, $comment, $watch ) {
                $this->mSessionKey = $this->getSessionKey();
@@ -154,7 +146,7 @@ class UploadFromChunks extends UploadBase {
 
        // Lets us return an api result (as flow for chunk uploads is kind of different than others.
        function performUpload( $summary = '', $comment = '', $watch = '', $user ){
-               global $wgServer, $wgScriptPath, $wgUser;
+               global $wgUser;
 
                if( $this->chunk_mode == UploadFromChunks::INIT ){
                        // firefogg expects a specific result per:
@@ -166,8 +158,8 @@ class UploadFromChunks extends UploadBase {
                        // c) (we need the token to validate chunks are coming from a non-xss request)
                        $token = urlencode( $wgUser->editToken() );
                        ob_clean();
-                       echo ApiFormatJson::getJsonEncode( array(
-                                       'uploadUrl' => "{$wgServer}{$wgScriptPath}/api.php?action=upload&".
+                       echo FormatJson::encode( array(
+                                       'uploadUrl' => wfExpandUrl( wfScript( 'api' ) ) . "?action=upload&".
                                                                        "token={$token}&format=json&enablechunks=true&chunksessionkey=".
                                                                        $this->setupChunkSession( $summary, $comment, $watch ) ) );
                        exit( 0 );
@@ -178,7 +170,7 @@ class UploadFromChunks extends UploadBase {
                                // firefogg expects a specific result per:
                                // http://www.firefogg.org/dev/chunk_post.html
                                ob_clean();
-                               echo ApiFormatJson::getJsonEncode( array(
+                               echo FormatJson::encode( array(
                                                'result' => 1,
                                                'filesize' => filesize( $this->getRealPath( $this->mTempAppendPath ) )
                                        )
@@ -191,7 +183,7 @@ class UploadFromChunks extends UploadBase {
                                return $status;
                        }
                } else if( $this->chunk_mode == UploadFromChunks::DONE ){
-                       // update the values from the local (session init) if not paseed again)
+                       // update the values from the local (session init) if not passed again)
                        if( $summary == '' )
                                $summary = $this->mSummary;
 
@@ -200,7 +192,9 @@ class UploadFromChunks extends UploadBase {
 
                        if( $watch == '' )
                                $watch = $this->mWatch;
+
                        $status = parent::performUpload( $summary, $comment, $watch, $user );
+
                        if( !$status->isGood() ) {
                                return $status;
                        }
@@ -208,14 +202,13 @@ class UploadFromChunks extends UploadBase {
                        // firefogg expects a specific result per:
                        // http://www.firefogg.org/dev/chunk_post.html
                        ob_clean();
-                       echo ApiFormatJson::getJsonEncode( array(
+                       echo FormatJson::encode( array(
                                        'result' => 1,
                                        'done' => 1,
                                        'resultUrl' => $file->getDescriptionUrl()
                                )
                        );
                        exit( 0 );
-
                }
        }