Changeset 1141
- Timestamp:
- 01/22/08 16:38:24 (9 months ago)
- Location:
- trunk
- Files:
-
- 4 modified
-
Changes (modified) (1 diff)
-
lib/OpenGuides.pm (modified) (7 diffs)
-
lib/OpenGuides/Utils.pm (modified) (2 diffs)
-
t/45_home_recent_changes.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Changes
r1140 r1141 5 5 6 6 0.62 7 Allow wiki page links (simple: [[Foo]], title: [[Foo|bar]]) in 8 change summaries. 7 9 Ensure that all modules we ship are versioned. 8 10 Added experimental support for local IP blacklisting modules; see the -
trunk/lib/OpenGuides.pm
r1132 r1141 339 339 metadata_was => { edit_type => "Normal edit" }, 340 340 ); 341 my $base_url = $config->script_name . '?'; 341 342 @recent = map { 342 343 { … … 345 346 CGI->escapeHTML($_->{last_modified}), 346 347 version => CGI->escapeHTML($_->{version}), 347 comment => 348 comment => OpenGuides::Utils::parse_change_comment( 348 349 CGI->escapeHTML($_->{metadata}{comment}[0]), 350 $base_url, 351 ), 349 352 username => 350 353 CGI->escapeHTML($_->{metadata}{username}[0]), 351 url => $ config->script_name . "?"354 url => $base_url 352 355 . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})) 353 356 } … … 653 656 unless $minor_edits; 654 657 my @rc = $self->{wiki}->list_recent_changes( %criteria ); 655 658 659 my $base_url = $config->script_name . '?'; 660 656 661 @rc = map { 657 662 { … … 659 664 last_modified => CGI->escapeHTML($_->{last_modified}), 660 665 version => CGI->escapeHTML($_->{version}), 661 comment => CGI->escapeHTML($_->{metadata}{comment}[0]), 666 comment => OpenGuides::Utils::parse_change_comment( 667 CGI->escapeHTML($_->{metadata}{comment}[0]), 668 $base_url, 669 ), 662 670 username => CGI->escapeHTML($_->{metadata}{username}[0]), 663 671 host => CGI->escapeHTML($_->{metadata}{host}[0]), 664 672 username_param => CGI->escape($_->{metadata}{username}[0]), 665 673 edit_type => CGI->escapeHTML($_->{metadata}{edit_type}[0]), 666 url => $ config->script_name . "?"674 url => $base_url 667 675 . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})), 668 676 } … … 678 686 my @rc = $self->{wiki}->list_recent_changes( %criteria ); 679 687 688 my $base_url = $config->script_name . '?'; 689 680 690 @rc = map { 681 691 { … … 683 693 last_modified => CGI->escapeHTML($_->{last_modified}), 684 694 version => CGI->escapeHTML($_->{version}), 685 comment => CGI->escapeHTML($_->{metadata}{comment}[0]), 695 comment => OpenGuides::Utils::parse_change_comment( 696 CGI->escapeHTML($_->{metadata}{comment}[0]), 697 $base_url, 698 ), 686 699 username => CGI->escapeHTML($_->{metadata}{username}[0]), 687 700 host => CGI->escapeHTML($_->{metadata}{host}[0]), 688 701 username_param => CGI->escape($_->{metadata}{username}[0]), 689 702 edit_type => CGI->escapeHTML($_->{metadata}{edit_type}[0]), 690 url => $ config->script_name . "?"703 url => $base_url 691 704 . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})), 692 705 } … … 1022 1035 modified => CGI->escapeHTML( $node_data{last_modified} ), 1023 1036 username => CGI->escapeHTML( $node_data{metadata}{username}[0] ), 1024 comment => CGI->escapeHTML( $node_data{metadata}{comment}[0] ), 1025 } if $node_data{version}; 1037 comment => OpenGuides::Utils::parse_change_comment( 1038 CGI->escapeHTML( $node_data{metadata}{comment}[0] ), 1039 $self->config->script_name . '?', 1040 ), 1041 } if $node_data{version}; 1026 1042 } 1027 1043 @history = reverse @history; -
trunk/lib/OpenGuides/Utils.pm
r1105 r1141 394 394 }; 395 395 396 =item B<parse_change_comment> 397 398 my $change_comment = parse_change_comment($string, $base_url); 399 400 Given a base URL (for example, C<http://example.com/wiki.cgi?>), takes a string, 401 replaces C<[[page]]> and C<[[page|titled link]]> with 402 403 <a href="http://example.com/wiki.cgi?page">page</a> 404 405 and 406 407 <a href="http://example.com/wiki.cgi?page">titled link</a> 408 409 respectively, and returns it. This is a limited subset of wiki markup suitable for 410 use in page change comments. 411 412 =cut 413 414 sub parse_change_comment { 415 my ($comment, $base_url) = @_; 416 417 my @links = $comment =~ m{\[\[(.*?)\]\]}g; 418 419 # It's not all that great having to reinvent the wheel in this way, but 420 # Text::WikiFormat won't let you specify the subset of wiki notation that 421 # you're interested in. C'est la vie. 422 foreach (@links) { 423 if (/(.*?)\|(.*)/) { 424 my ($page, $title) = ($1, $2); 425 $comment =~ s{\[\[$page\|$title\]\]} 426 {<a href="$base_url$page">$title</a>}; 427 } else { 428 my $page = $_; 429 $comment =~ s{\[\[$page\]\]} 430 {<a href="$base_url$page">$page</a>}; 431 } 432 } 433 434 return $comment; 435 } 436 396 437 =item B<send_email> 397 438 … … 421 462 422 463 =cut 464 423 465 424 466 sub send_email { -
trunk/t/45_home_recent_changes.t
r956 r1141 11 11 } 12 12 13 plan tests => 1 3;13 plan tests => 15; 14 14 15 15 my ( $config, $guide, $wiki ); … … 60 60 like( $output, qr/Edit this page/, "...edit this page link is there too" ); 61 61 62 OpenGuides::Test->write_data( 63 guide => $guide, 64 node => "Red Lion", 65 content => "A nice pub.", 66 username => "Earle", 67 comment => "I also edited it. For fun, here are two links: [[A Page]], and the same link [[A Page|again]].", 68 ); 69 70 # Reload page. 71 $output = $guide->display_node( 72 id => $config->home_name, 73 return_output => 1, 74 ); 75 76 like( $output, qr{<a href="\?A Page">A Page</a>}, "...simple wiki links appear in Recent Changes" ); 77 like( $output, qr{<a href="\?A Page">again</a>}, "...titled wiki links appear in Recent Changes" ); 78 79 62 80 # And that they don't show up if we don't want them. Turn off the navbar 63 81 # too, since we want to make sure the edit page link shows up regardless (it … … 78 96 unlike( $output, qr/Ten most.*recent changes/, "...heading not shown either" ); 79 97 like( $output, qr/Edit this page/, "...edit this page link is there though" ); 98
