Merge "(bug 43661) Added test for special link trail case"
[lhc/web/wiklou.git] / includes / upload / UploadBase.php
index d40b53d..48ea584 100644 (file)
@@ -63,6 +63,8 @@ abstract class UploadBase {
        const WINDOWS_NONASCII_FILENAME = 13;
        const FILENAME_TOO_LONG = 14;
 
+       const SESSION_STATUS_KEY = 'wsUploadStatusData';
+
        /**
         * @param $error int
         * @return string
@@ -233,6 +235,14 @@ abstract class UploadBase {
                return $this->mFileSize;
        }
 
+       /**
+        * Get the base 36 SHA1 of the file
+        * @return string
+        */
+       protected function getTempFileSha1Base36() {
+               return FSFile::getSha1Base36FromPath( $this->mTempPath );
+       }
+
        /**
         * @param $srcPath String: the source path
         * @return string the real path if it was a virtual URL
@@ -244,7 +254,7 @@ abstract class UploadBase {
                        // @TODO: just make uploads work with storage paths
                        // UploadFromStash loads files via virtuals URLs
                        $tmpFile = $repo->getLocalCopy( $srcPath );
-                       $tmpFile->bind( $this ); // keep alive with $thumb
+                       $tmpFile->bind( $this ); // keep alive with $this
                        wfProfileOut( __METHOD__ );
                        return $tmpFile->getPath();
                }
@@ -544,7 +554,9 @@ abstract class UploadBase {
        }
 
        /**
-        * Check for non fatal problems with the file
+        * Check for non fatal problems with the file.
+        *
+        * This should not assume that mTempPath is set.
         *
         * @return Array of warnings
         */
@@ -579,7 +591,7 @@ abstract class UploadBase {
 
                global $wgUploadSizeWarning;
                if ( $wgUploadSizeWarning && ( $this->mFileSize > $wgUploadSizeWarning ) ) {
-                       $warnings['large-file'] = $wgUploadSizeWarning;
+                       $warnings['large-file'] = array( $wgUploadSizeWarning, $this->mFileSize );
                }
 
                if ( $this->mFileSize == 0 ) {
@@ -592,7 +604,7 @@ abstract class UploadBase {
                }
 
                // Check dupes against existing files
-               $hash = FSFile::getSha1Base36FromPath( $this->mTempPath );
+               $hash = $this->getTempFileSha1Base36();
                $dupes = RepoGroup::singleton()->findBySha1( $hash );
                $title = $this->getTitle();
                // Remove all matches against self
@@ -785,13 +797,14 @@ abstract class UploadBase {
         * This method returns the file object, which also has a 'fileKey' property which can be passed through a form or
         * API request to find this stashed file again.
         *
+        * @param $user User
         * @return UploadStashFile stashed file
         */
-       public function stashFile() {
+       public function stashFile( User $user = null ) {
                // was stashSessionFile
                wfProfileIn( __METHOD__ );
 
-               $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
+               $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $user );
                $file = $stash->stashFile( $this->mTempPath, $this->getSourceType() );
                $this->mLocalFile = $file;
 
@@ -1494,6 +1507,32 @@ abstract class UploadBase {
                } else {
                        return intval( $wgMaxUploadSize );
                }
+       }
 
+       /**
+        * Get the current status of a chunked upload (used for polling).
+        * The status will be read from the *current* user session.
+        * @param $statusKey string
+        * @return Array|bool
+        */
+       public static function getSessionStatus( $statusKey ) {
+               return isset( $_SESSION[self::SESSION_STATUS_KEY][$statusKey] )
+                       ? $_SESSION[self::SESSION_STATUS_KEY][$statusKey]
+                       : false;
+       }
+
+       /**
+        * Set the current status of a chunked upload (used for polling).
+        * The status will be stored in the *current* user session.
+        * @param $statusKey string
+        * @param $value array|false
+        * @return void
+        */
+       public static function setSessionStatus( $statusKey, $value ) {
+               if ( $value === false ) {
+                       unset( $_SESSION[self::SESSION_STATUS_KEY][$statusKey] );
+               } else {
+                       $_SESSION[self::SESSION_STATUS_KEY][$statusKey] = $value;
+               }
        }
 }