예제 #1
0
 /**
  * A LocalFile wrapper around a file that has been temporarily stashed,
  * so we can do things like create thumbnails for it. Arguably
  * UnregisteredLocalFile should be handling its own file repo but that
  * class is a bit retarded currently.
  *
  * @param FileRepo $repo Repository where we should find the path
  * @param string $path Path to file
  * @param string $key Key to store the path and any stashed data under
  * @throws UploadStashBadPathException
  * @throws UploadStashFileNotFoundException
  */
 public function __construct($repo, $path, $key)
 {
     $this->fileKey = $key;
     // resolve mwrepo:// urls
     if ($repo->isVirtualUrl($path)) {
         $path = $repo->resolveVirtualUrl($path);
     } else {
         // check if path appears to be sane, no parent traversals,
         // and is in this repo's temp zone.
         $repoTempPath = $repo->getZonePath('temp');
         if (!$repo->validateFilename($path) || strpos($path, $repoTempPath) !== 0) {
             wfDebug("UploadStash: tried to construct an UploadStashFile " . "from a file that should already exist at '{$path}', but path is not valid\n");
             throw new UploadStashBadPathException('path is not valid');
         }
         // check if path exists! and is a plain file.
         if (!$repo->fileExists($path)) {
             wfDebug("UploadStash: tried to construct an UploadStashFile from " . "a file that should already exist at '{$path}', but path is not found\n");
             throw new UploadStashFileNotFoundException('cannot find path, or not a plain file');
         }
     }
     parent::__construct(false, $repo, $path, false);
     $this->name = basename($this->path);
 }