Beispiel #1
0
 /**
  * Generates a thumbnail according to the given parameters and saves it to storage
  * @param TempFSFile $tmpFile Temporary file where the rendered thumbnail will be saved
  * @param array $transformParams
  * @param int $flags
  * @return bool|MediaTransformOutput
  */
 public function generateAndSaveThumb($tmpFile, $transformParams, $flags)
 {
     global $wgIgnoreImageErrors;
     $stats = RequestContext::getMain()->getStats();
     $handler = $this->getHandler();
     $normalisedParams = $transformParams;
     $handler->normaliseParams($this, $normalisedParams);
     $thumbName = $this->thumbName($normalisedParams);
     $thumbUrl = $this->getThumbUrl($thumbName);
     $thumbPath = $this->getThumbPath($thumbName);
     // final thumb path
     $tmpThumbPath = $tmpFile->getPath();
     if ($handler->supportsBucketing()) {
         $this->generateBucketsIfNeeded($normalisedParams, $flags);
     }
     $starttime = microtime(true);
     // Actually render the thumbnail...
     $thumb = $handler->doTransform($this, $tmpThumbPath, $thumbUrl, $transformParams);
     $tmpFile->bind($thumb);
     // keep alive with $thumb
     $statTiming = microtime(true) - $starttime;
     $stats->timing('media.thumbnail.generate.transform', 1000 * $statTiming);
     if (!$thumb) {
         // bad params?
         $thumb = false;
     } elseif ($thumb->isError()) {
         // transform error
         /** @var $thumb MediaTransformError */
         $this->lastError = $thumb->toText();
         // Ignore errors if requested
         if ($wgIgnoreImageErrors && !($flags & self::RENDER_NOW)) {
             $thumb = $handler->getTransform($this, $tmpThumbPath, $thumbUrl, $transformParams);
         }
     } elseif ($this->repo && $thumb->hasFile() && !$thumb->fileIsSource()) {
         // Copy the thumbnail from the file system into storage...
         $starttime = microtime(true);
         $disposition = $this->getThumbDisposition($thumbName);
         $status = $this->repo->quickImport($tmpThumbPath, $thumbPath, $disposition);
         if ($status->isOK()) {
             $thumb->setStoragePath($thumbPath);
         } else {
             $thumb = $this->transformErrorOutput($thumbPath, $thumbUrl, $transformParams, $flags);
         }
         $statTiming = microtime(true) - $starttime;
         $stats->timing('media.thumbnail.generate.store', 1000 * $statTiming);
         // Give extensions a chance to do something with this thumbnail...
         Hooks::run('FileTransformed', array($this, $thumb, $tmpThumbPath, $thumbPath));
     }
     return $thumb;
 }
Beispiel #2
0
 /**
  * Generates a thumbnail according to the given parameters and saves it to storage
  * @param TempFSFile $tmpFile Temporary file where the rendered thumbnail will be saved
  * @param array $transformParams
  * @param int $flags
  * @return bool|MediaTransformOutput
  */
 public function generateAndSaveThumb($tmpFile, $transformParams, $flags)
 {
     global $wgUseSquid, $wgIgnoreImageErrors;
     $handler = $this->getHandler();
     $normalisedParams = $transformParams;
     $handler->normaliseParams($this, $normalisedParams);
     $thumbName = $this->thumbName($normalisedParams);
     $thumbUrl = $this->getThumbUrl($thumbName);
     $thumbPath = $this->getThumbPath($thumbName);
     // final thumb path
     $tmpThumbPath = $tmpFile->getPath();
     if ($handler->supportsBucketing()) {
         $this->generateBucketsIfNeeded($normalisedParams, $flags);
     }
     // Actually render the thumbnail...
     $thumb = $handler->doTransform($this, $tmpThumbPath, $thumbUrl, $transformParams);
     $tmpFile->bind($thumb);
     // keep alive with $thumb
     if (!$thumb) {
         // bad params?
         $thumb = false;
     } elseif ($thumb->isError()) {
         // transform error
         $this->lastError = $thumb->toText();
         // Ignore errors if requested
         if ($wgIgnoreImageErrors && !($flags & self::RENDER_NOW)) {
             $thumb = $handler->getTransform($this, $tmpThumbPath, $thumbUrl, $transformParams);
         }
     } elseif ($this->repo && $thumb->hasFile() && !$thumb->fileIsSource()) {
         // Copy the thumbnail from the file system into storage...
         $disposition = $this->getThumbDisposition($thumbName);
         $status = $this->repo->quickImport($tmpThumbPath, $thumbPath, $disposition);
         if ($status->isOK()) {
             $thumb->setStoragePath($thumbPath);
         } else {
             $thumb = $this->transformErrorOutput($thumbPath, $thumbUrl, $transformParams, $flags);
         }
         // Give extensions a chance to do something with this thumbnail...
         Hooks::run('FileTransformed', array($this, $thumb, $tmpThumbPath, $thumbPath));
     }
     // Purge. Useful in the event of Core -> Squid connection failure or squid
     // purge collisions from elsewhere during failure. Don't keep triggering for
     // "thumbs" which have the main image URL though (bug 13776)
     if ($wgUseSquid) {
         if (!$thumb || $thumb->isError() || $thumb->getUrl() != $this->getURL()) {
             SquidUpdate::purge(array($thumbUrl));
         }
     }
     return $thumb;
 }