X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMediaTransformOutput.php;h=9e94f06b9360b9e958fddfe74ec5b9bb19d29506;hb=06adafb3d506a347cc7cffbe50a3c15dc8368912;hp=8745bb5853fc99b0983695e32cee2a191f877e79;hpb=a15c419b3d130248f2556b9d00643ba9666a4189;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MediaTransformOutput.php b/includes/MediaTransformOutput.php index 8745bb5853..9e94f06b93 100644 --- a/includes/MediaTransformOutput.php +++ b/includes/MediaTransformOutput.php @@ -1,17 +1,23 @@ width; - } + } /** * Get the height of the output box @@ -36,12 +42,23 @@ abstract class MediaTransformOutput { /** * Fetch HTML for this transform output - * @param array $attribs Advisory associative array of HTML attributes supplied - * by the linker. These can be incorporated into the output in any way. - * @param array $linkAttribs Attributes of a suggested enclosing tag. - * May be ignored. + * + * @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 + * valign vertical-align property, if the output is an inline element + * img-class Class applied to the 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. + * + * @return string */ - abstract function toHtml( $attribs = array() , $linkAttribs = false ); + abstract function toHtml( $options = array() ); /** * This will be overridden to return true in error classes @@ -60,13 +77,29 @@ abstract class MediaTransformOutput { return $contents; } } + + function getDescLinkAttribs( $alt = false, $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( + 'href' => $this->file->getTitle()->getLocalURL( $query ), + 'class' => 'image', + 'title' => $alt + ); + } } /** * Media transform output for images * - * @addtogroup Media + * @ingroup Media */ class ThumbnailImage extends MediaTransformOutput { /** @@ -74,7 +107,8 @@ class ThumbnailImage extends MediaTransformOutput { * @param string $url URL path to the thumb * @private */ - function ThumbnailImage( $url, $width, $height, $path = false ) { + function ThumbnailImage( $file, $url, $width, $height, $path = false, $page = false ) { + $this->file = $file; $this->url = $url; # These should be integers when they get here. # If not, there's a bug somewhere. But let's at @@ -82,28 +116,58 @@ class ThumbnailImage extends MediaTransformOutput { $this->width = round( $width ); $this->height = round( $height ); $this->path = $path; + $this->page = $page; } /** * Return HTML tag for the thumbnail, will include * width and height attributes and a blank alt text (as required). * - * You can set or override additional attributes by passing an - * associative array of name => data pairs. The data will be escaped - * for HTML output, so should be in plaintext. + * @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 + * valign vertical-align property, if the output is an inline element + * img-class Class applied to the tag, if there is such a tag + * desc-query String, description link query params * - * If $linkAttribs is given, the image will be enclosed in an 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. * - * @param array $attribs - * @param array $linkAttribs * @return string * @public */ - function toHtml( $attribs = array(), $linkAttribs = false ) { - $attribs['src'] = $this->url; - $attribs['width'] = $this->width; - $attribs['height'] = $this->height; - if( !isset( $attribs['alt'] ) ) $attribs['alt'] = ''; + function toHtml( $options = array() ) { + if ( count( func_get_args() ) == 2 ) { + throw new MWException( __METHOD__ .' called in the old style' ); + } + + $alt = empty( $options['alt'] ) ? '' : $options['alt']; + $query = empty($options['desc-query']) ? '' : $options['desc-query']; + if ( !empty( $options['desc-link'] ) ) { + $linkAttribs = $this->getDescLinkAttribs( $alt, $query ); + } elseif ( !empty( $options['file-link'] ) ) { + $linkAttribs = array( 'href' => $this->file->getURL() ); + } else { + $linkAttribs = false; + } + + $attribs = array( + 'alt' => $alt, + 'src' => $this->url, + 'width' => $this->width, + 'height' => $this->height, + 'border' => 0, + ); + if ( !empty( $options['valign'] ) ) { + $attribs['style'] = "vertical-align: {$options['valign']}"; + } + if ( !empty( $options['img-class'] ) ) { + $attribs['class'] = $options['img-class']; + } return $this->linkWrap( $linkAttribs, Xml::element( 'img', $attribs ) ); } @@ -112,7 +176,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; @@ -130,7 +194,7 @@ class MediaTransformError extends MediaTransformOutput { $this->path = false; } - function toHtml( $attribs = array(), $linkAttribs = false ) { + function toHtml( $options = array() ) { return "width}px; height: {$this->height}px;\">
" . $this->htmlMsg . @@ -153,15 +217,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' ) ); } } - -