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};
49 my $page=$form->field("page");
51 return if $form->title ne "editpage"
52 || $form->field("do") ne "edit";
54 $page = IkiWiki::titlepage(IkiWiki::possibly_foolish_untaint($page));
55 return unless exists $pagesources{$page};
57 push @{$params{buttons}}, "Diff";
59 if ($form->submitted eq "Diff") {
60 my $content=$form->field('editcontent');
61 $content=~s/\r\n/\n/g;
64 my $diff = diff(srcfile($pagesources{$page}), $content);
65 $form->tmpl_param("page_preview", $diff);