Edgewall Software
Modify

Opened 10 years ago

Closed 10 years ago

#12025 closed enhancement (fixed)

Image macro should support InterMapTxt

Reported by: anonymous Owned by: Ryan J Ollos
Priority: normal Milestone: 1.1.5
Component: wiki system Version:
Severity: normal Keywords: interwiki imagemacro
Cc: Branch:
Release Notes:

Image macro supports InterWiki prefixes.

API Changes:
Internal Changes:

Description

The image macro does not seem to support InterMapTxt prefixes. This would allow to easily extend the image macro with new capabilities e.g. for frequently linked badges, build status icons etc.)

Attachments (0)

Change History (17)

comment:1 by anonymous, 10 years ago

As a workaround a custom plugin can be written:

from trac.core import *
from trac.wiki.macros import WikiMacroBase
from trac.wiki.formatter import format_to_oneliner
from trac.wiki.interwiki import InterWikiMap

class SpecialImageMacro(WikiMacroBase):
    """Expands to `[[Image(SpecialImage:$1,link=SpecialImageLink:$1)]]`.
   
    Two InterMapTxt prefixes must be defined:
    {{{
    SpecialImage      http://example.com/$1.png
    SpecialImageLink  http://example.com/$1.html
    }}}
    """
    def expand_macro(self, formatter, name, content, args):
        intermap = InterWikiMap(self.env)
        src = intermap.url("SpecialImage", content)[0]
        link = intermap.url("SpecialImageLink", content)[0]
        wiki = "[[Image(%s,link=%s,title=Special Image %s)]]" % (src, link, content)
        return format_to_oneliner(self.env, formatter.context, wiki)

comment:2 by Jun Omae, 10 years ago

Keywords: interwiki added; intermaptxt removed

comment:3 by Ryan J Ollos, 10 years ago

Milestone: next-major-releases

comment:4 by anonymous, 10 years ago

For example with this prefix:

shields https://img.shields.io/

Wiki markup like this:

[[Image(shields:travis/edgewall/trac.svg)]]
[[Image(shields:pypi/dm/trac.svg)]]
[[Image(shields:pypi/v/trac.svg)]]

should become: https://img.shields.io/travis/edgewall/trac.svg https://img.shields.io/pypi/dm/trac.svg https://img.shields.io/pypi/v/trac.svg etc.

comment:5 by Jun Omae, 10 years ago

Milestone: next-major-releasesunscheduled

comment:6 by anonymous, 10 years ago

  • trac/wiki/macros.py

    diff -r aebe73fe2b02 trac/wiki/macros.py
    a b  
    3838from trac.wiki.formatter import (
    3939    format_to_html, format_to_oneliner, extract_link, OutlineFormatter
    4040)
     41from trac.wiki.interwiki import InterWikiMap
    4142
    4243
    4344# TODO: should be moved in .api
     
    632633                attachment = Resource(realm, id).child('attachment', filename)
    633634        elif len(parts) == 2:
    634635            realm, filename = parts
     636            interwikimap = InterWikiMap(self.env)
    635637            if realm in browser_links:  # source:path
    636638                # TODO: use context here as well
    637639                rev = None
     
    641643                raw_url = formatter.href.browser(filename, rev=rev,
    642644                                                 format='raw')
    643645                desc = filespec
     646            elif realm in interwikimap:
     647                url, desc = interwikimap.url(realm, filename)
     648                raw_url = url
    644649            else:  # #ticket:attachment or WikiPage:attachment
    645650                # FIXME: do something generic about shorthand forms...
    646651                realm = None

comment:7 by Ryan J Ollos, 10 years ago

Milestone: unscheduled1.1.5
Owner: set to Ryan J Ollos
Status: newassigned

Tests and documentation update were also needed. Proposed changes in log:rjollos.git:t12025.

comment:8 by Ryan J Ollos, 10 years ago

Keywords: imagemacro added

comment:9 by Ryan J Ollos, 10 years ago

Release Notes: modified (diff)

comment:10 by Ryan J Ollos, 10 years ago

Resolution: fixed
Status: assignedclosed

Committed to trunk in [13988].

comment:11 by Jun Omae, 10 years ago

I think we should respect [wiki] safe_schemes option when using InterMapTxt.

in reply to:  11 ; comment:12 by Ryan J Ollos, 10 years ago

Replying to jomae:

I think we should respect [wiki] safe_schemes option when using InterMapTxt.

That sounds good, but is that a change needed in ImageMacro or InterWikiMap? If the change is in InterWikiMap, we should create a new ticket.

Last edited 10 years ago by Ryan J Ollos (previous) (diff)

in reply to:  12 comment:13 by Jun Omae, 10 years ago

Replying to rjollos:

That sounds good, but is that a change needed in ImageMacro or InterWikiMap? If the change is in InterWikiMap, we should create a new ticket.

I've created #12053.

I noticed InterWiki allows multiple parameters. However, image macro cannot accept interwiki with multiple parameters for image. Also, the link parameter allows interwiki link with multiple parameters like this.

[[Image(/chrome/common/trac_logo_mini.png, link=gmessage:trac-users:183g75yH65w/YgJ-q8AREpwJ)]]

/chrome/common/trac_logo_mini.png

Last edited 10 years ago by Jun Omae (previous) (diff)

comment:14 by Ryan J Ollos, 10 years ago

Resolution: fixed
Status: closedreopened

comment:15 by Jun Omae, 10 years ago

Proposed changes in [b12d7d12c/jomae.git] to support interwiki link with multiple parameters in image macro.

comment:16 by Ryan J Ollos, 10 years ago

The changes look good to me.

comment:17 by Jun Omae, 10 years ago

Resolution: fixed
Status: reopenedclosed

Thanks for the reviewing. Committed in [14047].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


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