* Support a w3mmode, which lets w3m run ikiwiki using its local CGI

support, to edit pages etc without a web server.
master
joey 2006-07-07 21:00:48 +00:00
parent 1cd1f073ff
commit 1bdfa4d8b5
13 changed files with 151 additions and 30 deletions

View File

@ -34,6 +34,7 @@ sub defaultconfig () { #{{{
rebuild => 0,
refresh => 0,
getctime => 0,
w3mmode => 0,
wrapper => undef,
wrappermode => undef,
svnrepo => undef,
@ -51,6 +52,15 @@ sub defaultconfig () { #{{{
} #}}}
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");
}

View File

@ -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");
}
} #}}}

View File

@ -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
}
}

2
debian/changelog vendored
View File

@ -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 <joeyh@debian.org> Fri, 7 Jul 2006 14:11:50 -0400

View File

@ -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.

View File

@ -48,8 +48,6 @@ Bulleted list
*one
*one
hi, mom!
----
[[haiku hint="sandbox play"]]

View File

@ -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.

View File

@ -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:
<a href="file:///$LIB/ikiwiki.cgi/home/joey/.ikiwiki/wrappers/ikiwiki.cgi">
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.

View File

@ -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

11
doc/w3mmode.mdwn 100644
View File

@ -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.

View File

@ -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&amp;r1=[[r1]]&amp;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}],
}

View File

@ -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},

15
ikiwiki-w3m.cgi 100755
View File

@ -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: $!";