#!/usr/bin/perl # -------------------------------------------------------- PerlInterpreter # PerlInterpreter must be the first line of the file. # # Copyright (c) 1995, Cunningham & Cunningham, Inc. # # This program has been generated by the HyperPerl # generator. The source hypertext can be found # at http://c2.com/cgi/wikibase. This program belongs # to Cunningham & Cunningham, Inc., is to be used # only by agreement with the owner, and then only # with the understanding that the owner cannot be # responsible for any behaviour of the program or # any damages that it may cause. # -------------------------------------------------------- InitialComments $ScriptName = $ENV{SCRIPT_NAME}; # -------------------------------------------------------- ScriptName sub AbortScript { local ($msg) = @_; print <The Wiki Wiki Server Can't Process Your Request $msg

This information has been logged.
We are sorry for any inconvenince. EOF die $msg; } # -------------------------------------------------------- AbortScript $DefaultTitle = Front . Page; # -------------------------------------------------------- DefaultTitle $linkWord = "[A-Z][a-z]+"; $LinkPattern = "($linkWord){2,}"; # -------------------------------------------------------- LinkPattern $DefaultRequest = browse; # -------------------------------------------------------- DefaultRequest if ($ENV{REQUEST_METHOD} eq GET){ $RawInput = $ENV{QUERY_STRING} || $DefaultTitle; $RawInput =~ s/^($LinkPattern)/$DefaultRequest=$1/; } if ($ENV{REQUEST_METHOD} eq POST){ read(STDIN, $RawInput, $ENV{CONTENT_LENGTH}); } # -------------------------------------------------------- RawInput $FieldSeparator = "\263"; # -------------------------------------------------------- FieldSeparator foreach $_ (split(/&/, $RawInput)) { s/\+/ /g; s/\%(..)/pack(C, hex($1))/geo; s/$FieldSeparator//g; ($_, $CookedInput) = split (/=/, $_, 2); $CookedInput{$_} = $CookedInput; } # -------------------------------------------------------- CookedInput sub RetrievePage { local($title) = pop(@_); split($FieldSeparator, $db{$title} || "text${FieldSeparator}Describe $title here."); } # -------------------------------------------------------- RetrievePage sub EscapeMetaCharacters { s/&/&/g; s//>/g; } # -------------------------------------------------------- EscapeMetaCharacters sub EmitCode { ($code, $depth) = @_; while (@code > $depth) {local($_) = pop @code; print "\n"} while (@code < $depth) {push (@code, ($code)); print "<$code>\n"} if ($code[$#code] ne $code) {print "<$code>\n"; $code[$#code] = $code;} } # -------------------------------------------------------- EmitCode $HostName = "c2.com"; # -------------------------------------------------------- HostName $ScriptUrl = "http://$HostName$ScriptName"; # -------------------------------------------------------- ScriptUrl sub AsAnchor { local($title) = pop(@_); defined $db{$title} ? "$title<\/a>" : "$title?<\/a>"; } # -------------------------------------------------------- AsAnchor sub AsLink { local($num) = (@_); local($ref) = $old{"r$num"}; defined $ref ? ($ref =~ /\.gif$/ ? "" : "[$num]<\/a>") : "[$num]"; } # -------------------------------------------------------- AsLink $SearchForm = < <\/form> EOF # -------------------------------------------------------- SearchForm sub PrintBodyText { s/\\\n/ /g; foreach (split(/\n/, $_)){ $code = ""; s/^\s*$/

/ && ($code = '...'); s/^(\t+)(.+):\t/

