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