]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/editdiff.pm
add Comments link when displaying a page inline
[git.ikiwiki.info.git] / IkiWiki / Plugin / editdiff.pm
index 46eb1168edddd42b6086b646ae48d63cb7dd2111..068b83b3c15f9b3a790e4c51c56fe5559eadff3a 100644 (file)
@@ -8,12 +8,21 @@ use IkiWiki 2.00;
 use HTML::Entities;
 use IPC::Open2;
 
 use HTML::Entities;
 use IPC::Open2;
 
-sub import { #{{{
+sub import {
+       hook(type => "getsetup", id => "editdiff", call => \&getsetup);
        hook(type => "formbuilder_setup", id => "editdiff",
                call => \&formbuilder_setup);
        hook(type => "formbuilder_setup", id => "editdiff",
                call => \&formbuilder_setup);
-} #}}}
+}
 
 
-sub diff ($$) { #{{{
+sub getsetup () {
+       return
+               plugin => {
+                       safe => 1,
+                       rebuild => 0,
+               },
+}
+
+sub diff ($$) {
        my $orig=shift;
        my $content=shift;
 
        my $orig=shift;
        my $content=shift;
 
@@ -25,7 +34,7 @@ sub diff ($$) { #{{{
 
        print DIFFIN $content;
        close DIFFIN;
 
        print DIFFIN $content;
        close DIFFIN;
-       my $ret;
+       my $ret='';
        while (<DIFFOUT>) {
                if (defined $ret) {
                        $ret.=$_;
        while (<DIFFOUT>) {
                if (defined $ret) {
                        $ret.=$_;
@@ -41,17 +50,16 @@ sub diff ($$) { #{{{
        return "couldn't run diff\n" if $sigpipe;
 
        return "<pre>".encode_entities($ret)."</pre>";
        return "couldn't run diff\n" if $sigpipe;
 
        return "<pre>".encode_entities($ret)."</pre>";
-} #}}}
+}
 
 
-sub formbuilder_setup { #{{{
+sub formbuilder_setup {
        my %params=@_;
        my $form=$params{form};
        my %params=@_;
        my $form=$params{form};
-       my $page=$form->field("page");
 
 
-       return if $form->title ne "editpage"
-                 || $form->field("do") ne "edit";
+       return if ! defined $form->field("do") || $form->field("do") ne "edit";
 
 
-       $page = IkiWiki::titlepage(IkiWiki::possibly_foolish_untaint($page));
+       my $page=$form->field("page");
+       $page = IkiWiki::possibly_foolish_untaint($page);
        return unless exists $pagesources{$page};
 
        push @{$params{buttons}}, "Diff";
        return unless exists $pagesources{$page};
 
        push @{$params{buttons}}, "Diff";
@@ -64,6 +72,6 @@ sub formbuilder_setup { #{{{
                my $diff = diff(srcfile($pagesources{$page}), $content);
                $form->tmpl_param("page_preview", $diff);
        }
                my $diff = diff(srcfile($pagesources{$page}), $content);
                $form->tmpl_param("page_preview", $diff);
        }
-} #}}}
+}
 
 1
 
 1