summaryrefslogtreecommitdiff
path: root/includes/media/MediaTransformOutput.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2013-01-18 16:46:04 +0100
committerPierre Schmitz <pierre@archlinux.de>2013-01-18 16:46:04 +0100
commit63601400e476c6cf43d985f3e7b9864681695ed4 (patch)
treef7846203a952e38aaf66989d0a4702779f549962 /includes/media/MediaTransformOutput.php
parent8ff01378c9e0207f9169b81966a51def645b6a51 (diff)
Update to MediaWiki 1.20.2
this update includes: * adjusted Arch Linux skin * updated FluxBBAuthPlugin * patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024
Diffstat (limited to 'includes/media/MediaTransformOutput.php')
-rw-r--r--includes/media/MediaTransformOutput.php99
1 files changed, 80 insertions, 19 deletions
diff --git a/includes/media/MediaTransformOutput.php b/includes/media/MediaTransformOutput.php
index fcfb2f45..773824cb 100644
--- a/includes/media/MediaTransformOutput.php
+++ b/includes/media/MediaTransformOutput.php
@@ -2,6 +2,21 @@
/**
* Base class for the output of file transformation methods.
*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
* @file
* @ingroup Media
*/
@@ -21,28 +36,37 @@ abstract class MediaTransformOutput {
protected $storagePath = false;
/**
- * Get the width of the output box
+ * @return integer Width of the output box
*/
public function getWidth() {
return $this->width;
}
/**
- * Get the height of the output box
+ * @return integer Height of the output box
*/
public function getHeight() {
return $this->height;
}
/**
- * @return string The thumbnail URL
+ * Get the final extension of the thumbnail.
+ * Returns false for scripted transformations.
+ * @return string|false
+ */
+ public function getExtension() {
+ return $this->path ? FileBackend::extensionFromPath( $this->path ) : false;
+ }
+
+ /**
+ * @return string|false The thumbnail URL
*/
public function getUrl() {
return $this->url;
}
/**
- * @return string|false The permanent thumbnail storage path
+ * @return string|bool The permanent thumbnail storage path
*/
public function getStoragePath() {
return $this->storagePath;
@@ -69,7 +93,7 @@ abstract class MediaTransformOutput {
* 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
+ * 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.
@@ -80,6 +104,7 @@ abstract class MediaTransformOutput {
/**
* This will be overridden to return true in error classes
+ * @return bool
*/
public function isError() {
return false;
@@ -90,7 +115,7 @@ abstract class MediaTransformOutput {
* 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.
- *
+ *
* @return Bool
*/
public function hasFile() {
@@ -113,7 +138,7 @@ abstract class MediaTransformOutput {
* Get the path of a file system copy of the thumbnail.
* Callers should never write to this path.
*
- * @return string|false Returns false if there isn't one
+ * @return string|bool Returns false if there isn't one
*/
public function getLocalCopyPath() {
if ( $this->isError() ) {
@@ -132,7 +157,14 @@ abstract class MediaTransformOutput {
* @return Bool success
*/
public function streamFile( $headers = array() ) {
- return $this->path && StreamFile::stream( $this->getLocalCopyPath(), $headers );
+ 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,25 +214,46 @@ class ThumbnailImage extends MediaTransformOutput {
* Get a thumbnail object from a file and parameters.
* If $path is set to null, the output file is treated as a source copy.
* If $path is set to false, no output file will be created.
- *
+ * $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 $url String: URL path to the thumb
- * @param $width Integer: file's width
- * @param $height Integer: file's height
- * @param $path String|false|null: filesystem path to the thumb
- * @param $page Integer: page number, for multipage files
+ * @param $path String|bool|null: filesystem path to the thumb
+ * @param $parameters Array: Associative array of parameters
* @private
*/
- function __construct( $file, $url, $width, $height, $path = false, $page = false ) {
+ function __construct( $file, $url, $path = false, $parameters = array() ) {
+ # Previous parameters:
+ # $file, $url, $width, $height, $path = false, $page = false
+
+ if( is_array( $parameters ) ){
+ $defaults = array(
+ 'page' => false
+ );
+ $actualParams = $parameters + $defaults;
+ } else {
+ # Using old format, should convert. Later a warning could be added here.
+ $numArgs = func_num_args();
+ $actualParams = array(
+ 'width' => $path,
+ 'height' => $parameters,
+ 'page' => ( $numArgs > 5 ) ? func_get_arg( 5 ) : false
+ );
+ $path = ( $numArgs > 4 ) ? func_get_arg( 4 ) : false;
+ }
+
$this->file = $file;
$this->url = $url;
+ $this->path = $path;
+
# These should be integers when they get here.
# If not, there's a bug somewhere. But let's at
# least produce valid HTML code regardless.
- $this->width = round( $width );
- $this->height = round( $height );
- $this->path = $path;
- $this->page = $page;
+ $this->width = round( $actualParams['width'] );
+ $this->height = round( $actualParams['height'] );
+
+ $this->page = $actualParams['page'];
}
/**
@@ -221,6 +274,9 @@ class ThumbnailImage extends MediaTransformOutput {
* 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
+ * parser-extlink-* Attributes added by parser for external links:
+ * parser-extlink-rel: add rel="nofollow"
+ * parser-extlink-target: link target, but overridden by custom-target-link
*
* For images, desc-link and file-link are implemented as a click-through. For
* sounds and videos, they may be displayed in other ways.
@@ -243,6 +299,11 @@ class ThumbnailImage extends MediaTransformOutput {
}
if ( !empty( $options['custom-target-link'] ) ) {
$linkAttribs['target'] = $options['custom-target-link'];
+ } elseif ( !empty( $options['parser-extlink-target'] ) ) {
+ $linkAttribs['target'] = $options['parser-extlink-target'];
+ }
+ if ( !empty( $options['parser-extlink-rel'] ) ) {
+ $linkAttribs['rel'] = $options['parser-extlink-rel'];
}
} elseif ( !empty( $options['custom-title-link'] ) ) {
$title = $options['custom-title-link'];
@@ -326,6 +387,6 @@ class TransformParameterError extends MediaTransformError {
parent::__construct( 'thumbnail_error',
max( isset( $params['width'] ) ? $params['width'] : 0, 120 ),
max( isset( $params['height'] ) ? $params['height'] : 0, 120 ),
- wfMsg( 'thumbnail_invalid_params' ) );
+ wfMessage( 'thumbnail_invalid_params' )->text() );
}
}