#!/bin/simple require "stdlib" $query os::getenv["QUERY_STRING"] $filename query.truncate_until[":"] $title filename $body "" $edit_link "" $sml "" object $reply $$get_reply: load_system_file $buf "*stdin*" buf.for_each_field " ": [entry] $key entry.before["="] $value entry.behind["="] value.begin while {value.find["%"]}: value.delete value.select_next 2 $hex_str value.selection[] value.delete value.insert string::character[parse_hex[hex_str]] value.replace_all "+" " " !reply[key] value $$load_wiki_file: # fails from within cgi-scripts! try: load_system_file !sml "wiki_files/"++filename++".sml" object $commands !commands.overview: !title "Topic Overview" list $linknames dir::open["wiki_files"].for_each: [entry] if entry.name.has_suffix[".sml"]: linknames.add entry.name.before["."] linknames.sort: [left right] {left.lower_case[] < right.lower_case[]} linknames.first_to_last: [linkname] body.write " &(linkname)
body.write "
&<New Topic&>
!commands.view: !edit_link "- &; edit body.write " Topic Overview

load_wiki_file sml.for_each_line: [$line] line.trim if line.has_prefix["%"]: !line line.range[2] if line.has_prefix[" "]: line.trim body.writeln "
  • " : body.writeln "
    &(line.before[" "])
    " line.truncate_until " " line == "": body.writeln "

    " line.replace_all "<" "&<" line.replace_all ">" "&>" try: line.begin while {line.find["**"]}: line.replace "" line.find "**" line.replace "" line.begin while {line.find["*"] && line[line.pos-2] != '\'}: line.replace "" line.find "*" line.replace "" line.begin while {line.find["\"]}: line.delete line.move 1 body.write line !commands.edit: !edit_link "- &; view title.prepend "edit " load_wiki_file body.write " Topic Overview



    !commands.update: get_reply if reply.sml?: save reply.sml "wiki_files/"++filename++".sml" commands::view !commands.request_new: body.write "
    Topic Name:

    !commands.new: get_reply if reply.topic.is_a[identifier]: !filename reply.topic !title filename save "" "wiki_files/&(filename).sml" commands::edit : !title "Error" body.write " Topic "&(reply.topic)" contains invalid characters! Topic Overview

    $cmd query.before[":"] if cmd == "": if query == "": !cmd "overview" : !cmd "view" if commands[cmd]?: commands[cmd] : !title "Error" body.write " No "&(cmd)" command found! writeln " Content-type: text/html &(title)

    &(title)&(edit_link)

    &(body)