jenkins-bot has submitted this change and it was merged.
Change subject: Support for image resizing
......................................................................
Support for image resizing
This reverts commit 10a271a82adbf3462d37c6e82939102fc2d4daa1.
Change-Id: Id95de48c956dcb9ad6dd62f81bee6ce68d793cb0
---
M js/lib/ext.core.LinkHandler.js
M js/lib/mediawiki.WikitextSerializer.js
M js/tests/mockAPI.js
M js/tests/parserTests.txt
4 files changed, 45 insertions(+), 19 deletions(-)
Approvals:
GWicke: Looks good to me, approved
jenkins-bot: Verified
diff --git a/js/lib/ext.core.LinkHandler.js b/js/lib/ext.core.LinkHandler.js
index 6311c8b..47978e3 100644
--- a/js/lib/ext.core.LinkHandler.js
+++ b/js/lib/ext.core.LinkHandler.js
@@ -446,12 +446,10 @@
function handleDims( height, width, info, dataAttribs ) {
if ( info.height ) {
height = info.height;
- dataAttribs.img.h = height;
}
if ( info.width ) {
width = info.width;
- dataAttribs.img.w = width;
}
if ( info.thumburl && info.thumbheight ) {
@@ -461,7 +459,10 @@
if ( info.thumburl && info.thumbwidth ) {
width = info.thumbwidth;
}
-
+ // Keep final size of the image in dataAttribs so it can be used on the
way back to compare with
+ // new size (width and height of img tag) to detect if image was
resized.
+ dataAttribs.img.h = height;
+ dataAttribs.img.w = width;
return {
h: height,
w: width
diff --git a/js/lib/mediawiki.WikitextSerializer.js
b/js/lib/mediawiki.WikitextSerializer.js
index 03f0e60..22cb06c 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -1105,6 +1105,14 @@
}
break;
+ /* TODO: Cleanup - size, width and height should be combined
into one option */
+ case 'size':
+ cb( optName.replace(
+ '$1',
+ optVal + 'x' + optVal
+ ) );
+ break;
+
case 'width':
val = DU.getAttributeShadowInfo( imgnode, 'width' );
@@ -1153,6 +1161,17 @@
}
}
return false;
+};
+
+WSP.removeOpt = function ( opts, optName ) {
+ var ix;
+
+ for ( ix = 0; ix < opts.length; ix++ ) {
+ if ( opts[ix].ck === optName ) {
+ opts = opts.splice( ix, 1 );
+ return;
+ }
+ }
};
// XXX: This should probably be refactored. -rsmith
@@ -1341,22 +1360,19 @@
htAttr = imgnode.getAttribute( 'height' );
wdAttr = imgnode.getAttribute( 'width' );
- if ( htAttr && !this.hasOpt( opts, 'height' ) ) {
+ // Detect image size change
+ if ( !dp.img.h || !dp.img.w || dp.img.h.toString() !==
htAttr.toString() || dp.img.w.toString() !== wdAttr.toString() ) {
+ // If size of the image was changed handle it as a
'size' option and remove two other
+ // options - 'height' and 'width'.
+ this.removeOpt( opts, 'height' );
+ this.removeOpt( opts, 'width' );
+
dp.img.htset = true;
-
- opts.push( {
- ck: 'height',
- v: 'x' + htAttr,
- ak: mwAliases.img_width.last()
- } );
- }
-
- if ( wdAttr && !this.hasOpt( opts, 'width' ) ) {
dp.img.wdset = true;
opts.push( {
- ck: 'width',
- v: wdAttr,
+ ck: 'size',
+ v: Math.max( htAttr, wdAttr ),
ak: mwAliases.img_width.last()
} );
}
diff --git a/js/tests/mockAPI.js b/js/tests/mockAPI.js
index 60c58fc..9dbe2ff 100644
--- a/js/tests/mockAPI.js
+++ b/js/tests/mockAPI.js
@@ -100,12 +100,12 @@
if ( twidth ) {
if ( theight === undefined || theight === null
) {
- theight = Math.ceil( height * ( twidth
/ width ) );
+ theight = Math.round( height * twidth /
width );
} else {
- if ( Math.ceil( height * ( twidth /
width ) ) > theight ) {
- twidth = Math.ceil( width * (
theight / height ) );
+ if ( Math.round( height * twidth /
width ) > theight ) {
+ twidth = Math.ceil( width *
theight / height );
} else {
- theight = Math.ceil( height * (
twidth / width ) );
+ theight = Math.round( height *
twidth / width );
}
}
diff --git a/js/tests/parserTests.txt b/js/tests/parserTests.txt
index 2f0c471..36ca53d 100644
--- a/js/tests/parserTests.txt
+++ b/js/tests/parserTests.txt
@@ -15808,6 +15808,15 @@
</p>
!!end
+!! test
+Image: Modyfing size of an imge
+!! options
+parsoid=html2wt
+!! input
+[[Image:Wiki.png|230x230px]]
+!! result
+<p data-parsoid='{"dsr":[0,24,0,0]}'><span typeof="mw:Image"
data-parsoid='{"optList":[{"ck":"width","ak":"100px"}],"cacheKey":"[[Image:Wiki.png|100px]]","img":{"h":115,"w":100,"wdset":true},"dsr":[0,24,null,null]}'><a
href="./File:Wiki.png" data-parsoid='{"a":{"href":"./File:Wiki.png"}}'><img
resource="./File:Wiki.png"
src="//upload.wikimedia.org/wikipedia/en/thumb/b/bc/Wiki.png/100px-Wiki.png"
height="230" width="200"
data-parsoid='{"a":{"resource":"./File:Wiki.png"},"sa":{"resource":"Image:Wiki.png"}}'></a></span></p>
+!!end
TODO:
more images
--
To view, visit https://gerrit.wikimedia.org/r/70784
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id95de48c956dcb9ad6dd62f81bee6ce68d793cb0
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Inez <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits