Things I've used to muck with the contents of a [wikit]... JC ---- '''Dump all scripts from a wiki as text files:''' set infile wikit.tkd set outfile out.txt package require Mk4tcl mk::file open db $infile -readonly set f [open $outfile w] mk::loop c db.scripts { array set a [mk::get $c] puts $f "=========\n$a(name)\n=========" set text $a(text) catch {set text [zip -mode decompress $text]} puts $f $text } close $f exit If you change "db.scripts" to "db.pages", you'll get a dump of all pages in the wikit (yes, this sort of stuff needs to be streamlined into a more general little helper/tool, I just never got that far...). For the new-style (VFS?) wikit (tclkit wikit.kit wikit.tkd), I used "set text $a(page)" to get pages out. To get at the actual scripts, the wikit.kit needs to be looked at instead. ---- '''Extract all scripts as individual files:''' file mkdir w proc Set {view index name n text t date d} { puts "w/$n [clock format $d -gmt 1]" set fd [open w/$n w] #fconfigure $fd -translation crlf puts -nonewline $fd $t close $fd } source w.scripts To use this, you must first dump all scripts to file, using the command line: tclkit wikit.tkd --scripts= >w.scripts That creates a single Tcl script with Set commands. The above snippet then sources that scripts and saves each entry as file. Note that you can now edit them and then reload these files back in with the command: tclkit wikit.tkd --scripts=w/ This approach might also be used to extract each wiki page as a file (use "--pages=" instead), but this gets tricky if page titles are not valid file names. ---- '''Upgrading a non-compressing WiKit to the newer compressed-script style:''' At some point, I introduced compression for scripts into WiKit. The scripts have changed to use Trf's "zip" command to deal with this. Unfortunately, there is one place where this is impossible: the header of a WiKit has a few lines which cannot be replaced easily. If you replace the main WiKit scripts with compression-aware ones, you will run into a problem when the boostrap header ("cli.tcl") gets saved in compressed form. Here's a hack to end up with a new header which ought to support compression. Fasten your seatbelts: * Create a file called "header.tcl", containing the following lines: #!/bin/sh # \ exec tclkit "$0" ${1+"$@"} package require Mk4tcl 1.1 if [catch {mk::file open doc [info script] -nocommit} msg] { puts stderr "Cannot open '[info script]' (it may be in use)" exit 1 } package require Trf 1.3 set script [mk::get doc.scripts!0 text] catch {set script [zip -mode decompress $script]} eval $script return ######### * Now the weird part: edit this file and add hashes at the end of the trailing comment line, until the file size is a multiple of 16 bytes. * Move your wikit file to a backup, perhaps doing: mv wikit.tkd wikit-old.tkd * Create a new file which starts with the new header: cat header.tcl wikit-old.tkd >wikit.tkd * Make the new file executable again: chmod a+rx wikit.tkd That's it. You should now have a functional wikit which can deal with compression. Now, you can update the wikit scripts to the latest version, which will probably be done with a line such as: ./wikit.tkd --scripts=scripts/ ---- '''Script to rename titles and compact the datafile''' ''Here's a little script to manually make changes to wikit titles:'' #! /usr/bin/env tclkit # Rename (optional) and compact wikit file -jcw, 20020625 lassign $argv inf outf page name if {$inf == ""} { puts stderr "Usage: $argv0 infile outfile ?pagenum newtitle?" exit 1 } mk::file open db $inf -readonly if {[file exists $outf]} { error "$outf: output file already exists" } if {$page != ""} { if {$name == ""} { error "no new title specified for page $page" } set oname [mk::get db.pages!$page name] puts "Changing name of page $page" puts " old: $oname" puts " new: $name" mk::set db.pages!$page name $name } set fd [open $outf w] mk::file save db $fd close $fd puts "Done, old size [file size $inf]b, new size [file size $outf]b." ---- Note that such title changes do not adjust references to the page, you will have to do that manually. Then again, if the change is just to alter capitalization, or fix a typo, this script does get the job done. This script will write the resulting datafile to a new one with unused space removed. To finish the conversion, copy the new data over the old (when the datafile is not in use). Example: ./renwikit wikit.tkd wikit.new 1 Wikit # just to change case cat wikit.new >wikit.tkd && rm wikit.new # preserves file mode ---- [Category Wikit] - [Category Tcler's Wiki]