Wikit web Preview button

This page describes a modification to Wikit to add a "Preview" button to the editing page in the web interface. I (sm) have not tried it with caching of pages, but it works great without the caching.

Below is a context diff of the change. It is to the file web.tcl, version dated 2004-01-10.


 *** web.tcl.old        Fri Jan 23 13:08:45 2004
 --- web.tcl        Fri Jan 23 13:16:14 2004
 ***************
 *** 280,285 ****
 --- 280,290 ----
             SavePage $N $C $host $name
           }
           # end of change, 03-09-2003
 +         # If a preview of the saved page is requested, generate
 +         # that page instead.
 +         if {$editAction == "Preview"} {
 +            set cmd Preview
 +         }

           mk::file commit wdb
           # a general improvement: redirect through a fetch again
 ***************
 *** 387,393 ****
             }

             cgi_body bgcolor=#ffffff {
 !             cgi_h2 [Wiki - $N]

               cgi_form $::script_name/$N {
                 cgi_export O=$origtag
 --- 392,398 ----
             }

             cgi_body bgcolor=#ffffff {
 !             cgi_h2 "Edit $name"

               cgi_form $::script_name/$N {
                 cgi_export O=$origtag
 ***************
 *** 401,408 ****
                 p
                 # thx Alistair Grant, see https://wiki.tcl-lang.org/9747
                 #submit_button "=  Save  "
 -               # Create Save and Cancel buttons

                 submit_button "Action=Save"
                 cgi_puts " [nbspace] "
                 submit_button "Action=Cancel"
 --- 406,415 ----
                 p
                 # thx Alistair Grant, see https://wiki.tcl-lang.org/9747
                 #submit_button "=  Save  "

 +               # Create Preview, Save, and Cancel buttons
 +               submit_button "Action=Preview"
 +               cgi_puts " [nbspace] "
                 submit_button "Action=Save"
                 cgi_puts " [nbspace] "
                 submit_button "Action=Cancel"
 ***************
 *** 418,423 ****
 --- 425,485 ----
             }
           }

 +         Preview { # called to generate a preview page
 +           cgi_head {
 +             cgi_http_equiv Content-type "text/html; charset=utf-8"
 +             cgi_title "Preview of $name"
 +             cgi_meta name=robots content=noindex,nofollow
 +             cgi_http_equiv Pragma no-cache
 +             cgi_http_equiv Expire "Mon, 04 Dec 1999 21:29:02 GMT"
 +             stylesheet
 +             if {$N != "2" && [info exists ::env(WIKIT_BASE)]} {
 +               cgi_base href=$::env(WIKIT_BASE)
 +             }
 +           }
 + 
 +           cgi_body bgcolor=#ffffff {
 +             cgi_h2 "Preview of $name"
 + 
 +             set U ""
 +             foreach {Content U} [Expand_HTML $C] break
 +             p $Content
 + 
 +             hr noshade
 + 
 +             cgi_h2 "Re-edit $name"
 +             p
 + 
 +             cgi_form $::script_name/$N {
 +               cgi_export O=$origtag
 +               catch {
 +                 set z "http://$::env(HTTP_HOST)$::env(REDIRECT_URL)"
 +                 regsub {@$} $z {} z
 +                 cgi_export Z=$z
 +               }
 +               textarea C=$C rows=30 cols=72 wrap=virtual \
 +                 style=width:100%
 +               p
 +               # thx Alistair Grant, see https://wiki.tcl-lang.org/9747
 +               #submit_button "=  Save  "
 +               # Create Preview, Save, and Cancel buttons
 +               submit_button "Action=Preview"
 +               cgi_puts " [nbspace] "
 +               submit_button "Action=Save"
 +               cgi_puts " [nbspace] "
 +               submit_button "Action=Cancel"
 +               # end of change, 03-09-2003
 +               if {$date != 0} {
 +                 cgi_puts " [nbspace] [nbspace] [nbspace] "
 +                 cgi_puts [italic "Last saved on [bold $date]"]
 +               }
 +               p
 +               cgi_puts $::EditInstructions
 +             }
 + 
 +           }
 +         }
 + 
           ! { # called to generate a page with references

             cgi_head {

MHo: Wouldn't it be nice to add this function as a standard feature?

rpremuz: Yes, it would be really nice. With this feature you could check appearance of changes while editing a page without the need to save it. I guess that this way a page would have a smaller number of revisions.

DKF: It is part of this wiki.