Changeset 1064

Show
Ignore:
Timestamp:
06/11/07 03:23:11 (16 months ago)
Author:
kake
Message:

Add intercept_redirect parameter to Openguides->display_node - used with the return_output parameter for testing.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides.pm

    r1056 r1064  
    164164                      ); 
    165165 
    166 If C<version> is omitted then the latest version will be displayed. 
     166If C<version> is omitted then it will assume you want the latest version. 
     167 
     168Note that if you pass the C<return_output> parameter, and your node is a 
     169redirecting node, this method will fake the redirect and return the output 
     170that will actually end up in the user's browser.  If instead you want to see 
     171the HTTP headers that will be printed in order to perform the redirect, pass 
     172the C<intercept_redirect> parameter as well.  The C<intercept_redirect> 
     173parameter has no effect if the node isn't a redirect, or if the 
     174C<return_output> parameter is omitted. 
     175 
     176(At the moment, C<return_tt_vars> acts as if the C<intercept_redirect> 
     177parameter was passed.) 
    167178 
    168179=cut 
     
    171182    my ($self, %args) = @_; 
    172183    my $return_output = $args{return_output} || 0; 
     184    my $intercept_redirect = $args{intercept_redirect}; 
    173185    my $version = $args{version}; 
    174186    my $id = $args{id} || $self->config->home_name; 
     
    277289        } elsif ( $wiki->node_exists($redirect) && $redirect ne $id && $redirect ne $oldid ) { 
    278290            # Avoid loops by not generating redirects to the same node or the previous node. 
    279             my $output = $self->redirect_to_node($redirect, $id); 
    280             return $output if $return_output; 
    281             print $output; 
     291            if ( $return_output ) { 
     292                if ( $intercept_redirect ) { 
     293                    return $self->redirect_to_node( $redirect, $id ); 
     294                } else { 
     295                    return $self->display_node( id            => $redirect, 
     296                                                oldid         => $id, 
     297                                                return_output => 1, 
     298                                              ); 
     299                } 
     300            } 
     301            print $self->redirect_to_node( $redirect, $id ); 
    282302            return 0; 
    283303        } 
  • trunk/t/51_display_node.t

    r1056 r1064  
    5151$wiki->write_node( 'Redirect Test', '#REDIRECT Test Page', undef ); 
    5252 
    53 $output = $guide->display_node( id => 'Redirect Test', return_output => 1 ); 
     53$output = $guide->display_node( id => 'Redirect Test', 
     54                                return_output => 1, 
     55                                intercept_redirect => 1 ); 
    5456 
    5557like( $output, qr{^\QLocation: http://example.com/wiki.cgi?id=Test_Page;oldid=Redirect_Test}ms, 
  • trunk/t/54_redirect.t

    r956 r1064  
    4242  or die "Can't write node"; 
    4343my $output = eval { 
    44     $guide->display_node( id => "Test Page", return_output => 1 ); 
     44    $guide->display_node( id => "Test Page", 
     45                          return_output => 1, 
     46                          intercept_redirect => 1 ); 
    4547}; 
    4648is( $@, "", "->display_node doesn't die when page is a redirect" );