Tags:
create new tag
view all tags
Core team,

While browsing through the edit script, I started wondering why there were two methods for calling "redirect" on an error condition. The first is to call TWiki::redirect and the second is to print $query->redirect.

On delving further, I got more confused than ever. First off, TWiki::redirect says in its pod comment:

Redirects the request to $url, via the CGI module object $query unless
overridden by a plugin.  Note that this is currently only called by
Func::redirectCgiQuery() at the request of a plugin!  All of the redirects
done internally by TWiki are not overridable.
but then it gets called everywhere (95 times in bin). I can understand an out-of-date comment, but can someone please document the correct protocol for calling TWiki::redirect?

Second, there's a frequently duplicated code fragment:

    my( $mirrorSiteName, $mirrorViewURL ) = &TWiki::readOnlyMirrorWeb( $webName );
    if( $mirrorSiteName ) {
        my $url = &TWiki::getOopsUrl( $webName, $topic, "oopsmirror", $mirrorSiteName, $mirrorViewURL );
        print $query->redirect( $url );
        return;
    }
which has been there since 2001, and relates to mirror webs. Questions:
  1. Is anyone actually using this code? Do we know mirror sites work i.e. do we test them?
  2. I assume it's using a $query->redirect because a mirror site won't have active plugins, right? if that is the case, then in most scripts there are other detected error conditions which will do a TWiki::redirect before the mirror site is checked. So surely those calls will also fall over strangely for the user?

There are three other suspicious uses of $query->redirect that I just plain don't understand; I'd love to comment them if I could work out why they are done this way, rather than with TWiki::redirect. The first is in edit:

     # Prevent editing existing topic?
    if( $onlyNewTopic && $topicExists ) {
       # Topic exists and user requested oops if it exists
       my $url = &TWiki::getOopsUrl( $webName, $topic, "oopscreatenewtopic" );
       print $query->redirect( $url );
       return;       
    }
the second in save:
    } elsif( ! $text ) {
        # empty topic not allowed
        my $url = &TWiki::getOopsUrl( $webName, $topic, "oopsempty" );
        print $query->redirect( $url );
        return;
    }
and the third in preview:
        $text = $query->param( "text" );
        if( ! $text ) {
            # empty topic not allowed
            my $url = &TWiki::getOopsUrl( $webName, $topic, "oopsempty" );
            print $query->redirect( $url );
            return;
        }

There is one other call that doesn't seem quite right, in TWiki.pm, look for oopsbadcharset.

Please help me out here; this is doing my head in.

-- CrawfordCurrie - 08 Apr 2004

the first is to stop a topic creation from overwriting someone else's topic creation (where they have hit save (breaking the lock) before you do

the second and third are because we currently do not allow you to save a topic with no text in it (can you tell i don't agree with this?)

as the mirror code is not used much, it should be moved into a plugin, to be maintained by the few users thereof, thus reducing the maintainence burden from mainline (its huge enough already)

also - isn't this a place where an exception would be better?

-- SvenDowideit - 17 Oct 2004

I changed it to use exceptions as appropriate. It now throws an "OopsException" when a redirect is required. Much cleaner.

-- CrawfordCurrie - 13 Feb 2005

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2005-02-13 - SamHasler
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.