{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-
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.HTTP (urlEncodeVars)
import qualified Text.StringTemplate as T
import Data.Maybe (isNothing)
import Text.Blaze.Html5 hiding (s, article, map)
import Text.Blaze.Html5.Attributes hiding (id)
import Data.String (IsString(fromString))
import Text.Blaze.Html.Renderer.String (renderHtml)

defaultPageLayout :: PageLayout
defaultPageLayout :: PageLayout
defaultPageLayout = PageLayout
  { pgPageName :: [Char]
pgPageName       = [Char]
""
  , pgRevision :: Maybe [Char]
pgRevision       = Maybe [Char]
forall a. Maybe a
Nothing
  , pgPrintable :: Bool
pgPrintable      = Bool
False
  , pgMessages :: [[Char]]
pgMessages       = []
  , pgTitle :: [Char]
pgTitle          = [Char]
""
  , pgScripts :: [[Char]]
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 PageLayout
layout Html
htmlContents = do
  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
  renderer layout htmlContents

-- | Given a compiled string template, returns a page renderer.
defaultRenderPage :: T.StringTemplate String -> PageLayout -> Html -> Handler
defaultRenderPage :: StringTemplate [Char] -> PageLayout -> Html -> Handler
defaultRenderPage StringTemplate [Char]
templ PageLayout
layout Html
htmlContents = do
  cfg <- GititServerPart Config
getConfig
  base' <- getWikiBase
  ok . setContentType "text/html; charset=utf-8" . toResponse . T.render .
       filledPageTemplate base' cfg layout htmlContents $ templ

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

      scripts :: [[Char]]
scripts  = [[Char]
"jquery.min.js", [Char]
"jquery-ui.min.js", [Char]
"footnotes.js"] [[Char]] -> [[Char]] -> [[Char]]
forall a. [a] -> [a] -> [a]
++ PageLayout -> [[Char]]
pgScripts PageLayout
layout
      scriptLink :: [Char] -> Html
scriptLink [Char]
x = Html -> Html
script (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
src ([Char] -> AttributeValue
forall a. IsString a => [Char] -> a
fromString ([Char] -> AttributeValue) -> [Char] -> AttributeValue
forall a b. (a -> b) -> a -> b
$  [Char] -> [Char]
prefixedScript [Char]
x) (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
!
        AttributeValue -> Attribute
type_ AttributeValue
"text/javascript" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ Html
forall a. Monoid a => a
mempty
      javascriptlinks :: [Char]
javascriptlinks = Html -> [Char]
renderHtml (Html -> [Char]) -> Html -> [Char]
forall a b. (a -> b) -> a -> b
$ [Html] -> Html
forall a. Monoid a => [a] -> a
mconcat ([Html] -> Html) -> [Html] -> Html
forall a b. (a -> b) -> a -> b
$ ([Char] -> Html) -> [[Char]] -> [Html]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> Html
scriptLink [[Char]]
scripts
      article :: [Char]
article = if [Char] -> Bool
isDiscussPage [Char]
page then Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
drop Int
1 [Char]
page else [Char]
page
      discussion :: [Char]
discussion = Char
'@'Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:[Char]
article
      tabli :: Tab -> Html -> Html
tabli 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) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"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
&& [Char]
page [Char] -> [[Char]] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` Config -> [[Char]]
noEdit Config
cfg)]
      tabs :: Html
tabs = (Html -> Html
ul (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"tabs") (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ (Tab -> Html) -> [Tab] -> Html
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((Tab -> Html -> Html)
-> [Char] -> [Char] -> Maybe [Char] -> Tab -> Html
linkForTab Tab -> Html -> Html
tabli [Char]
base' [Char]
page Maybe [Char]
rev) [Tab]
tabs'
      setStrAttr :: [Char] -> [Char] -> StringTemplate b -> StringTemplate b
setStrAttr  [Char]
attr = [Char] -> [Char] -> StringTemplate b -> StringTemplate b
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
attr ([Char] -> StringTemplate b -> StringTemplate b)
-> ([Char] -> [Char])
-> [Char]
-> StringTemplate b
-> StringTemplate b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Html -> [Char]
renderHtml (Html -> [Char]) -> ([Char] -> Html) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => [Char] -> a
fromString @Html
      setBoolAttr :: [Char] -> Bool -> StringTemplate b -> StringTemplate b
setBoolAttr [Char]
attr Bool
test = if Bool
test then [Char] -> [Char] -> StringTemplate b -> StringTemplate b
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
attr ([Char]
"true"::[Char]) else StringTemplate b -> StringTemplate b
forall a. a -> a
id
  in               [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
"base" [Char]
base' (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> Bool -> StringTemplate [Char] -> StringTemplate [Char]
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
"feed" (PageLayout -> Bool
pgLinkToFeed PageLayout
layout) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> [Char] -> StringTemplate b -> StringTemplate b
setStrAttr [Char]
"wikititle" (Config -> [Char]
wikiTitle Config
cfg) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> [Char] -> StringTemplate b -> StringTemplate b
setStrAttr [Char]
"pagetitle" (PageLayout -> [Char]
pgTitle PageLayout
layout) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
"javascripts" [Char]
javascriptlinks (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> [Char] -> StringTemplate b -> StringTemplate b
setStrAttr [Char]
"pagename" [Char]
page (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> [Char] -> StringTemplate b -> StringTemplate b
setStrAttr [Char]
"articlename" [Char]
article (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> [Char] -> StringTemplate b -> StringTemplate b
setStrAttr [Char]
"discussionname" [Char]
discussion (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> [Char] -> StringTemplate b -> StringTemplate b
setStrAttr [Char]
"pageUrl" ([Char] -> [Char]
urlForPage [Char]
page) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> [Char] -> StringTemplate b -> StringTemplate b
setStrAttr [Char]
"articleUrl" ([Char] -> [Char]
urlForPage [Char]
article) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> [Char] -> StringTemplate b -> StringTemplate b
setStrAttr [Char]
"discussionUrl" ([Char] -> [Char]
urlForPage [Char]
discussion) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> Bool -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> Bool -> StringTemplate b -> StringTemplate b
setBoolAttr [Char]
"ispage" ([Char] -> Bool
isPage [Char]
page) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> Bool -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> Bool -> StringTemplate b -> StringTemplate b
setBoolAttr [Char]
"isarticlepage" ([Char] -> Bool
isPage [Char]
page Bool -> Bool -> Bool
&& Bool -> Bool
not ([Char] -> Bool
isDiscussPage [Char]
page)) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> Bool -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> Bool -> StringTemplate b -> StringTemplate b
setBoolAttr [Char]
"isdiscusspage" ([Char] -> Bool
isDiscussPage [Char]
page) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> Bool -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> Bool -> StringTemplate b -> StringTemplate b
setBoolAttr [Char]
"pagetools" (PageLayout -> Bool
pgShowPageTools PageLayout
layout) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> Bool -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> Bool -> StringTemplate b -> StringTemplate b
setBoolAttr [Char]
"sitenav" (PageLayout -> Bool
pgShowSiteNav PageLayout
layout) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   (StringTemplate [Char] -> StringTemplate [Char])
-> (Text -> StringTemplate [Char] -> StringTemplate [Char])
-> Maybe Text
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe StringTemplate [Char] -> StringTemplate [Char]
forall a. a -> a
id ([Char] -> Text -> StringTemplate [Char] -> StringTemplate [Char]
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
"markuphelp") (PageLayout -> Maybe Text
pgMarkupHelp PageLayout
layout) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> Bool -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> Bool -> StringTemplate b -> StringTemplate b
setBoolAttr [Char]
"printable" (PageLayout -> Bool
pgPrintable PageLayout
layout) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   (StringTemplate [Char] -> StringTemplate [Char])
-> ([Char] -> StringTemplate [Char] -> StringTemplate [Char])
-> Maybe [Char]
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe StringTemplate [Char] -> StringTemplate [Char]
forall a. a -> a
id ([Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
"revision") Maybe [Char]
rev (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   (if [Tab] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (PageLayout -> [Tab]
pgTabs PageLayout
layout) then StringTemplate [Char] -> StringTemplate [Char]
forall a. a -> a
id else [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
"tabs"
                       (Html -> [Char]
renderHtml Html
tabs)) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   (\[[Char]] -> StringTemplate [Char] -> StringTemplate [Char]
f StringTemplate [Char] -> StringTemplate [Char]
x [[Char]]
xs -> if [[Char]] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Char]]
xs then StringTemplate [Char] -> StringTemplate [Char]
x else [[Char]] -> StringTemplate [Char] -> StringTemplate [Char]
f [[Char]]
xs) ([Char]
-> [[Char]] -> StringTemplate [Char] -> StringTemplate [Char]
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
"messages") StringTemplate [Char] -> StringTemplate [Char]
forall a. a -> a
id (PageLayout -> [[Char]]
pgMessages PageLayout
layout) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> Bool -> StringTemplate [Char] -> StringTemplate [Char]
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
"usecache" (Config -> Bool
useCache Config
cfg) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> [Char] -> StringTemplate [Char] -> StringTemplate [Char]
forall a b.
(ToSElem a, Stringable b) =>
[Char] -> a -> StringTemplate b -> StringTemplate b
T.setAttribute [Char]
"content" (Html -> [Char]
renderHtml Html
htmlContents) (StringTemplate [Char] -> StringTemplate [Char])
-> (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char]
-> StringTemplate [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                   [Char] -> Bool -> StringTemplate [Char] -> StringTemplate [Char]
forall {b}.
Stringable b =>
[Char] -> Bool -> StringTemplate b -> StringTemplate b
setBoolAttr [Char]
"wikiupload" ( Config -> Bool
uploadsAllowed Config
cfg) (StringTemplate [Char] -> StringTemplate [Char])
-> StringTemplate [Char] -> StringTemplate [Char]
forall a b. (a -> b) -> a -> b
$
                   StringTemplate [Char]
templ


-- auxiliary functions:

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

uploadsAllowed :: Config -> Bool
uploadsAllowed :: Config -> Bool
uploadsAllowed = (Integer
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