* Stream the file if there were no errors
*
* @param array $headers Additional HTTP headers to send on success
- * @return bool Success
+ * @return Status
+ * @since 1.27
*/
- public function streamFile( $headers = array() ) {
+ public function streamFileWithStatus( $headers = array() ) {
if ( !$this->path ) {
- return false;
+ return Status::newFatal( 'backend-fail-stream', '<no path>' );
} elseif ( FileBackend::isStoragePath( $this->path ) ) {
$be = $this->file->getRepo()->getBackend();
-
- return $be->streamFile( array( 'src' => $this->path, 'headers' => $headers ) )->isOK();
+ return $be->streamFile( array( 'src' => $this->path, 'headers' => $headers ) );
} else { // FS-file
- return StreamFile::stream( $this->getLocalCopyPath(), $headers );
+ $success = StreamFile::stream( $this->getLocalCopyPath(), $headers );
+ return $success ? Status::newGood() : Status::newFatal( 'backend-fail-stream', $this->path );
}
}
+ /**
+ * Stream the file if there were no errors
+ *
+ * @deprecated since 1.26, use streamFileWithStatus
+ * @param array $headers Additional HTTP headers to send on success
+ * @return bool Success
+ */
+ public function streamFile( $headers = array() ) {
+ $this->streamFileWithStatus( $headers )->isOK();
+ }
+
/**
* Wrap some XHTML text in an anchor tag with the given attributes
*
throw new MWException( __METHOD__ . ' called in the old style' );
}
- $alt = empty( $options['alt'] ) ? '' : $options['alt'];
+ $alt = isset( $options['alt'] ) ? $options['alt'] : '';
- $query = empty( $options['desc-query'] ) ? '' : $options['desc-query'];
+ $query = isset( $options['desc-query'] ) ? $options['desc-query'] : '';
+
+ $attribs = array(
+ 'alt' => $alt,
+ 'src' => $this->url,
+ );
if ( !empty( $options['custom-url-link'] ) ) {
$linkAttribs = array( 'href' => $options['custom-url-link'] );
$linkAttribs = array( 'href' => $this->file->getURL() );
} else {
$linkAttribs = false;
+ if ( !empty( $options['title'] ) ) {
+ $attribs['title'] = $options['title'];
+ }
}
- $attribs = array(
- 'alt' => $alt,
- 'src' => $this->url,
- );
-
if ( empty( $options['no-dimensions'] ) ) {
$attribs['width'] = $this->width;
$attribs['height'] = $this->height;
$attribs['srcset'] = Html::srcSet( $this->responsiveUrls );
}
- wfRunHooks( 'ThumbnailBeforeProduceHTML', array( $this, &$attribs, &$linkAttribs ) );
+ Hooks::run( 'ThumbnailBeforeProduceHTML', array( $this, &$attribs, &$linkAttribs ) );
return $this->linkWrap( $linkAttribs, Xml::element( 'img', $attribs ) );
}
wfMessage( 'thumbnail_invalid_params' )->text() );
}
}
+
+/**
+ * Shortcut class for parameter file size errors
+ *
+ * @ingroup Media
+ * @since 1.25
+ */
+class TransformTooBigImageAreaError extends MediaTransformError {
+ function __construct( $params, $maxImageArea ) {
+ $msg = wfMessage( 'thumbnail_toobigimagearea' );
+
+ parent::__construct( 'thumbnail_error',
+ max( isset( $params['width'] ) ? $params['width'] : 0, 120 ),
+ max( isset( $params['height'] ) ? $params['height'] : 0, 120 ),
+ $msg->rawParams(
+ $msg->getLanguage()->formatComputingNumbers(
+ $maxImageArea, 1000, "size-$1pixel" )
+ )->text()
+ );
+ }
+}