web commit by http://jeremie.koenig.myopenid.com/: update
[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   * May I hijack the `page_preview` template variable to show
25     my diff output? (the patch below assumes this).
26   * Using the formbuilder hook to add a button, and coerce `editpage()`
27     into showing the edit form again rather that saving the page needs
28     the following patch. (note that this is not the only template which has
29     its submit buttons hardcoded; is this supposed to work around something?)
30
31 <pre>
32 Index: templates/editpage.tmpl
33 ===================================================================
34 --- templates/editpage.tmpl     (rĂ©vision 4130)
35 +++ templates/editpage.tmpl     (copie de travail)
36 @@ -57,9 +57,7 @@
37  Optional comment about this change:<br />
38  <TMPL_VAR FIELD-COMMENTS><br />
39  </TMPL_IF>
40 -<input id="_submit" name="_submit" type="submit" value="Save Page" />
41 -<input id="_submit_2" name="_submit" type="submit" value="Preview" />
42 -<input id="_submit_3" name="_submit" type="submit" value="Cancel" />
43 +<TMPL_VAR FORM-SUBMIT>
44  <TMPL_VAR HELPONFORMATTINGLINK>
45  <TMPL_VAR FORM-END>
46  
47 Index: IkiWiki/CGI.pm
48 ===================================================================
49 --- IkiWiki/CGI.pm      (rĂ©vision 4130)
50 +++ IkiWiki/CGI.pm      (copie de travail)
51 @@ -304,6 +304,7 @@
52         eval q{use CGI::FormBuilder};
53         error($@) if $@;
54         my $form = CGI::FormBuilder->new(
55 +               title => "editpage",
56                 fields => \@fields,
57                 charset => "utf-8",
58                 method => 'POST',
59 @@ -321,7 +322,8 @@
60         );
61         
62         run_hooks(formbuilder_setup => sub {
63 -               shift->(form => $form, cgi => $q, session => $session);
64 +               shift->(form => $form, cgi => $q, session => $session,
65 +                       buttons => \@buttons);
66         });
67         
68         decode_form_utf8($form);
69 @@ -402,12 +404,12 @@
70                         preprocess($page, $page,
71                         filter($page, $page, $form->field('editcontent')), 0, 1))));
72         }
73 -       else {
74 +       elsif ($form->submitted eq "Save Page") {
75                 $form->tmpl_param("page_preview", "");
76         }
77         $form->tmpl_param("page_conflict", "");
78         
79 -       if (! $form->submitted || $form->submitted eq "Preview" || 
80 +       if ($form->submitted ne "Save Page" || 
81             ! $form->validate) {
82                 if ($form->field("do") eq "create") {
83                         my @page_locs;
84 </pre>
85
86 --[[JeremieKoenig]]