Edgewall Software
Modify

Opened 9 years ago

Last modified 7 years ago

#10670 new enhancement

Image macro references inconsistent with attachment links

Reported by: Mikael Relbe Owned by:
Priority: normal Milestone: next-major-releases
Component: wiki system Version: 0.13dev
Severity: normal Keywords: imagemacro bitesized
Cc: Ryan J Ollos Branch:
Release Notes:
API Changes:
Internal Changes:

Description

The format of the reference for Image macro is not aligned with that of attachment: links.

External reference to attachment is stated as "attachment:file:module:id". It would be nice if one could copy an attachment link to the Image macro by just ripping away "attachment:"

Now, one has to swap parts of the attachment reference to suit the Image macro:

attachment:file:module:id > [[Image(module:id:file)]]

This is annoying/confusing.

My view is that the Image macro is fault since both attachment: and comment: links use the same pattern. (Hard to accept, I imagine, since that would break existing image references to external resources.)

Attachments (0)

Change History (7)

comment:1 by Mikael Relbe, 9 years ago

Type: defectenhancement

Sorry, didn't mean to report this as a defect, this is of cource an enhancement proposal (however painful…)

comment:2 by Ryan J Ollos <ryano@…>, 9 years ago

Cc: ryano@… added

comment:3 by Christian Boos, 9 years ago

Milestone: next-dev-1.1.x

So we should support [[Image(file:module:id)]]attachment:file:module:id.

As a first step, it shouldn't be that problematic to try supporting both.

Given 1:2:3, check whether:

  • 2:3 refers to a resource (using extract_link) (new syntax)
  • if not, that 1:2 refers to a resource (old syntax)

comment:4 by Ryan J Ollos <ryano@…>, 9 years ago

Keywords: bitesized added

comment:5 by Ryan J Ollos <ryano@…>, 9 years ago

It looks like module:id:file is a legacy TracLink syntax, supported by the attachment module trunk/trac/attachment.py@11112:966-975#L962. From the documentation for the attachment TracLink: Note that the older way, putting the filename at the end, is still supported: attachment:ticket:753:the_file.txt.

I started an implementation that is patterned after that for the attachment module. I couldn't see a way to do it using extract_link that was as clean. There seems to be some undocumented intertrac support, however it doesn't seem to work, and I can't understand how the ImageMacro could even benefit from intertrac support.

So here is a partial patch that would not preserve the existing intertrac functionality, but I'm hoping to get some feedback on how to deal with that before proceeding.

  • trac-trunk/trac/wiki/macros.py

     
    2626
    2727from trac.core import *
    2828from trac.resource import (
    29     Resource, ResourceNotFound, get_resource_name, get_resource_summary,
    30     get_resource_url
     29    Resource, ResourceNotFound, ResourceSystem, get_resource_name,
     30    get_resource_summary, get_resource_url
    3131)
    3232from trac.util.datefmt import format_date, from_utimestamp, user_time
    3333from trac.util.html import escape, find_element
     
    595595            if params:
    596596                url += '?' + params
    597597            raw_url, desc = url, filespec
    598         elif len(parts) == 3:                 # realm:id:attachment-filename
    599             #                                 # or intertrac:realm:id
    600             realm, id, filename = parts
     598        elif len(parts) == 3:
     599            known_realms = ResourceSystem(self.env).get_known_realms()
     600            if parts[1] in known_realms: # new-style: filename:realm:id
     601                filename, realm, id = parts
     602            else: # old-style: realm:id:filename       
     603                realm, id, filename = parts
    601604            intertrac_target = "%s:%s" % (id, filename)
    602             it = formatter.get_intertrac_url(realm, intertrac_target)
     605            it = formatter.get_intertrac_url(realm, intertrac_target) # intertrac:realm:id
    603606            if it:
    604607                url, desc = it
    605608                raw_url = url + unicode_quote('?format=raw')

comment:7 by Ryan J Ollos, 7 years ago

Cc: Ryan J Ollos added; ryano@… removed

comment:8 by Ryan J Ollos, 7 years ago

Milestone: next-dev-1.1.xnext-major-releases

Retargetting tickets to narrow focus for milestone:1.2. Please move the ticket back to milestone:next-dev-1.1.x if you intend to resolve it by milestone:1.2.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.