You are here: Foswiki>Tasks Web>Item9208 (15 Mar 2011, GeorgeClark)Edit Attach

Item9208: Attach.pm size tag not usable by macros

pencil
Priority: Enhancement
Current State: Confirmed
Released In: n/a
Target Release: n/a
Applies To: Engine
Component: TopicAttachment
Branches:
Reported By: TimotheLitt
Waiting For:
Last Change By: GeorgeClark
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{"$ 'THUMBNAILPLUGIN_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).

-- TimotheLitt - 27 Jun 2010

Changed to enhancement. A full patch would be useful to get this included.

-- KennethLavrsen - 27 Jun 2010

Fair enough. Here's a consolidated patch file for all but the last item; I'm not quite sure how best to do the conditional expansion. As a work-around, I now manually set ATTACHEDIMAGEFORMAT everyplace I set THUMBNAILPLUGIN_ENABLE - which I'll probably regret the first time I have to change it globally frown, sad smile

-- TimotheLitt - 29 Jun 2010
 

ItemTemplate edit

Summary Attach.pm size tag not usable by macros
ReportedBy TimotheLitt
Codebase trunk
SVN Range
AppliesTo Engine
Component TopicAttachment
Priority Enhancement
CurrentState Confirmed
WaitingFor
Checkins
TargetRelease n/a
ReleasedIn n/a
Topic revision: r4 - 15 Mar 2011, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy