Merged FileBackend branch. Manually avoiding merging the many prop-only changes SVN...
[lhc/web/wiklou.git] / includes / media / MediaTransformOutput.php
index 1e1b459..f7c5270 100644 (file)
@@ -22,31 +22,24 @@ abstract class MediaTransformOutput {
        /**
         * Get the width of the output box
         */
-       function getWidth() {
+       public function getWidth() {
                return $this->width;
        }
 
        /**
         * Get the height of the output box
         */
-       function getHeight() {
+       public function getHeight() {
                return $this->height;
        }
 
        /**
         * @return string The thumbnail URL
         */
-       function getUrl() {
+       public function getUrl() {
                return $this->url;
        }
 
-       /**
-        * @return String: destination file path (local filesystem)
-        */
-       function getPath() {
-               return $this->path;
-       }
-
        /**
         * Fetch HTML for this transform output
         *
@@ -67,15 +60,57 @@ abstract class MediaTransformOutput {
         *
         * @return string
         */
-       abstract function toHtml( $options = array() );
+       abstract public function toHtml( $options = array() );
 
        /**
         * This will be overridden to return true in error classes
         */
-       function isError() {
+       public function isError() {
                return false;
        }
 
+       /**
+        * Check if an output thumbnail file was actually made.
+        * This will return false if there was an error, the
+        * thumnail is to be handled client-side only, or if
+        * transformation was deferred via TRANSFORM_LATER.
+        *
+        * @return Bool
+        */
+       public function hasFile() {
+               // If TRANSFORM_LATER, $this->path will be false
+               return ( !$this->isError() && $this->path );
+       }
+
+       /**
+        * Check if the output thumbnail file 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 === $this->file->getLocalRefPath() );
+       }
+
+       /**
+        * Get the path of a file system copy of the thumbnail
+        *
+        * @return string|false Returns false if there isn't one
+        */
+       public function getLocalCopyPath() {
+               return $this->path;
+       }
+
+       /**
+        * Stream the file if there were no errors
+        *
+        * @param $headers Array Additional HTTP headers to send on success
+        * @return Bool success
+        */
+       public function streamFile( $headers = array() ) {
+               return $this->path && StreamFile::stream( $this->path, $headers );
+       }
+
        /**
         * Wrap some XHTML text in an anchor tag with the given attributes
         *
@@ -97,7 +132,7 @@ abstract class MediaTransformOutput {
         * @param $params array
         * @return array
         */
-       function getDescLinkAttribs( $title = null, $params = '' ) {
+       public function getDescLinkAttribs( $title = null, $params = '' ) {
                $query = $this->page ? ( 'page=' . urlencode( $this->page ) ) : '';
                if( $params ) {
                        $query .= $query ? '&'.$params : $params;