web commit by http://jeremie.koenig.myopenid.com/: difficulties with a "show diff...
[ikiwiki] / doc / todo / preview_changes.mdwn
1 When editing a page, it would help to have a "preview changes" or "show diff" button, which brings up a diff from the current page content to the proposed new page content. --[[JoshTriplett]]
2
3 Some discussion from the main [[/index/discussion]] page:
4
5 >It would be nice to be able to have a button to show "Differences" (or "Show Diff") when
6 >editing a page. Is that an option that can be enabled?
7 >
8 >> It's doable, it could even be done by a [[todo/plugin]], I think.
9 >> --[[Joey]]
10
11 ---
12
13 I need help with this. Supposedly, such a plugin would provide a `formbuilder_setup`
14 hook which would add the button, and a cgi hook which would interecept
15 "Show Diff" clicks. This would show a diff between
16 `titlepage(possibly_foolish_untaint($form->field("page")))`
17 and the provided `$form->field("editcontent")`.
18
19 But:
20
21   * How could the case of concurrent editing be handled ?
22     Especially as (I think) only the RCS backend can know that
23     this has happened.
24   * Doing the formbuilder trick for adding a button needs the following
25     patch. (note that this is not the only template which has its submit
26     buttons hardcoded; is this supposed to work around something?)
27
28 <pre>
29 Index: templates/editpage.tmpl
30 ===================================================================
31 --- templates/editpage.tmpl     (rĂ©vision 4130)
32 +++ templates/editpage.tmpl     (copie de travail)
33 @@ -57,9 +57,7 @@
34  Optional comment about this change:<br />
35  <TMPL_VAR FIELD-COMMENTS><br />
36  </TMPL_IF>
37 -<input id="_submit" name="_submit" type="submit" value="Save Page" />
38 -<input id="_submit_2" name="_submit" type="submit" value="Preview" />
39 -<input id="_submit_3" name="_submit" type="submit" value="Cancel" />
40 +<TMPL_VAR FORM-SUBMIT>
41  <TMPL_VAR HELPONFORMATTINGLINK>
42  <TMPL_VAR FORM-END>
43  
44 Index: IkiWiki/CGI.pm
45 ===================================================================
46 --- IkiWiki/CGI.pm      (rĂ©vision 4130)
47 +++ IkiWiki/CGI.pm      (copie de travail)
48 @@ -304,6 +304,7 @@
49         eval q{use CGI::FormBuilder};
50         error($@) if $@;
51         my $form = CGI::FormBuilder->new(
52 +               title => "editpage",
53                 fields => \@fields,
54                 charset => "utf-8",
55                 method => 'POST',
56 @@ -321,7 +322,8 @@
57         );
58  
59         run_hooks(formbuilder_setup => sub {
60 -               shift->(form => $form, cgi => $q, session => $session);
61 +               shift->(form => $form, cgi => $q, session => $session,
62 +                       buttons => \@buttons);
63         });
64  
65         decode_form_utf8($form);
66 </pre>
67
68 --[[JeremieKoenig]]