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