You are here: Foswiki>Tasks Web>Item15013 (29 Jan 2021, MichaelDaum)Edit Attach

Item15013: deprecate date format tokens in attachment format

Priority: Normal
Current State: New
Released In: 2.2.0
Target Release: minor
Applies To: Engine
Reported By: MichaelDaum
Waiting For:
Last Change By: MichaelDaum
This is a followup on Item15012 where DateManipPlugin might actually break attachment links. While digging deeper it became clear that the code in Foswiki::Attach is piping all of the content of ATTACHEDFILELINKFORMAT through Foswiki::Time::formatTime() in the (rare) case any format tokens as defined in System.VarGMTIME might be present. This causes a series of problems, i.e. any code in ATTACHEDFILELINKFORMAT that by accident recemples one of the VarGMTIME format tokens will inevitably be processed where ever it is in the ATTACHEDFILELINKFORMAT string. This is actually quite overactive just for the purpose of rendering the attachment's modification time. Also, the locale of the date time tokens will be those of the user who createrd the attachment link, not the one that views the date time information later on.

In real world scenarios those date format tokens are rarely used. So the impact of the patch inItem15012 is relatively low.

Proposed changes:

(1) There should be a new $filetime token that returns the epoch seconds of the attachment's modification time. Anybody interested in the actuall date time should be using extra macros that process epoch seconds to format the desired output.

(2) There is no macro instandard Foswiki that allows to render epoch second into a proper date string (that's why there is DateManipPlugin for one). The current date tokens are

  • DISPLAYTIME: displays either local or gmt time
  • GMTIME: displays the current gmt time
  • SERVERTIME: displays the local server time

None of these macros have a parameter such as epoch="..." which could be used to render the $filetime of an attachment. At least DISPLAYTIME should have an epoch parameter.

With these changes the plain format tokens such as $day $month $year - $hour:$min should be deprecated from ATTACHEDFILELINKFORMAT.

Deprecated format string:

   * Set ATTACHEDFILELINKFORMAT = [[$percntATTACHURL$percnt/$fileurl][$filename]], modified $day $month $year - $hour:$min

Proposed format string:

   * Set ATTACHEDFILELINKFORMAT = [[$percntATTACHURL$percnt/$fileurl][$filename]], modified $percntDISPLAYTIME{epoch="$filetime"}$percnt

Note that the default setting for ATTACHEDFILELINKFORMAT in System.DefaultPreferences does not include any date format tokens, and people rarely use this feature as far as I know.

This change will give the date time information a clean scope where within ATTACHEDFILELINKFORMAT the format string the information is to be inserted.

-- MichaelDaum - 29 Jan 2021


ItemTemplate edit

Summary deprecate date format tokens in attachment format
ReportedBy MichaelDaum
SVN Range
AppliesTo Engine
Priority Normal
CurrentState New
TargetRelease minor
ReleasedIn 2.2.0
Topic revision: r1 - 29 Jan 2021, 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