#!/usr/local/bin/perl -w use strict; use CGI; use HTML::Entities; my $cgi = new CGI; my $url = "/sigma/"; my(@param, $action, $subject, $header, $body); dbmopen(my %WIKI, "wiki", 0644); @param = $cgi->param; $action = (defined $param[0] and $param[0] eq "keywords" ? $cgi->param("keywords") : $param[0]) || "HomePage"; $body = $cgi->p(wikimake("InvalidAction")) if $action !~ /^(search|edit)?([A-Z][a-z]+([A-Z][a-z]+)+)/; $subject = $action; $subject =~ s/^[a-z]+(.*)/$1/; # a subject is an abbreviated action if ($body) { $header = $action } else { if ($action =~ /^edit/) { if (defined $cgi->param($action)) { my $value = $cgi->param($action); $WIKI{$subject} = encode_entities $value; $action = $subject; $header = $action; print $cgi->redirect("?$subject"); exit; } else { $body .= $cgi->startform("post", $url) . $cgi->p($cgi->textarea({-style=>"width:100%;height:3in",-name=>"$action", -default=>(defined $WIKI{$subject} ? decode_entities $WIKI{$subject} : "")})) . $cgi->p($cgi->submit) . $cgi->endform } } elsif ($action =~ /^search/) { while ((my $key, my $value) = each %WIKI) { $body .= $cgi->h2(wikimake($key)) . $cgi->p(wikimake($value)) if $value =~ /$subject/ } } if ($subject eq $action) { # this is the viewing condition $header = $cgi->a({-href=>"?search$subject"}, wixpand($action)); $body = $cgi->p(wikimake((decode_entities $WIKI{$subject}))); } else { $header = $cgi->a({-href=>"?$subject"}, wixpand($action)) } $body .= $cgi->hr . $cgi->p($cgi->a({-href=>"?edit$subject"},"Edit this page ($subject)")) } print $cgi->header(-charset=>"UTF-8") . $cgi->start_html(-title=>$action) . $cgi->h1($cgi->a({-href=> $url},"WikiWiki")." : $header") . $body . $cgi->end_html; dbmclose(%WIKI); sub wikimake { my $z = shift; $z =~ s/\{(.+?)\}/$cgi->em($1)/eg; $z =~ s/\*(.+?)\*/$cgi->strong($1)/eg; $z =~ s/_(.+?)_/$1<\/ins>/g; $z =~ s/\B-(.+?)-\B/$1<\/del>/g; $z =~ s/\[(.+?)\]/$1<\/code>/g; $z =~ s/\b([A-Z][a-z]+([A-Z][a-z]+)+)/$cgi->a({-href=>"?$1"},wixpand($1))/eg; $z =~ s/(ftp:|http:|news:|mailto:)(\S+)/$cgi->a({-href=>"$1$2"},$1.$2)." "/eg; $z =~ s/\b(\S+\@\S+\.\S+)/$cgi->a({-href=>"mailto:$1"}, $1)/eg; $z =~ s/aim:(\S+)/$cgi->a({-href=>"aim:GoIm?screenname=$1"}, $1)." "/eg; $z =~ s/\015?\012/$cgi->br/eg; return $z } sub wixpand { my $z = shift; $z =~ s/([a-z])([A-Z])/"$1 $2"/eg; return $z; }