$2
/ && &EmitCode(DL, length $1); s/^(\t+)\*/
  • / && &EmitCode(UL, length $1); s/^(\t+)\d+\.?/
  • / && &EmitCode(OL, length $1); /^\s/ && &EmitCode(PRE, 1); $code || &EmitCode("", 0); s/'{3}(.*)'{3}/$1<\/strong>/g; s/'{2}(.*)'{2}/$1<\/em>/g; s/^-----*/
    /; s/$LinkPattern/&AsAnchor($&)/geo; s/\[(\d+)\]/&AsLink($1)/geo; s/\[Search\]/$SearchForm/; print "$_\n"; } &EmitCode("", 0); } # -------------------------------------------------------- PrintBodyText sub HandleBrowse { $title = $CookedInput{browse}; print < $title

    $title

    EOF %old = &RetrievePage($title); $_ = $old{text}; &EscapeMetaCharacters; &PrintBodyText; print <
    Edit Text<\/a> of this page (last edited $old{date})
    Find Page<\/a> by browsing or searching
    EOF } # -------------------------------------------------------- HandleBrowse sub HandleEdit { $title = $CookedInput{edit} || $CookedInput{copy}; $title =~ /^$LinkPattern$/ || &AbortScript("edit: improper name: $title"); %old = &RetrievePage($title); $_ = $CookedInput{copy} ? $old{copy} : $old{text}; $note = 'Copy of ' if $CookedInput{copy}; s/\r\n/\n/g; &EscapeMetaCharacters; $convert = "checked" if $ENV{HTTP_USER_AGENT} =~ /WebExplorer/; print < Edit $note$title

    $note$title


    I can't type tabs. Please
    ConvertSpacesToTabs for me when I save.

    GoodStyle tips for editing.
    EditLinks to other web servers.
    EOF print <EditCopy from previous author.
    EOF print < EOF } # -------------------------------------------------------- HandleEdit sub HandleLinks { $title = $CookedInput{links}; $title =~ /^$LinkPattern$/ || &AbortScript("link: improper name: $title"); %old = &RetrievePage($title); print <$title Links

    $title Links

    [1]
    [2]
    [3]
    [4]

    Type the full URL (http:// ...) for each reference cited in the text.

    EOF } # -------------------------------------------------------- HandleLinks sub HandleSearch { local($m, $n, @rec); $pat = $CookedInput{search}; $pat =~ s/[+?.*()[\]{}|\\]/\\$&/g; print "Search Results\n"; print "

    Search Results

    \n"; while (($key, $value) = each %db){ $n++; %rec = split($SEP, $value); if ($key =~/\b\w*($pat)\w*\b/i || $rec{text} =~ /\b\w*($pat)\w*\b/i){ $m++; print "$key<\/a> . . . . . . $&
    \n"; } } $m = $m || No; print "
    $m pages found out of $n pages searched."; } # -------------------------------------------------------- HandleSearch sub CookSpaces { $CookedInput{text} =~ s/ {3,8}/\t/g if $CookedInput{convert}; } # -------------------------------------------------------- CookSpaces @path = split('/', $ScriptName); $LockDirectory = "/tmp/".pop(@path); # -------------------------------------------------------- LockDirectory sub RequestLock { local ($n) = 0; while (mkdir($LockDirectory, 0555) == 0) { $! = 17 || &AbortScript("can't make $LockDirectory: $!\n"); # EEXIST == 17 is OK, try later. $n++ < 30 || &AbortScript("timed out waiting for $LockDirectory\n"); sleep(1); } } # -------------------------------------------------------- RequestLock sub BackupCopy { $old{copy} = $old{text} if $old{host} && $old{host} ne $ENV{REMOTE_HOST}; } # -------------------------------------------------------- BackupCopy ($sec, $min, $hour, $mday, $mon, $year) = localtime($^T); $DateToday = (January, February, March, April, May, June, July, August, September, October, November, December)[$mon] . " " . $mday . ", " . ($year+1900); # -------------------------------------------------------- DateToday sub ReplacePage { local($title, *page) = @_; local($value, @value); $page{date} = $DateToday; $page{host} = $ENV{REMOTE_HOST}; $page{agent} = $ENV{HTTP_USER_AGENT}; $page{rev}++; @value = %page; $value = join($FieldSeparator, @value); open (WDB, ">$DBM.wdb/$title"); print WDB $value; close WDB; $db{$title} = $value; } # -------------------------------------------------------- ReplacePage sub ReleaseLock { rmdir($LockDirectory); } # -------------------------------------------------------- ReleaseLock $SignatureUrl = "http://c2.com/sig/ward.gif"; # -------------------------------------------------------- SignatureUrl sub HandlePost { $title = $CookedInput{post}; &CookSpaces; &RequestLock; dbmopen(%db, $DBM , 0666) || &AbortScript("can't open $DBM for update\n"); %old = &RetrievePage($title); &BackupCopy; for (keys(%CookedInput)) { next if /post/ || /form/ || /title/; $old{$_} = $CookedInput{$_} if $CookedInput{$_}; } &ReplacePage($title, *old); %rc = &RetrievePage(RecentChanges); $rc{text} =~ s/\t\* $title.*\n//; $rc{text} .= "\n$DateToday\n\n" unless $rc{text} =~ /$DateToday/; $rc{text} .= "\t* $title . . . . . . $ENV{REMOTE_HOST}\n"; &ReplacePage(RecentChanges, *rc); dbmclose(db); &ReleaseLock; $anchor = &AsAnchor($title); print <Thanks for $title Edits Thank you for editing $anchor.
    Your careful attention to detail is much appreciated.

    p.s. Be sure to Reload your old pages.
    EOF } # -------------------------------------------------------- HandlePost sub DumpBinding { local(*dict) = @_; print "
    \n"; for (keys(%dict)){print "
    $_
    $dict{$_}\n";} print "

    \n"; } # -------------------------------------------------------- DumpBinding # InitialComments print "Content-type: text/html\n\n"; $DBM = "/usr/ward/$ScriptName"; dbmopen(%db, $DBM , 0666) || &AbortScript("can't open $DBM"); $CookedInput{browse} && &HandleBrowse; $CookedInput{edit} && &HandleEdit; $CookedInput{copy} && &HandleEdit; $CookedInput{links} && &HandleLinks; $CookedInput{search} && &HandleSearch; dbmclose (%db); if ($ENV{REQUEST_METHOD} eq POST) { $CookedInput{post} && &HandlePost; } # &DumpBinding(*CookedInput); # &DumpBinding(*old); # &DumpBinding(*ENV); # -------------------------------------------------------- WikiInHyperPerl