| | 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 | |