From d169108eebc64c9187515f9cb3c2f6e474f8b716 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Sun, 26 Jan 2014 22:59:30 +0000 Subject: [PATCH] Implement SVGMaxSize wgSVGMaxSize sets the maximum size for the shortest edge of a vector image. Pass this through to MWImageNodes. Change-Id: I6410e7cda137cf4828d12280cb1e5cfc27805859 --- VisualEditor.hooks.php | 5 ++-- modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js | 31 +++++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) 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 ) ); };