Version 3 of Some WiKit scripts

Updated 2002-08-14 09:05:50

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 wikit (tclkit wikit.kit wikit.tkd), I had to use "set text $a(page)" to get pages out. Using db.scripts instead db.pages didn't return anything, though.


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/

Category Wikit - Category Tcler's Wiki