Version 27 of wikitool

Updated 2008-01-11 17:54:01 by LV

Introduction

Wikitool is a script to get information from the wikit metakit data file from the command line. It's special because it is coded in pure Tcl.

The script can be downloaded from http://www.equi4.com/pub/sk/wikitool.tcl .

To use this tool, cd into the directory where you have a wikit.tkd file - that's the data portion of the wikit. Then, execute

 wikitool.tcl -l

Be certain that you get the most current copy - as mentioned elsewhere, previous versions are not likely to work.

The results you should expect to see, on stdout, consist of lines such as:

   10:  2002/06/19 06:45:26  80.126.24.9      Jean-Claude Wippler

The format is:

 Field: 1                2                 3                4              5
 page-number:  last-update-date last-update-time last-updater's-IP  page-title

14apr03 jcw - There's another far more sophisticated "wikitool" by Tom Krehbiel; it's on sdarchive. Might be an idea to rename this thing to "wikiutil" or some such, just to avoid confusion...


Using Tom Krehbiel's wikitool.kit as CGI in tclhttpd

7 October 2003: I'd like to use the wikitool from Tom Krehbiel as a CGI, to maintain my own wiki which runs as a CGI inside my local tclhttpd.

To do this, you have to adapt the "wikitool.kit" (found on http://mini.net/sdarchive/wikitool.kit ), to avoid a "package require Tk". So do an:

 sdx unwrap wikitool.kit

and then

  • in "main.tcl" surround "wm withdraw ." with a catch
  • and in "lib/wikit.vfs/lib/wikit/wikit.tcl" surround "package require Tk" with a catch and remove or uncomment the "exit .." in case of a failure of "package require Wikit::Gui"

wrap it up again:

 sdx wrap wikitool.kit

Furthermore you can use the following "wikitool_admin.cgi"-script and place it into your cgi-bin.

 #!/bin/sh
 # \
 exec tclsh84 "$0" ${1+"$@"}
 source cgilib.tcl

 # available commands
 set cmds {
 pages,report
 pages,out
 pages,html
 pages,index
 pages,add
 pages,update
 pages,fix
 images,report
 images,add
 images,update
 images,out
 xref,refs
 xref,page@page
 xref,page2image
 xref,image2page
 sweep,report
 sweep,mark
 sweep,unmark
 sweep,clean
 defrag
 }

 # little "Vignette"-like wrapper ... ugh
 proc SHOW {var} {
   upvar $var _var
   return [expr {[info exists _var] ? "$_var" : ""}]
 }

 # build up a select-box for all commands
 proc showCommands {cmds selected} {
   set result {}
   foreach cmd $cmds {
     append result "<option value=\"$cmd\"[expr {$selected == $cmd ? " selected" : ""}]>[split $cmd ,]</option>"
   }
   return $result
 }
 # initialize query-parameters to variable values
 foreach {key value} [Cgi_List] {
   set $key $value
 }
 if {![info exists commands]} {
   set commands [lindex $cmds 0]
 }

 puts "Content-Type: text/html"
 puts ""
 puts [subst {<html>
 <body>
 <form action="$env(SCRIPT_NAME)" method="get">
 <table>
 <tr><th>Database</th><th>Commands</th><th>args</th></tr>
 <tr><td><input type="text" name="database" value="[SHOW database]"></td>
     <td><select name="commands">[showCommands $cmds [SHOW commands]]</select></td>
   <td><input type="text" name="arguments" value="[SHOW arguments]"></td></tr>
 </table>
     <input type="submit">
 </form>
 <hr>
 <b>Result:</b><br>
 }]

 # call the wikitool with given parameters
 # set cmd "| tclkitsh.exe wikitool.kit wikit.tkd pages report"
 if {[info exists database]} {
   foreach {command subcommand} [split [SHOW commands] ,] {break}
   set cmd "| tclkitsh wikitool.kit $database $command $subcommand [SHOW arguments]"
   # for the defragmention we pass "y" the query "really defrag (y/n)"
   if {$command == "defrag"} {
     append cmd " << y"
   }
   puts "Executing: $cmd"
   if {[catch {open $cmd} fh] } {
     puts "Error: Can't open pipe. $fh"
   }
   set PIPE $fh
   fconfigure $PIPE -buffering none
   set OUTPUT ""
   puts "<pre>"
   while { [gets $PIPE DATA] >= 0 } {
     puts $DATA
   }
   puts "</pre>"
   catch {close $PIPE} msg
 }

 puts "<br>[SHOW cmd] finished.</body></html>"

 exit 0

  • Place this script into the cgi-bin of your tclhttpd and place the "wikitool.kit" there as well.
  • Furthermore you need the tclkitsh-program lying around somewhere in your path.
  • Now take your wiki-data file (I assume "wikit.tkd") and place it into the cgi-bin-directory as well.
  • go to http://<yourserver:andport>/cgi-bin/wikitool_admin.cgi
  • Enter "wikit.tkd" as the "Database", choose "pages report" and GO

Pay attention that now everybody who can access your webserver can administrate your wiki, so you should consider some security-mechanisms.

Have fun Stefan Vogel.

... I just tried this code with tclhttpd and am unable to see the output from wikitool, which I expected from 'puts $DATA' - just several empty lines. The cgi script is working, as I am able to duplicate the command execution code above within the wikitool_admin.cgi file and successfully execute and see the result from that command. I've tried it on IRIX and Linux platforms - is there something simple I'm missing? Thanks in advance for taking the time to respond.

28 Mai 2004: Stefan Vogel I just tested that again (I had some problems with my own description, so I updated a few things). It works well at least on Windows XP. Have you adapted the "wikitool.kit" (because that uses Tk)?

Does

  %..cgi-bin> tclkitsh wikitool.kit wikit.tkd pages report

puts something on the console? ...yes, it gives the correct output, but ... you were astute in asking me to check whether I had made the changes to wikitool. I had made the changes, but accidently copied the original wikitool.kit into cgi-bin instead of the modified version. I have it working now, just as you described it. Thanks again for your help!


How do you use Tom Krehbiel's wikitool.kit ? Are there any explanatory notes for wikitool.kit commands/parameters? Yes... Run wikitool.kit in TK GUI mode and see the command descriptions. If you are running wikitool.kit with the catch {tk} mods, wikitool_admin.cgi by Stefan Vogel (see above), through CGI, you won't see the command help! [31Aug04 CvK]