Wikit configuration

Wikit supports a number of configuration settings, defined by a number of configuration variables:

WIKIT_ADMIN
Set this to ignore the protected-pages list, which normally prevents editing certain pages
WIKIT_BASE
Set this to define the URL of the wiki pages - this causes generated pages to always refer to wiki pages with this base location (no more cgi-bin URLs), see below for more info.
WIKIT_CACHE
Set this to a writable dir, and wikit will save new pages in HTML form in this area. This can be used with Apache to maintain a fast-access page cache so most accesses never launch CGI.
WIKIT_CSS
Set this to the URL of the style sheet to use, and wikit will become CSS-enabled.
WIKIT_DUMP
This is a debug facility, set this to a writable file and all accesses will append info to that file.
WIKIT_EMAIL
Set this to email address to use to report CGI failures (default goes nowhere).
WIKIT_HIST
Set this to a writable directory, and wikit will save every modified page in raw text form, under a unique name. It also appends entries to a ".index" text file in there. This is used by the Tcl'ers Wiki to move all page edits into a CVS repository (this is an independent cron script).
WIKIT_REVS
This is a URL prefix. When set, wikit will append "/<N>" to it as a link on each editable page, called "Revisions".
WIKIT_SAVE
If this is set to "0", and WIKIT_CACHE is set as well, then clear the cache on edit changes, but do not save changes back to it. This is needed in special cases, i.e. when accessing the same wiki from two different URLs, one using CSS and the other not. The format which should not be saved back in the cache should use WIKIT_SAVE=0 in the corresponding CGI script.
WIKIT_WRU
This variable is special-purpose, it allows the Tcler's Wiki to interact with the wru utility ("who are you, see [L1 ]) to pick up cookie which add the initials of the poster to page edits and recent changes.

Static page access in Apache

There is a way to make Apache use static page copies, based on an error-redirect trick. The idea is to make all pages static, and remove them from the cache when edited. An access to a page which is not in the cache forces a CGI call, which generates the page and updates the cache.

Here's what I do to make this work:

  • say the area you want to present is "mywiki"
  • create a "mywiki/" dir, writable for CGI (usually user apache, www, or nobody)
  • create a file "mywiki/.htaccess" containing:
        ErrorDocument 404 /mywiki/nph-blah.cgi
        DirectoryIndex /mywiki/nph-blah.cgi/0
        Options MultiViews
  • create a file "mywiki/nph-blah.cgi" containing:
        #!/bin/sh
        echo HTTP/1.0 200 OK
        cd /path/to/my/datafile
        WIKIT_BASE=http://<mysite>/mywiki/
        export WIKIT_BASE
        WIKIT_CACHE=/path/to/mywiki
        export WIKIT_CACHE
        #WIKIT_CSS=http://url/of/my/style/sheet.css
        #export WIKIT_CSS
        # uncomment following as needed
        #WIKIT_DUMP=/path/to/mywikilogfile
        #export WIKIT_DUMP
        #WIKIT_HIST=/path/to/mywikihistdir
        #export WIKIT_HIST
        exec /path/to/tclkit wikit.kit mywikit.tkd
  • (add "-readonly" at the end to make the wiki readonly)

The "Options MultiViews" cause an access for page "123" to be satisfied when file "123.html" is present.

Note that the "nph-" part of the naming of the script is significant. I (MNO) had a number of problems which turned out to be because I didn't do this.

27July03 Daniel Steffen - I am sucessfully using apache url rewriting instead of the error-redirect approach, which works just as well and should perform better, c.f. [L2 ].


24June03 CM - I found that the "DirectoryIndex /mywiki/nph-blah.cgi/0" option prevents all directory indexes to work. If you are using Apache, you can instead use this in 'httpd.conf':

 # DirectoryIndex: Name of the file or files to use as a pre-written HTML
 # directory index.  Separate multiple entries with spaces.
 #
 <IfModule mod_dir.c>
     DirectoryIndex index.html 0.html
 </IfModule>

