#!/usr/bin/tclsh # (find-es "tcl" "httpwiki") # (find-angg "TCL/httpwiki-old") # By Edrx, 2007feb18 # This is MHo's program with a few small changes. # "How to edit Wikit pages with Emacs": http://wiki.tcl.tk/627 # (find-sh "~/TCL/httpwiki eget http://wiki.tcl.tk 33") # (find-sh "~/TCL/httpwiki eget http://wiki.tcl.tk 627") # (find-sh "wget -q -O - http://wiki.tcl.tk/edit/627@") # (find-sh "wget -q -O - http://wiki.tcl.tk/edit/627@" "input type=hidden") # Sending doesn't work right now because of the hidden field package require http 1.0 proc getpage {wikiurl N} { set s [http_data [http_get $wikiurl/edit/${N}@]] if {[regexp "" $s -> text]} { regsub -all {\"} $text "\"" text regsub -all {\<} $text {<} text regsub -all {\>} $text {>} text regsub -all {\&} $text {&} text } else { error "Bad edit page" } return $text } proc sendpage {wikiurl N text} { set answer [http_data [http_get $wikiurl/$N.html \ -query [http_formatQuery C $text]]] } proc emacsheader {argv0 wikiurl N} { return \ "; To send back the edited version, place the cursor at the beginning ; of the first non-void line after the S-expression and do a C-x C-e. ; $wikiurl/${N} ; $wikiurl/edit/${N}@ ; (shell-command-on-region (point) (point-max) \"$argv0 send $wikiurl $N\")\n\n\n" } if {$argc!=3} { puts stderr "Usage: $argv0 get|eget|send wikiurl pagenumber" puts stderr "Example: $argv0 eget http://wiki.tcl.tk 33 | tee 33" puts stderr " then edit the file \"33\" with Emacs and follow the instructions there." exit 1 } foreach {action wikiurl N} $argv {} switch $action { get { puts -nonewline [getpage $wikiurl $N] } eget { puts -nonewline "[emacsheader $argv0 $wikiurl $N][getpage $wikiurl $N]" } send { sendpage $wikiurl $N [read stdin] } default { puts stderr "Bad action!" exit 1 } }