Merge "ToC: Use display:table, so that we can behave like a block element"
[lhc/web/wiklou.git] / includes / media / MediaTransformOutput.php
index 1d197b1..c49d3f2 100644 (file)
@@ -32,7 +32,7 @@ abstract class MediaTransformOutput {
         */
        var $file;
 
-       var $width, $height, $url, $page, $path;
+       var $width, $height, $url, $page, $path, $lang;
 
        /**
         * @var array Associative array mapping optional supplementary image files
@@ -197,17 +197,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',
@@ -242,10 +251,12 @@ class ThumbnailImage extends MediaTransformOutput {
                # Previous parameters:
                #   $file, $url, $width, $height, $path = false, $page = false
 
+               $defaults = array(
+                       'page' => false,
+                       'lang' => false
+               );
+
                if ( is_array( $parameters ) ) {
-                       $defaults = array(
-                               'page' => false
-                       );
                        $actualParams = $parameters + $defaults;
                } else {
                        # Using old format, should convert. Later a warning could be added here.
@@ -254,7 +265,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 +280,7 @@ class ThumbnailImage extends MediaTransformOutput {
                $this->height = round( $actualParams['height'] );
 
                $this->page = $actualParams['page'];
+               $this->lang = $actualParams['lang'];
        }
 
        /**
@@ -286,6 +298,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
@@ -347,6 +361,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 ) ) {