Version 4 of Wikit write patch

Updated 2003-10-29 17:47:00

Michael Heca simple patch for enable writing in Wikit embeded httpd server:

 diff -Naur wikit.vfs/lib/app-wikit/start.tcl wikit.vfs-original/lib/app-wikit/start.tcl
 --- wikit.vfs/lib/app-wikit/start.tcl        2003-10-29 18:02:16.000000000 +0100
 +++ wikit.vfs-original/lib/app-wikit/start.tcl        2003-06-06 00:43:50.000000000 +0200
 @@ -162,7 +162,7 @@
        package require Web
        package require wikithttpd
        #warning, POST not supported! read-only!
 -      #set roflag 1
 +      set roflag 1

        #set ::httpd::debug 1
        eval [mk::get wdb.pages!9 page]
 diff -Naur wikit.vfs/lib/httpd/wikithttpd.tcl wikit.vfs-original/lib/httpd/wikithttpd.tcl
 --- wikit.vfs/lib/httpd/wikithttpd.tcl        2003-10-29 18:02:16.000000000 +0100
 +++ wikit.vfs-original/lib/httpd/wikithttpd.tcl        2003-06-06 00:43:50.000000000 +0200
 @@ -67,19 +67,16 @@
              }
              data {
                  append server($channel.data) [read $channel]
 -                if { $server($channel.contentLength) > -1 } {
 +                if { $server($channel.contentLenght) > -1 } {
                      if {[string length $server($channel.data)] >= \
 -                            $server($channel.contentLength) } {
 +                            $server($channel.contentLenght) } {
                          processRequestData $channel
                      }
                  } else {
 -                    httpReturn $channel 501 text/plain "501 Unknown content length"
 -                    close $channel
 -                    cleanupChannel $channel
                      #seeing as we don't know how many bytes to expect 
                      #we must, alas, process every time...
                      #note that this code is untested...
 -                    #processRequestData $channel
 +                    processRequestData $channel
                  }
              }
          }
 @@ -110,7 +107,7 @@

          if { [info exists server($channel.ch.Content-Length)] && \
                   [string is integer $server($channel.ch.Content-Length)]} {
 -            set server($channel.contentLength) $server($channel.ch.Content-Length)
 +            set server(contentLength) $server($channel.ch.Content-Length)
          }

          log  "\[[lindex [fconfigure $channel -peername] 0]\]" "$method $uri"
 @@ -120,9 +117,6 @@
              "GET" {
                  runWikit $channel
              }
 -            "POST" {
 -                set server($channel.position) data
 -            }
              default {
                  httpReturn $channel 501 text/plain "501 Method not supported\nSorry wikit-httpd only supports GET"
                  close $channel
 @@ -220,9 +214,6 @@
          set ::env(SERVER_SOFTWARE) $serverSoftware
          set ::env(PATH_INFO) $server($channel.uri)
          set ::env(PATH_TRANSLATED) [file join $documentRoot $server($channel.uri)]
 -        if { $server($channel.contentLength) != -1 } {
 -            set ::env(CONTENT_LENGTH) $server($channel.contentLength)
 -        }

          rename ::puts ::real_puts
          rename ::httpd::capture_puts ::puts
 @@ -248,6 +239,11 @@

      }

 +    proc processRequestData { channel } {
 +        variable server
 +
 +    }
 +
      proc httpReturn { channel code type data } {
          variable serverSoftware

 @@ -327,9 +323,9 @@

      proc log { type text } {
          variable debug
 -        variable server
 -            $server(puts) "[httpTime]: $type $text"
 -        }
 +        variable server                    
 +        $server(puts) "[httpTime]: $type $text"
 +    }



 @@ -341,8 +337,8 @@
          #arguments, reading stdin: [read stdin length]
          #or some other fd: [read fd]

 -        if { [llength $args] == 2 && [lindex $args 0] == "stdin" } {
 -            return $::httpd::server(cgidata)
 +        if { [llength $args] == 3 } {
 +            return $server(cgidata)
          } else {
              eval real_read $args
          }
 diff -Naur wikit.vfs/lib/wikit/web.tcl wikit.vfs-original/lib/wikit/web.tcl
 --- wikit.vfs/lib/wikit/web.tcl        2003-10-29 18:09:53.000000000 +0100
 +++ wikit.vfs-original/lib/wikit/web.tcl        2003-10-15 02:35:41.000000000 +0200
 @@ -102,13 +102,6 @@

    set ::script_name $::env(SCRIPT_NAME)

 -  # fix embedded wikithttpd server script name
 -  if { [string first "WikitHttpd" $env(SERVER_SOFTWARE)] > -1 } {
 -      if { $::script_name == "/" } {
 -          set ::script_name ""
 -      }
 -  }
 -
    # this code added 1-5-2001 to handle ErrorDocument redirection/caching
    if {[info exists ::env(REDIRECT_URL)]} {

 @@ -353,7 +346,7 @@
            }

            cgi_body bgcolor=#ffffff {
 -            cgi_h2 [Wiki - $N]
 +            cgi_puts [h2 [Wiki - $N]]

              cgi_form $::script_name/$N {
                cgi_export O=$origtag
 @@ -396,7 +389,7 @@
            }

            cgi_body bgcolor=#ffffff {
 -            cgi_h2 "References to [Wiki - $N]"
 +            cgi_puts [h2 "References to [Wiki - $N]"]

              set refList ""
              foreach r $refs {

jcw - Hey, this is great. I'm trying it out - but there still seems to be one thing going wrong: on the references pages (or click on a page title), and on edit pages, I see a duplicate header showing up. There is a very strange mixup going on, here's an example:

  <html>
  <head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8"></meta>
  <title>References to Recent Changes</title>
  <meta http-equiv="Pragma" content="no-cache"></meta>
  <meta http-equiv="Expire" content="Mon, 04 Dec 1999 21:29:02 GMT"></meta>
  </head>
  <body bgcolor="#ffffff" >
  <h2>References to <a href="4">Recent Changes</a></h2>Content-type: text/html
  Pragma: no-cache

  <html>
  <head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8"></meta>
  <title>References to Recent Changes</title>
  <meta http-equiv="Pragma" content="no-cache"></meta>
  <meta http-equiv="Expire" content="Mon, 04 Dec 1999 21:29:02 GMT"></meta>
  </head>
  <body bgcolor="#ffffff" >
  <h2>References to <a href="4">Recent Changes</a></h2>
  <ul><li>2003/09/26 11:36:36 . . . <a href="3">Help</a> . . . local</li></ul><hr noshade /><font size="-1"><a href="2">Search</a> -  -  - About <a href="1">Wikit</a> -  - Go to <a href="0">My Wiki</a></font>
  </body>
  </html>

Note the restarted <html> section.

Michael Heca 2003-10-29 - Problem is in invalid use of h2 proc. H2 proc call put and return nothing. Patch is now fixed. I hope this not broke CGI usage of wikit.