2 package IkiWiki
::Plugin
::getsource
;
7 use open qw{:utf8
:std
};
10 hook
(type
=> "getsetup", id
=> "getsource", call
=> \
&getsetup
);
11 hook
(type
=> "pagetemplate", id
=> "getsource", call
=> \
&pagetemplate
);
12 hook
(type
=> "cgi", id
=> "getsource", call
=> \
&cgi_getsource
);
22 getsource_mimetype
=> {
24 example
=> "text/plain; charset=utf-8",
25 description
=> "Mime type for returned source.",
31 sub pagetemplate
(@
) {
34 my $page=$params{page
};
35 my $template=$params{template
};
37 if (length $config{cgiurl
}) {
38 $template->param(getsourceurl
=> IkiWiki
::cgiurl
(do => "getsource", page
=> $page));
39 $template->param(have_actions
=> 1);
43 sub cgi_getsource
($) {
46 return unless defined $cgi->param('do') &&
47 $cgi->param("do") eq "getsource";
49 IkiWiki
::decode_cgi_utf8
($cgi);
51 my $page=$cgi->param('page');
53 if (! defined $page || $page !~ /$config{wiki_file_regexp}/) {
54 error
("invalid page parameter");
60 if (! exists $pagesources{$page}) {
61 IkiWiki
::cgi_custom_failure
(
64 IkiWiki
::misctemplate
(gettext
("missing page"),
66 sprintf(gettext
("The page %s does not exist."),
67 htmllink
("", "", $page)).
72 if (! defined pagetype
($pagesources{$page})) {
73 IkiWiki
::cgi_custom_failure
(
74 $cgi->header(-status
=> "403 Forbidden"),
75 IkiWiki
::misctemplate
(gettext
("not a page"),
77 sprintf(gettext
("%s is an attachment, not a page."),
78 htmllink
("", "", $page)).
83 if (! $config{getsource_mimetype
}) {
84 $config{getsource_mimetype
} = "text/plain; charset=utf-8";
87 print "Content-Type: $config{getsource_mimetype}\r\n";
89 print readfile
(srcfile
($pagesources{$page}));