Item15012: remove time tokens in ATTACHEDFILELINKFORMAT

pencil
Priority: Normal
Current State: Closed
Released In: 2.1.7
Target Release: patch
Applies To: Extension
Component:
Branches: Release02x01 master
Reported By: ChristianKern
Waiting For:
Last Change By: MichaelDaum
When I attach a file to a wiki topic and set the check mark at "Create a link to the attached file Images will be displayed, for other attachments a link will be created." then the link which is created does not link to %ATTACHURL... but to WednesdayTTACHURL...

Obviously, the %A is interpreted as a date instruction.

The problem disappears when I deactivate DateManipPlugin and reappears when I reactivate it :-/

I've tested this on a freshly created topic, but in a foswiki with several other plugins ...

-- ChristianKern - 27 Jan 2021

Are there any other customizations or plugins on your system? What are the values of

%ATTACHEDFILELINKFORMAT%
%ATTACHEDIMAGEFORMAT%

on your system?

-- MichaelDaum - 27 Jan 2021

Here's a hotfix:

diff --git a/core/lib/Foswiki/Attach.pm b/core/lib/Foswiki/Attach.pm
index 479a4de53..8ca4a180a 100644
--- a/core/lib/Foswiki/Attach.pm
+++ b/core/lib/Foswiki/Attach.pm
@@ -413,11 +413,12 @@ sub getAttachmentLink {
 
     # I18N: Site specified %ATTACHEDIMAGEFORMAT% or %ATTACHEDFILELINKFORMAT%,
     # ensure that filename is URL encoded - first $name must be URL.
-    $fileLink =~ s/\$name/$attName/;        # deprecated
-    $fileLink =~ s/\$name/$attName/;        # deprecated, see Item1814
+    $fileLink =~ s/\$name/$attName/g;        # deprecated
+    $fileLink =~ s/\$name/$attName/g;        # deprecated, see Item1814
     $fileLink =~ s/\$filename/$attName/g;
     $fileLink =~ s/\$fileurl/$attName/g;
-    $fileLink =~ s/\$fileext/$fileExt/;
+    $fileLink =~ s/\$fileext/$fileExt/g;
+    $fileLink =~ s/\$filetime/$fileTime/g;
 
     # Expand \t and \n early (only in the format, not
     # in the comment) - TWikibug:Item4581
@@ -427,8 +428,8 @@ sub getAttachmentLink {
     $fileLink =~ s/\$size/$imgSize/g;
     $fileLink =~ s/([^\n])$/$1\n/;
 
-    require Foswiki::Time;
-    $fileLink = Foswiki::Time::formatTime( $fileTime, $fileLink );
+    #require Foswiki::Time;
+    #$fileLink = Foswiki::Time::formatTime( $fileTime, $fileLink );
     $fileLink = Foswiki::expandStandardEscapes($fileLink);
 
     return $fileLink;

Note that this might break support for VarGMTIME tokens in the. Instead you will have to use a new $filetime token to create any date-time info.

Explanation: all of the ATTACHEDFILELINKFORMAT is processsed by Foswiki::Time::formatTime() in the hope that it will ignore any other format tokens. This is quite over the top. Instead there should be a way to format epoch seconds into the desired string. Bad news: there is no such thing in core Foswiki. None of the XXXDATE macros provides a parameter to specify the actual date time to be formatted. %SERVERTIME, %GMTIME, %DATE, %DISPLAYTIME all take the current time, not any other epoch seconds. So there is no way to render the file time properly, such as in:

   Set ATTACHEDFILELINKFORMAT = \n   * [[%ATTACHURLPATH%/$fileurl][$filename]], modified $percntDISPLAYTIME{epoch=\"$filetime\"}$percnt

This actually would be my prefered solution to fix the code.

-- MichaelDaum - 27 Jan 2021

Thumbs up! The fix above works. Thank you for that quick solution.

-- ChristianKern - 28 Jan 2021

Regarding your questions above:

> Are there any other customizations or plugins on your system?

Just a few smile

SpreadSheetPlugin, CommentPlugin, ActionTrackerPlugin, SlideShowPlugin, AutoViewTemplatePlugin, CalendarPlugin, ChartPlugin, ChecklistPlugin, CompareRevisionsAddonPlugin, ConfigurePlugin, ControlWikiWordPlugin, DateManipPlugin, DirectedGraphPlugin, DpSyntaxHighlighterPlugin, EditChapterPlugin, EditTablePlugin, ExplicitNumberingPlugin, FilterPlugin, GenPDFAddOnPlugin, HistoryPlugin, HolidaylistPlugin, ImagePlugin, InterwikiPlugin, JEditableContribPlugin, JQueryLibPlugin, JQueryPlugin, LazyLoadPlugin, MailerContribPlugin, NatEditPlugin, PageOptimizerPlugin, PreferencesPlugin, RedirectPlugin, RenderListPlugin, RenderPlugin, SmiliesPlugin, TablePlugin, TagCloudPlugin, TagMePlugin, TreeBrowserPlugin, TreePlugin, TwistyPlugin, VotePlugin

%ATTACHEDFILELINKFORMAT% yields:

\n * $filename: $comment

%ATTACHEDIMAGEFORMAT% yields:

\n * $comment: Error: (3) can't find $fileurl in Sandbox

-- ChristianKern - 28 Jan 2021

Further changes on the Foswiki core mitigating the problem will be discussed on Item15013.

-- MichaelDaum - 29 Jan 2021

Note that another solution to circumvent the problem is by installing Extensions.TopicInteractionPlugin as it does not use the Foswiki core code to insert attachment links.

-- MichaelDaum - 29 Jan 2021

I've reissued this task so that we can get rid of the old time tokens asap. This in parts reverts Item5935.

-- MichaelDaum - 01 Mar 2021
 
Topic revision: r6 - 31 Mar 2022, MichaelDaum
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