* Make tests work better together. Tests are now skipped or marked incomplete.
[lhc/web/wiklou.git] / includes / MediaTransformOutput.php
index 5dc6cd8..a3fcc96 100644 (file)
@@ -1,9 +1,13 @@
 <?php
+/**
+ * @file
+ * @ingroup Media
+ */
 
 /**
  * Base class for the output of MediaHandler::doTransform() and File::transform().
  *
- * @addtogroup Media
+ * @ingroup Media
  */
 abstract class MediaTransformOutput {
        var $file, $width, $height, $url, $page, $path;
@@ -13,7 +17,7 @@ abstract class MediaTransformOutput {
         */
        function getWidth() {
                return $this->width;
-       } 
+       }
 
        /**
         * Get the height of the output box
@@ -39,18 +43,20 @@ abstract class MediaTransformOutput {
        /**
         * Fetch HTML for this transform output
         *
-        * @param array $options Associative array of options. Boolean options 
-        *     should be indicated with a value of true for true, and false or 
+        * @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.
         *
         *     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
         *
-        * For images, desc-link and file-link are implemented as a click-through. For 
-        * sounds and videos, they may be displayed in other ways. 
+        * For images, desc-link and file-link are implemented as a click-through. For
+        * sounds and videos, they may be displayed in other ways.
         *
         * @return string
         */
@@ -74,17 +80,19 @@ abstract class MediaTransformOutput {
                }
        }
 
-       function getDescLinkAttribs( $alt = false ) {
+       function getDescLinkAttribs( $title = null, $params = '' ) {
                $query = $this->page ? ( 'page=' . urlencode( $this->page ) ) : '';
-               $title = $this->file->getTitle();
-               if ( strval( $alt ) === '' ) {
-                       $alt = $title->getText();
+               if( $params ) {
+                       $query .= $query ? '&'.$params : $params;
                }
-               return array( 
+               $attribs = array(
                        'href' => $this->file->getTitle()->getLocalURL( $query ),
                        'class' => 'image',
-                       'title' => $alt
                );
+               if ( $title ) {
+                       $attribs['title'] = $title;
+               }
+               return $attribs;
        }
 }
 
@@ -92,7 +100,7 @@ abstract class MediaTransformOutput {
 /**
  * Media transform output for images
  *
- * @addtogroup Media
+ * @ingroup Media
  */
 class ThumbnailImage extends MediaTransformOutput {
        /**
@@ -115,19 +123,23 @@ 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 array $options Associative array of options. Boolean options 
-        *     should be indicated with a value of true for true, and false or 
+        *
+        * @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.
         *
-        *     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. 
+        * For images, desc-link and file-link are implemented as a click-through. For
+        * sounds and videos, they may be displayed in other ways.
         *
         * @return string
         * @public
@@ -138,8 +150,22 @@ class ThumbnailImage extends MediaTransformOutput {
                }
 
                $alt = empty( $options['alt'] ) ? '' : $options['alt'];
-               if ( !empty( $options['desc-link'] ) ) {
-                       $linkAttribs = $this->getDescLinkAttribs( $alt );
+
+               $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 {
@@ -151,7 +177,6 @@ class ThumbnailImage extends MediaTransformOutput {
                        'src' => $this->url,
                        'width' => $this->width,
                        'height' => $this->height,
-                       'style' => 'border: none',
                );
                if ( !empty( $options['valign'] ) ) {
                        $attribs['style'] = "vertical-align: {$options['valign']}";
@@ -167,7 +192,7 @@ class ThumbnailImage extends MediaTransformOutput {
 /**
  * Basic media transform error class
  *
- * @addtogroup Media
+ * @ingroup Media
  */
 class MediaTransformError extends MediaTransformOutput {
        var $htmlMsg, $textMsg, $width, $height, $url, $path;
@@ -208,15 +233,13 @@ class MediaTransformError extends MediaTransformOutput {
 /**
  * Shortcut class for parameter validation errors
  *
- * @addtogroup Media
+ * @ingroup Media
  */
 class TransformParameterError extends MediaTransformError {
        function __construct( $params ) {
-               parent::__construct( 'thumbnail_error', 
-                       max( isset( $params['width']  ) ? $params['width']  : 0, 180 ), 
-                       max( isset( $params['height'] ) ? $params['height'] : 0, 180 ), 
+               parent::__construct( 'thumbnail_error',
+                       max( isset( $params['width']  ) ? $params['width']  : 0, 180 ),
+                       max( isset( $params['height'] ) ? $params['height'] : 0, 180 ),
                        wfMsg( 'thumbnail_invalid_params' ) );
        }
 }
-
-