2 # This plugin adds a "Diff" button to the page edit form.
3 package IkiWiki::Plugin::editdiff;
12 hook(type => "formbuilder_setup", id => "editdiff",
13 call => \&formbuilder_setup);
21 $SIG{PIPE} = sub { $sigpipe=1; };
23 my $pid = open2(*DIFFOUT, *DIFFIN, 'diff', '-u', $orig, '-');
24 binmode($_, ':utf8') foreach (*DIFFIN, *DIFFOUT);
26 print DIFFIN $content;
41 return "couldn't run diff\n" if $sigpipe;
43 return "<pre>".encode_entities($ret)."</pre>";
46 sub formbuilder_setup { #{{{
48 my $form=$params{form};
50 return if defined ! $form->field("do") || $form->field("do") ne "edit";
52 my $page=$form->field("page");
53 $page = IkiWiki::possibly_foolish_untaint($page);
54 return unless exists $pagesources{$page};
56 push @{$params{buttons}}, "Diff";
58 if ($form->submitted eq "Diff") {
59 my $content=$form->field('editcontent');
60 $content=~s/\r\n/\n/g;
63 my $diff = diff(srcfile($pagesources{$page}), $content);
64 $form->tmpl_param("page_preview", $diff);