Remove function call from for loop test part in GIFMetadataExtractor::readGCT()
[lhc/web/wiklou.git] / includes / media / MediaTransformOutput.php
index 1c2dfdd..81b285e 100644 (file)
  * @ingroup Media
  */
 abstract class MediaTransformOutput {
-       /**
-        * @var File
-        */
-       var $file;
-
-       var $width, $height, $url, $page, $path;
-
        /**
         * @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;
 
        /**
@@ -156,6 +171,7 @@ abstract class MediaTransformOutput {
                        $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
@@ -173,6 +189,7 @@ abstract class MediaTransformOutput {
                        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 );
@@ -197,17 +214,26 @@ abstract class MediaTransformOutput {
 
        /**
         * @param $title string
-        * @param $params array
+        * @param $params string|array Query parameters to add
         * @return array
         */
-       public function getDescLinkAttribs( $title = null, $params = '' ) {
-               $query = '';
+       public function getDescLinkAttribs( $title = null, $params = array() ) {
+               if ( is_array( $params ) ) {
+                       $query = $params;
+               } else {
+                       $query = array();
+               }
                if ( $this->page && $this->page !== 1 ) {
-                       $query = 'page=' . urlencode( $this->page );
+                       $query['page'] = $this->page;
+               }
+               if ( $this->lang ) {
+                       $query['lang'] = $this->lang;
                }
-               if( $params ) {
-                       $query .= $query ? '&' . $params : $params;
+
+               if ( is_string( $params ) && $params !== '' ) {
+                       $query = $params . '&' . wfArrayToCgi( $query );
                }
+
                $attribs = array(
                        'href' => $this->file->getTitle()->getLocalURL( $query ),
                        'class' => 'image',
@@ -215,6 +241,7 @@ abstract class MediaTransformOutput {
                if ( $title ) {
                        $attribs['title'] = $title;
                }
+
                return $attribs;
        }
 }
@@ -242,10 +269,12 @@ class ThumbnailImage extends MediaTransformOutput {
                # Previous parameters:
                #   $file, $url, $width, $height, $path = false, $page = false
 
-               if( is_array( $parameters ) ) {
-                       $defaults = array(
-                               'page' => false
-                       );
+               $defaults = array(
+                       'page' => false,
+                       'lang' => false
+               );
+
+               if ( is_array( $parameters ) ) {
                        $actualParams = $parameters + $defaults;
                } else {
                        # Using old format, should convert. Later a warning could be added here.
@@ -254,7 +283,7 @@ class ThumbnailImage extends MediaTransformOutput {
                                'width' => $path,
                                'height' => $parameters,
                                'page' => ( $numArgs > 5 ) ? func_get_arg( 5 ) : false
-                       );
+                       ) + $defaults;
                        $path = ( $numArgs > 4 ) ? func_get_arg( 4 ) : false;
                }
 
@@ -269,6 +298,7 @@ class ThumbnailImage extends MediaTransformOutput {
                $this->height = round( $actualParams['height'] );
 
                $this->page = $actualParams['page'];
+               $this->lang = $actualParams['lang'];
        }
 
        /**
@@ -286,6 +316,8 @@ class ThumbnailImage extends MediaTransformOutput {
         *     valign       vertical-align property, if the output is an inline element
         *     img-class    Class applied to the \<img\> tag, if there is such a tag
         *     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
         *     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
@@ -301,7 +333,7 @@ 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'];
@@ -328,7 +360,10 @@ class ThumbnailImage extends MediaTransformOutput {
                                '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 {
@@ -347,6 +382,12 @@ class ThumbnailImage extends MediaTransformOutput {
                if ( !empty( $options['img-class'] ) ) {
                        $attribs['class'] = $options['img-class'];
                }
+               if ( isset( $options['override-height'] ) ) {
+                       $attribs['height'] = $options['override-height'];
+               }
+               if ( isset( $options['override-width'] ) ) {
+                       $attribs['width'] = $options['override-width'];
+               }
 
                // Additional densities for responsive images, if specified.
                if ( !empty( $this->responsiveUrls ) ) {
@@ -357,7 +398,6 @@ class ThumbnailImage extends MediaTransformOutput {
 
                return $this->linkWrap( $linkAttribs, Xml::element( 'img', $attribs ) );
        }
-
 }
 
 /**
@@ -366,7 +406,11 @@ class ThumbnailImage extends MediaTransformOutput {
  * @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 );