which will add "0.html" as a way to find a directory index, in the Wiki and elsewhere; but will not prevent the automatic index to work in non-wiki directories. This only works if a static page already exists in the cache, however... (it's usually the case for "0").


10apr03 rf - I had to use the "execCGI" option in my "mywiki/.htaccess" to get it working:

        ErrorDocument 404 /mywiki/nph-blah.cgi
        DirectoryIndex /mywiki/nph-blah.cgi/0
        Options MultiViews execCGI

Hmmm... is WIKIT_CACHE really available?? It doesn't seem to work at all. Also, just a wee small thingy, can WIKIT_CACHE be /path/to/my/htdocs? Will that work? I generally do not want people to be able to poke their browsers into my cgi area ;^)

12nov02 jcw - Yes it is, that's how the Tclers' Wiki is set up. The trick is the redirect everything to a CGI. So what you do is create a dir just for the cache, make that the public one, i.e. the "real" public area, then redirect page misses to a CGI elsewhere, telling that CGI to update this area. When it does, the page will exist, i.e. not trigger an error from then on, hence be served statically. If you follow what I'm saying...

10 Jun 2003 -WL- I finally got the cache to work, yay! One annoying thing is every search becomes a file not found.... I kind of wish the cache feature was a bit more straightforward. IE, if CACHE=blah, wikit knows to look in $CACHE for the file first, instead of bouncing around with 404 and WIKIT_BASE, etc. Now that the cache is there, I guess the next thing to do is to give wikit the ability to send out gzip encoded files...


13dec2002 ps I wonder why the above .cgi has [echo HTTP/1.0 200 OK], my apache doesn't like it... It works fine without that statement. (I had similar problems so left it off until I realised that the "nph-" part of the script name is significant to Apache, and once you name the script thus, it needs to have the "echo" statement --MNO).

And if you are having trouble with the parameters in the .htaccess file (like I had), it could well be that you need to set the options in a <Directory /mywiki> entry in your httpd.conf like this:

 <VirtualHost *>
        ServerName www.mywiki.com
        AddHandler cgi-script .cgi
        <Directory />
                ErrorDocument 404 /mywiki/wiki.cgi
                DirectoryIndex /mywiki/wiki.cgi/0
                Options ExecCGI MultiViews
        </Directory>
 </VirtualHost>

Because your httpd.conf may (quite rightly) have global AllowOverride None, which prevents .htaccess from working...


Wikit and AOLserver

Although the Apache solution is the better one, with the possibility for static page access, I use AOLserver a lot so I want wikit to work in AOLserver too.

The first thing that needs to be done is add a couple of lines to wikit/lib/wikit/web.tcl, near the beginning of [ProcessCGI] is a line:

 set ::script_name $::env(SCRIPT_NAME)

Right before that, insert:

 if { [string first "AOLserver/3" $::env(SERVER_SOFTWARE)] > -1 } {
    #Aolserver does not provide a correct SCRIPT_NAME
    #fix this by parsing the WIKIT_BASE (which is mandatory anyway)
    catch {
        regexp -nocase {^http://[^/]+(/.+)/$} $::env(WIKIT_BASE) -> ::env(SCRIPT_NAME)
    }
 }     

This fixes the problem that the edit pages do not allow you to save the page (because the URL is wrong).

I am working on a [ns_register_proc] to handle static page access, like the apache solution. Any chance someone has already done that? Should be simple enough:

 if { the_static_page_exists } {
     ns_returnfile 200 text/html $static_file
 } else { 
     ns_returnredirect /mywiki/wiki.cgi/$pagenumber
 }

But might need some tweaks to wikit so two different types of urls are used for internal links.

-- PS.

06feb03 jcw - I've just added your first patch to the wikit code base, should now work with AOLserver - thx.


Static page access in Tclhttpd

07mai03 I'd like to have this static-feature in Tclhttpd, too. Therefore I used the following tcl-code. Place it in the custom-directory of tclhttpd (if you have problems, that tclhttpd isn't reading the custom-directory, see [L3 ].

 set wikitCacheDir mywiki ;# above mentioned as WIKIT_CACHE
 set wikitCgiDir /cgi-bin/wikit.cgi

 Url_PrefixInstall /$wikitCacheDir [list wikit_handler $wikitCacheDir $wikitCgiDir]

 proc wikit_handler {wikitCacheDir wikitCgiDir sock suffix} {
     global Config
     upvar #0 Httpd$sock data

     # make suffix "relative"
     regsub {^/} $suffix {} suffix

     # redirect to "homepage" of wikit, if no "page"/suffix is given
     if {![string length $suffix]} {
         set suffix "0"
     }
     set cachefile [file join $Config(docRoot) $wikitCacheDir $suffix]

     # the url is http://xyz/0, but the cached file will be "0.html"
     # only append ".html" if request has no extension
     # (this avoids appending ".html" for other files in cache-dir, like
     # wikit.css
     if {[string equal [file extension $cachefile] ""]} {
         append cachefile ".html"
     }

     # check if file is in cache
     if {[file exists $cachefile]} {
         # file is in cache, so simply return cached file
         Httpd_ReturnFile $sock text/html $cachefile
     } else {
         # REDIRECT_URL must be set, because WIKIT checks it for caching
         # and tclhttpd doesn't set it itself
         set ::env(REDIRECT_URL) [file join $wikitCgiDir $suffix]
         Httpd_Redirect $::env(REDIRECT_URL) $sock
     }
 }

I don't know if this is the preferred solution, but it works for me (at least for Tclhttpd 3.4.2).

For running TclHttpd on Windows I've set the following Windows-System-Environment-variables (let's say my Tclhttpd is installed in

  tclhttpd = D:/tclhttpd3.4.2

)

 WIKIT_CACHE = D:/tclhttpd3.4.2/mywiki/
 WIKIT_BASE = http://localhost:8015/mywiki/

I suppose the trailing / is important.

When I have a CSS, I use, e.g.:

  WIKIT_CSS = http://localhost:8015/mywiki/wikit.css

-- Stefan Vogel.

31July03 Jeff Smith I tried the above script on tclhttpd 3.4.2. It is redirecting to the /cgi-bin/wikit.cgi and working OK but no static pages are generated in the mywiki/ directory. My wikit.cgi script looks like

 #!/bin/sh

 WIKIT_BASE=http://cobra:8015/mywiki/
 export WIKIT_BASE
 WIKIT_CACHE=/usr/local/tclkit/mywiki
 export WIKIT_CACHE
 exec /usr/local/tclkit/tclkit /usr/local/tclkit/wikit.kit

Any ideas?

31July03 Jeff Smith Added

 lappend Cgi(env-pass) REDIRECT_URL

To the beginning of the script above

 set wikitCacheDir mywiki ;# above mentioned as WIKIT_CACHE

and now static pages appear in mywiki/ directory. I think with cgi processing in tclhttpd on unix, not all the environment variables are passed, whereas with tclhttpd on windows they are.

04 September 2003 Jeff Smith I had a go at making a Starkit of Wikit with inbuilt Tclhttpd including Stefan's script.

June 2004 BBW Here is the URL domain handler I have for launching a wikit CGI script. This is similar in spirit to that provided by Stefan Vogel but I don't really care about the cache. I just wanted the URLs to not reference the CGI script.

 # Create a tclhttpd domain that wires directly into the wiki cgi script
 # I deploy this as wiki/custom/wiki_startup.tcl
 # and I have the CGI script in wiki/bin
 # Start bin/httpd.tcl with the -library wiki/custom option

 set here [file dirname [info script]]
 set WikiCGI [file join $here ../bin/wiki.cgi]

 Url_PrefixRemove /      ;# Remove normal doc domain
 Url_PrefixInstall / [list WikiDomain /]

 proc WikiDomain {prefix sock suffix} {
   global WikiCGI
   upvar #0 Httpd$sock data
   set extra /$suffix
   # er, extra == $data(url)
   WikiHandle $data(url) $extra $WikiCGI $sock
 }
 proc WikiHandle {url extra path sock} {
   global Doc env
   # We pass in / for the url argument because that turns
   # into the SCRIPT_NAME env var, which the wikit's web.tcl glues
   # onto $extra.
   # extra -> PATH_INFO
   # url -> SCRIPT_NAME
   Cgi_SetEnvAll $sock $path $extra / env
   CgiSpawn $sock $path
 }

 # We need a few files, like images and the stylesheet

 Doc_AddRoot /htdocs [file join $here ../htdocs]
 Doc_AddRoot /images [file join $here ../htdocs/images]

 # Set up logging

 file mkdir [file join $here ../log]
 set config::Config(LogFile) [file join $here ../log/log]

MHo: Can't get caching to always work right. The problem is: WIKIT_BASE has to be specified full qualified. This means, it contains the servername and if I test on the same machine running the server on, the cached files contain something like <base href="http://localhost/wikiccsas/ ">, which is obviouseley wrong when accessing these cached html from another machine. The reason for this is I'm constructing WIKIT_BASE with Httpd_SelfUrl, which resolves in this situation to localhost. Heres my caching implementation:

 # support more than one wiki
 Url_PrefixInstall /wikiccsas [list wikiHandler ccsas]
 Url_PrefixInstall /wikiccpm  [list wikiHandler ccpm]

 proc wikiHandler {prefix sock suffix} {

      # additional vars for wikit
     set ::env(WIKIT_CACHE)  [file join [Doc_Root] wikicache $prefix]
     set ::env(WIKIT_HIST)   [file join [Doc_Root] wikihist  $prefix]
     set ::env(WIKIT_BASE)   [Httpd_SelfUrl /wiki$prefix/]; # scheint problematisch (localhost?)
     # prevent WIKIT_HIST from beeing overwritten late in patched cgi.tcl's (internal regarding to my own tclhttpd.exe..., not of interest here)
     set ::Config(WIKIT_HIST) $::env(WIKIT_HIST)

     global Config
     upvar #0 Httpd$sock data
     set wikitCgiDir /cgi-bin/wiki/${prefix}.exe; # PB-Wrapper to tclkitsh wikit.kit because with wikitsh.exe there are search-problems...

     # make suffix "relative"
     regsub {^/} $suffix {} suffix

     # redirect to "homepage" of wikit, if no "page"/suffix is given
     if {![string length $suffix]} {
         set suffix "0"
     }
     set cachefile [file join [Doc_Root] $::env(WIKIT_CACHE) $suffix]

     # the url is http://xyz/0, but the cached file will be "0.html"
     # only append ".html" if request has no extension
     # (this avoids appending ".html" for other files in cache-dir, like
     # wikit.css
     if {[string equal [file extension $cachefile] ""]} {
         append cachefile ".html"
     }

     # check if file is in cache
     if {[file exists $cachefile]} {
         # file is in cache, so simply return cached file
         Httpd_ReturnFile $sock text/html $cachefile
     } else {
         # REDIRECT_URL must be set, because WIKIT checks it for caching
         # and tclhttpd doesn't set it itself
         set ::env(REDIRECT_URL) [file join $wikitCgiDir $suffix]
         Httpd_RedirectSelf $::env(REDIRECT_URL) $sock
     }
 }

How do I configure in windows?

19may03 Richard -- I dont get it. How do I set these variables (WIKIT_CSS for example) when using windows and the TCL-webserver? 17jun04 I'm running wikit.kit under tclhttpd on windows in CGI-mode successfully. See Matthias Hoffmann - Other Utilities for a possible solution.

June 10, 2003 LV On Linux/Solaris what I do is invoke wikit from a CGI shell script. In that script, I set these variables and then invoke the wikit command itself. Would that be a possible solution for you as well?


9 October 2003 Stefan Vogel You might want to use the wikitool (from Tom Krehbiel) to admin your wikit inside tclhttpd. Have a look at wikitool


13-feb-2005 VK: is it possible to use other than utf-8 encoding in generated HTMLs? I want to use CP-1251 for editing my wiki pages, which I use on my own site (setting wikit was easy, thanks!).