Convert Special:DeletedContributions to use OOUI.
[lhc/web/wiklou.git] / includes / filebackend / TempFSFile.php
index fa4eb5f..f572840 100644 (file)
@@ -31,9 +31,6 @@ class TempFSFile extends FSFile {
        /** @var bool Garbage collect the temp file */
        protected $canDelete = false;
 
-       /** @var array Active temp files to purge on shutdown */
-       protected static $instances = array();
-
        /** @var array Map of (path => 1) for paths to delete on shutdown */
        protected static $pathsCollect = null;
 
@@ -41,8 +38,8 @@ class TempFSFile extends FSFile {
                parent::__construct( $path );
 
                if ( self::$pathsCollect === null ) {
-                       self::$pathsCollect = array();
-                       register_shutdown_function( array( __CLASS__, 'purgeAllOnShutdown' ) );
+                       self::$pathsCollect = [];
+                       register_shutdown_function( [ __CLASS__, 'purgeAllOnShutdown' ] );
                }
        }
 
@@ -55,26 +52,25 @@ class TempFSFile extends FSFile {
         * @return TempFSFile|null
         */
        public static function factory( $prefix, $extension = '' ) {
-               $base = wfTempDir() . '/' . $prefix . wfRandomString( 12 );
-               $ext = ( $extension != '' ) ? ".{$extension}" : "";
-               for ( $attempt = 1; true; $attempt++ ) {
-                       $path = "{$base}-{$attempt}{$ext}";
-                       wfSuppressWarnings();
+               $ext = ( $extension != '' ) ? ".{$extension}" : '';
+
+               $attempts = 5;
+               while ( $attempts-- ) {
+                       $path = wfTempDir() . '/' . $prefix . wfRandomString( 12 ) . $ext;
+                       MediaWiki\suppressWarnings();
                        $newFileHandle = fopen( $path, 'x' );
-                       wfRestoreWarnings();
+                       MediaWiki\restoreWarnings();
                        if ( $newFileHandle ) {
                                fclose( $newFileHandle );
-                               break; // got it
-                       }
-                       if ( $attempt >= 5 ) {
-
-                               return null; // give up
+                               $tmpFile = new self( $path );
+                               $tmpFile->autocollect();
+                               // Safely instantiated, end loop.
+                               return $tmpFile;
                        }
                }
-               $tmpFile = new self( $path );
-               $tmpFile->autocollect(); // safely instantiated
 
-               return $tmpFile;
+               // Give up
+               return null;
        }
 
        /**
@@ -84,9 +80,9 @@ class TempFSFile extends FSFile {
         */
        public function purge() {
                $this->canDelete = false; // done
-               wfSuppressWarnings();
+               MediaWiki\suppressWarnings();
                $ok = unlink( $this->path );
-               wfRestoreWarnings();
+               MediaWiki\restoreWarnings();
 
                unset( self::$pathsCollect[$this->path] );
 
@@ -103,7 +99,7 @@ class TempFSFile extends FSFile {
                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 = [];
                        }
                        $object->tempFSFileReferences[] = $this;
                }
@@ -144,9 +140,9 @@ class TempFSFile extends FSFile {
         */
        public static function purgeAllOnShutdown() {
                foreach ( self::$pathsCollect as $path ) {
-                       wfSuppressWarnings();
+                       MediaWiki\suppressWarnings();
                        unlink( $path );
-                       wfRestoreWarnings();
+                       MediaWiki\restoreWarnings();
                }
        }