From 08aa4418c30cfc18ccc69a0f0f9cb9e17be6c196 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Mon, 12 Aug 2013 09:28:15 +0200 Subject: Update to MediaWiki 1.21.1 --- includes/media/MediaTransformOutput.php | 43 ++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'includes/media/MediaTransformOutput.php') diff --git a/includes/media/MediaTransformOutput.php b/includes/media/MediaTransformOutput.php index 773824cb..1f95bc3b 100644 --- a/includes/media/MediaTransformOutput.php +++ b/includes/media/MediaTransformOutput.php @@ -33,6 +33,13 @@ abstract class MediaTransformOutput { 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(); + protected $storagePath = false; /** @@ -73,7 +80,7 @@ abstract class MediaTransformOutput { } /** - * @param $storagePath string The permanent storage path + * @param string $storagePath The permanent storage path * @return void */ public function setStoragePath( $storagePath ) { @@ -83,7 +90,7 @@ abstract class MediaTransformOutput { /** * Fetch HTML for this transform output * - * @param $options array Associative array of options. Boolean options + * @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. * @@ -153,7 +160,7 @@ abstract class MediaTransformOutput { /** * Stream the file if there were no errors * - * @param $headers Array Additional HTTP headers to send on success + * @param array $headers Additional HTTP headers to send on success * @return Bool success */ public function streamFile( $headers = array() ) { @@ -189,9 +196,12 @@ abstract class MediaTransformOutput { * @return array */ public function getDescLinkAttribs( $title = null, $params = '' ) { - $query = $this->page ? ( 'page=' . urlencode( $this->page ) ) : ''; + $query = ''; + if ( $this->page && $this->page !== 1 ) { + $query = 'page=' . urlencode( $this->page ); + } if( $params ) { - $query .= $query ? '&'.$params : $params; + $query .= $query ? '&' . $params : $params; } $attribs = array( 'href' => $this->file->getTitle()->getLocalURL( $query ), @@ -218,16 +228,16 @@ class ThumbnailImage extends MediaTransformOutput { * It may also include a 'page' parameter for multipage files. * * @param $file File object - * @param $url String: URL path to the thumb + * @param string $url URL path to the thumb * @param $path String|bool|null: filesystem path to the thumb - * @param $parameters Array: Associative array of parameters + * @param array $parameters Associative array of parameters * @private */ function __construct( $file, $url, $path = false, $parameters = array() ) { # Previous parameters: # $file, $url, $width, $height, $path = false, $page = false - if( is_array( $parameters ) ){ + if( is_array( $parameters ) ) { $defaults = array( 'page' => false ); @@ -260,7 +270,7 @@ class ThumbnailImage extends MediaTransformOutput { * Return HTML tag for the thumbnail, will include * width and height attributes and a blank alt text (as required). * - * @param $options array Associative array of options. Boolean options + * @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. * @@ -281,6 +291,7 @@ class ThumbnailImage extends MediaTransformOutput { * For images, desc-link and file-link are implemented as a click-through. For * sounds and videos, they may be displayed in other ways. * + * @throws MWException * @return string */ function toHtml( $options = array() ) { @@ -290,7 +301,7 @@ class ThumbnailImage extends MediaTransformOutput { $alt = empty( $options['alt'] ) ? '' : $options['alt']; - $query = empty( $options['desc-query'] ) ? '' : $options['desc-query']; + $query = empty( $options['desc-query'] ) ? '' : $options['desc-query']; if ( !empty( $options['custom-url-link'] ) ) { $linkAttribs = array( 'href' => $options['custom-url-link'] ); @@ -323,7 +334,7 @@ class ThumbnailImage extends MediaTransformOutput { 'alt' => $alt, 'src' => $this->url, 'width' => $this->width, - 'height' => $this->height, + 'height' => $this->height ); if ( !empty( $options['valign'] ) ) { $attribs['style'] = "vertical-align: {$options['valign']}"; @@ -331,6 +342,14 @@ class ThumbnailImage extends MediaTransformOutput { if ( !empty( $options['img-class'] ) ) { $attribs['class'] = $options['img-class']; } + + // Additional densities for responsive images, if specified. + if ( !empty( $this->responsiveUrls ) ) { + $attribs['srcset'] = Html::srcSet( $this->responsiveUrls ); + } + + wfRunHooks( 'ThumbnailBeforeProduceHTML', array( $this, &$attribs, &$linkAttribs ) ); + return $this->linkWrap( $linkAttribs, Xml::element( 'img', $attribs ) ); } @@ -385,7 +404,7 @@ class MediaTransformError extends MediaTransformOutput { class TransformParameterError extends MediaTransformError { function __construct( $params ) { parent::__construct( 'thumbnail_error', - max( isset( $params['width'] ) ? $params['width'] : 0, 120 ), + max( isset( $params['width'] ) ? $params['width'] : 0, 120 ), max( isset( $params['height'] ) ? $params['height'] : 0, 120 ), wfMessage( 'thumbnail_invalid_params' )->text() ); } -- cgit v1.2.2 From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/media/MediaTransformOutput.php | 53 ++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'includes/media/MediaTransformOutput.php') diff --git a/includes/media/MediaTransformOutput.php b/includes/media/MediaTransformOutput.php index 1f95bc3b..c49d3f20 100644 --- a/includes/media/MediaTransformOutput.php +++ b/includes/media/MediaTransformOutput.php @@ -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 @@ -151,7 +151,12 @@ abstract class MediaTransformOutput { if ( $this->isError() ) { return false; } elseif ( $this->path === null ) { - return $this->file->getLocalRefPath(); + return $this->file->getLocalRefPath(); // assume thumb was not scaled + } elseif ( FileBackend::isStoragePath( $this->path ) ) { + $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 } @@ -192,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( $params ) { - $query .= $query ? '&' . $params : $params; + if ( $this->lang ) { + $query['lang'] = $this->lang; } + + if ( is_string( $params ) && $params !== '' ) { + $query = $params . '&' . wfArrayToCgi( $query ); + } + $attribs = array( 'href' => $this->file->getTitle()->getLocalURL( $query ), 'class' => 'image', @@ -237,10 +251,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. @@ -249,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; } @@ -264,6 +280,7 @@ class ThumbnailImage extends MediaTransformOutput { $this->height = round( $actualParams['height'] ); $this->page = $actualParams['page']; + $this->lang = $actualParams['lang']; } /** @@ -281,6 +298,8 @@ class ThumbnailImage extends MediaTransformOutput { * 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 + * 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 @@ -296,7 +315,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']; @@ -342,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 ) ) { -- cgit v1.2.2