shwiki.scm
(module hwiki mzscheme
        (require (planet "hwikireq.scm" ("oesterholt" "hwiki.plt" 1 0)))
        (require (planet "hwiki-internal.scm" ("oesterholt" "hwiki.plt" 1 0)))
        
        (provide interface-version instance-expiration-handler manager start)
        
        (require (planet "hwiki-manager.scm" ("oesterholt" "hwiki.plt" 1 0)))
        
        (define interface-version 'v2-transitional)
        (define (instance-expiration-handler failed-request) 
          (display (format "~s~%" failed-request))
          )
        (define manager (create-hwiki-manager instance-expiration-handler))
        ;(provide interface-version timeout start)
        
        ;(define interface-version 'v1)
        ;(define timeout 30)  ;;; default timeout. Configuration file timeout for servlets should be set to 1 day
        
        
        (define (set-timeout context)
          (debug (format "set-timout: logged-in=~a, ~s" (-> context logged-in?) adjust-timeout!))
          (if (-> context logged-in?)
              (let ((seconds (* 3 3600.0)))
                (debug (format "set-timeout:adjusting timeout for the current continuation to ~a seconds" seconds))
                ;(adjust-timeout! +inf.0)
                )))
;                (adjust-timeout! seconds))))
;              (begin
;                (debug (format "set-timeout:adjuring timeout for the current continuation to ~a seconds" 120))
;                (adjust-timeout! 120))))
        
        (define (start request)
          (hwiki-start request set-timeout))
        
        ;;;; Initialize environment
        
        (if (not (getenv "HWIKI_TINYMCE")) 
            (error "The location of the 'tinymce' directory must be given through environment variable HWIKI_TINYMCE"))
        (if (not (getenv "HWIKI_PLUGINS"))
            (error "The location of 'hwiki-plugins.scm' must be given through environment variable HWIKI_PLUGINS"))
        (if (not (getenv "HWIKI_DATA"))
            (error "The hwiki data directory must be given through environment variable HWIKI_DATA"))
        (if (not (getenv "HWIKI_HTDOCS"))
            (error "The htdocs directory must be given through environment variable HWIKI_HTDOCS"))
        (if (not (getenv "HWIKI_LOGS"))
            (error "The hwiki logs directory must be given through environment variable HWIKI_LOGS"))
        (if (not (getenv "HWIKI_SRCDIR"))
            (error "The hwiki source directory must be given through environment variable HWIKI_SRCDIR"))

        ;;;; * tinymce
        (let ((src (getenv "HWIKI_TINYMCE"))
              (dst (build-path (getenv "HWIKI_HTDOCS") "tinymce")))
          (if (not (directory-exists? dst))
              (copy-directory/files src dst)))
        
        ;;;; * plugins
        (let ((src (getenv "HWIKI_PLUGINS"))
              (dst (build-path (current-directory) "hwiki-plugins.scm")))
          (if (not (file-exists? dst))
              (copy-to src dst)))
        
        ;;;; * rewrites
        (let ((src (getenv "HWIKI_REWRITES"))
              (dst (build-path (current-directory) "rewrite-rules.scm")))
          (if (file-exists? src)
              (if (not (file-exists? dst))
                  (copy-to src dst))))
        
        ;;;; * default css's
        (let ((srcdir (build-path (getenv "HWIKI_SRCDIR") "examples"))
              (dstdir (build-path (getenv "HWIKI_DATA") "css"))
              (htdocd (build-path (getenv "HWIKI_HTDOCS"))))
          (if (not (directory-exists? dstdir))
              (make-directory* dstdir))
          (if (not (directory-exists? htdocd))
              (make-directory* htdocd))
          (if (not (file-exists? (build-path dstdir "admin")))
              (begin
                (copy-to (build-path srcdir "admin") (build-path dstdir "admin"))
                (copy-to (build-path srcdir "admin") (build-path htdocd "admin.css"))))
          (if (not (file-exists? (build-path dstdir "default")))
              (begin
                (copy-to (build-path srcdir "default") (build-path dstdir "default"))
                (copy-to (build-path srcdir "default") (build-path htdocd "default.css"))))
          )
                
        
        )