Changeset 1141

Show
Ignore:
Timestamp:
01/22/08 16:38:24 (9 months ago)
Author:
earle
Message:

Allow wiki links in change summaries. Closes #115.

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r1140 r1141  
    55 
    660.62     
     7        Allow wiki page links (simple: [[Foo]], title: [[Foo|bar]]) in 
     8          change summaries. 
    79        Ensure that all modules we ship are versioned. 
    810        Added experimental support for local IP blacklisting modules; see the 
  • trunk/lib/OpenGuides.pm

    r1132 r1141  
    339339                metadata_was   => { edit_type => "Normal edit" }, 
    340340            ); 
     341            my $base_url = $config->script_name . '?'; 
    341342            @recent = map { 
    342343                            { 
     
    345346                                  CGI->escapeHTML($_->{last_modified}), 
    346347                              version       => CGI->escapeHTML($_->{version}), 
    347                               comment       => 
     348                              comment       => OpenGuides::Utils::parse_change_comment( 
    348349                                  CGI->escapeHTML($_->{metadata}{comment}[0]), 
     350                                  $base_url, 
     351                              ), 
    349352                              username      => 
    350353                                  CGI->escapeHTML($_->{metadata}{username}[0]), 
    351                               url           => $config->script_name . "?" 
     354                              url           => $base_url 
    352355                                             . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})) 
    353356                            } 
     
    653656          unless $minor_edits; 
    654657        my @rc = $self->{wiki}->list_recent_changes( %criteria ); 
    655   
     658 
     659        my $base_url = $config->script_name . '?'; 
     660         
    656661        @rc = map { 
    657662            { 
     
    659664              last_modified => CGI->escapeHTML($_->{last_modified}), 
    660665              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              ), 
    662670              username    => CGI->escapeHTML($_->{metadata}{username}[0]), 
    663671              host        => CGI->escapeHTML($_->{metadata}{host}[0]), 
    664672              username_param => CGI->escape($_->{metadata}{username}[0]), 
    665673              edit_type   => CGI->escapeHTML($_->{metadata}{edit_type}[0]), 
    666               url         => $config->script_name . "?" 
     674              url         => $base_url 
    667675      . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})), 
    668676        } 
     
    678686            my @rc = $self->{wiki}->list_recent_changes( %criteria ); 
    679687 
     688            my $base_url = $config->script_name . '?'; 
     689             
    680690            @rc = map { 
    681691            { 
     
    683693              last_modified => CGI->escapeHTML($_->{last_modified}), 
    684694              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              ), 
    686699              username    => CGI->escapeHTML($_->{metadata}{username}[0]), 
    687700              host        => CGI->escapeHTML($_->{metadata}{host}[0]), 
    688701              username_param => CGI->escape($_->{metadata}{username}[0]), 
    689702              edit_type   => CGI->escapeHTML($_->{metadata}{edit_type}[0]), 
    690               url         => $config->script_name . "?" 
     703              url         => $base_url 
    691704      . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})), 
    692705        } 
     
    10221035            modified => CGI->escapeHTML( $node_data{last_modified} ), 
    10231036            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}; 
    10261042    } 
    10271043    @history = reverse @history; 
  • trunk/lib/OpenGuides/Utils.pm

    r1105 r1141  
    394394}; 
    395395 
     396=item B<parse_change_comment> 
     397 
     398    my $change_comment = parse_change_comment($string, $base_url); 
     399     
     400Given a base URL (for example, C<http://example.com/wiki.cgi?>), takes a string,  
     401replaces C<[[page]]> and C<[[page|titled link]]> with 
     402 
     403    <a href="http://example.com/wiki.cgi?page">page</a> 
     404 
     405and 
     406 
     407    <a href="http://example.com/wiki.cgi?page">titled link</a> 
     408 
     409respectively, and returns it. This is a limited subset of wiki markup suitable for 
     410use in page change comments. 
     411 
     412=cut 
     413 
     414sub 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 
    396437=item B<send_email> 
    397438 
     
    421462 
    422463=cut 
     464 
    423465 
    424466sub send_email { 
  • trunk/t/45_home_recent_changes.t

    r956 r1141  
    1111} 
    1212 
    13 plan tests => 13; 
     13plan tests => 15; 
    1414 
    1515my ( $config, $guide, $wiki ); 
     
    6060like( $output, qr/Edit this page/, "...edit this page link is there too" ); 
    6161 
     62OpenGuides::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 
     76like( $output, qr{<a href="\?A Page">A Page</a>}, "...simple wiki links appear in Recent Changes" ); 
     77like( $output, qr{<a href="\?A Page">again</a>},  "...titled wiki links appear in Recent Changes" ); 
     78 
     79 
    6280# And that they don't show up if we don't want them.  Turn off the navbar 
    6381# too, since we want to make sure the edit page link shows up regardless (it 
     
    7896unlike( $output, qr/Ten most.*recent changes/, "...heading not shown either" ); 
    7997like( $output, qr/Edit this page/, "...edit this page link is there though" ); 
     98