Make the instantiation tests actually work.
[lhc/web/wiklou.git] / includes / MediaTransformOutput.php
index 9e94f06..a3fcc96 100644 (file)
@@ -50,6 +50,8 @@ abstract class MediaTransformOutput {
         *     alt          Alternate text or caption
         *     desc-link    Boolean, show a description link
         *     file-link    Boolean, show a file download link
+        *     custom-url-link    Custom URL to link to
+        *     custom-title-link  Custom Title object to link to
         *     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
         *
@@ -78,20 +80,19 @@ abstract class MediaTransformOutput {
                }
        }
 
-       function getDescLinkAttribs( $alt = false, $params = '' ) {
+       function getDescLinkAttribs( $title = null, $params = '' ) {
                $query = $this->page ? ( 'page=' . urlencode( $this->page ) ) : '';
                if( $params ) {
                        $query .= $query ? '&'.$params : $params;
                }
-               $title = $this->file->getTitle();
-               if ( strval( $alt ) === '' ) {
-                       $alt = $title->getText();
-               }
-               return array(
+               $attribs = array(
                        'href' => $this->file->getTitle()->getLocalURL( $query ),
                        'class' => 'image',
-                       'title' => $alt
                );
+               if ( $title ) {
+                       $attribs['title'] = $title;
+               }
+               return $attribs;
        }
 }
 
@@ -127,12 +128,15 @@ class ThumbnailImage extends MediaTransformOutput {
         *     should be indicated with a value of true for true, and false or
         *     absent for false.
         *
-        *     alt          Alternate text or caption
+        *     alt          HTML alt attribute
+        *     title        HTML title attribute
         *     desc-link    Boolean, show a description link
         *     file-link    Boolean, show a file download link
         *     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
+        *     custom-url-link    Custom URL to link to
+        *     custom-title-link  Custom Title object to link to
         *
         * For images, desc-link and file-link are implemented as a click-through. For
         * sounds and videos, they may be displayed in other ways.
@@ -146,9 +150,22 @@ class ThumbnailImage extends MediaTransformOutput {
                }
 
                $alt = empty( $options['alt'] ) ? '' : $options['alt'];
-               $query = empty($options['desc-query'])  ? '' : $options['desc-query'];
-               if ( !empty( $options['desc-link'] ) ) {
-                       $linkAttribs = $this->getDescLinkAttribs( $alt, $query );
+
+               $query = empty( $options['desc-query'] )  ? '' : $options['desc-query'];
+
+               if ( !empty( $options['custom-url-link'] ) ) {
+                       $linkAttribs = array( 'href' => $options['custom-url-link'] );
+                       if ( !empty( $options['title'] ) ) {
+                               $linkAttribs['title'] = $options['title'];
+                       }
+               } elseif ( !empty( $options['custom-title-link'] ) ) {
+                       $title = $options['custom-title-link'];
+                       $linkAttribs = array(
+                               'href' => $title->getLinkUrl(),
+                               'title' => empty( $options['title'] ) ? $title->getFullText() : $options['title']
+                       );
+               } elseif ( !empty( $options['desc-link'] ) ) {
+                       $linkAttribs = $this->getDescLinkAttribs( empty( $options['title'] ) ? null : $options['title'], $query );
                } elseif ( !empty( $options['file-link'] ) ) {
                        $linkAttribs = array( 'href' => $this->file->getURL() );
                } else {
@@ -160,7 +177,6 @@ class ThumbnailImage extends MediaTransformOutput {
                        'src' => $this->url,
                        'width' => $this->width,
                        'height' => $this->height,
-                       'border' => 0,
                );
                if ( !empty( $options['valign'] ) ) {
                        $attribs['style'] = "vertical-align: {$options['valign']}";