Implement SVGMaxSize

wgSVGMaxSize sets the maximum size for the shortest edge of a
vector image. Pass this through to MWImageNodes.

Change-Id: I6410e7cda137cf4828d12280cb1e5cfc27805859
This commit is contained in:
Ed Sanders 2014-01-26 22:59:30 +00:00 committed by Krinkle
parent 20d6df9a65
commit d169108eeb
2 changed files with 28 additions and 8 deletions

View file

@ -309,7 +309,7 @@ class VisualEditorHooks {
* Adds extra variables to the page config.
*/
public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $out ) {
global $wgStylePath;
global $wgStylePath, $wgSVGMaxSize;
$pageLanguage = $out->getTitle()->getPageLanguage();
@ -320,7 +320,8 @@ class VisualEditorHooks {
'/common/images/magnify-clip' .
( $pageLanguage->isRTL() ? '-rtl' : '' ) . '.png',
'pageLanguageCode' => $pageLanguage->getHtmlCode(),
'pageLanguageDir' => $pageLanguage->getDir()
'pageLanguageDir' => $pageLanguage->getDir(),
'svgMaxSize' => $wgSVGMaxSize,
);
return true;

View file

@ -5,6 +5,8 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
/*global mw */
/**
* ContentEditable MediaWiki image node.
*
@ -134,14 +136,31 @@ ve.ce.MWImageNode.prototype.onFocus = function () {
ve.ce.MWImageNode.prototype.fetchDimensions = function () {
return this.getModel().getImageInfo()
.done( ve.bind( function ( imageInfo ) {
var dimensions = {
'width': imageInfo.width,
'height': imageInfo.height
};
var svgMaxSize, maxDimensions,
dimensions = {
'width': imageInfo.width,
'height': imageInfo.height
};
this.setOriginalDimensions( dimensions );
// Bitmaps can't be upscaled
if ( imageInfo.mediatype === 'BITMAP' ) {
this.setMaxDimensions( dimensions );
maxDimensions = dimensions;
} else if ( imageInfo.mediatype === 'DRAWING' ) {
svgMaxSize = mw.config.get( 'wgVisualEditor' ).svgMaxSize;
if ( this.getRatio() > 1 ) {
maxDimensions = {
'width': Math.round( svgMaxSize * this.getRatio() ),
'height': svgMaxSize
};
} else {
maxDimensions = {
'width': svgMaxSize,
'height': Math.round( svgMaxSize / this.getRatio() )
};
}
}
if ( maxDimensions ) {
this.setMaxDimensions( maxDimensions );
}
}, this ) );
};