Edgewall Software
Modify

Opened 18 years ago

Closed 18 years ago

#3643 closed enhancement (fixed)

InterWiki Link Colon Esacape

Reported by: trac@… Owned by: Christian Boos
Priority: low Milestone: 0.10
Component: wiki system Version: devel
Severity: minor Keywords: interwiki
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

How about providing some kind of escape mechanism for colons in InterWiki links.

Maybe something a little less horrible than using the following:

t = target.replace("!:", "\x00")
args = t.split(':')
args = [argn.replace("\x00", ":") for argn in args]

instead of just:

args = target.split(':')

in interwiki.py.

(Sorry, I'm just learning Python.)

Attachments (0)

Change History (11)

comment:1 by Matthew Good, 18 years ago

Keywords: needinfo added

Where are you trying to use a colon in InterWiki links that requires escaping?

I don't think that ":"s should be allowed in the InterWiki prefixes, since this will just lead to confusion. However, if there's another problem with the use of colons in InterWiki links please provide an explanation.

comment:2 by trac@…, 18 years ago

It's for our general Wiki, which is based on MediaWiki. We just use Trac for individual projects. MediaWiki was our first Wiki engine; it has a lot of history, and it is not practical to move that stuff to Trac.

MediaWiki uses colons in some of the URLs. For instance, my user page would be at User:Dmahn, so I'd like to use an InterWiki link of the form: MyOtherWiki:User:Dmahn.

I have two other ideas about this:

  1. Just create a different InterWiki link for each type of link with a colon.
  2. Try to check the InterWiki output format while parsing the link, and if there aren't any parameters then don't bother splitting any arguments for it.

InterWiki needs special attention for the colons. Plain URLs with colons (e.g. http://digidescorp.com/wiki/User:Dmahn) don't cause problems.

in reply to:  2 comment:3 by Christian Boos, 18 years ago

Keywords: interwiki added; needinfo removed
Milestone: 0.10.1
Owner: changed from Jonas Borgström to Christian Boos
Priority: normallow
Severity: normalminor

Replying to trac@digidescorp.com:

  1. Just create a different InterWiki link for each type of link with a colon.

Yes, why not something like:

User http://digidescorp.com/wiki/User: # User $1 in Main Wiki

…unless you have a great variety of such URLs.

Anyway, b. makes sense.

comment:4 by trac@…, 18 years ago

Yes I believe there are several:

  • Special:
  • User:
  • Category:

… And I'm not familiar enough with it to know if there are more. I think another option would be to create one kind of InterWiki link for this type of link, like:

MyWiki      http://digidescorp.com/wiki/
MyWikiTyped http://digidescorp.com/wiki/$1:$2

Then I can use MyWikiTyped:User:Dmahn.

This may be a way to keep down the number of links to remember/manage. However, after sleeping on it, I think option b. would ultimately be most intuitive:

        numargs = len( re.findall(InterWikiMap._argspec_re, url) )
        if numargs > 0:
            args = target.split(':', (numargs - 1))
        else:
            args = [target]

What do you think?

comment:5 by trac@…, 18 years ago

P.S. The code above for option b. seems to work like a charm!

comment:6 by Christian Boos, 18 years ago

Status: newassigned

Yes, something like that ;) Thanks for the code snippet.

comment:7 by trac@…, 18 years ago

No problem!

However, I've reconsidered about breaking out the extra arguments (i.e. (numargs - 1)). That could work badly for duplicated or missing arguments, so probably should just do all or nothing — split them all or none. Otherwise, would have to check the actual numbers of each argument and find the highest number.

I'm still a little perplexed about Python's callbacks. I mean, they don't seem to have any extra arguments to put pointers, etc. into. For instance … the re.sub() function could be used to find the max argument number (not replacing the strings, but examining them), but the function doesn't take an extra argument that could be used to accumulate the max value.

I'm having an unrelated problem like that, where there is a callback for each line of data, but I just want to accumulate them all (for FTP). I can use a globals() thing, but I would hate to do that.

comment:8 by trac@…, 18 years ago

OK, so just for my own edification, I mean some better options might be …

Either this (all or nothing):

        isargform = (len( re.findall(InterWikiMap._argspec_re, url) ) > 0)
        if isargform:
            args = target.split(':')
        else:
            args = [target]

Or this (which doesn't account for args intended to be omitted above the highest numbered):

        formalargs = re.findall(InterWikiMap._argspec_re, url)
        maxargnum = 0
        for a in formalargs:
            num = int(a[1:])
            if num > maxargnum:
                maxargnum = num
        if maxargnum > 0:
            args = target.split(':', (maxargnum - 1))
        else:
            args = [target]

comment:9 by trac@…, 18 years ago

Or … here's a variant of the second one with more of the "one-liner" feel that Python seems to promote:

        maxargnum = max( [int(a[1:]) for a in re.findall(InterWikiMap._argspec_re, url)].append(0) )
        if maxargnum > 0:
            args = target.split(':', (maxargnum - 1))
        else:
            args = [target]

This second option is probably not as "correct" as the first one (all or nothing), but I see it maybe having more of the "do what I mean" ability.

comment:10 by Dan <trac@…>, 18 years ago

Sorry … too greedy on that last one, as append() appears to return None.

        maxargnum = max( [0] + [int(a[1:]) for a in re.findall(InterWikiMap._argspec_re, url)] )
        if maxargnum > 0:
            args = target.split(':', (maxargnum - 1))
        else:
            args = [target]

comment:11 by Christian Boos, 18 years ago

Milestone: 0.10.10.10
Resolution: fixed
Status: assignedclosed

Fixed in [3711]. As there were some other bugfixes to do for InterWiki, I took this occasion to integrate your code. Thanks!

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos 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.