2008-08-20 Blog With Oddmuse

The key to painless blogging with Oddmuse is easy page creation. In my Firefox, I defined a bookmark for http://www.emacswiki.org/cgi-bin/alex?action=new with the keyword *new*. Whenever I type “new” into the address field of my browser, I go to this page.

Firefox

http://www.emacswiki.org/cgi-bin/alex?action=new

The page is implemented using a new action. The code below also adds the new action to the *Administration* menu.

Note how the code will also reject untagged pages.

push(@MyAdminCode, sub {
       my ($id, $menuref, $restref) = @_;
       push(@$menuref, ScriptLink('action=new', T('New'), 'new'));
     });

$Action{new} = \&DoNew;

sub DoNew {
  if (GetParam('tags', '') and GetParam('id', '')) {
    DoEdit(GetParam('id', ''), "\n\n\nTags: "
	   . join (' ', map { "[[tag:$_]]" } split(' ', GetParam('tags', //))),
	   1);
  } else {
    print GetHeader(//, T('New')), $q->start_div({-class=>'content categories'}),
      GetFormStart(undef, 'get', 'cat');
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime();
    my $today = sprintf("%d-%02d-%02d", $year + 1900, $mon + 1, $mday);
    my $go = T('Go!');
    print $q->p(T('Title: '),
		qq{<input type="text" name="id" value="$today" tabindex="1" />},
		GetHiddenValue('action', 'new'));
    print $q->p(T('Tags: '),
		qq{<input type="text" name="tags" tabindex="2" />});
    print $q->p(qq{<input type="submit" value="$go" tabindex="3" />});
    print $q->end_form, $q->end_div();
    PrintFooter();
  }
}

This code also appeared in some of the “blogging” extensions I wrote for Oddmuse.

​#Oddmuse