Attach.pm allows created links to be formatted using the ATTACHIMAGEFORMAT preference variable.
Intended for internationalization, it turns out that it can be useful for other purposes, such as invoking the thumbnail plugin.
The $size string is almost usable as a macro argument - except that it uses single instead of double quotes and the macro parser won't handle this.
--- lib/TWiki/Attach.pm~ 2008-09-11 23:41:58.000000000 -0400
+++ lib/TWiki/Attach.pm 2010-06-27 07:00:49.000000000 -0400
@@ -298,11 +298,11 @@
my( $nx, $ny ) = &_imgsize( $stream, $attName );
my @attrs;
if( $nx > 0 && $ny > 0 ) {
push( @attrs, width=>$nx, height=>$ny );
- $imgSize = "width='$nx' height='$ny'";
+ $imgSize = "width=\"$nx\" height=\"$ny\"";
}
$fileLink = $prefs->getPreferencesValue( 'ATTACHEDIMAGEFORMAT' );
unless( $fileLink ) {
push( @attrs, src=>"%ATTACHURLPATH%/$fileURL" );
Also, note that
$comment
should be expanded
after $size
; currently a comment containing
$size
will include
width='n' height='m'
, which probably is not what was intended.
For extra points, implement
$width
and
$height
.
For serious points, allow conditional expansion. Here's the actual application (wrapped for display):
* Set ATTACHEDIMAGEFORMAT = \n * %IF{"$ 'THUMBNAIL_PLUGIN_ENABLE'"
then="%THUMBVIEW{"$name" $size caption="$comment"}%"
else="$comment: <br />\n <img src="%ATTACHURLPATH%/$name" alt="$name" $size />"}%
This puts the entire %IF into the topic text as the link; ideally one would like only the expansion of the %IF (but not the expansion of %ATTACHURLPATH).
--
TWiki:Main/TimotheLitt
- 27 Jun 2010
Thank you Timothe for reporting the issue and for providing the patch.
1. The single/double quote issue should go into trunk and 5.0 branch.
2.
$comment
should be expanded
after $size
: Yes, should go into trunk and 5.0 branch.
3. Implement
$width
and
$height
: Good idea. Should go into trunk and 5.0 branch. Should be documented in
TWikiPreferences.
4. THUMBVIEW support: I am not in favor of having IF statement in the topic text for images, because the IMG tag is handled properly by the WYSIWYG editor. For example, you can resize the image. This no longer works if we have the IMG tag hidden in an IF.
I suggest to file an enhancement request for item 4 to have control over variable expansion for the ATTACHEDIMAGEFORMAT setting. Preferably a generic spec that works for other settings too. It is a bit complex because in the ATTACHEDIMAGEFORMAT case we want to have IF expanded, but not THUMBVIEW and ATTACHURLPATH.
Since you have SVN core access, could you commit items 1, 2, 3? Item 4 should be handled as an enhancement request with new TWikibug item.
--
TWiki:Main.PeterThoeny
- 28 Jun 2010
[1] and [2] done. I could not test what timotthe suggested, need to install plugin etc. will check this later.
--
TWiki:Main.SopanShewale
- 29 Jun 2010
[3] is done too, thanks to patch Timothe sent via e-mail. Thanks Timothe!
Doc update in
TWiki.TWikiPreferences is done too. Now in SVN trunk and 5.0 branch.
--
TWiki:Main.PeterThoeny
- 30 Jun 2010