/usr/share/perl5/Wiki/Toolkit/Formatter/Default.pm is in libwiki-toolkit-perl 0.85-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | package Wiki::Toolkit::Formatter::Default;
use strict;
use vars qw( $VERSION @ISA @_links_found );
$VERSION = '0.02';
use Wiki::Toolkit::Formatter::WikiLinkFormatterParent;
use CGI ":standard";
use Carp qw(croak carp);
use Text::WikiFormat as => 'wikiformat';
use HTML::PullParser;
@ISA = qw( Wiki::Toolkit::Formatter::WikiLinkFormatterParent );
=head1 NAME
Wiki::Toolkit::Formatter::Default - A formatter for Wiki::Toolkit.
=head1 DESCRIPTION
A formatter backend for L<Wiki::Toolkit>.
=head1 SYNOPSIS
my $store = Wiki::Toolkit::Store::SQLite->new( ... );
# See below for parameter details.
my $formatter = Wiki::Toolkit::Formatter::Default->new( %config );
my $wiki = Wiki::Toolkit->new( store => $store,
formatter => $formatter );
=head1 METHODS
=over 4
=item B<new>
my $formatter = Wiki::Toolkit::Formatter::Default->new(
extended_links => 0,
implicit_links => 1,
allowed_tags => [qw(b i)], # defaults to none
macros => {},
node_prefix => 'wiki.cgi?node=' );
Parameters will default to the values shown above (apart from
C<allowed_tags>, which defaults to allowing no tags).
=over 4
=item * macros - be aware that macros are processed I<after> filtering
out disallowed HTML tags. Currently macros are just strings, maybe later
we can add in subs if we think it might be useful.
=back
Macro example:
macros => { qr/(^|\b)\@SEARCHBOX(\b|$)/ =>
qq(<form action="wiki.cgi" method="get">
<input type="hidden" name="action" value="search">
<input type="text" size="20" name="terms">
<input type="submit"></form>) }
=cut
sub new {
my ($class, @args) = @_;
my $self = {};
bless $self, $class;
$self->_init(@args) or return undef;
return $self;
}
sub _init {
my ($self, %args) = @_;
# Store the parameters or their defaults.
my %defs = ( extended_links => 0,
implicit_links => 1,
allowed_tags => [],
macros => {},
node_prefix => 'wiki.cgi?node=',
);
my %collated = (%defs, %args);
foreach my $k (keys %defs) {
$self->{"_".$k} = $collated{$k};
}
return $self;
}
=item B<format>
my $html = $formatter->format( $content );
Escapes any tags which weren't specified as allowed on creation, then
interpolates any macros, then calls Text::WikiFormat::format (with the
config set up when B<new> was called) to translate the raw Wiki
language supplied into HTML.
=cut
sub format {
my ($self, $raw) = @_;
my $safe = "";
my %allowed = map {lc($_) => 1, "/".lc($_) => 1} @{$self->{_allowed_tags}};
if (scalar keys %allowed) {
# If we are allowing some HTML, parse and get rid of the nasties.
my $parser = HTML::PullParser->new(doc => $raw,
start => '"TAG", tag, text',
end => '"TAG", tag, text',
text => '"TEXT", tag, text');
while (my $token = $parser->get_token) {
my ($flag, $tag, $text) = @$token;
if ($flag eq "TAG" and !defined $allowed{lc($tag)}) {
$safe .= CGI::escapeHTML($text);
} else {
$safe .= $text;
}
}
} else {
# Else just escape everything.
$safe = CGI::escapeHTML($raw);
}
# Now process any macros.
my %macros = %{$self->{_macros}};
foreach my $regexp (keys %macros) {
$safe =~ s/$regexp/$macros{$regexp}/g;
}
return wikiformat($safe, {},
{ extended => $self->{_extended_links},
prefix => $self->{_node_prefix},
implicit_links => $self->{_implicit_links} } );
}
=back
=head1 SEE ALSO
L<Wiki::Toolkit::Formatter::WikiLinkFormatterParent>
L<Wiki::Toolkit>
=head1 AUTHOR
Kake Pugh (kake@earth.li).
=head1 COPYRIGHT
Copyright (C) 2002-2003 Kake Pugh. All Rights Reserved.
Copyright (C) 2006 the Wiki::Toolkit team. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1;
|