1How 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? 2 3 I'd like this too (and might try to implement it). -- [[users/jon]] 4 5I just implemented this. There is one [[patch]] to the default page template, and a new plugin. -- [[Will]] 6 7All of this code is licensed under the GPLv2+. -- [[Will]] 8 9> The use of sessioncgi here seems undesirable: on wikis where anonymity is 10> not allowed, you'll be asked to log in. Couldn't you achieve the same thing 11> by loading the index with IkiWiki::loadindex, like [[plugins/goto]] does? 12> --[[smcv]] 13 14[[done]] 15 16>> I've applied the patch below in a git branch, fixed my earlier criticism, 17>> and also fixed a couple of other issues I noticed: 18>> 19>> * missing pages could be presented better as a real 404 page 20>> * the default Content-type should probably be UTF-8 since the rest of 21>> IkiWiki tends to assume that 22>> * emitting attachments (images, etc.) as text/plain isn't going to work :-) 23>> 24>> Any opinions on my branch? I think it's ready for merge, if Joey approves. 25>> 26>> --[[smcv]] 27 28>>> I need a copyright&license statement, so debian/copyright can be updated for 29>>> the plugin, before I can merge this. Otherwise ready. --[[Joey]] 30 31>>> That looks like a nice set of fixes. One more that might be worthwhile: instead of reading the page source into a var, and then writing it out later, it might be nice to just 32>>> `print readfile(srcfile(pagesources{$page}));` at the appropriate point. -- [[Will]] 33 34>>>> OK, I've committed that. --[[smcv]] 35 36---- 37 38 diff --git a/templates/page.tmpl b/templates/page.tmpl 39 index f2f9c34..3176bed 100644 40 --- a/templates/page.tmpl 41 +++ b/templates/page.tmpl 42 @@ -46,6 +46,9 @@ 43 <TMPL_IF NAME="HISTORYURL"> 44 <li><a href="<TMPL_VAR HISTORYURL>">History</a></li> 45 </TMPL_IF> 46 +<TMPL_IF NAME="GETSOURCEURL"> 47 +<li><a href="<TMPL_VAR GETSOURCEURL>">Get Source</a></li> 48 +</TMPL_IF> 49 <TMPL_IF NAME="PREFSURL"> 50 <li><a href="<TMPL_VAR PREFSURL>">Preferences</a></li> 51 </TMPL_IF> 52 53---- 54 55 #!/usr/bin/perl 56 package IkiWiki::Plugin::getsource; 57 58 use warnings; 59 use strict; 60 use IkiWiki; 61 use open qw{:utf8 :std}; 62 63 sub import { 64 hook(type => "getsetup", id => "getsource", call => \&getsetup); 65 hook(type => "pagetemplate", id => "getsource", call => \&pagetemplate); 66 hook(type => "sessioncgi", id => "getsource", call => \&cgi_getsource); 67 } 68 69 sub getsetup () { 70 return 71 plugin => { 72 safe => 1, 73 rebuild => 1, 74 }, 75 getsource_mimetype => { 76 type => "string", 77 example => "application/octet-stream", 78 description => "Mime type for returned source.", 79 safe => 1, 80 rebuild => 0, 81 }, 82 } 83 84 sub pagetemplate (@) { 85 my %params=@_; 86 87 my $page=$params{page}; 88 my $template=$params{template}; 89 90 if (length $config{cgiurl}) { 91 $template->param(getsourceurl => IkiWiki::cgiurl(do => "getsource", page => $page)); 92 $template->param(have_actions => 1); 93 } 94 } 95 96 sub cgi_getsource ($$) { 97 my $cgi=shift; 98 my $session=shift; 99 100 # Note: we use sessioncgi rather than just cgi 101 # because we need $IkiWiki::pagesources{} to be 102 # populated. 103 104 return unless (defined $cgi->param('do') && 105 $cgi->param("do") eq "getsource"); 106 107 IkiWiki::decode_cgi_utf8($cgi); 108 109 my $page=$cgi->param('page'); 110 111 if ($IkiWiki::pagesources{$page}) { 112 113 my $data = IkiWiki::readfile(IkiWiki::srcfile($IkiWiki::pagesources{$page})); 114 115 if (! $config{getsource_mimetype}) { 116 $config{getsource_mimetype} = "text/plain"; 117 } 118 119 print "Content-Type: $config{getsource_mimetype}\r\n"; 120 121 print ("\r\n"); 122 123 print $data; 124 125 exit 0; 126 } 127 128 error("Unable to find page source for page: $page"); 129 130 exit 0; 131 } 132 133 1 134 135[[done]] --[[smcv]] 136