"Edit this page" bookmarklet

by Gerald Oskoboiny

I added an an "Edit this page" bookmarklet to my browser toolbar. When clicked, it causes Netscape to spawn an xterm with vi on the current document, then does a cvs commit afterwards.


How it works

I have a bookmarklet in my Firefox toolbar that directs the browser to a special URI like x-edit:http://foo.example.org/bar/baz, and Firefox is configured to send any such URIs to a shell script with that URI as its only parameter.

That shell script then spawns an xterm window with my preferred text editor (vi) on the given file, then does an HTML validation check and a cvs commit afterwards.

Sample of my desktop after clicking the "Edit this page" bookmarklet:

[Screen shot of an xterm with vi editing the current web page]

How it use it on your system

  1. Bookmark this link, then move it to your "Personal Toolbar Folder" or equivalent:
  2. Download the web-edit shell script and install that on your system somewhere in your path
  3. Edit your copy of the web-edit script to customize it for your system
  4. Configure your browser to recognize the x-edit URI scheme. With Gnome2 and Firefox, I used these commands:
      gconftool-2 -t string -s /desktop/gnome/url-handlers/x-edit/command "/home/gerald/www/people/gerald/2000/12/web-edit %s"
      gconftool-2 -t bool -s /desktop/gnome/url-handlers/x-edit/needs_terminal false
      gconftool-2 -t bool -s /desktop/gnome/url-handlers/x-edit/enabled true

    (thanks to Dom and Thomas for clues on setting this up)

The old way (may still be useful if you are not able to set up the x-edit URI scheme as needed above.)

  1. Do steps 1-3 above, but use this bookmarklet instead: javascript:void(self.location='http://impressive.net/people/gerald/2000/12/edit?uri='+escape(self.location));
  2. add a new MIME handler to your browser, for the MIME type 'text/x-edit-uri', with the 'Application' set to 'web-edit %s'
    note: in Galeon, the %s doesn't seem to be needed; simply use 'web-edit')

    Sample Netscape dialog box:

    [Screen shot of adding a MIME type to netscape]

  3. (optional) Install the 'edit' CGI script somewhere on your server, and update the bookmarklet to point to yours instead of mine (you can use mine if you want, but the URI of every document you edit will show up in my access log)


CGI script, 'edit'

#!/usr/bin/perl -w
# edit: CGI script to return an HTTP response with a special MIME type
# that indicates that the given URI should be edited
# Gerald Oskoboiny, 6 Dec 2000

my $uri = $ENV{QUERY_STRING};

$uri =~ s,uri=,,;
$uri =~ s,%3a,:,gi;	# @@ should be more thorough

print "Content-Type: text/x-edit-uri\n\n";
print $uri, "\n";


Valid HTML 4.0! Last modified: $Date: 2005/09/12 21:01:38 $
Gerald Oskoboiny, <[email protected]>