Merge "Fixed dependencies for jquery.collapsibleTabs"
[lhc/web/wiklou.git] / includes / filebackend / TempFSFile.php
index 00f1080..11e125c 100644 (file)
@@ -43,7 +43,7 @@ class TempFSFile extends FSFile {
         */
        public static function factory( $prefix, $extension = '' ) {
                wfProfileIn( __METHOD__ );
-               $base = wfTempDir() . '/' . $prefix . dechex( mt_rand( 0, 99999999 ) );
+               $base = wfTempDir() . '/' . $prefix . wfRandomString( 12 );
                $ext = ( $extension != '' ) ? ".{$extension}" : "";
                for ( $attempt = 1; true; $attempt++ ) {
                        $path = "{$base}-{$attempt}{$ext}";
@@ -54,7 +54,7 @@ class TempFSFile extends FSFile {
                                fclose( $newFileHandle );
                                break; // got it
                        }
-                       if ( $attempt >= 15 ) {
+                       if ( $attempt >= 5 ) {
                                wfProfileOut( __METHOD__ );
                                return null; // give up
                        }
@@ -82,21 +82,37 @@ class TempFSFile extends FSFile {
         * Clean up the temporary file only after an object goes out of scope
         *
         * @param $object Object
-        * @return void
+        * @return TempFSFile This object
         */
        public function bind( $object ) {
                if ( is_object( $object ) ) {
+                       if ( !isset( $object->tempFSFileReferences ) ) {
+                               // Init first since $object might use __get() and return only a copy variable
+                               $object->tempFSFileReferences = array();
+                       }
                        $object->tempFSFileReferences[] = $this;
                }
+               return $this;
        }
 
        /**
         * Set flag to not clean up after the temporary file
         *
-        * @return void
+        * @return TempFSFile This object
         */
        public function preserve() {
                $this->canDelete = false;
+               return $this;
+       }
+
+       /**
+        * Set flag clean up after the temporary file
+        *
+        * @return TempFSFile This object
+        */
+       public function autocollect() {
+               $this->canDelete = true;
+               return $this;
        }
 
        /**