line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::Export; |
2
|
1
|
|
|
1
|
|
28700
|
use Kwiki::Plugin -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use mixin 'Kwiki::Installer'; |
4
|
|
|
|
|
|
|
use Kwiki; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
const class_id => 'export'; |
9
|
|
|
|
|
|
|
const class_title => 'Export Content'; |
10
|
|
|
|
|
|
|
const cgi_class => 'Kwiki::Export::CGI'; |
11
|
|
|
|
|
|
|
const config_file => 'export.yaml'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Archive::Any::Create; |
14
|
|
|
|
|
|
|
use DirHandle; |
15
|
|
|
|
|
|
|
use File::Spec; |
16
|
|
|
|
|
|
|
use HTML::WikiConverter; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub register { |
19
|
|
|
|
|
|
|
my $registry = shift; |
20
|
|
|
|
|
|
|
$registry->add(action => 'export'); |
21
|
|
|
|
|
|
|
$registry->add(toolbar => 'export_button', |
22
|
|
|
|
|
|
|
template => 'export_button.html', |
23
|
|
|
|
|
|
|
show_for => [ 'display', 'revisions', 'edit', 'edit_contention' ]); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub export { |
27
|
|
|
|
|
|
|
my $page = $self->pages->current; |
28
|
|
|
|
|
|
|
my $formatter = $self->cgi->formatter || $self->config->default_export; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
if ($self->cgi->export_all) { |
31
|
|
|
|
|
|
|
return $self->export_all($formatter); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $content = $self->cgi->revision_id |
35
|
|
|
|
|
|
|
? $self->hub->archive->fetch($page, $self->cgi->revision_id) |
36
|
|
|
|
|
|
|
: $page->content; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$content ||= $self->config->default_content; |
39
|
|
|
|
|
|
|
if ($formatter) { |
40
|
|
|
|
|
|
|
$content = $self->convert_wiki($self->hub->formatter->text_to_html($content), $formatter); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->render_screen( |
44
|
|
|
|
|
|
|
screen_title => $page->title, |
45
|
|
|
|
|
|
|
page_content => $content, |
46
|
|
|
|
|
|
|
formatter => $formatter, |
47
|
|
|
|
|
|
|
formats => [ $self->get_dialects ], |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub export_all { |
52
|
|
|
|
|
|
|
my $formatter = shift; |
53
|
|
|
|
|
|
|
my $ext = $self->hub->config->export_format; |
54
|
|
|
|
|
|
|
my $name = "kwiki-$formatter.$ext"; |
55
|
|
|
|
|
|
|
my $archive = Archive::Any::Create->new; |
56
|
|
|
|
|
|
|
$archive->container("kwiki-$formatter"); |
57
|
|
|
|
|
|
|
for my $page ($self->pages->all) { |
58
|
|
|
|
|
|
|
my $newformat = $self->convert_wiki($page->to_html, $formatter); |
59
|
|
|
|
|
|
|
$archive->add_file($page->id, $newformat); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
print "Content-Type: application/octet-stream; name=$name\r\n", |
63
|
|
|
|
|
|
|
"Content-Disposition: attachment; filename=$name\r\n\r\n"; |
64
|
|
|
|
|
|
|
$archive->write_filehandle(\*STDOUT, $ext); |
65
|
|
|
|
|
|
|
return ''; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_dialects { |
69
|
|
|
|
|
|
|
my @dialects; |
70
|
|
|
|
|
|
|
for my $inc (@INC) { |
71
|
|
|
|
|
|
|
my $dir = File::Spec->catfile($inc, 'HTML', 'WikiConverter'); |
72
|
|
|
|
|
|
|
my $dh = DirHandle->new($dir) or next; |
73
|
|
|
|
|
|
|
while (my $f = $dh->read) { |
74
|
|
|
|
|
|
|
next if $f !~ /^(\w+)\.pm$/ || $f eq 'Kwiki.pm'; |
75
|
|
|
|
|
|
|
push @dialects, $1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
return @dialects; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub convert_wiki { |
82
|
|
|
|
|
|
|
my($html, $formatter) = @_; |
83
|
|
|
|
|
|
|
utf8::encode($html); |
84
|
|
|
|
|
|
|
my $c = HTML::WikiConverter->new( dialect => $formatter ); |
85
|
|
|
|
|
|
|
my $wiki = $c->html2wiki($html); |
86
|
|
|
|
|
|
|
utf8::decode($wiki); |
87
|
|
|
|
|
|
|
$wiki; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
package Kwiki::Export::CGI; |
91
|
|
|
|
|
|
|
use base 'Kwiki::CGI'; |
92
|
|
|
|
|
|
|
cgi 'formatter'; |
93
|
|
|
|
|
|
|
cgi 'revision_id'; |
94
|
|
|
|
|
|
|
cgi 'export_all'; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
package Kwiki::Export; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
__DATA__ |