+ /**
+ * Check if an output thumbnail file actually exists.
+ *
+ * This will return false if there was an error, the
+ * thumbnail is to be handled client-side only, or if
+ * transformation was deferred via TRANSFORM_LATER.
+ * This file may exist as a new file in /tmp, a file
+ * in permanent storage, or even refer to the original.
+ *
+ * @return bool
+ */
+ public function hasFile() {
+ // If TRANSFORM_LATER, $this->path will be false.
+ // Note: a null path means "use the source file".
+ return ( !$this->isError() && ( $this->path || $this->path === null ) );
+ }
+
+ /**
+ * Check if the output thumbnail is the same as the source.
+ * This can occur if the requested width was bigger than the source.
+ *
+ * @return bool
+ */
+ public function fileIsSource() {
+ return ( !$this->isError() && $this->path === null );
+ }
+
+ /**
+ * Get the path of a file system copy of the thumbnail.
+ * Callers should never write to this path.
+ *
+ * @return string|bool Returns false if there isn't one
+ */
+ public function getLocalCopyPath() {
+ if ( $this->isError() ) {
+ return false;
+ } elseif ( $this->path === null ) {
+ return $this->file->getLocalRefPath(); // assume thumb was not scaled
+ } elseif ( FileBackend::isStoragePath( $this->path ) ) {
+ $be = $this->file->getRepo()->getBackend();
+ // The temp file will be process cached by FileBackend
+ $fsFile = $be->getLocalReference( [ 'src' => $this->path ] );
+
+ return $fsFile ? $fsFile->getPath() : false;
+ } else {
+ return $this->path; // may return false
+ }
+ }
+
+ /**
+ * Stream the file if there were no errors
+ *
+ * @param array $headers Additional HTTP headers to send on success
+ * @return Status
+ * @since 1.27
+ */
+ public function streamFileWithStatus( $headers = [] ) {
+ if ( !$this->path ) {
+ return Status::newFatal( 'backend-fail-stream', '<no path>' );
+ } elseif ( FileBackend::isStoragePath( $this->path ) ) {
+ $be = $this->file->getRepo()->getBackend();
+ return $be->streamFile( [ 'src' => $this->path, 'headers' => $headers ] );
+ } else { // FS-file
+ $success = StreamFile::stream( $this->getLocalCopyPath(), $headers );
+ return $success ? Status::newGood() : Status::newFatal( 'backend-fail-stream', $this->path );
+ }
+ }
+
+ /**
+ * Stream the file if there were no errors
+ *
+ * @deprecated since 1.26, use streamFileWithStatus
+ * @param array $headers Additional HTTP headers to send on success
+ * @return bool Success
+ */
+ public function streamFile( $headers = [] ) {
+ $this->streamFileWithStatus( $headers )->isOK();
+ }
+