return new ThumbnailImage( $image, $dstUrl, $dstPath, $params );
}
+ $metadata = $this->unpackMetadata( $image->getMetadata() );
+ if ( isset( $metadata['error'] ) ) { // sanity check
+ $err = wfMessage( 'svg-long-error', $metadata['error']['message'] )->text();
+ return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, $err );
+ }
+
if ( !wfMkdirParents( dirname( $dstPath ), null, __METHOD__ ) ) {
return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight,
wfMessage( 'thumbnail_dest_directory' )->text() );
$srcPath = $image->getLocalRefPath();
$status = $this->rasterize( $srcPath, $dstPath, $physicalWidth, $physicalHeight );
- if( $status === true ) {
+ if ( $status === true ) {
return new ThumbnailImage( $image, $dstUrl, $dstPath, $params );
} else {
return $status; // MediaTransformError
if ( isset( $metadata['width'] ) && isset( $metadata['height'] ) ) {
return array( $metadata['width'], $metadata['height'], 'SVG',
"width=\"{$metadata['width']}\" height=\"{$metadata['height']}\"" );
+ } else { // error
+ return array( 0, 0, 'SVG', "width=\"0\" height=\"0\"" );
}
}
*/
function getLongDesc( $file ) {
global $wgLang;
+
+ $metadata = $this->unpackMetadata( $file->getMetadata() );
+ if ( isset( $metadata['error'] ) ) {
+ return wfMessage( 'svg-long-error', $metadata['error']['message'] )->text();
+ }
+
$size = $wgLang->formatSize( $file->getSize() );
if ( $this->isAnimatedImage( $file ) ) {
$msg = wfMessage( 'svg-long-desc' );
}
- $msg->numParams(
- $file->getWidth(),
- $file->getHeight()
- );
- $msg->Params( $size );
+ $msg->numParams( $file->getWidth(), $file->getHeight() )->params( $size );
+
return $msg->parse();
}
function getMetadata( $file, $filename ) {
+ $metadata = array( 'version' => self::SVG_METADATA_VERSION );
try {
- $metadata = SVGMetadataExtractor::getMetadata( $filename );
- } catch( Exception $e ) {
- // Broken file?
+ $metadata += SVGMetadataExtractor::getMetadata( $filename );
+ } catch( MWException $e ) { // @TODO: SVG specific exceptions
+ // File not found, broken, etc.
+ $metadata['error'] = array(
+ 'message' => $e->getMessage(),
+ 'code' => $e->getCode()
+ );
wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
- return '0';
}
- $metadata['version'] = self::SVG_METADATA_VERSION;
return serialize( $metadata );
}
return false;
}
$metadata = $this->unpackMetadata( $metadata );
- if ( !$metadata ) {
+ if ( !$metadata || isset( $metadata['error'] ) ) {
return false;
}
'file-nohires' => 'No higher resolution available.',
'svg-long-desc' => 'SVG file, nominally $1 × $2 pixels, file size: $3',
'svg-long-desc-animated' => 'Animated SVG file, nominally $1 × $2 pixels, file size: $3',
+'svg-long-error' => 'Invalid SVG file: $1',
'show-big-image' => 'Full resolution',
'show-big-image-preview' => 'Size of this preview: $1.',
'show-big-image-other' => 'Other {{PLURAL:$2|resolution|resolutions}}: $1.',
* $3 is the file size including a unit (for example "10 KB").
Start with a lowercase letter, unless the first word is “SVG”.',
+
+'svg-long-error' => 'Displayed for invalid SVG file metadata.
+* $1 is the error message.',
'show-big-image' => 'Displayed under an image at the image description page, when it is displayed smaller there than it was uploaded.',
'show-big-image-other' => 'Message shown under the image description page thumbnail, next to {{msg-mw|show-big-image-preview}}, if the image is in high resolution.',
'show-big-image-size' => '