    {-# LANGUAGE FlexibleContexts #-}
    {-
    Copyright (C) 2009 John MacFarlane <jgm@berkeley.edu>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    -}

    {- Functions and data structures for wiki page layout.
    -}

    module Network.Gitit.Layout ( defaultPageLayout
                                , defaultRenderPage
                                , formattedPage
                                , filledPageTemplate
                                , uploadsAllowed
                                )
    where
    import Network.Gitit.Server
    import Network.Gitit.Framework
    import Network.Gitit.State
    import Network.Gitit.Types
    import Network.Gitit.Export (exportFormats)
    import Network.HTTP (urlEncodeVars)
    import qualified Text.StringTemplate as T
    import Text.XHtml hiding ( (</>), dir, method, password, rev )
    import Text.XHtml.Strict ( stringToHtmlString )
    import Data.Maybe (isNothing, isJust, fromJust)

    defaultPageLayout :: PageLayout
    defaultPageLayout :: PageLayout
    defaultPageLayout = PageLayout :: String
    -> Maybe String
    -> Bool
    -> [String]
    -> String
    -> [String]
    -> Bool
    -> Bool
    -> Maybe Text
    -> [Tab]
    -> Tab
    -> Bool
    -> PageLayout
    PageLayout
      { pgPageName :: String
    pgPageName       = ""
      , pgRevision :: Maybe String
    pgRevision       = Maybe String
    forall a. Maybe a
    Nothing
      , pgPrintable :: Bool
    pgPrintable      = Bool
    False
      , pgMessages :: [String]
    pgMessages       = []
      , pgTitle :: String
    pgTitle          = ""
      , pgScripts :: [String]
    pgScripts        = []
      , pgShowPageTools :: Bool
    pgShowPageTools  = Bool
    True
      , pgShowSiteNav :: Bool
    pgShowSiteNav    = Bool
    True
      , pgMarkupHelp :: Maybe Text
    pgMarkupHelp     = Maybe Text
    forall a. Maybe a
    Nothing
      , pgTabs :: [Tab]
    pgTabs           = [Tab
    ViewTab, Tab
    EditTab, Tab
    HistoryTab, Tab
    DiscussTab]
      , pgSelectedTab :: Tab
    pgSelectedTab    = Tab
    ViewTab
      , pgLinkToFeed :: Bool
    pgLinkToFeed     = Bool
    False
      }

    -- | Returns formatted page
    formattedPage :: PageLayout -> Html -> Handler
    formattedPage :: PageLayout -> Html -> Handler
    formattedPage layout :: PageLayout
    layout htmlContents :: Html
    htmlContents = do
      PageLayout -> Html -> Handler
    renderer <- (GititState -> PageLayout -> Html -> Handler)
    -> ServerPartT
         (ReaderT WikiState IO) (PageLayout -> Html -> Handler)
    forall (m :: * -> *) a. MonadIO m => (GititState -> a) -> m a
    queryGititState GititState -> PageLayout -> Html -> Handler
    renderPage
      PageLayout -> Html -> Handler
    renderer PageLayout
    layout Html
    htmlContents

    -- | Given a compiled string template, returns a page renderer.
    defaultRenderPage :: T.StringTemplate String -> PageLayout -> Html -> Handler
    defaultRenderPage :: StringTemplate String -> PageLayout -> Html -> Handler
    defaultRenderPage templ :: StringTemplate String
    templ layout :: PageLayout
    layout htmlContents :: Html
    htmlContents = do
      Config
    cfg <- GititServerPart Config
    getConfig
      String
    base' <- ServerPartT (ReaderT WikiState IO) String
    forall (m :: * -> *). ServerMonad m => m String
    getWikiBase
      Response -> Handler
    forall (m :: * -> *) a. FilterMonad Response m => a -> m a
    ok (Response -> Handler)
    -> (StringTemplate String -> Response)
    -> StringTemplate String
    -> Handler
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> Response -> Response
    setContentType "text/html; charset=utf-8" (Response -> Response)
    -> (StringTemplate String -> Response)
    -> StringTemplate String
    -> Response
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> Response
    forall a. ToMessage a => a -> Response
    toResponse (String -> Response)
    -> (StringTemplate String -> String)
    -> StringTemplate String
    -> Response
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StringTemplate String -> String
    forall a. Stringable a => StringTemplate a -> a
    T.render (StringTemplate String -> String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
           String
    -> Config
    -> PageLayout
    -> Html
    -> StringTemplate String
    -> StringTemplate String
    filledPageTemplate String
    base' Config
    cfg PageLayout
    layout Html
    htmlContents (StringTemplate String -> Handler)
    -> StringTemplate String -> Handler
    forall a b. (a -> b) -> a -> b
    $ StringTemplate String
    templ

    -- | Returns a page template with gitit variables filled in.
    filledPageTemplate :: String -> Config -> PageLayout -> Html ->
                          T.StringTemplate String -> T.StringTemplate String
    filledPageTemplate :: String
    -> Config
    -> PageLayout
    -> Html
    -> StringTemplate String
    -> StringTemplate String
    filledPageTemplate base' :: String
    base' cfg :: Config
    cfg layout :: PageLayout
    layout htmlContents :: Html
    htmlContents templ :: StringTemplate String
    templ =
      let rev :: Maybe String
    rev  = PageLayout -> Maybe String
    pgRevision PageLayout
    layout
          page :: String
    page = PageLayout -> String
    pgPageName PageLayout
    layout
          prefixedScript :: String -> String
    prefixedScript x :: String
    x = case String
    x of
                               'h':'t':'t':'p':_  -> String
    x
                               _                  -> String
    base' String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ "/js/" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    x

          scripts :: [String]
    scripts  = ["jquery.min.js", "jquery-ui.min.js", "footnotes.js"] [String] -> [String] -> [String]
    forall a. [a] -> [a] -> [a]
    ++ PageLayout -> [String]
    pgScripts PageLayout
    layout
          scriptLink :: String -> Html
    scriptLink x :: String
    x = Html -> Html
    script (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    ! [String -> HtmlAttr
    src (String -> String
    prefixedScript String
    x),
            String -> HtmlAttr
    thetype "text/javascript"] (Html -> Html) -> Html -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << Html
    noHtml
          javascriptlinks :: String
    javascriptlinks = Html -> String
    forall html. HTML html => html -> String
    renderHtmlFragment (Html -> String) -> Html -> String
    forall a b. (a -> b) -> a -> b
    $ [Html] -> Html
    forall a. HTML a => [a] -> Html
    concatHtml ([Html] -> Html) -> [Html] -> Html
    forall a b. (a -> b) -> a -> b
    $ (String -> Html) -> [String] -> [Html]
    forall a b. (a -> b) -> [a] -> [b]
    map String -> Html
    scriptLink [String]
    scripts
          article :: String
    article = if String -> Bool
    isDiscussPage String
    page then Int -> String -> String
    forall a. Int -> [a] -> [a]
    drop 1 String
    page else String
    page
          discussion :: String
    discussion = '@'Char -> String -> String
    forall a. a -> [a] -> [a]
    :String
    article
          tabli :: Tab -> Html -> Html
    tabli tab :: Tab
    tab = if Tab
    tab Tab -> Tab -> Bool
    forall a. Eq a => a -> a -> Bool
    == PageLayout -> Tab
    pgSelectedTab PageLayout
    layout
                         then Html -> Html
    li (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    ! [String -> HtmlAttr
    theclass "selected"]
                         else Html -> Html
    li
          tabs' :: [Tab]
    tabs' = [Tab
    x | Tab
    x <- PageLayout -> [Tab]
    pgTabs PageLayout
    layout,
                    Bool -> Bool
    not (Tab
    x Tab -> Tab -> Bool
    forall a. Eq a => a -> a -> Bool
    == Tab
    EditTab Bool -> Bool -> Bool
    && String
    page String -> [String] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` Config -> [String]
    noEdit Config
    cfg)]
          tabs :: Html
    tabs = Html -> Html
    ulist (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    ! [String -> HtmlAttr
    theclass "tabs"] (Html -> Html) -> [Html] -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << (Tab -> Html) -> [Tab] -> [Html]
    forall a b. (a -> b) -> [a] -> [b]
    map ((Tab -> Html -> Html)
    -> String -> String -> Maybe String -> Tab -> Html
    linkForTab Tab -> Html -> Html
    tabli String
    base' String
    page Maybe String
    rev) [Tab]
    tabs'
          setStrAttr :: String -> String -> StringTemplate b -> StringTemplate b
    setStrAttr  attr :: String
    attr = String -> String -> StringTemplate b -> StringTemplate b
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute String
    attr (String -> StringTemplate b -> StringTemplate b)
    -> (String -> String)
    -> String
    -> StringTemplate b
    -> StringTemplate b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    stringToHtmlString
          setBoolAttr :: String -> Bool -> StringTemplate b -> StringTemplate b
    setBoolAttr attr :: String
    attr test :: Bool
    test = if Bool
    test then String -> String -> StringTemplate b -> StringTemplate b
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute String
    attr "true" else StringTemplate b -> StringTemplate b
    forall a. a -> a
    id
      in               String -> String -> StringTemplate String -> StringTemplate String
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute "base" String
    base' (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> Bool -> StringTemplate String -> StringTemplate String
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute "feed" (PageLayout -> Bool
    pgLinkToFeed PageLayout
    layout) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> String -> StringTemplate b -> StringTemplate b
    setStrAttr "wikititle" (Config -> String
    wikiTitle Config
    cfg) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> String -> StringTemplate b -> StringTemplate b
    setStrAttr "pagetitle" (PageLayout -> String
    pgTitle PageLayout
    layout) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute "javascripts" String
    javascriptlinks (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> String -> StringTemplate b -> StringTemplate b
    setStrAttr "pagename" String
    page (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> String -> StringTemplate b -> StringTemplate b
    setStrAttr "articlename" String
    article (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> String -> StringTemplate b -> StringTemplate b
    setStrAttr "discussionname" String
    discussion (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> String -> StringTemplate b -> StringTemplate b
    setStrAttr "pageUrl" (String -> String
    urlForPage String
    page) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> String -> StringTemplate b -> StringTemplate b
    setStrAttr "articleUrl" (String -> String
    urlForPage String
    article) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> String -> StringTemplate b -> StringTemplate b
    setStrAttr "discussionUrl" (String -> String
    urlForPage String
    discussion) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> Bool -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> Bool -> StringTemplate b -> StringTemplate b
    setBoolAttr "ispage" (String -> Bool
    isPage String
    page) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> Bool -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> Bool -> StringTemplate b -> StringTemplate b
    setBoolAttr "isarticlepage" (String -> Bool
    isPage String
    page Bool -> Bool -> Bool
    && Bool -> Bool
    not (String -> Bool
    isDiscussPage String
    page)) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> Bool -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> Bool -> StringTemplate b -> StringTemplate b
    setBoolAttr "isdiscusspage" (String -> Bool
    isDiscussPage String
    page) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> Bool -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> Bool -> StringTemplate b -> StringTemplate b
    setBoolAttr "pagetools" (PageLayout -> Bool
    pgShowPageTools PageLayout
    layout) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> Bool -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> Bool -> StringTemplate b -> StringTemplate b
    setBoolAttr "sitenav" (PageLayout -> Bool
    pgShowSiteNav PageLayout
    layout) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       (StringTemplate String -> StringTemplate String)
    -> (Text -> StringTemplate String -> StringTemplate String)
    -> Maybe Text
    -> StringTemplate String
    -> StringTemplate String
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe StringTemplate String -> StringTemplate String
    forall a. a -> a
    id (String -> Text -> StringTemplate String -> StringTemplate String
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute "markuphelp") (PageLayout -> Maybe Text
    pgMarkupHelp PageLayout
    layout) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> Bool -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> Bool -> StringTemplate b -> StringTemplate b
    setBoolAttr "printable" (PageLayout -> Bool
    pgPrintable PageLayout
    layout) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       (StringTemplate String -> StringTemplate String)
    -> (String -> StringTemplate String -> StringTemplate String)
    -> Maybe String
    -> StringTemplate String
    -> StringTemplate String
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe StringTemplate String -> StringTemplate String
    forall a. a -> a
    id (String -> String -> StringTemplate String -> StringTemplate String
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute "revision") Maybe String
    rev (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute "exportbox"
                           (Html -> String
    forall html. HTML html => html -> String
    renderHtmlFragment (Html -> String) -> Html -> String
    forall a b. (a -> b) -> a -> b
    $  String -> Config -> String -> Maybe String -> Html
    exportBox String
    base' Config
    cfg String
    page Maybe String
    rev) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       (if [Tab] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null (PageLayout -> [Tab]
    pgTabs PageLayout
    layout) then StringTemplate String -> StringTemplate String
    forall a. a -> a
    id else String -> String -> StringTemplate String -> StringTemplate String
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute "tabs"
                           (Html -> String
    forall html. HTML html => html -> String
    renderHtmlFragment Html
    tabs)) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       (\f :: [String] -> StringTemplate String -> StringTemplate String
    f x :: StringTemplate String -> StringTemplate String
    x xs :: [String]
    xs -> if [String] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [String]
    xs then StringTemplate String -> StringTemplate String
    x else [String] -> StringTemplate String -> StringTemplate String
    f [String]
    xs) (String
    -> [String] -> StringTemplate String -> StringTemplate String
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute "messages") StringTemplate String -> StringTemplate String
    forall a. a -> a
    id (PageLayout -> [String]
    pgMessages PageLayout
    layout) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> Bool -> StringTemplate String -> StringTemplate String
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute "usecache" (Config -> Bool
    useCache Config
    cfg) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> String -> StringTemplate String -> StringTemplate String
    forall a b.
    (ToSElem a, Stringable b) =>
    String -> a -> StringTemplate b -> StringTemplate b
    T.setAttribute "content" (Html -> String
    forall html. HTML html => html -> String
    renderHtmlFragment Html
    htmlContents) (StringTemplate String -> StringTemplate String)
    -> (StringTemplate String -> StringTemplate String)
    -> StringTemplate String
    -> StringTemplate String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                       String -> Bool -> StringTemplate String -> StringTemplate String
    forall b.
    Stringable b =>
    String -> Bool -> StringTemplate b -> StringTemplate b
    setBoolAttr "wikiupload" ( Config -> Bool
    uploadsAllowed Config
    cfg) (StringTemplate String -> StringTemplate String)
    -> StringTemplate String -> StringTemplate String
    forall a b. (a -> b) -> a -> b
    $
                       StringTemplate String
    templ

    exportBox :: String -> Config -> String -> Maybe String -> Html
    exportBox :: String -> Config -> String -> Maybe String -> Html
    exportBox base' :: String
    base' cfg :: Config
    cfg page :: String
    page rev :: Maybe String
    rev | Bool -> Bool
    not (String -> Bool
    isSourceCode String
    page) =
      String -> Html -> Html
    gui (String
    base' String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    urlForPage String
    page) (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    ! [String -> HtmlAttr
    identifier "exportbox"] (Html -> Html) -> [Html] -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    <<
        ([ String -> Html
    textfield "revision" Html -> [HtmlAttr] -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    ! [String -> HtmlAttr
    thestyle "display: none;",
             String -> HtmlAttr
    value (Maybe String -> String
    forall a. HasCallStack => Maybe a -> a
    fromJust Maybe String
    rev)] | Maybe String -> Bool
    forall a. Maybe a -> Bool
    isJust Maybe String
    rev ] [Html] -> [Html] -> [Html]
    forall a. [a] -> [a] -> [a]
    ++
         [ Html -> Html
    select (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    ! [String -> HtmlAttr
    name "format"] (Html -> Html) -> [Html] -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    <<
             ((String, String -> Pandoc -> Handler) -> Html)
    -> [(String, String -> Pandoc -> Handler)] -> [Html]
    forall a b. (a -> b) -> [a] -> [b]
    map ((\f :: String
    f -> Html -> Html
    option (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    ! [String -> HtmlAttr
    value String
    f] (Html -> Html) -> String -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << String
    f) (String -> Html)
    -> ((String, String -> Pandoc -> Handler) -> String)
    -> (String, String -> Pandoc -> Handler)
    -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (String, String -> Pandoc -> Handler) -> String
    forall a b. (a, b) -> a
    fst) (Config -> [(String, String -> Pandoc -> Handler)]
    exportFormats Config
    cfg)
         , String -> Html
    primHtmlChar "nbsp"
         , String -> String -> Html
    submit "export" "Export" ])
    exportBox _ _ _ _ = Html
    noHtml

    -- auxiliary functions:

    linkForTab :: (Tab -> Html -> Html) -> String -> String -> Maybe String -> Tab -> Html
    linkForTab :: (Tab -> Html -> Html)
    -> String -> String -> Maybe String -> Tab -> Html
    linkForTab tabli :: Tab -> Html -> Html
    tabli base' :: String
    base' page :: String
    page _ HistoryTab =
      Tab -> Html -> Html
    tabli Tab
    HistoryTab (Html -> Html) -> Html -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << Html -> Html
    anchor (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    ! [String -> HtmlAttr
    href (String -> HtmlAttr) -> String -> HtmlAttr
    forall a b. (a -> b) -> a -> b
    $ String
    base' String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ "/_history" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    urlForPage String
    page] (Html -> Html) -> String -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << "history"
    linkForTab tabli :: Tab -> Html -> Html
    tabli _ _ _ DiffTab =
      Tab -> Html -> Html
    tabli Tab
    DiffTab (Html -> Html) -> Html -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << Html -> Html
    anchor (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    ! [String -> HtmlAttr
    href ""] (Html -> Html) -> String -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << "diff"
    linkForTab tabli :: Tab -> Html -> Html
    tabli base' :: String
    base' page :: String
    page rev :: Maybe String
    rev ViewTab =
      let origPage :: String -> String
    origPage s :: String
    s = if String -> Bool
    isDiscussPage String
    s
                          then Int -> String -> String
    forall a. Int -> [a] -> [a]
    drop 1 String
    s
                          else String
    s
      in if String -> Bool
    isDiscussPage String
    page
            then Tab -> Html -> Html
    tabli Tab
    DiscussTab (Html -> Html) -> Html -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << Html -> Html
    anchor (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    !
                  [String -> HtmlAttr
    href (String -> HtmlAttr) -> String -> HtmlAttr
    forall a b. (a -> b) -> a -> b
    $ String
    base' String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    urlForPage (String -> String
    origPage String
    page)] (Html -> Html) -> String -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << "page"
            else Tab -> Html -> Html
    tabli Tab
    ViewTab (Html -> Html) -> Html -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << Html -> Html
    anchor (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    !
                  [String -> HtmlAttr
    href (String -> HtmlAttr) -> String -> HtmlAttr
    forall a b. (a -> b) -> a -> b
    $ String
    base' String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    urlForPage String
    page String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++
                          case Maybe String
    rev of
                               Just r :: String
    r  -> "?revision=" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    r
                               Nothing -> ""] (Html -> Html) -> String -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << "view"
    linkForTab tabli :: Tab -> Html -> Html
    tabli base' :: String
    base' page :: String
    page _ DiscussTab =
      Tab -> Html -> Html
    tabli (if String -> Bool
    isDiscussPage String
    page then Tab
    ViewTab else Tab
    DiscussTab) (Html -> Html) -> Html -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    <<
      Html -> Html
    anchor (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    ! [String -> HtmlAttr
    href (String -> HtmlAttr) -> String -> HtmlAttr
    forall a b. (a -> b) -> a -> b
    $ String
    base' String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ if String -> Bool
    isDiscussPage String
    page then "" else "/_discuss" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++
                       String -> String
    urlForPage String
    page] (Html -> Html) -> String -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << "discuss"
    linkForTab tabli :: Tab -> Html -> Html
    tabli base' :: String
    base' page :: String
    page rev :: Maybe String
    rev EditTab =
      Tab -> Html -> Html
    tabli Tab
    EditTab (Html -> Html) -> Html -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << Html -> Html
    anchor (Html -> Html) -> [HtmlAttr] -> Html -> Html
    forall a. ADDATTRS a => a -> [HtmlAttr] -> a
    !
        [String -> HtmlAttr
    href (String -> HtmlAttr) -> String -> HtmlAttr
    forall a b. (a -> b) -> a -> b
    $ String
    base' String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ "/_edit" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    urlForPage String
    page String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++
                case Maybe String
    rev of
                      Just r :: String
    r   -> "?revision=" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    r String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ "&" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++
                                   [(String, String)] -> String
    urlEncodeVars [("logMsg", "Revert to " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    r)]
                      Nothing  -> ""] (Html -> Html) -> String -> Html
    forall a b. HTML a => (Html -> b) -> a -> b
    << if Maybe String -> Bool
    forall a. Maybe a -> Bool
    isNothing Maybe String
    rev
                                             then "edit"
                                             else "revert"

    uploadsAllowed :: Config -> Bool
    uploadsAllowed :: Config -> Bool
    uploadsAllowed = (0 Integer -> Integer -> Bool
    forall a. Ord a => a -> a -> Bool
    <) (Integer -> Bool) -> (Config -> Integer) -> Config -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Config -> Integer
    maxUploadSize