[pmwiki-users] Clean URLS cookbook question

H. Fox haganfox at users.sourceforge.net
Sun Feb 5 16:16:58 CST 2006


On 2/5/06, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> On Sat, Feb 04, 2006 at 11:12:36PM -0700, H. Fox wrote:
> > On 2/4/06, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> > > The CleanUrls page currently has the information about $PubDirUrl
> > > and $UploadUrlFmt in a separate section at the bottom of the page.
> >
> > This was deliberate, not happenstance.  Explanation below...
> >
> > > Since using CleanUrls nearly always requires setting these
> > > variables,
> >
> > They *used to* nearly always need to be set for clean URLs to work.
> > My refined instructions were, in part, intended to eliminate that
> > necessity.  :-)
>
> Unfortunately, it's not working for $UploadUrlFmt.

Oh.  It worked when I tested it.  Not sure why...

> > $UploadUrlFmt is about the same.
> >
> >   SDV($UploadUrlFmt,preg_replace('#/[^/]*$#',"/$UploadDir",$ScriptUrl,1));
>
> The difference between $PubDirUrl and $UploadUrlFmt is that
> $PubDirUrl is set *before* local customizations are performed
> while $UploadUrlFmt is set *after* local customization are performed.
>
> So, $PubDirUrl is set using the value of $ScriptUrl that is coming
> from mod_rewrite (works), but $UploadUrlFmt is being set using the
> value of $ScriptUrl from config.php (doesn't work).

Oh, I see.  and I think I have a solution...

It looks to me like $PubDirUrl and UploadUrlFmt are nearly always the
same, except for one ends in "pub" and the other ends in "uploads". 
Is that the case?  If so, you could replace

SDV($UploadUrlFmt,preg_replace('#/[^/]*$#',"/$UploadDir",$ScriptUrl,1));

with something like

$UploadDirBase = basename($UploadDir);
SDV($UploadUrlFmt,preg_replace('#/[^/]*$#',"/$UploadDirBase",$PubDirUrl,1));

and nail it that way.

> I've set up a couple of test cases on pmichaud.com using the CleanUrl
> instructions for examples 1 and 2, you can see that uploads aren't
> working.
>
>     http://www.pmichaud.com/clean1/pmwiki
>     http://www.pmichaud.com/clean2

You're getting

    http://www.pmichaud.com/clean1/uploads/Main/pmwiki-32.gif
    http://www.pmichaud.com/uploads/Main/pmwiki-32.gif

instead of these

    http://www.pmichaud.com/clean1/pmwiki/uploads/Main/pmwiki-32.gif
    http://www.pmichaud.com/pmwiki/uploads/Main/pmwiki-32.gif

.  Based on these

    http://www.pmichaud.com/clean1/pmwiki/pub/
    http://www.pmichaud.com/pmwiki/pub/

The above code would work.  :-)

> > > AFAIK it's rare that $UploadDir has to be changed as a result of
> > > CleanUrls, so I'd leave that one out entirely.
> >
> > That variable is directly related to $UploadUrlFmt, so IMHO those two
> > should be explained together.
>
> While it's true that $UploadUrlFmt often depends on the setting of
> $UploadDir, the reverse isn't true.  With the exception of sites
> installed on sourceforge.net, I think it's quite rare that admins
> will be customizing $UploadDir -- usually that remains "uploads/
> in the current directory".  Instead, $UploadUrlFmt tends to be
> much more tightly integrated to changes with $ScriptUrl.

I think it more closely follows changes in $PubDirUrl.

> > To that end, I think it would be *much* easier to get uploads running
> > if $UploadDir and $UploadUrlFmt  were documented in sample-config.php.
>
> My only (admittedly minor) concern is that many people, even
> experts, tend to confuse urls and directories.  Listing these
> together might exacerbate that confusion.  Since $UploadDir
> rarely needs to be changed, I'm thinking it might be better
> left unmentioned.

I don't think so.  This is based on some related experience
(supporting Qdig -- or not needing to do so, whichever way you want to
look at it :-)  ).

This brings me to the subject of accurately guessing $ScriptUrl, which
I'll save for its own thread.

> Still, the version you propose makes sense to me, so I could
> see about including it.
>
> >   ##  $UploadDirFmt is the filesystem path and $UploadUrlFmt is the URL
> >   ##  where a browser would look for the same directory.
> >   # $UploadDir = '/filesystem/path/to/uploads';
> >   # $UploadUrlFmt = 'http://www.mydomain.com/path/to/uploads';

It would have averted some frustration for me personally.

Ideally it will rarely be necessary to set either one of them.  :-)

Hagan




More information about the pmwiki-users mailing list