When an attachment URL such as
%ATTACHURL%/filename.txt
is INCLUDE'd, TWiki retrieves the attachment directly rather than issuing an HTTP request to itself.
But that shortcut works only for
.txt
,
.htm
, and
.html
.
Attachment files of other extensions result in HTTP requests to itself.
This behavior is not optimal.
A better behavior
INCLUDE is supposed to:
- Handle all attachment URLs on the TWiki site directly regardless of file name extension
- Determine MIME type of an attachment based on file name extension in the same manner as the
viewfile
script and behave accordingly
- Observe the
allowanytype
parameter even when it retrieves an attachment directly
Implementation details
File name extension to MIME type conversion takes place in
TWiki::UI::View::_suffixToMimeType()
.
For INCLUDE to behave consistently with the
viewfile
script regarding file name extension to MIME type correspondence, that function needs to be used by INCLUDE.
TWiki::UI::View::_suffixToMimeType()
should change in the following two aspects.
-
TWiki::UI::View::_suffixToMimeType()
is a local function of TWiki::UI::View
and not supposed be called from TWiki::_includeUrl()
. As such, TWiki::UI::View::_suffixToMimeType()
should be moved to TWiki::suffixToMimeType()
.
-
TWiki::UI::View::_suffixToMimeType()
takes two arguments: $session
and $fileName
. There is no need for $session
to determine MIME type. So TWiki::suffixToMimeType()
takes one argument, $fileName
, only.
--
TWiki:Main/HideyoImazu
- 2014-11-30