Modify

Opened 17 years ago

Last modified 4 years ago

#2066 new defect

problems with the links

Reported by: anonymous Owned by:
Priority: high Component: MediaWikiPluginMacro
Severity: normal Keywords:
Cc: Trac Release: 0.10

Description

First problem: when a link? is inserted in the mediawiki macro, a page like ...wiki/link/ is linked. That "/" is not needed. (line 956 of parser.py ?)

Second problem: the links are converted to lower case in the slugify_bit function, I don't know about the default on mediawiki, but it make it very hard to link inside de mediawiki macro trac's wiki pages (CamelCase everywhere).

Third problem: The last part of the address is deleted in the links to substitute it with the new link. Example1 . we are in .../wiki/MyPage1 and we link to MyPage2 , we take off MyPage1 and put MyPage2 there. Perfect Example2. We click "wiki" in the navigation bar. We go to .../wiki, we link to MyPage2, we take off wiki and put MyPage2 there. ... Page not found

Attachments (0)

Change History (4)

comment:1 Changed 17 years ago by anonymous

Resolution: wontfix
Status: newclosed

comment:2 Changed 17 years ago by anonymous

Resolution: wontfix
Status: closedreopened

comment:3 Changed 4 years ago by anonymous

As someone who's been mandated to use MediaWiki in addition to Trac, I find this plugin an interesting academic exercise. I originally added this plugin to our Trac projects a decade or more ago in hopes that it could be used for complex markup that our users would know how to do from their Mediawiki experience. However, this just didn't pan out, and now I realize that apparently a lot of the sophisticated stuff we do with MediaWiki goes way beyond the reaches of this plugin, and doesn't have so much to do with markup syntax but other features of the Mediawiki system itself (of which I'm still mostly blissfully unaware).

On the other hand, our mandate to use our Mediawiki is predicated on the idea that most people would be interested in editing WikiPedia, and would therefore know the syntax. I've learned over the years that WikiPedia is guarded by a rabid herd of "editors" who won't let you change much of anything in any article that proclaims, shall we say, the "mainstream narrative" (and I'm not really even talking about politics, but there are many areas of life where this kind of authority-driven thinking exists). That makes WikiPedia markup syntax moot for the most part, because I can't see most people being interested in editing it. Especially if you get threatened with being banned like I did originally because I didn't realize I was in a "revert war" with the elite corps of "editors" (young adults living in their parents' basements who apparently don't have much else to do with their lives?). ... Although I suppose WikiPedia is useful for truly uncontroversial topics, and to keep up on celebrities and certain current events.

Anyway, I was interested in this ticket and created some modifications that could be of interest to someone with regard to the links. The plugin as it has existed for the last decade is definitely broken with regards to links, since it can only make wiki ("internal") links relative to the current page (sub-pages). I think the links at least need to be relative to the Trac wiki.

In order to get the base href to the Trac wiki, I used formatter.req.href.base (I actually add a trailing slash to that) and passed that from the expand_macro() call to parse() and finally replaceInternalLinks(). Enjoy.

def slugifyBit(bit, to_lower_case=True):
    #bit = _removePat.sub(u'', bit)
    bit = _nonWordSpaceDashPat.sub(u'', bit)
    bit = _multiSpacePat.sub(u' ', bit)
    bit = bit.strip()
    bit = _spacePat.sub(u'-', bit)
    if to_lower_case:
        bit = bit.lower()
    return bit

def slugify(text, to_lower_case=True):
    return u'/'.join(slugifyBit(t, to_lower_case) for t in text.split(u'/'))

_linkPat = re.compile(ur'^([A-Za-z0-9\s]+:)?(#)?([A-Za-z0-9_\.\-\s\/\(\)]+)(?:\|([^\n]+?))?\]\](.*)$', re.UNICODE | re.DOTALL)
def replaceInternalLinks(text, base_href):
    arr = text.split('[[')
    sb = []
    sb.append(arr.pop(0))
    for bit in arr:
        namespace, anchorchar, link, alt, rest = None, None, None, None, None
        match = _linkPat.match(bit)
        if match:
            namespace, anchorchar, link, alt, rest = match.groups()
        if link:
            if not namespace:
                namespace = u'wiki'
            namespace = slugify(namespace)
            if namespace == "image":
                sb.append(u'<a href="/image/')
                sb.append(slugify(link, False))
                sb.append(u'"><img src="/static/')
                sb.append(link)
                if alt:
                    sb.append(u'" alt="')
                    sb.append(alt)
                sb.append(u'" /></a>')
            elif namespace == 'wiki' or namespace == 'ticket':
                sb.append(u'<a href="')
                if anchorchar:
                    sb.append(u'#')
                    sb.append(slugifyBit(link))
                    sb.append(u'">')
                else:
                    if len(link) > 1 and link[0] == '/':
                        # This is a page-relative link.
                        if link[-1] == '/':
                            # remove the page-relative notation
                            link = link[:-1]
                            if len(link) > 1:
                                link = link[1:]
                            sb.append(slugify(link, False))
                        else:
                            sb.append(slugify(link[1:], False))
                    elif base_href:
                        sb.append(base_href)
                        sb.append(namespace)
                        sb.append(u'/')
                        sb.append(slugify(link, False))
                    else:
                        sb.append(slugify(link, False))
                    sb.append(u'">')
                if alt:
                    link = alt
                sb.append(link)
                sb.append(u'</a>')
            sb.append(rest)
        else:
            sb.append(u'[[')
            sb.append(bit)
    return u''.join(sb)

comment:4 Changed 4 years ago by Ryan J Ollos

Owner: permon deleted
Status: reopenednew

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.