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

Allow wiki links in change summaries. Closes #115.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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 {