Changeset 1066
- Timestamp:
- 06/11/07 04:06:21 (1 year ago)
- Files:
-
- trunk/lib/OpenGuides.pm (modified) (1 diff)
- trunk/lib/OpenGuides/RDF.pm (modified) (2 diffs)
- trunk/lib/OpenGuides/Utils.pm (modified) (1 diff)
- trunk/t/11_utils.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/OpenGuides.pm
r1064 r1066 269 269 . "?id="; 270 270 } 271 272 if ( $node_data{content} && $node_data{content} =~ /^#REDIRECT\s+(.+?)\s*$/ ) { 273 my $redirect = $1; 274 # Strip off enclosing [[ ]] in case this is an extended link. 275 $redirect =~ s/^\[\[//; 276 $redirect =~ s/\]\]\s*$//; 277 271 272 my $redirect = OpenGuides::Utils->detect_redirect( 273 content => $node_data{content} ); 274 if ( $redirect ) { 278 275 # Don't redirect if the parameter "redirect" is given as 0. 279 276 if ($do_redirect == 0) { trunk/lib/OpenGuides/RDF.pm
r1060 r1066 2 2 3 3 use strict; 4 5 use OpenGuides::Utils; 4 6 5 7 use vars qw( $VERSION ); … … 140 142 $tt_vars{version} ); 141 143 142 # Should probably be moved into OpenGuides::Utils.143 if ($node_data{content} =~ /^\#REDIRECT \[\[(.*?)]\]$/) {144 my $redirect = $1;144 my $redirect = OpenGuides::Utils->detect_redirect( content => 145 $node_data{content} ); 146 if ( $redirect ) { 145 147 $tt_vars{redirect} = $config->script_url . $config->script_name 146 148 . "?id=" trunk/lib/OpenGuides/Utils.pm
r1032 r1066 329 329 } 330 330 331 =item B<detect_redirect> 332 333 $redir = OpenGuides::Utils->detect_redirect( content => "foo" ); 334 335 Checks the content of a node to see if the node is a redirect to another 336 node. If so, returns the name of the node that this one redirects to. If 337 not, returns false. 338 339 (Also returns false if no content is provided.) 340 341 =cut 342 343 sub detect_redirect { 344 my ( $self, %args ) = @_; 345 return unless $args{content}; 346 347 if ( $args{content} =~ /^#REDIRECT\s+(.+?)\s*$/ ) { 348 my $redirect = $1; 349 350 # Strip off enclosing [[ ]] in case this is an extended link. 351 $redirect =~ s/^\[\[//; 352 $redirect =~ s/\]\]\s*$//; 353 354 return $redirect; 355 } 356 } 357 331 358 =back 332 359 trunk/t/11_utils.t
r958 r1066 3 3 use OpenGuides::Config; 4 4 use OpenGuides::Utils; 5 use Test::More tests => 8;5 use Test::More tests => 10; 6 6 7 7 eval { my $wiki = OpenGuides::Utils->make_wiki_object; }; … … 29 29 30 30 SKIP: { 31 skip "DBD::SQLite could not be used - no database to test with. ($sqlite_error)", 5 31 skip "DBD::SQLite could not be used - no database to test with. " 32 . "($sqlite_error)", 7 32 33 unless $have_sqlite; 33 34 … … 60 61 ok( $wiki->search_obj, "...and search defined" ); 61 62 ok( $wiki->formatter, "...and formatter defined" ); 63 64 # Now test ->detect_redirect 65 is( OpenGuides::Utils->detect_redirect( content => "#REDIRECT [[Foo]]" ), 66 "Foo", 67 "->detect_redirect successfully detects redirect content" ); 68 ok( !OpenGuides::Utils->detect_redirect( content => "Mmmm, tea." ), 69 "...and successfully detects non-redirect content" ); 62 70 }
