#! /usr/local/bin/alan # # NAME # wikimini.al - WikiMini clone; Alan version # # INSTALL # 1) install Alan and locate it to /usr/local/bin/alan # 2) locate wikimini.al into any CGI enable directory # 3) mkdir /any/path/to/wikimini.d and set it to CONTENT_DIR in wikimini.al # # Copyright (C) 2006- by Fumisky Wells # Licensed under GPL. # # Acknowledge to Hiroshi Yuki; original WikiMini creator import Filesys end str: CONTENT_DIR = "wikimini.d" # Please create this dir before running str: THISURL = "wikimini.sh" str: FRONTPAGE = "FrontPage" str: WIKI_NAME = "[A-Z][a-z]+([A-Z][a-z]+)+" # BUG: v0.15 doesn't support \x##, \s, \S in rex rex: LINK = "((mailto|http|https|ftp):[^[:space:]]*|(" + WIKI_NAME + "))" map[str]: form void: cgi_parse() for str:parm in if ENV("REQUEST_METHOD") == "POST" then get(ENV("CONTENT_LENGTH").int) else ENV("QUERY_STRING") end.split('&') do list[str]: p = parm.split('=') if p.size == 2 then # BUG: v0.15 doesn't support closure nor Perl s//eg so quite verbose..: str: work = p(1).gsub("+", " ") str: work2="" loop if work in /%([A-Fa-f0-9][A-Fa-f0-9])/ then work2 += work.substr(0, matched(0).offset) + matched(1).hex.byte work = work.substr(matched(0).offset+3) else work2 += work break end end form(p(0)) = work2 elsif p.size == 1 then # for URL?WikiName case form(p(0)) = "" end end end str: escape(str: s) s.gsub("&", "&") .gsub("<", "<") .gsub(">", ">") end void: put_header(str: title; bool: canedit) put( "Content-type: text/html;\n" ,"\n" ,"" , "", title, "" , "" , "" , "" , "" , "" , "" , "

", title, "

" , "", FRONTPAGE , "" , if canedit then " | Edit" else "" end , " | Index" , " | a/WikiMini" , "
" ) end str: make_link(substr: s) if s in /^(http|https|ftp):/ then "" + s + "" elsif s in /^(mailto):(.*)$/ then "" + matched(2) + "" elsif exist(CONTENT_DIR+'/'+s) then "" + s + "" else s + "?" end end # storing content in file rather than DBM. void: put_content() file: f = CONTENT_DIR + '/' + form("page") || put("
");
      return;
   end
   put("
")
   for str: line in f do
      # BUG: v0.15 doesn't support closure nor Perl s//eg so quite verbose..:
      if line in LINK then
         str: work2
         loop
            if line in LINK then
               work2 += line.substr(0, LINK.matched(0).offset)
                        + make_link(LINK.matched(0))
               line  =  line.substr(LINK.matched(0).offset
                                    + LINK.matched(0).size)
            else
               work2 += line
               break
            end
         end
         put(work2)
      else
         put(escape(line))
      end
   end
   put("
") end void: put_footer() put("") end void: do_edit() put_header(form("page"), false) put( "
" ,"" ,"" ,"
\n") put_footer end void: do_write() begin file: f = (CONTENT_DIR + "/" + form("page"), file.WRITE) f.put(form("msg")) end # ensure to close put_header(form("page"), true) put_content put_footer end void: do_index() put_header("Index", false) put("") put_footer end #------------------------------------------------------------------ # CGI transactions #------------------------------------------------------------------ void: do_read() put_header(form("page"), true) put_content put_footer end #------------------------------------------------------------------ # Main #------------------------------------------------------------------ cgi_parse # BUG: v0.15 doesn't support str-var embedding into rex: rex: wiki_name = "^" + WIKI_NAME + "$" for str:key in form do if key in wiki_name then # for URL?WikiName case form("cmd") = "read" form("page") = key break end end str: cmd = form("cmd") || "" end if cmd == "read" then do_read elsif cmd == "write" then do_write elsif cmd == "edit" then do_edit elsif cmd == "index" then do_index else form("page") = FRONTPAGE do_read end