diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 892cd22d63..e71050e484 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -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; diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js index 0fd2ed6721..152d8f6563 100644 --- a/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js +++ b/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js @@ -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 ) ); };