On Oct 14, 2009, at 02:57 , Andrew Jaquith wrote:

So, I want to understand this, and I think I'm close.

If page "HyperlinkToo" exists, JSPWikiMarkupParser will render
"hyperlink   too" as:

"HyperlinkToo"

...but if "HyperlinkToo" does not exist, it will render as:

"Hyperlink too"

Is that right? It is, in essence, producing different canonical page
names depending on whether the page exists. That is strange.

Close, but not quite.

[hyperlink too] gets rendered as "Hyperlink too", iff page "Hyperlink too" exists (in a case-insensitive manner). If it does not exist, we check for the existence of "HyperlinkToo", and if it does, we then use that. To grab the relevant code from 2.8:

                   // Straight-away check for "Hyperlink too"
        boolean isThere = simplePageExists( page );
        String  finalName = page;

        // "hyperlink too" && "hyperlink toos"
        if ( !isThere && m_matchEnglishPlurals )
        {
            if ( page.endsWith( "s" ) )
            {
                finalName = page.substring( 0, page.length() - 1 );
            }
            else
            {
                finalName += "s";
            }

            isThere = simplePageExists( finalName );
        }

        // This is where we check for the alternate name.
        // "HyperlinkToo" & "HyperlinkToos"

        if( !isThere )
        {
            finalName = MarkupParser.wikifyLink( page );
            isThere = simplePageExists(finalName);

            if( !isThere && m_matchEnglishPlurals )
            {
                if( finalName.endsWith( "s" ) )
                {
finalName = finalName.substring( 0, finalName.length() - 1 );
                }
                else
                {
                    finalName += "s";
                }

                isThere = simplePageExists( finalName );
            }
        }

        return isThere ? finalName : null;

It also makes creating (say) a singleton caching WikiPath factory
difficult because you'd need to know whether the page exists (and
hence hold a reference to the ContentManager) before you could figure
out what to canonicalize the path to.

I would hesitate doing that in the first place. I learned that the hard way doing Priha - there are some fairly interesting and hairy issues as to when to empty the cache resulting in really hard-to-debug problems - and the performance gain is probably not that big anyway. Let's not do it now.

I expect this is all stuff you considered before -- but want to make
sure I understand before I correct any more unit tests.


The reason why this is done is quite simple: we don't want to break old pages or old URLs. This allows you to simply grab your old wikimarkup without having to change anything. However, new pages will be created with spaces in names, if you use the [ ] -linking style and have a space. But of course [HyperlinkToo] and HyperlinkToo still link to a page called "HyperlinkToo", and it would not match "Hyperlink too". But [Hyperlink too] would first check for "Hyperlink Too" and after that check for "HyperlinkToo".

The 2.6-2.8 way is very literal and quite easy to remember. It just works :-). I haven't had complaints (other than from Murray, but his requirement is for XML names, so it's not something most people would really ask for).

/Janne

Reply via email to