d86933a172c3a6b1b17aed015662953b7c53fb2f
[lhc/web/wiklou.git] / includes / upload / UploadStash.php
1 <?php
2 /**
3 * UploadStash is intended to accomplish a few things:
4 * - enable applications to temporarily stash files without publishing them to the wiki.
5 * - Several parts of MediaWiki do this in similar ways: UploadBase, UploadWizard, and FirefoggChunkedExtension
6 * And there are several that reimplement stashing from scratch, in idiosyncratic ways. The idea is to unify them all here.
7 * Mostly all of them are the same except for storing some custom fields, which we subsume into the data array.
8 * - enable applications to find said files later, as long as the db table or temp files haven't been purged.
9 * - enable the uploading user (and *ONLY* the uploading user) to access said files, and thumbnails of said files, via a URL.
10 * We accomplish this using a database table, with ownership checking as you might expect. See SpecialUploadStash, which
11 * implements a web interface to some files stored this way.
12 *
13 * UploadStash represents the entire stash of temporary files.
14 * UploadStashFile is a filestore for the actual physical disk files.
15 * UploadFromStash extends UploadBase, and represents a single stashed file as it is moved from the stash to the regular file repository
16 */
17 class UploadStash {
18
19 // Format of the key for files -- has to be suitable as a filename itself (e.g. ab12cd34ef.jpg)
20 const KEY_FORMAT_REGEX = '/^[\w-\.]+\.\w*$/';
21
22 // When a given stashed file can't be loaded, wait for the slaves to catch up. If they're more than MAX_LAG
23 // behind, throw an exception instead. (at what point is broken better than slow?)
24 const MAX_LAG = 30;
25
26 /**
27 * repository that this uses to store temp files
28 * public because we sometimes need to get a LocalFile within the same repo.
29 *
30 * @var LocalRepo
31 */
32 public $repo;
33
34 // array of initialized repo objects
35 protected $files = array();
36
37 // cache of the file metadata that's stored in the database
38 protected $fileMetadata = array();
39
40 // fileprops cache
41 protected $fileProps = array();
42
43 // current user
44 protected $user, $userId, $isLoggedIn;
45
46 /**
47 * Represents a temporary filestore, with metadata in the database.
48 * Designed to be compatible with the session stashing code in UploadBase (should replace it eventually)
49 *
50 * @param $repo FileRepo
51 */
52 public function __construct( $repo, $user = null ) {
53 // this might change based on wiki's configuration.
54 $this->repo = $repo;
55
56 // if a user was passed, use it. otherwise, attempt to use the global.
57 // this keeps FileRepo from breaking when it creates an UploadStash object
58 if ( $user ) {
59 $this->user = $user;
60 } else {
61 global $wgUser;
62 $this->user = $wgUser;
63 }
64
65 if ( is_object( $this->user ) ) {
66 $this->userId = $this->user->getId();
67 $this->isLoggedIn = $this->user->isLoggedIn();
68 }
69
70 // Age of the repository in seconds. That is, after how long will files be assumed abandoned and deleted?
71 global $wgUploadStashMaxAge;
72 if( $wgUploadStashMaxAge === null ) {
73 $wgUploadStashMaxAge = 6 * 3600; // default: 6 hours.
74 }
75 }
76
77 /**
78 * Get a file and its metadata from the stash.
79 *
80 * @param $key String: key under which file information is stored
81 * @param $noAuth Boolean (optional) Don't check authentication. Used by maintenance scripts.
82 * @throws UploadStashFileNotFoundException
83 * @throws UploadStashNotLoggedInException
84 * @throws UploadStashWrongOwnerException
85 * @throws UploadStashBadPathException
86 * @return UploadStashFile
87 */
88 public function getFile( $key, $noAuth = false ) {
89
90 if ( ! preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
91 throw new UploadStashBadPathException( "key '$key' is not in a proper format" );
92 }
93
94 if ( !$noAuth ) {
95 if ( !$this->isLoggedIn ) {
96 throw new UploadStashNotLoggedInException( __METHOD__ . ' No user is logged in, files must belong to users' );
97 }
98 }
99
100 $dbr = $this->repo->getSlaveDb();
101
102 if ( !isset( $this->fileMetadata[$key] ) ) {
103 // try this first. if it fails to find the row, check for lag, wait, try again. if its still missing, throw an exception.
104 // this more complex solution keeps things moving for page loads with many requests
105 // (ie. validating image ownership) when replag is high
106 if ( !$this->fetchFileMetadata( $key ) ) {
107 $lag = $dbr->getLag();
108 if ( $lag > 0 && $lag <= self::MAX_LAG ) {
109 // if there's not too much replication lag, just wait for the slave to catch up to our last insert.
110 sleep( ceil( $lag ) );
111 } elseif ( $lag > self::MAX_LAG ) {
112 // that's a lot of lag to introduce into the middle of the UI.
113 throw new UploadStashMaxLagExceededException(
114 'Couldn\'t load stashed file metadata, and replication lag is above threshold: (MAX_LAG=' . self::MAX_LAG . ')'
115 );
116 }
117
118 // now that the waiting has happened, try again
119 $this->fetchFileMetadata( $key );
120 }
121
122 if ( !isset( $this->fileMetadata[$key] ) ) {
123 throw new UploadStashFileNotFoundException( "key '$key' not found in stash" );
124 }
125
126 // create $this->files[$key]
127 $this->initFile( $key );
128
129 // fetch fileprops
130 $path = $this->fileMetadata[$key]['us_path'];
131 if ( $this->repo->isVirtualUrl( $path ) ) {
132 $path = $this->repo->resolveVirtualUrl( $path );
133 }
134 $this->fileProps[$key] = File::getPropsFromPath( $path );
135 }
136
137 if ( ! $this->files[$key]->exists() ) {
138 wfDebug( __METHOD__ . " tried to get file at $key, but it doesn't exist\n" );
139 throw new UploadStashBadPathException( "path doesn't exist" );
140 }
141
142 if ( !$noAuth ) {
143 if ( $this->fileMetadata[$key]['us_user'] != $this->userId ) {
144 throw new UploadStashWrongOwnerException( "This file ($key) doesn't belong to the current user." );
145 }
146 }
147
148 return $this->files[$key];
149 }
150
151 /**
152 * Getter for file metadata.
153 *
154 * @param key String: key under which file information is stored
155 * @return Array
156 */
157 public function getMetadata ( $key ) {
158 $this->getFile( $key );
159 return $this->fileMetadata[$key];
160 }
161
162 /**
163 * Getter for fileProps
164 *
165 * @param key String: key under which file information is stored
166 * @return Array
167 */
168 public function getFileProps ( $key ) {
169 $this->getFile( $key );
170 return $this->fileProps[$key];
171 }
172
173 /**
174 * Stash a file in a temp directory and record that we did this in the database, along with other metadata.
175 *
176 * @param $path String: path to file you want stashed
177 * @param $sourceType String: the type of upload that generated this file (currently, I believe, 'file' or null)
178 * @param $key String: optional, unique key for this file. Used for directory hashing when storing, otherwise not important
179 * @throws UploadStashBadPathException
180 * @throws UploadStashFileException
181 * @throws UploadStashNotLoggedInException
182 * @return UploadStashFile: file, or null on failure
183 */
184 public function stashFile( $path, $sourceType = null, $key = null ) {
185 if ( ! file_exists( $path ) ) {
186 wfDebug( __METHOD__ . " tried to stash file at '$path', but it doesn't exist\n" );
187 throw new UploadStashBadPathException( "path doesn't exist" );
188 }
189 $fileProps = File::getPropsFromPath( $path );
190 wfDebug( __METHOD__ . " stashing file at '$path'\n" );
191
192 // we will be initializing from some tmpnam files that don't have extensions.
193 // most of MediaWiki assumes all uploaded files have good extensions. So, we fix this.
194 $extension = self::getExtensionForPath( $path );
195 if ( ! preg_match( "/\\.\\Q$extension\\E$/", $path ) ) {
196 $pathWithGoodExtension = "$path.$extension";
197 if ( ! rename( $path, $pathWithGoodExtension ) ) {
198 throw new UploadStashFileException( "couldn't rename $path to have a better extension at $pathWithGoodExtension" );
199 }
200 $path = $pathWithGoodExtension;
201 }
202
203 // If no key was supplied, make one. a mysql insertid would be totally reasonable here, except
204 // that some users of this function might expect to supply the key instead of using the generated one.
205 if ( is_null( $key ) ) {
206 // some things that when combined will make a suitably unique key.
207 // see: http://www.jwz.org/doc/mid.html
208 list ($usec, $sec) = explode( ' ', microtime() );
209 $usec = substr($usec, 2);
210 $key = wfBaseConvert( $sec . $usec, 10, 36 ) . '.' .
211 wfBaseConvert( mt_rand(), 10, 36 ) . '.'.
212 $this->userId . '.' .
213 $extension;
214 }
215
216 $this->fileProps[$key] = $fileProps;
217
218 if ( ! preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
219 throw new UploadStashBadPathException( "key '$key' is not in a proper format" );
220 }
221
222 wfDebug( __METHOD__ . " key for '$path': $key\n" );
223
224 // if not already in a temporary area, put it there
225 $storeStatus = $this->repo->storeTemp( basename( $path ), $path );
226
227 if ( ! $storeStatus->isOK() ) {
228 // It is a convention in MediaWiki to only return one error per API exception, even if multiple errors
229 // are available. We use reset() to pick the "first" thing that was wrong, preferring errors to warnings.
230 // This is a bit lame, as we may have more info in the $storeStatus and we're throwing it away, but to fix it means
231 // redesigning API errors significantly.
232 // $storeStatus->value just contains the virtual URL (if anything) which is probably useless to the caller
233 $error = $storeStatus->getErrorsArray();
234 $error = reset( $error );
235 if ( ! count( $error ) ) {
236 $error = $storeStatus->getWarningsArray();
237 $error = reset( $error );
238 if ( ! count( $error ) ) {
239 $error = array( 'unknown', 'no error recorded' );
240 }
241 }
242 throw new UploadStashFileException( "error storing file in '$path': " . implode( '; ', $error ) );
243 }
244 $stashPath = $storeStatus->value;
245
246 // fetch the current user ID
247 if ( !$this->isLoggedIn ) {
248 throw new UploadStashNotLoggedInException( __METHOD__ . ' No user is logged in, files must belong to users' );
249 }
250
251 // insert the file metadata into the db.
252 wfDebug( __METHOD__ . " inserting $stashPath under $key\n" );
253 $dbw = $this->repo->getMasterDb();
254
255 // select happens on the master so this can all be in a transaction, which
256 // avoids a race condition that's likely with multiple people uploading from the same
257 // set of files
258 $dbw->begin();
259 // first, check to see if it's already there.
260 $row = $dbw->selectRow(
261 'uploadstash',
262 'us_user, us_timestamp',
263 array( 'us_key' => $key ),
264 __METHOD__
265 );
266
267 // The current user can't have this key if:
268 // - the key is owned by someone else and
269 // - the age of the key is less than $wgUploadStashMaxAge
270 if ( is_object( $row ) ) {
271 if ( $row->us_user != $this->userId &&
272 $row->wfTimestamp( TS_UNIX, $row->us_timestamp ) > time() - $wgUploadStashMaxAge
273 ) {
274 $dbw->rollback();
275 throw new UploadStashWrongOwnerException( "Attempting to upload a duplicate of a file that someone else has stashed" );
276 }
277 }
278
279 $this->fileMetadata[$key] = array(
280 'us_user' => $this->userId,
281 'us_key' => $key,
282 'us_orig_path' => $path,
283 'us_path' => $stashPath,
284 'us_size' => $fileProps['size'],
285 'us_sha1' => $fileProps['sha1'],
286 'us_mime' => $fileProps['mime'],
287 'us_media_type' => $fileProps['media_type'],
288 'us_image_width' => $fileProps['width'],
289 'us_image_height' => $fileProps['height'],
290 'us_image_bits' => $fileProps['bits'],
291 'us_source_type' => $sourceType,
292 'us_timestamp' => $dbw->timestamp(),
293 'us_status' => 'finished'
294 );
295
296 // if a row exists but previous checks on it passed, let the current user take over this key.
297 $dbw->replace(
298 'uploadstash',
299 'us_key',
300 $this->fileMetadata[$key],
301 __METHOD__
302 );
303 $dbw->commit();
304
305 // store the insertid in the class variable so immediate retrieval (possibly laggy) isn't necesary.
306 $this->fileMetadata[$key]['us_id'] = $dbw->insertId();
307
308 # create the UploadStashFile object for this file.
309 $this->initFile( $key );
310
311 return $this->getFile( $key );
312 }
313
314 /**
315 * Remove all files from the stash.
316 * Does not clean up files in the repo, just the record of them.
317 *
318 * @throws UploadStashNotLoggedInException
319 * @return boolean: success
320 */
321 public function clear() {
322 if ( !$this->isLoggedIn ) {
323 throw new UploadStashNotLoggedInException( __METHOD__ . ' No user is logged in, files must belong to users' );
324 }
325
326 wfDebug( __METHOD__ . " clearing all rows for user $userId\n" );
327 $dbw = $this->repo->getMasterDb();
328 $dbw->delete(
329 'uploadstash',
330 array( 'us_user' => $this->userId ),
331 __METHOD__
332 );
333
334 # destroy objects.
335 $this->files = array();
336 $this->fileMetadata = array();
337
338 return true;
339 }
340
341 /**
342 * Remove a particular file from the stash. Also removes it from the repo.
343 *
344 * @throws UploadStashNotLoggedInException
345 * @throws UploadStashWrongOwnerException
346 * @return boolean: success
347 */
348 public function removeFile( $key ) {
349 if ( !$this->isLoggedIn ) {
350 throw new UploadStashNotLoggedInException( __METHOD__ . ' No user is logged in, files must belong to users' );
351 }
352
353 $dbw = $this->repo->getMasterDb();
354
355 // this is a cheap query. it runs on the master so that this function still works when there's lag.
356 // it won't be called all that often.
357 $row = $dbw->selectRow(
358 'uploadstash',
359 'us_user',
360 array( 'us_key' => $key ),
361 __METHOD__
362 );
363
364 if( !$row ) {
365 throw new UploadStashNoSuchKeyException( "No such key ($key), cannot remove" );
366 }
367
368 if ( $row->us_user != $this->userId ) {
369 throw new UploadStashWrongOwnerException( "Can't delete: the file ($key) doesn't belong to this user." );
370 }
371
372 return $this->removeFileNoAuth( $key );
373 }
374
375
376 /**
377 * Remove a file (see removeFile), but doesn't check ownership first.
378 *
379 * @return boolean: success
380 */
381 public function removeFileNoAuth( $key ) {
382 wfDebug( __METHOD__ . " clearing row $key\n" );
383
384 $dbw = $this->repo->getMasterDb();
385
386 // this gets its own transaction since it's called serially by the cleanupUploadStash maintenance script
387 $dbw->begin();
388 $dbw->delete(
389 'uploadstash',
390 array( 'us_key' => $key ),
391 __METHOD__
392 );
393 $dbw->commit();
394
395 // TODO: look into UnregisteredLocalFile and find out why the rv here is sometimes wrong (false when file was removed)
396 // for now, ignore.
397 $this->files[$key]->remove();
398
399 unset( $this->files[$key] );
400 unset( $this->fileMetadata[$key] );
401
402 return true;
403 }
404
405 /**
406 * List all files in the stash.
407 *
408 * @throws UploadStashNotLoggedInException
409 * @return Array
410 */
411 public function listFiles() {
412 if ( !$this->isLoggedIn ) {
413 throw new UploadStashNotLoggedInException( __METHOD__ . ' No user is logged in, files must belong to users' );
414 }
415
416 $dbr = $this->repo->getSlaveDb();
417 $res = $dbr->select(
418 'uploadstash',
419 'us_key',
420 array( 'us_key' => $key ),
421 __METHOD__
422 );
423
424 if ( !is_object( $res ) || $res->numRows() == 0 ) {
425 // nothing to do.
426 return false;
427 }
428
429 // finish the read before starting writes.
430 $keys = array();
431 foreach ( $res as $row ) {
432 array_push( $keys, $row->us_key );
433 }
434
435 return $keys;
436 }
437
438 /**
439 * Find or guess extension -- ensuring that our extension matches our mime type.
440 * Since these files are constructed from php tempnames they may not start off
441 * with an extension.
442 * XXX this is somewhat redundant with the checks that ApiUpload.php does with incoming
443 * uploads versus the desired filename. Maybe we can get that passed to us...
444 */
445 public static function getExtensionForPath( $path ) {
446 // Does this have an extension?
447 $n = strrpos( $path, '.' );
448 $extension = null;
449 if ( $n !== false ) {
450 $extension = $n ? substr( $path, $n + 1 ) : '';
451 } else {
452 // If not, assume that it should be related to the mime type of the original file.
453 $magic = MimeMagic::singleton();
454 $mimeType = $magic->guessMimeType( $path );
455 $extensions = explode( ' ', MimeMagic::singleton()->getExtensionsForType( $mimeType ) );
456 if ( count( $extensions ) ) {
457 $extension = $extensions[0];
458 }
459 }
460
461 if ( is_null( $extension ) ) {
462 throw new UploadStashFileException( "extension is null" );
463 }
464
465 return File::normalizeExtension( $extension );
466 }
467
468 /**
469 * Helper function: do the actual database query to fetch file metadata.
470 *
471 * @param $key String: key
472 * @return boolean
473 */
474 protected function fetchFileMetadata( $key ) {
475 // populate $fileMetadata[$key]
476 $dbr = $this->repo->getSlaveDb();
477 $row = $dbr->selectRow(
478 'uploadstash',
479 '*',
480 array( 'us_key' => $key ),
481 __METHOD__
482 );
483
484 if ( !is_object( $row ) ) {
485 // key wasn't present in the database. this will happen sometimes.
486 return false;
487 }
488
489 $this->fileMetadata[$key] = array(
490 'us_user' => $row->us_user,
491 'us_key' => $row->us_key,
492 'us_orig_path' => $row->us_orig_path,
493 'us_path' => $row->us_path,
494 'us_size' => $row->us_size,
495 'us_sha1' => $row->us_sha1,
496 'us_mime' => $row->us_mime,
497 'us_media_type' => $row->us_media_type,
498 'us_image_width' => $row->us_image_width,
499 'us_image_height' => $row->us_image_height,
500 'us_image_bits' => $row->us_image_bits,
501 'us_source_type' => $row->us_source_type,
502 'us_timestamp' => $row->us_timestamp,
503 'us_status' => $row->us_status
504 );
505
506 return true;
507 }
508
509 /**
510 * Helper function: Initialize the UploadStashFile for a given file.
511 *
512 * @param $path String: path to file
513 * @param $key String: key under which to store the object
514 * @throws UploadStashZeroLengthFileException
515 * @return bool
516 */
517 protected function initFile( $key ) {
518 $file = new UploadStashFile( $this->repo, $this->fileMetadata[$key]['us_path'], $key );
519 if ( $file->getSize() === 0 ) {
520 throw new UploadStashZeroLengthFileException( "File is zero length" );
521 }
522 $this->files[$key] = $file;
523 return true;
524 }
525 }
526
527 class UploadStashFile extends UnregisteredLocalFile {
528 private $fileKey;
529 private $urlName;
530 protected $url;
531
532 /**
533 * A LocalFile wrapper around a file that has been temporarily stashed, so we can do things like create thumbnails for it
534 * Arguably UnregisteredLocalFile should be handling its own file repo but that class is a bit retarded currently
535 *
536 * @param $repo FSRepo: repository where we should find the path
537 * @param $path String: path to file
538 * @param $key String: key to store the path and any stashed data under
539 * @throws UploadStashBadPathException
540 * @throws UploadStashFileNotFoundException
541 */
542 public function __construct( $repo, $path, $key ) {
543 $this->fileKey = $key;
544
545 // resolve mwrepo:// urls
546 if ( $repo->isVirtualUrl( $path ) ) {
547 $path = $repo->resolveVirtualUrl( $path );
548 } else {
549
550 // check if path appears to be sane, no parent traversals, and is in this repo's temp zone.
551 $repoTempPath = $repo->getZonePath( 'temp' );
552 if ( ( ! $repo->validateFilename( $path ) ) ||
553 ( strpos( $path, $repoTempPath ) !== 0 ) ) {
554 wfDebug( "UploadStash: tried to construct an UploadStashFile from a file that should already exist at '$path', but path is not valid\n" );
555 throw new UploadStashBadPathException( 'path is not valid' );
556 }
557
558 // check if path exists! and is a plain file.
559 if ( ! $repo->fileExists( $path, FileRepo::FILES_ONLY ) ) {
560 wfDebug( "UploadStash: tried to construct an UploadStashFile from a file that should already exist at '$path', but path is not found\n" );
561 throw new UploadStashFileNotFoundException( 'cannot find path, or not a plain file' );
562 }
563 }
564
565 parent::__construct( false, $repo, $path, false );
566
567 $this->name = basename( $this->path );
568 }
569
570 /**
571 * A method needed by the file transforming and scaling routines in File.php
572 * We do not necessarily care about doing the description at this point
573 * However, we also can't return the empty string, as the rest of MediaWiki demands this (and calls to imagemagick
574 * convert require it to be there)
575 *
576 * @return String: dummy value
577 */
578 public function getDescriptionUrl() {
579 return $this->getUrl();
580 }
581
582 /**
583 * Get the path for the thumbnail (actually any transformation of this file)
584 * The actual argument is the result of thumbName although we seem to have
585 * buggy code elsewhere that expects a boolean 'suffix'
586 *
587 * @param $thumbName String: name of thumbnail (e.g. "120px-123456.jpg" ), or false to just get the path
588 * @return String: path thumbnail should take on filesystem, or containing directory if thumbname is false
589 */
590 public function getThumbPath( $thumbName = false ) {
591 $path = dirname( $this->path );
592 if ( $thumbName !== false ) {
593 $path .= "/$thumbName";
594 }
595 return $path;
596 }
597
598 /**
599 * Return the file/url base name of a thumbnail with the specified parameters.
600 * We override this because we want to use the pretty url name instead of the
601 * ugly file name.
602 *
603 * @param $params Array: handler-specific parameters
604 * @return String: base name for URL, like '120px-12345.jpg', or null if there is no handler
605 */
606 function thumbName( $params ) {
607 return $this->generateThumbName( $this->getUrlName(), $params );
608 }
609
610 /**
611 * Helper function -- given a 'subpage', return the local URL e.g. /wiki/Special:UploadStash/subpage
612 * @param {String} $subPage
613 * @return {String} local URL for this subpage in the Special:UploadStash space.
614 */
615 private function getSpecialUrl( $subPage ) {
616 return SpecialPage::getTitleFor( 'UploadStash', $subPage )->getLocalURL();
617 }
618
619 /**
620 * Get a URL to access the thumbnail
621 * This is required because the model of how files work requires that
622 * the thumbnail urls be predictable. However, in our model the URL is not based on the filename
623 * (that's hidden in the db)
624 *
625 * @param $thumbName String: basename of thumbnail file -- however, we don't want to use the file exactly
626 * @return String: URL to access thumbnail, or URL with partial path
627 */
628 public function getThumbUrl( $thumbName = false ) {
629 wfDebug( __METHOD__ . " getting for $thumbName \n" );
630 return $this->getSpecialUrl( 'thumb/' . $this->getUrlName() . '/' . $thumbName );
631 }
632
633 /**
634 * The basename for the URL, which we want to not be related to the filename.
635 * Will also be used as the lookup key for a thumbnail file.
636 *
637 * @return String: base url name, like '120px-123456.jpg'
638 */
639 public function getUrlName() {
640 if ( ! $this->urlName ) {
641 $this->urlName = $this->fileKey;
642 }
643 return $this->urlName;
644 }
645
646 /**
647 * Return the URL of the file, if for some reason we wanted to download it
648 * We tend not to do this for the original file, but we do want thumb icons
649 *
650 * @return String: url
651 */
652 public function getUrl() {
653 if ( !isset( $this->url ) ) {
654 $this->url = $this->getSpecialUrl( 'file/' . $this->getUrlName() );
655 }
656 return $this->url;
657 }
658
659 /**
660 * Parent classes use this method, for no obvious reason, to return the path (relative to wiki root, I assume).
661 * But with this class, the URL is unrelated to the path.
662 *
663 * @return String: url
664 */
665 public function getFullUrl() {
666 return $this->getUrl();
667 }
668
669 /**
670 * Getter for file key (the unique id by which this file's location & metadata is stored in the db)
671 *
672 * @return String: file key
673 */
674 public function getFileKey() {
675 return $this->fileKey;
676 }
677
678 /**
679 * Remove the associated temporary file
680 * @return Status: success
681 */
682 public function remove() {
683 if ( !$this->repo->fileExists( $this->path, FileRepo::FILES_ONLY ) ) {
684 // Maybe the file's already been removed? This could totally happen in UploadBase.
685 return true;
686 }
687
688 return $this->repo->freeTemp( $this->path );
689 }
690
691 public function exists() {
692 return $this->repo->fileExists( $this->path, FileRepo::FILES_ONLY );
693 }
694
695 }
696
697 class UploadStashNotAvailableException extends MWException {};
698 class UploadStashFileNotFoundException extends MWException {};
699 class UploadStashBadPathException extends MWException {};
700 class UploadStashFileException extends MWException {};
701 class UploadStashZeroLengthFileException extends MWException {};
702 class UploadStashNotLoggedInException extends MWException {};
703 class UploadStashWrongOwnerException extends MWException {};
704 class UploadStashMaxLagExceededException extends MWException {};
705 class UploadStashNoSuchKeyException extends MWException {};