Merge "Add no-dimensions option to MediaTransformOutput::toHtml"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 6 Dec 2013 21:44:45 +0000 (21:44 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 6 Dec 2013 21:44:45 +0000 (21:44 +0000)
1  2 
includes/media/MediaTransformOutput.php

   * @ingroup Media
   */
  abstract class MediaTransformOutput {
 -      /**
 -       * @var File
 -       */
 -      var $file;
 -
 -      var $width, $height, $url, $page, $path, $lang;
 -
        /**
         * @var array Associative array mapping optional supplementary image files
         * from pixel density (eg 1.5 or 2) to additional URLs.
         */
        public $responsiveUrls = array();
  
 +      /** @var File object */
 +      protected $file;
 +
 +      /** @var int Image width */
 +      protected $width;
 +
 +      /** @var int Image height */
 +      protected $height;
 +
 +      /** @var string URL path to the thumb */
 +      protected $url;
 +
 +      /** @var bool|string */
 +      protected $page;
 +
 +      /** @var bool|string Filesystem path to the thumb  */
 +      protected $path;
 +
 +      /** @var bool|string Language code, false if not set */
 +      protected $lang;
 +
 +      /** @var bool|string Permanent storage path  */
        protected $storagePath = false;
  
        /**
                        $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
                        return false;
                } elseif ( FileBackend::isStoragePath( $this->path ) ) {
                        $be = $this->file->getRepo()->getBackend();
 +
                        return $be->streamFile( array( 'src' => $this->path, 'headers' => $headers ) )->isOK();
                } else { // FS-file
                        return StreamFile::stream( $this->getLocalCopyPath(), $headers );
                if ( $title ) {
                        $attribs['title'] = $title;
                }
 +
                return $attribs;
        }
  }
@@@ -318,6 -300,8 +318,8 @@@ class ThumbnailImage extends MediaTrans
         *     desc-query   String, description link query params
         *     override-width     Override width attribute. Should generally not set
         *     override-height    Override height attribute. Should generally not set
+        *     no-dimensions      Boolean, skip width and height attributes (useful if
+        *                        set in CSS)
         *     custom-url-link    Custom URL to link to
         *     custom-title-link  Custom Title object to link to
         *     custom target-link Value of the target attribute, for custom-target-link
                                'title' => empty( $options['title'] ) ? $title->getFullText() : $options['title']
                        );
                } elseif ( !empty( $options['desc-link'] ) ) {
 -                      $linkAttribs = $this->getDescLinkAttribs( empty( $options['title'] ) ? null : $options['title'], $query );
 +                      $linkAttribs = $this->getDescLinkAttribs(
 +                              empty( $options['title'] ) ? null : $options['title'],
 +                              $query
 +                      );
                } elseif ( !empty( $options['file-link'] ) ) {
                        $linkAttribs = array( 'href' => $this->file->getURL() );
                } else {
                $attribs = array(
                        'alt' => $alt,
                        'src' => $this->url,
-                       'width' => $this->width,
-                       'height' => $this->height
                );
+               if ( empty( $options['no-dimensions'] ) ) {
+                       $attribs['width'] = $this->width;
+                       $attribs['height'] = $this->height;
+               }
                if ( !empty( $options['valign'] ) ) {
                        $attribs['style'] = "vertical-align: {$options['valign']}";
                }
  
                return $this->linkWrap( $linkAttribs, Xml::element( 'img', $attribs ) );
        }
 -
  }
  
  /**
   * @ingroup Media
   */
  class MediaTransformError extends MediaTransformOutput {
 -      var $htmlMsg, $textMsg, $width, $height, $url, $path;
 +      /** @var string HTML formatted version of the error */
 +      private $htmlMsg;
 +
 +      /** @var string Plain text formatted version of the error */
 +      private $textMsg;
  
        function __construct( $msg, $width, $height /*, ... */ ) {
                $args = array_slice( func_get_args(), 3 );