diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2014-12-27 15:41:37 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2014-12-31 11:43:28 +0100 |
commit | c1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch) | |
tree | 2b38796e738dd74cb42ecd9bfd151803108386bc /includes/media/MediaTransformOutput.php | |
parent | b88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff) |
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/media/MediaTransformOutput.php')
-rw-r--r-- | includes/media/MediaTransformOutput.php | 98 |
1 files changed, 69 insertions, 29 deletions
diff --git a/includes/media/MediaTransformOutput.php b/includes/media/MediaTransformOutput.php index c49d3f20..bc9e9173 100644 --- a/includes/media/MediaTransformOutput.php +++ b/includes/media/MediaTransformOutput.php @@ -27,46 +27,67 @@ * @ingroup Media */ abstract class MediaTransformOutput { - /** - * @var File + /** @var array Associative array mapping optional supplementary image files + * from pixel density (eg 1.5 or 2) to additional URLs. */ - var $file; + public $responsiveUrls = array(); - var $width, $height, $url, $page, $path, $lang; + /** @var File */ + protected $file; - /** - * @var array Associative array mapping optional supplementary image files - * from pixel density (eg 1.5 or 2) to additional URLs. - */ - public $responsiveUrls = array(); + /** @var int Image width */ + protected $width; + + /** @var int Image height */ + protected $height; + + /** @var string URL path to the thumb */ + protected $url; + /** @var bool|string */ + protected $page; + + /** @var bool|string Filesystem path to the thumb */ + protected $path; + + /** @var bool|string Language code, false if not set */ + protected $lang; + + /** @var bool|string Permanent storage path */ protected $storagePath = false; /** - * @return integer Width of the output box + * @return int Width of the output box */ public function getWidth() { return $this->width; } /** - * @return integer Height of the output box + * @return int Height of the output box */ public function getHeight() { return $this->height; } /** + * @return File + */ + public function getFile() { + return $this->file; + } + + /** * Get the final extension of the thumbnail. * Returns false for scripted transformations. - * @return string|false + * @return string|bool */ public function getExtension() { return $this->path ? FileBackend::extensionFromPath( $this->path ) : false; } /** - * @return string|false The thumbnail URL + * @return string|bool The thumbnail URL */ public function getUrl() { return $this->url; @@ -85,6 +106,9 @@ abstract class MediaTransformOutput { */ public function setStoragePath( $storagePath ) { $this->storagePath = $storagePath; + if ( $this->path === false ) { + $this->path = $storagePath; + } } /** @@ -119,11 +143,14 @@ abstract class MediaTransformOutput { /** * Check if an output thumbnail file actually exists. + * * This will return false if there was an error, the * thumbnail is to be handled client-side only, or if * transformation was deferred via TRANSFORM_LATER. + * This file may exist as a new file in /tmp, a file + * in permanent storage, or even refer to the original. * - * @return Bool + * @return bool */ public function hasFile() { // If TRANSFORM_LATER, $this->path will be false. @@ -135,7 +162,7 @@ abstract class MediaTransformOutput { * Check if the output thumbnail is the same as the source. * This can occur if the requested width was bigger than the source. * - * @return Bool + * @return bool */ public function fileIsSource() { return ( !$this->isError() && $this->path === null ); @@ -156,6 +183,7 @@ abstract class MediaTransformOutput { $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 @@ -166,13 +194,14 @@ abstract class MediaTransformOutput { * Stream the file if there were no errors * * @param array $headers Additional HTTP headers to send on success - * @return Bool success + * @return bool Success */ public function streamFile( $headers = array() ) { if ( !$this->path ) { return false; } elseif ( FileBackend::isStoragePath( $this->path ) ) { $be = $this->file->getRepo()->getBackend(); + return $be->streamFile( array( 'src' => $this->path, 'headers' => $headers ) )->isOK(); } else { // FS-file return StreamFile::stream( $this->getLocalCopyPath(), $headers ); @@ -182,9 +211,8 @@ abstract class MediaTransformOutput { /** * Wrap some XHTML text in an anchor tag with the given attributes * - * @param $linkAttribs array - * @param $contents string - * + * @param array $linkAttribs + * @param string $contents * @return string */ protected function linkWrap( $linkAttribs, $contents ) { @@ -196,8 +224,8 @@ abstract class MediaTransformOutput { } /** - * @param $title string - * @param $params string|array Query parameters to add + * @param string $title + * @param string|array $params Query parameters to add * @return array */ public function getDescLinkAttribs( $title = null, $params = array() ) { @@ -224,6 +252,7 @@ abstract class MediaTransformOutput { if ( $title ) { $attribs['title'] = $title; } + return $attribs; } } @@ -241,11 +270,10 @@ class ThumbnailImage extends MediaTransformOutput { * $parameters should include, as a minimum, (file) 'width' and 'height'. * It may also include a 'page' parameter for multipage files. * - * @param $file File object + * @param File $file * @param string $url URL path to the thumb - * @param $path String|bool|null: filesystem path to the thumb + * @param string|bool $path Filesystem path to the thumb * @param array $parameters Associative array of parameters - * @private */ function __construct( $file, $url, $path = false, $parameters = array() ) { # Previous parameters: @@ -300,6 +328,8 @@ class ThumbnailImage extends MediaTransformOutput { * 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 + * no-dimensions Boolean, skip width and height attributes (useful if + * set in CSS) * 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 @@ -336,13 +366,17 @@ class ThumbnailImage extends MediaTransformOutput { $linkAttribs['rel'] = $options['parser-extlink-rel']; } } elseif ( !empty( $options['custom-title-link'] ) ) { + /** @var Title $title */ $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 ); + $linkAttribs = $this->getDescLinkAttribs( + empty( $options['title'] ) ? null : $options['title'], + $query + ); } elseif ( !empty( $options['file-link'] ) ) { $linkAttribs = array( 'href' => $this->file->getURL() ); } else { @@ -352,9 +386,12 @@ class ThumbnailImage extends MediaTransformOutput { $attribs = array( 'alt' => $alt, 'src' => $this->url, - 'width' => $this->width, - 'height' => $this->height ); + + if ( empty( $options['no-dimensions'] ) ) { + $attribs['width'] = $this->width; + $attribs['height'] = $this->height; + } if ( !empty( $options['valign'] ) ) { $attribs['style'] = "vertical-align: {$options['valign']}"; } @@ -377,7 +414,6 @@ class ThumbnailImage extends MediaTransformOutput { return $this->linkWrap( $linkAttribs, Xml::element( 'img', $attribs ) ); } - } /** @@ -386,7 +422,11 @@ class ThumbnailImage extends MediaTransformOutput { * @ingroup Media */ class MediaTransformError extends MediaTransformOutput { - var $htmlMsg, $textMsg, $width, $height, $url, $path; + /** @var string HTML formatted version of the error */ + private $htmlMsg; + + /** @var string Plain text formatted version of the error */ + private $textMsg; function __construct( $msg, $width, $height /*, ... */ ) { $args = array_slice( func_get_args(), 3 ); |