* Support a w3mmode, which lets w3m run ikiwiki using its local CGI
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Fri, 7 Jul 2006 21:00:48 +0000 (21:00 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Fri, 7 Jul 2006 21:00:48 +0000 (21:00 +0000)
  support, to edit pages etc without a web server.

13 files changed:
IkiWiki.pm
IkiWiki/CGI.pm
Makefile.PL
debian/changelog
doc/features.mdwn
doc/sandbox.mdwn
doc/serverless.mdwn [deleted file]
doc/todo/terminalclient.mdwn
doc/usage.mdwn
doc/w3mmode.mdwn [new file with mode: 0644]
doc/w3mmode/ikiwiki.setup [new file with mode: 0644]
ikiwiki
ikiwiki-w3m.cgi [new file with mode: 0755]

index d8b2721..4964f97 100644 (file)
@@ -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");
        }
index 3b4228b..671f0b9 100644 (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");
        }
 } #}}}
 
index 89a8f32..59c5d86 100755 (executable)
@@ -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
 }
 }
 
index 3cea775..359ea1c 100644 (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
 
index 1406f5a..1b09a32 100644 (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.
index 538d034..a536303 100644 (file)
@@ -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 (file)
index 2cbf6e2..0000000
+++ /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.
index 8c80288..b420a3d 100644 (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.
index 7bc9e53..8404d15 100644 (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
diff --git a/doc/w3mmode.mdwn b/doc/w3mmode.mdwn
new file mode 100644 (file)
index 0000000..3afee5c
--- /dev/null
@@ -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 (file)
index 0000000..ed65e0f
--- /dev/null
@@ -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}],
+}
diff --git a/ikiwiki b/ikiwiki
index 099a821..cdb2042 100755 (executable)
--- 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 (executable)
index 0000000..fd0b0d6
--- /dev/null
@@ -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: $!";