Useful functions for defining wiki handlers.
- withUserFromSession :: Handler -> Handler
- withUserFromHTTPAuth :: Handler -> Handler
- authenticateUserThat :: (User -> Bool) -> AuthenticationLevel -> Handler -> Handler
- authenticate :: AuthenticationLevel -> Handler -> Handler
- getLoggedInUser :: GititServerPart (Maybe User)
- unlessNoEdit :: Handler -> Handler -> Handler
- unlessNoDelete :: Handler -> Handler -> Handler
- guardCommand :: String -> GititServerPart ()
- guardPath :: (String -> Bool) -> GititServerPart ()
- guardIndex :: GititServerPart ()
- guardBareBase :: GititServerPart ()
- getPath :: ServerMonad m => m String
- getPage :: GititServerPart String
- getReferer :: ServerMonad m => m String
- getWikiBase :: ServerMonad m => m String
- uriPath :: String -> String
- isPage :: String -> Bool
- isPageFile :: FilePath -> Bool
- isDiscussPage :: String -> Bool
- isDiscussPageFile :: FilePath -> Bool
- isSourceCode :: String -> Bool
- withMessages :: ServerMonad m => [String] -> m a -> m a
- urlForPage :: String -> String
- pathForPage :: String -> FilePath
- getMimeTypeForExtension :: String -> GititServerPart String
- validate :: [(Bool, String)] -> [String]
- filestoreFromConfig :: Config -> FileStore
Combinators for dealing with users
withUserFromSession :: Handler -> HandlerSource
Run the handler after setting REMOTE_USER
with the user from
the session.
withUserFromHTTPAuth :: Handler -> HandlerSource
Run the handler after setting REMOTE_USER
from the authorization
header. Works with simple HTTP authentication or digest authentication.
authenticateUserThat :: (User -> Bool) -> AuthenticationLevel -> Handler -> HandlerSource
Like authenticate
, but with a predicate that the user must satisfy.
authenticate :: AuthenticationLevel -> Handler -> HandlerSource
Require a logged in user if the authentication level demands it. Run the handler if a user is logged in, otherwise redirect to login page.
getLoggedInUser :: GititServerPart (Maybe User)Source
Returns Just
logged in user or Nothing
.
Combinators to exclude certain actions
unlessNoEdit :: Handler -> Handler -> HandlerSource
unlessNoEdit responder fallback
runs responder
unless the
page has been designated not editable in configuration; in that
case, runs fallback
.
unlessNoDelete :: Handler -> Handler -> HandlerSource
unlessNoDelete responder fallback
runs responder
unless the
page has been designated not deletable in configuration; in that
case, runs fallback
.
Guards for routing
guardIndex :: GititServerPart ()Source
Succeeds if path is an index path: e.g. /foo/bar/
.
Functions to get info from the request
getPath :: ServerMonad m => m StringSource
Returns the current path (subtracting initial commands like /_edit
).
getPage :: GititServerPart StringSource
Returns the current page name (derived from the path).
getReferer :: ServerMonad m => m StringSource
Returns the contents of the referer header.
getWikiBase :: ServerMonad m => m StringSource
Returns the base URL of the wiki in the happstack server.
So, if the wiki handlers are behind a dir
, getWikiBase will
return foo
/foo/
. getWikiBase doesn't know anything about HTTP
proxies, so if you use proxies to map a gitit wiki to /foo/
,
you'll still need to follow the instructions in README.
uriPath :: String -> StringSource
Returns path portion of URI, without initial /
.
Consecutive spaces are collapsed. We don't want to distinguish
Hi There
and Hi There
.
Useful predicates
isPageFile :: FilePath -> BoolSource
isDiscussPage :: String -> BoolSource
isSourceCode :: String -> BoolSource
Combinators that change the request locally
withMessages :: ServerMonad m => [String] -> m a -> m aSource
Runs a server monad in a local context after setting the messages request header.
Miscellaneous
urlForPage :: String -> StringSource
Returns encoded URL path for the page with the given name, relative to the wiki base.
pathForPage :: String -> FilePathSource
Returns the filestore path of the file containing the page's source.
getMimeTypeForExtension :: String -> GititServerPart StringSource
Retrieves a mime type based on file extension.
Simple helper for validation of forms.
filestoreFromConfig :: Config -> FileStoreSource
Returns a filestore object derived from the repository path and filestore type specified in configuration.