]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Interpreter/PageList.hs
List all pages
[Rakka.git] / Rakka / Wiki / Interpreter / PageList.hs
index 1ad6728c3ba370649cb961b8deeb8e452727ab2a..fd4d364ebde2ad6af3c7ae37f9bdfb72c935ad1d 100644 (file)
@@ -7,16 +7,36 @@ import           Control.Monad
 import           Data.Maybe
 import           Data.Time
 import           Network.HTTP.Lucu.RFC1123DateTime
-import           Rakka.Page
+import           Network.URI
 import           Rakka.Storage
+import           Rakka.SystemConfig
 import           Rakka.Utils
 import           Rakka.Wiki
 import           Rakka.Wiki.Interpreter
+import           System.FilePath
 import           Text.HyperEstraier
 
 
 interpreters :: [Interpreter]
-interpreters = [ recentUpdatesInterp ]
+interpreters = [ recentUpdatesURLInterp
+               , recentUpdatesInterp
+               ]
+
+
+recentUpdatesURLInterp :: Interpreter
+recentUpdatesURLInterp
+    = InlineCommandInterpreter {
+        iciName = "recentUpdatesURL"
+      , iciInterpret
+          = \ ctx _ -> do BaseURI baseURI <- getSysConf (ctxSysConf ctx)
+                          let uri = baseURI {
+                                      uriPath  = uriPath baseURI </> "search.html"
+                                    , uriQuery = '?' : mkQueryString [ ("q"    , "[UVSET]")
+                                                                     , ("order", "@mdate NUMD")
+                                                                     ]
+                                    }
+                          return $ ExternalLink uri (Just "List all pages")
+      }
 
 
 -- <div class="recentUpdates">
@@ -44,33 +64,29 @@ recentUpdatesInterp
                     sto            = ctxStorage ctx
                 
                 cond <- newCondition
-                setPhrase   cond "[UVSET]"
                 when onlyEntity
                     $ addAttrCond cond "@type STRNE application/x-rakka-redirection"
                 when onlySummarized
                     $ addAttrCond cond "rakka:summary STRNE" -- summary が空でない
-                setOrder    cond "@mdate NUMD"
-                setMax      cond items
+                setPhrase cond "[UVSET]"
+                setOrder  cond "@mdate NUMD"
+                setMax    cond items
 
                 result <- searchPages sto cond
-                pages  <- mapM ( \ (name, rev)
-                                     -> getPage sto name (Just rev) >>= return . fromJust
-                               ) result
-
-                mkPageList showSummary pages
+                mkPageList showSummary (srPages result)
       }
     where
-      mkPageList :: Bool -> [Page] -> IO BlockElement
+      mkPageList :: Bool -> [HitPage] -> IO BlockElement
       mkPageList showSummary pages
           = do items <- mapM (mkListItem showSummary) pages
                return (Div [("class", "recentUpdates")]
                        [ Block (List Bullet items) ])
 
-      mkListItem :: Bool -> Page -> IO ListItem
+      mkListItem :: Bool -> HitPage -> IO ListItem
       mkListItem showSummary page
-          = do lastMod <- utcToLocalZonedTime (entityLastMod page)
+          = do lastMod <- utcToLocalZonedTime (hpLastMod page)
                return ( [ Inline ( PageLink {
-                                     linkPage     = Just (pageName page)
+                                     linkPage     = Just (hpPageName page)
                                    , linkFragment = Nothing
                                    , linkText     = Nothing
                                    }
@@ -80,7 +96,7 @@ recentUpdatesInterp
                                 )
                         ]
                         ++
-                        case (showSummary, entitySummary page) of
+                        case (showSummary, hpSummary page) of
                           (True, Just s)
                               -> [ Block (Paragraph [Text s]) ]
                           _   -> []