X-Git-Url: https://ruin.nu/git/?p=yawbih.git;a=blobdiff_plain;f=Main.hs;h=418c16820b88fafff475bcc544eee02f227bcabd;hp=93a56168c0c75507a639ba35b78eb3816f43e645;hb=64b58e5b75b4c8e95574fa9080166f5cf1079005;hpb=38f06e9262e9b2dd14906492539006602225d49e diff --git a/Main.hs b/Main.hs index 93a5616..418c168 100644 --- a/Main.hs +++ b/Main.hs @@ -1,21 +1,156 @@ module Main where -import CGI hiding (div, head, map, span) +import CGI hiding (div, head, map, span, Text) import RawCGIInternal import CGIOutput +import CGITypes +import System +import Wiki +import Control.Monad -main = start [] cgi - -cgi CGIInfo {cgiUrl = url, cgiPathInfo = pi, cgiContentType = ct, cgiContents = c, cgiCookies = co, cgiArgs = as, cgiHandle = h} parms = do - putStr "content-type: text/html\n\n" - print parms - print url - print pi - print ct - print co - print co - print as - print h - case assocParm "test" parms of - Nothing -> putStr "Parameter 'test' not provided" - Just x -> putStr $ "Value of test = "++x +import Text.ParserCombinators.Parsec + +testDB = createPGB "wave" "wiki" "wiki" "12wiki34db" + +--main = start [] cgi + +main = do + db <- testDB + runWithHook [] (\(key:act) -> showPage db (filter (/= '\\') key)) $ showPage db "MainPage" + +ps a = standardQuery "Hello" a + +editPage db key = do + s <- io $ getCurrent db key + s' <- case s of + Nothing -> return "" + Just (x,_) -> return x + standardQuery key $ do + t <- p $ makeTextarea s' (attr_SS "rows" "10" ## attr_SS "cols" "75" ## attr_SS "colspan" "2") + p empty + text "Author: " + a <- textInputField (fieldSIZE 20) + p empty + text "Comment: " + c <- textInputField (fieldSIZE 20) + --p $ submit (F2 t a) testing (attr "value" "Send") + p $ defaultSubmit (F3 t a c) (savePage db key) (attr "value" "Send") + --submit0 (sp db key []) (attr "value" "Send1") + + +savePage db key (F3 t a c) = do + io $ update db key fulltext author comment + showPage db key + where + fulltext = value t + author = value a + comment = value c + +showPage db key = do + s <- io $ getCurrent db key + standardQuery key $ do + case s of + Nothing -> text "No text added for this keyword" + Just (full, date) -> do + parseText full + p $ tt $ text $ "Last edited: "++date + footer db key + +parseText full = case parse wikiParser "" full of + Right n -> toWash n + Left e -> do + text "PARSE ERROR: " + text (show e) + p $ text full + +footer db key = do + hr empty + table $ tr $ do + td $ submitLink0 (showPage db "MainPage") (text "Back to main page") + when (e key) $ td $ submitLink0 (editPage db key) (text "Edit this keyword") + when (e key) $ td $ submitLink0 (listRevs db key) (text "List old versions") + td $ submitLink0 (listKeywords db) (text "List all keywords") + td $ text "Keyword: " + td $ activate (showPage db) textInputField empty + +e "" = False +e _ = True + +listRevs db key = do + list <- io $ getList db key + standardQuery key $ table $ do + tr $ mapM (\header -> th (text header)) + ["Id", "Date", "Author", "Comment"] + mapM (revRow db key) list + +listKeywords db = do + list <- io $ listKeys db + standardQuery "List of keywords" $ do + table (do + tr $ th (text "Keyword") + mapM (\key -> tr $ td $ linkKey db key) list) + footer db "" + +linkKey db key = submitLink0 (showPage db key) (text key) + +revRow db key (id, date, author, comment) = tr $ do + td $ submitLink0 (showRev db key id) (text id) + td $ text date + td $ linkKey db author + td $ text comment + +showRev db key id = do + s <- io $ get db key id + standardQuery key $ do + case s of + Nothing -> text "No such revision" + Just s -> parseText s + p empty + submitLink0 (changeCurrent db key id) (text "Set this version as the current one") + footer db key +changeCurrent db key id = do + b <- io $ setCurrent db key id + if b then showPage db key + else standardQuery key $ do + text "Could not set this revision as the current active one." + p empty + linkKey db key + +toWash [] = return () +toWash ((Paragraph):xs) = do + p empty + toWash xs +toWash ((Text s):xs) = do + text s + toWash xs +toWash ((Link l d):xs) = do + hlink (URL {unURL = ("wiki?"++l)}) (text d) + toWash xs +toWash ((Bold d):xs) = do + b (toWash d) + toWash xs +toWash ((Emph d):xs) = do + em (toWash d) + toWash xs +toWash ((Underline d):xs) = do + u (toWash d) + toWash xs +toWash ((Strike d):xs) = do + strike (toWash d) + toWash xs +toWash ((Heading n d):xs) = do + heading n $ toWash d + toWash xs +toWash ((Url l):xs) = do + hlink (URL {unURL = (l)}) (text l) + toWash xs +toWash ((Pre s):xs) = do + pre $ text s + toWash xs + +heading 1 = h1 +heading 2 = h2 +heading 3 = h3 +heading 4 = h4 +heading 5 = h5 +heading 6 = h6