MediaWiki  1.23.8
TempFSFile.php
Go to the documentation of this file.
1 <?php
30 class TempFSFile extends FSFile {
32  protected $canDelete = false;
33 
35  protected static $instances = array();
36 
45  public static function factory( $prefix, $extension = '' ) {
46  wfProfileIn( __METHOD__ );
47  $base = wfTempDir() . '/' . $prefix . wfRandomString( 12 );
48  $ext = ( $extension != '' ) ? ".{$extension}" : "";
49  for ( $attempt = 1; true; $attempt++ ) {
50  $path = "{$base}-{$attempt}{$ext}";
52  $newFileHandle = fopen( $path, 'x' );
54  if ( $newFileHandle ) {
55  fclose( $newFileHandle );
56  break; // got it
57  }
58  if ( $attempt >= 5 ) {
59  wfProfileOut( __METHOD__ );
60 
61  return null; // give up
62  }
63  }
64  $tmpFile = new self( $path );
65  $tmpFile->canDelete = true; // safely instantiated
66  wfProfileOut( __METHOD__ );
67 
68  return $tmpFile;
69  }
70 
76  public function purge() {
77  $this->canDelete = false; // done
79  $ok = unlink( $this->path );
81 
82  return $ok;
83  }
84 
91  public function bind( $object ) {
92  if ( is_object( $object ) ) {
93  if ( !isset( $object->tempFSFileReferences ) ) {
94  // Init first since $object might use __get() and return only a copy variable
95  $object->tempFSFileReferences = array();
96  }
97  $object->tempFSFileReferences[] = $this;
98  }
99 
100  return $this;
101  }
102 
108  public function preserve() {
109  $this->canDelete = false;
110 
111  return $this;
112  }
113 
119  public function autocollect() {
120  $this->canDelete = true;
121 
122  return $this;
123  }
124 
128  function __destruct() {
129  if ( $this->canDelete ) {
131  unlink( $this->path );
133  }
134  }
135 }
TempFSFile\$canDelete
bool $canDelete
Garbage collect the temp file *.
Definition: TempFSFile.php:31
TempFSFile\$instances
static $instances
Definition: TempFSFile.php:34
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
TempFSFile\purge
purge()
Purge this file off the file system.
Definition: TempFSFile.php:75
FSFile\$path
string $path
Path to file *.
Definition: FSFile.php:30
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
TempFSFile\bind
bind( $object)
Clean up the temporary file only after an object goes out of scope.
Definition: TempFSFile.php:90
$ok
$ok
Definition: UtfNormalTest.php:71
TempFSFile\factory
static factory( $prefix, $extension='')
Make a new temporary file on the file system.
Definition: TempFSFile.php:44
TempFSFile
This class is used to hold the location and do limited manipulation of files stored temporarily (this...
Definition: TempFSFile.php:30
FSFile
Class representing a non-directory file on the file system.
Definition: FSFile.php:29
TempFSFile\autocollect
autocollect()
Set flag clean up after the temporary file.
Definition: TempFSFile.php:118
TempFSFile\__destruct
__destruct()
Cleans up after the temporary file by deleting it.
Definition: TempFSFile.php:127
wfTempDir
wfTempDir()
Tries to get the system directory for temporary files.
Definition: GlobalFunctions.php:2564
$ext
$ext
Definition: NoLocalSettings.php:34
TempFSFile\preserve
preserve()
Set flag to not clean up after the temporary file.
Definition: TempFSFile.php:107
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:300