From: joey Date: Fri, 7 Jul 2006 21:00:48 +0000 (+0000) Subject: * Support a w3mmode, which lets w3m run ikiwiki using its local CGI X-Git-Tag: 1.9~26 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/1bdfa4d8b54763eee1c266e3516bb50dd864cedc * Support a w3mmode, which lets w3m run ikiwiki using its local CGI support, to edit pages etc without a web server. --- diff --git a/IkiWiki.pm b/IkiWiki.pm index d8b272125..4964f97a1 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -34,6 +34,7 @@ sub defaultconfig () { #{{{ rebuild => 0, refresh => 0, getctime => 0, + w3mmode => 0, wrapper => undef, wrappermode => undef, svnrepo => undef, @@ -49,8 +50,17 @@ sub defaultconfig () { #{{{ plugin => [qw{mdwn inline htmlscrubber}], timeformat => '%c', } #}}} - + sub checkconfig () { #{{{ + if ($config{w3mmode}) { + eval q{use Cwd q{abs_path}}; + $config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir})); + $config{destdir}=possibly_foolish_untaint(abs_path($config{destdir})); + $config{cgiurl}="file:///\$LIB/ikiwiki-w3m.cgi/".$config{cgiurl} + unless $config{cgiurl} =~ m!file:///!; + $config{url}="file://".$config{destdir}; + } + if ($config{cgi} && ! length $config{url}) { error("Must specify url to wiki with --url when using --cgi\n"); } diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 3b4228b75..671f0b924 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -9,6 +9,18 @@ use Encode; package IkiWiki; +sub redirect ($$) { #{{{ + my $q=shift; + my $url=shift; + if (! $config{w3mmode}) { + print $q->redirect($url); + } + else { + print "Content-type: text/plain\n"; + print "W3m-control: GOTO $url\n\n"; + } +} #}}} + sub page_locked ($$;$) { #{{{ my $page=shift; my $session=shift; @@ -158,7 +170,7 @@ sub cgi_signin ($$) { #{{{ $session->param("name", $form->field("name")); if (defined $form->field("do") && $form->field("do") ne 'signin') { - print $q->redirect(cgiurl( + redirect($q, cgiurl( do => $form->field("do"), page => $form->field("page"), title => $form->field("title"), @@ -167,7 +179,7 @@ sub cgi_signin ($$) { #{{{ )); } else { - print $q->redirect($config{url}); + redirect($q, $config{url}); } } elsif ($form->submitted eq 'Register') { @@ -272,11 +284,11 @@ sub cgi_prefs ($$) { #{{{ if ($form->submitted eq 'Logout') { $session->delete(); - print $q->redirect($config{url}); + redirect($q, $config{url}); return; } elsif ($form->submitted eq 'Cancel') { - print $q->redirect($config{url}); + redirect($q, $config{url}); return; } elsif ($form->submitted eq "Save Preferences" && $form->validate) { @@ -356,7 +368,7 @@ sub cgi_editpage ($$) { #{{{ } if ($form->submitted eq "Cancel") { - print $q->redirect("$config{url}/".htmlpage($page)); + redirect($q, "$config{url}/".htmlpage($page)); return; } elsif ($form->submitted eq "Preview") { @@ -419,7 +431,7 @@ sub cgi_editpage ($$) { #{{{ if (! @page_locs) { # hmm, someone else made the page in the # meantime? - print $q->redirect("$config{url}/".htmlpage($page)); + redirect($q, "$config{url}/".htmlpage($page)); return; } @@ -504,7 +516,7 @@ sub cgi_editpage ($$) { #{{{ # The trailing question mark tries to avoid broken # caches and get the most recent version of the page. - print $q->redirect("$config{url}/".htmlpage($page)."?updated"); + redirect($q, "$config{url}/".htmlpage($page)."?updated"); } } #}}} diff --git a/Makefile.PL b/Makefile.PL index 89a8f3232..59c5d86ba 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -39,6 +39,9 @@ extra_install: install -d $(PREFIX)/sbin install ikiwiki-mass-rebuild $(PREFIX)/sbin + + install -d $(PREFIX)/lib/w3m/cgi-bin + install ikiwiki-w3m.cgi $(PREFIX)/lib/w3m/cgi-bin } } diff --git a/debian/changelog b/debian/changelog index 3cea775be..359ea1c13 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ ikiwiki (1.9) UNRELEASED; urgency=low * Patch from Recai to fix utf8 issues in git backend. * Add wikitext markup plugin, which supports ".wiki" pages written in the original wiki syntax, CamelCase links and all. + * Support a w3mmode, which lets w3m run ikiwiki using its local CGI + support, to edit pages etc without a web server. -- Joey Hess Fri, 7 Jul 2006 14:11:50 -0400 diff --git a/doc/features.mdwn b/doc/features.mdwn index 1406f5a1b..1b09a3274 100644 --- a/doc/features.mdwn +++ b/doc/features.mdwn @@ -136,7 +136,7 @@ Some of ikiwiki's features: After rather a lot of fiddling, we think that ikiwiki correctly and fully supports utf8 everywhere. -* [[serverless]] mode +* [[w3mmode]] Can be set up so that w3m can be used to browse a wiki and edit pages without using a web server. diff --git a/doc/sandbox.mdwn b/doc/sandbox.mdwn index 538d03403..a536303d2 100644 --- a/doc/sandbox.mdwn +++ b/doc/sandbox.mdwn @@ -48,8 +48,6 @@ Bulleted list *one *one -hi, mom! - ---- [[haiku hint="sandbox play"]] diff --git a/doc/serverless.mdwn b/doc/serverless.mdwn deleted file mode 100644 index 2cbf6e2f7..000000000 --- a/doc/serverless.mdwn +++ /dev/null @@ -1,3 +0,0 @@ -It's possible to use all of ikiwiki's web features (page editing, etc) in -the `w3m` web browser without using a web server. `w3m` supports local CGI -scripts, and ikiwiki can be set up to run that way. diff --git a/doc/todo/terminalclient.mdwn b/doc/todo/terminalclient.mdwn index 8c802888b..b420a3d17 100644 --- a/doc/todo/terminalclient.mdwn +++ b/doc/todo/terminalclient.mdwn @@ -2,23 +2,9 @@ Hack together a local ikiwiki w/o a web server using w3m's cgi-less mode and $EDITOR. Browse around a wiki, select pages to edit and get dropped right into the editor and have the page committed to svn automatically. +[[todo/done]] + Less grandiosely, a simple command line util to add a new page would be useful, especially if it made it easy to add blog entries to the wiki. I have a special purpose version of this in my [blog script](http://kitenet.net/~joey/code/bin.html). - ----- - -w3m's cgi mode requires that cgis be in /usr/lib/w3m/cgi-bin/, and the url -for it can be $LIB/script. This presents a problem, since a regular user -can't add an ikiwiki wrapper to there (nor should they). But, -/usr/lib/w3m/cgi-bin/ikiwiki could be a meta-wrapper, that is passed the -path to the real wrapper in PATH_INFO, validates it, and runs the real -wrapper. So: - - - -Validation is important, because we don't want just any html document -including an evil w3m cgi that gets unintentionally run. The validation I'm -thinking of is that the ikiwiki meta-wrapper only runs wrappers in -$HOME/.ikiwiki/wrappers/, which the user presumably controls. diff --git a/doc/usage.mdwn b/doc/usage.mdwn index 7bc9e5314..8404d15da 100644 --- a/doc/usage.mdwn +++ b/doc/usage.mdwn @@ -200,6 +200,11 @@ These options configure the wiki. Be vebose about what is being done. +* --w3mmode, --no-w3mmode + + Enable [[w3mmode]], which allows w3m to use ikiwiki as a local CGI script, + without a web server. + * --getctime Pull last changed time for each new page out of the revision control diff --git a/doc/w3mmode.mdwn b/doc/w3mmode.mdwn new file mode 100644 index 000000000..3afee5c9b --- /dev/null +++ b/doc/w3mmode.mdwn @@ -0,0 +1,11 @@ +It's possible to use all of ikiwiki's web features (page editing, etc) in +the `w3m` web browser without using a web server. `w3m` supports local CGI +scripts, and ikiwiki can be set up to run that way. This requires some +special configuration: + + * `w3mmode` must be enabled + * A CGI wrapper must be created, in ~/.ikiwiki/wrappers/ + * `cgiurl` should be set to just the base of the filename of the CGI + wrapper. + +This [[ikiwiki.setup]] is an example of setting up a wiki using w3mmode. diff --git a/doc/w3mmode/ikiwiki.setup b/doc/w3mmode/ikiwiki.setup new file mode 100644 index 000000000..ed65e0f91 --- /dev/null +++ b/doc/w3mmode/ikiwiki.setup @@ -0,0 +1,81 @@ +#!/usr/bin/perl +# Configuration file for ikiwiki (w3m mode). +# Passing this to ikiwiki --setup will make ikiwiki generate wrappers and +# build the wiki. +# +# Remember to re-run ikiwiki --setup any time you edit this file. + +use IkiWiki::Setup::Standard { + wikiname => "ikiwiki", + #adminuser => ["yourname", ], + #adminemail => 'me@myhost', + + # Be sure to customise these.. + srcdir => "doc", + destdir => "html", + + # Enable w3m mode. + w3mmode => 1, + + cgiurl => 'ikiwiki.cgi', + #templatedir => "/usr/share/ikiwiki/templates", + + rcs => "", + + # Subversion stuff. + #rcs => "svn", + #historyurl => "http://svn.myhost/trunk/[[file]]", + #diffurl => "http://svn.someurl/trunk/[[file]]?root=wiki&r1=[[r1]]&r2=[[r2]]", + #svnrepo => "/svn/wiki", + #svnpath => "trunk", + + # Git stuff. + #rcs => "git", + #historyurl => "http://git.host/gitweb.cgi?p=wiki.git;a=history;f=[[file]]", + #diffurl => "http://git.host/gitweb.cgi?p=wiki.git;a=blobdiff;h=[[sha1_to]];hp=[[sha1_from]];hb=[[sha1_parent]];f=[[file]]", + + wrappers => [ + { + # The cgi wrapper. + cgi => 1, + wrapper => "$ENV{HOME}/.ikiwiki/wrappers/ikiwiki.cgi", + wrappermode => "0755", + }, + #{ + # # The svn post-commit wrapper. + # # Note that this will overwrite any existing + # # post-commit hook script, which may not be + # # what you want. + # wrapper => "/svn/wikirepo/hooks/post-commit", + # wrappermode => "04755", + # # Enable mail notifications of commits. + # notify => 1, + #}, + #{ + # # The git post-update wrapper. + # # Note that this will overwrite any existing + # # post-update hook script, which may not be + # # what you want. + # wrapper => "/git/wikirepo/.git/hooks/post-update", + # wrappermode => "04755", + # # Enable mail notifications of commits. + # notify => 1, + #}, + ], + + # Can anonymous web users edit pages? + anonok => 1, + # Generate rss feeds for pages? + rss => 1, + # Urls to ping with XML-RPC when rss feeds are updated + #pingurl => [qw{http://rpc.technorati.com/rpc/ping}], + # Include discussion links on all pages? + discussion => 1, + # Time format (for strftime) + #timeformat => '%c', + + # To add plugins, list them here. + #add_plugins => [qw{pagecount brokenlinks search smiley wikitext}], + # If you want to disable any of the default plugins, list them here. + #disable_plugins => [qw{inline htmlscrubber}], +} diff --git a/ikiwiki b/ikiwiki index 099a821b7..cdb2042e1 100755 --- a/ikiwiki +++ b/ikiwiki @@ -29,6 +29,7 @@ sub getconfig () { #{{{ "rss!" => \$config{rss}, "cgi!" => \$config{cgi}, "discussion!" => \$config{discussion}, + "w3mmode!" => \$config{w3mmode}, "notify!" => \$config{notify}, "url=s" => \$config{url}, "cgiurl=s" => \$config{cgiurl}, diff --git a/ikiwiki-w3m.cgi b/ikiwiki-w3m.cgi new file mode 100755 index 000000000..fd0b0d677 --- /dev/null +++ b/ikiwiki-w3m.cgi @@ -0,0 +1,15 @@ +#!/usr/bin/perl +# ikiwiki w3m cgi meta-wrapper +if (! exists $ENV{PATH_INFO} || ! length $ENV{PATH_INFO}) { + die "PATH_INFO should be set"; +} +my $path=$ENV{PATH_INFO}; +$path=~s!/!!g; +$path="$ENV{HOME}/.ikiwiki/wrappers/$path"; +if (! -x $path) { + print "Content-type: text/html\n\n"; + print "Cannot find ikiwiki wrapper: $path\n"; + exit 1; +} +exec $path; +die "$path: exec error: $!";