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