UseModWiki | WikiPatches | RecentChanges | Preferences

The $SlashLinks config variable introduced with UseModWiki 1.0 only controls how page links are generated, but doesn't make the script actually interpret them. See also WikiBugs/SlashLinksDoNotWork.

To fix this behavior, add the following (highlighted) code in the InitRequest function:

  sub InitRequest {
    my @ScriptPath = split('/', "$ENV{SCRIPT_NAME}");
    $CGI::POST_MAX = $MaxPost;
    if ($UseUpload) {
      $CGI::DISABLE_UPLOADS = 0;  # allow uploads
    } else {
      $CGI::DISABLE_UPLOADS = 1;  # no uploads
    # Modify query string and script path for slashed links
    if ($SlashLinks && (length($ENV{'PATH_INFO'}) > 1)) {
      $ENV{'QUERY_STRING'} .= '&' if ($ENV{'QUERY_STRING'});
      $ENV{'QUERY_STRING'} .= substr($ENV{'PATH_INFO'}, 1);
    $q = new CGI;
    # Fix some issues with editing UTF8 pages (if charset specified)
    if ($HttpCharset ne '') {
    $Now = time;                     # Reset in case script is persistent
    $ScriptName = pop(@ScriptPath);  # Name used in links
    # Fix script name for relative links when slashed page links are used
    if ($SlashLinks) {
      my $numberOfSlashes = ($ENV{PATH_INFO} =~ tr[/][/]);
      $ScriptName = ('../' x $numberOfSlashes) . $ScriptName;
    $IndexInit = 0;                  # Must be reset for each request

While I agree that modifying environment variables is a bit hacky, at least it provides for a concise fix. :-) --MichaelBuschbeck

This patch works great under mod_cgi, but appears to fail under mod_perl. For some reason it just ignores slashed links as if the parameters weren't passed. After noticing that the query string still worked I thought to be more explicit when instantiating the CGI object in sub InitRequest and it actually worked:


 $q = new CGI;


if   ($ENV{'REQUEST_METHOD'} eq 'GET') {
  $q = new CGI($ENV{'QUERY_STRING'});
elsif($ENV{'REQUEST_METHOD'} eq 'POST') {
  read (STDIN, $q, $ENV{'CONTENT_LENGTH'});
  $q = new CGI($q);

This eliminates the need for the second part of your patch to "Fix script name for relative links". Thanks for your work on this--JAPH

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited September 2, 2007 4:41 pm by MarkusLude (diff)