ng                   -- ^ The page ID.
        -> M (Maybe XML.Document)   -- ^ The cleaned XML-document, if found any.
getData pageId = do
    Config{..} <- ask
    xs         <- lift getArgs
    let file   = cacheDir <> "/" <> pageId <> ".html"

    str <- lift $ case xs of
        "cache" : _ -> Just <$> LT.readFile file
        "fetch" : _ -> do
                        r <- LT.decodeUtf8 <$> simpleHttp (fetchUrl ++ pageId)
                        if "<title>Log In" `LT.isInfixOf` r
                            then do
                                liftIO $ putStrLn (" * Private Wiki Table - Can't read...")
                                return Nothing
                            else do
                                liftIO $ putStrLn (" * Writing to file: " ++ file)
                                LT.writeFile file r >> return (Just r)
        _           -> putStrLn " * Usage: opetussivut <fetch|cache>" >> exitFailure

    return $ cleanAndParse <$> str


{- | This function takes a whole wiki table in 'Text' form and removes some
    standard HTML tags from the text (see @'regexes'@ for more information). It
    then parses an XML document from the HTML body 'Text' stream.

    Uses the @'XML.decodeHtmlEntities'@ setting to decode the 'LT.Text' into
    XML.
-}
cleanAndParse 
getData :: String                   -- ^ The page ID.
        -> M (Maybe XML.Document)
getData pageId = do
    Config{..} <- ask
    xs         <- lift getArgs
    let file   = cacheDir <> "/" <> pageId <> ".html"

    str <- lift $ case xs of
        "cache" : _ -> Just <$> LT.readFile file
        "fetch" : _ -> do
                        r <- LT.decodeUtf8 <$> simpleHttp (fetchUrl ++ pageId)
                        if "<title>Log In" `LT.isInfixOf` r
                            then do
                                liftIO $ putStrLn (" * Private Wiki Table - Can't read...")
                                return Nothing
                            else do
                                liftIO $ putStrLn (" * Writing to file: " ++ file)
                                LT.writeFile file r >> return (Just r)
        _           -> putStrLn " * Usage: opetussivut <fetch|cache>" >> exitFailure

    return $ cleanAndParse <$> str


{- | This function takes a whole wiki table in 'Text' form and removes some
    standard HTML tags from the text (see @'regexes'@ for more information). It
    then parses an XML document from the HTML body 'Text' stream.

    Uses the @'XML.decodeHtmlEntities'@ setting to decode the 'LT.Text' into
    XML.
-}
getData pageId = do
    Config{..} <- ask
    xs         <- lift getArgs
    let file   = cacheDir <> "/" <> pageId <> ".html"

    str <- lift $ case xs of
        "cache" : _ -> Just <$> LT.readFile file
        "fetch" : _ -> do
                        r <- LT.decodeUtf8 <$> simpleHttp (fetchUrl ++ pageId)
                        if "<title>Log In" `LT.isInfixOf` r
                            then do
                                liftIO $ putStrLn (" * Private Wiki Table - Can't read...")
                                return Nothing
                            else do
                                liftIO $ putStrLn (" * Writing to file: " ++ file)
                                LT.writeFile file r >> return (Just r)
        _           -> putStrLn " * Usage: opetussivut <fetch|cache>" >> exitFailure

    return $ cleanAndParse <$> str


{- | This function takes a whole wiki table in 'Text' form and removes some
    standard HTML tags from the text (see @'regexes'@ for more information). It
    then parses an XML document from the HTML body 'Text' stream.

    Uses the @'XML.decodeHtmlEntities'@ setting to decode the 'LT.Text' into
    XML.
-}