Merge "Added/Removed spaces around string concatenation"
[lhc/web/wiklou.git] / includes / media / MediaTransformOutput.php
index 110c659..2616edb 100644 (file)
@@ -80,7 +80,7 @@ abstract class MediaTransformOutput {
        }
 
        /**
-        * @param $storagePath string The permanent storage path
+        * @param string $storagePath The permanent storage path
         * @return void
         */
        public function setStoragePath( $storagePath ) {
@@ -90,7 +90,7 @@ abstract class MediaTransformOutput {
        /**
         * Fetch HTML for this transform output
         *
-        * @param $options array Associative array of options. Boolean options
+        * @param array $options Associative array of options. Boolean options
         *     should be indicated with a value of true for true, and false or
         *     absent for false.
         *
@@ -151,7 +151,12 @@ abstract class MediaTransformOutput {
                if ( $this->isError() ) {
                        return false;
                } elseif ( $this->path === null ) {
-                       return $this->file->getLocalRefPath();
+                       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( array( 'src' => $this->path ) );
+                       return $fsFile ? $fsFile->getPath() : false;
                } else {
                        return $this->path; // may return false
                }
@@ -160,7 +165,7 @@ abstract class MediaTransformOutput {
        /**
         * Stream the file if there were no errors
         *
-        * @param $headers Array Additional HTTP headers to send on success
+        * @param array $headers Additional HTTP headers to send on success
         * @return Bool success
         */
        public function streamFile( $headers = array() ) {
@@ -198,10 +203,10 @@ abstract class MediaTransformOutput {
        public function getDescLinkAttribs( $title = null, $params = '' ) {
                $query = '';
                if ( $this->page && $this->page !== 1 ) {
-                         $query = 'page=' . urlencode( $this->page );
+                       $query = 'page=' . urlencode( $this->page );
                }
                if( $params ) {
-                       $query .= $query ? '&'.$params : $params;
+                       $query .= $query ? '&' . $params : $params;
                }
                $attribs = array(
                        'href' => $this->file->getTitle()->getLocalURL( $query ),
@@ -228,9 +233,9 @@ class ThumbnailImage extends MediaTransformOutput {
         * It may also include a 'page' parameter for multipage files.
         *
         * @param $file File object
-        * @param $url String: URL path to the thumb
+        * @param string $url URL path to the thumb
         * @param $path String|bool|null: filesystem path to the thumb
-        * @param $parameters Array: Associative array of parameters
+        * @param array $parameters Associative array of parameters
         * @private
         */
        function __construct( $file, $url, $path = false, $parameters = array() ) {
@@ -270,7 +275,7 @@ class ThumbnailImage extends MediaTransformOutput {
         * Return HTML <img ... /> tag for the thumbnail, will include
         * width and height attributes and a blank alt text (as required).
         *
-        * @param $options array Associative array of options. Boolean options
+        * @param array $options Associative array of options. Boolean options
         *     should be indicated with a value of true for true, and false or
         *     absent for false.
         *
@@ -296,12 +301,12 @@ class ThumbnailImage extends MediaTransformOutput {
         */
        function toHtml( $options = array() ) {
                if ( count( func_get_args() ) == 2 ) {
-                       throw new MWException( __METHOD__ .' called in the old style' );
+                       throw new MWException( __METHOD__ . ' called in the old style' );
                }
 
                $alt = empty( $options['alt'] ) ? '' : $options['alt'];
 
-               $query = empty( $options['desc-query'] )  ? '' : $options['desc-query'];
+               $query = empty( $options['desc-query'] ) ? '' : $options['desc-query'];
 
                if ( !empty( $options['custom-url-link'] ) ) {
                        $linkAttribs = array( 'href' => $options['custom-url-link'] );
@@ -404,7 +409,7 @@ class MediaTransformError extends MediaTransformOutput {
 class TransformParameterError extends MediaTransformError {
        function __construct( $params ) {
                parent::__construct( 'thumbnail_error',
-                       max( isset( $params['width']  ) ? $params['width']  : 0, 120 ),
+                       max( isset( $params['width'] ) ? $params['width'] : 0, 120 ),
                        max( isset( $params['height'] ) ? $params['height'] : 0, 120 ),
                        wfMessage( 'thumbnail_invalid_params' )->text() );
        }