1 How about a direct link from the page header to the source of the latest version, to avoid the need to either use edit or navigate to the current version via the history link?
3 I'd like this too (and might try to implement it). -- [[users/jon]]
5 I just implemented this. There is one [[patch]] to the default page template, and a new plugin. -- [[Will]]
7 > The use of sessioncgi here seems undesirable: on wikis where anonymity is
8 > not allowed, you'll be asked to log in. Couldn't you achieve the same thing
9 > by loading the index with IkiWiki::loadindex, like [[plugins/goto]] does?
14 diff --git a/templates/page.tmpl b/templates/page.tmpl
15 index f2f9c34..3176bed 100644
16 --- a/templates/page.tmpl
17 +++ b/templates/page.tmpl
19 <TMPL_IF NAME="HISTORYURL">
20 <li><a href="<TMPL_VAR HISTORYURL>">History</a></li>
22 +<TMPL_IF NAME="GETSOURCEURL">
23 +<li><a href="<TMPL_VAR GETSOURCEURL>">Get Source</a></li>
25 <TMPL_IF NAME="PREFSURL">
26 <li><a href="<TMPL_VAR PREFSURL>">Preferences</a></li>
32 package IkiWiki::Plugin::getsource;
37 use open qw{:utf8 :std};
40 hook(type => "getsetup", id => "getsource", call => \&getsetup);
41 hook(type => "pagetemplate", id => "getsource", call => \&pagetemplate);
42 hook(type => "sessioncgi", id => "getsource", call => \&cgi_getsource);
51 getsource_mimetype => {
53 example => "application/octet-stream",
54 description => "Mime type for returned source.",
60 sub pagetemplate (@) {
63 my $page=$params{page};
64 my $template=$params{template};
66 if (length $config{cgiurl}) {
67 $template->param(getsourceurl => IkiWiki::cgiurl(do => "getsource", page => $page));
68 $template->param(have_actions => 1);
72 sub cgi_getsource ($$) {
76 # Note: we use sessioncgi rather than just cgi
77 # because we need $IkiWiki::pagesources{} to be
80 return unless (defined $cgi->param('do') &&
81 $cgi->param("do") eq "getsource");
83 IkiWiki::decode_cgi_utf8($cgi);
85 my $page=$cgi->param('page');
87 if ($IkiWiki::pagesources{$page}) {
89 my $data = IkiWiki::readfile(IkiWiki::srcfile($IkiWiki::pagesources{$page}));
91 if (! $config{getsource_mimetype}) {
92 $config{getsource_mimetype} = "text/plain";
95 print "Content-Type: $config{getsource_mimetype}\r\n";
104 error("Unable to find page source for page: $page");