]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
redirection
authorpho <pho@cielonegro.org>
Thu, 27 Dec 2007 04:31:10 +0000 (13:31 +0900)
committerpho <pho@cielonegro.org>
Thu, 27 Dec 2007 04:31:10 +0000 (13:31 +0900)
darcs-hash:20071227043110-62b54-97de9113f75a87b77da2288e1e17ae735f0cebe0.gz

Rakka/Resource.hs
Rakka/Resource/PageEntity.hs
defaultPages/StyleSheet/Default.xml
js/Makefile
js/redirection.js [new file with mode: 0644]

index adbd706d6e9d07c6eb79a3f7bec776be9064b9d4..21acb4b02c16e74faea015adf5ea9743618bf8c5 100644 (file)
@@ -1,6 +1,7 @@
 module Rakka.Resource
     ( runIdempotentA
     , runXmlA
+    , getEntityType
     , outputXmlPage
     )
     where
index 1a8eb03c4d07e750760193e12035c9e360ff5f6f..d84ddc7b6af0024b9792aafff1d1c835fb29ead6 100644 (file)
@@ -7,6 +7,7 @@ import           Control.Arrow
 import           Control.Arrow.ArrowIO
 import           Control.Arrow.ArrowIf
 import           Control.Arrow.ArrowList
+import           Control.Monad.Trans
 import           Data.Char
 import           Data.Maybe
 import           Network.HTTP.Lucu
@@ -19,9 +20,12 @@ import           Rakka.Storage
 import           Rakka.SystemConfig
 import           Rakka.Wiki.Engine
 import           System.FilePath
+import           Text.XML.HXT.Arrow.WriteDocument
 import           Text.XML.HXT.Arrow.XmlArrow
+import           Text.XML.HXT.Arrow.XmlIOStateArrow
 import           Text.XML.HXT.Arrow.XmlNodeSet
 import           Text.XML.HXT.DOM.TypeDefs
+import           Text.XML.HXT.DOM.XmlKeywords
 
 
 fallbackPageEntity :: Environment -> [String] -> IO (Maybe ResourceDef)
@@ -60,13 +64,34 @@ handleGet env name
 
 {-
   HTTP/1.1 302 Found
-  Location: http://example.org/Destination#Redirect:Source
+  Location: http://example.org/Destination.html#Redirect:Source
 -}
 handleRedirect :: (ArrowXml a, ArrowIO a) => Environment -> a Page (Resource ())
 handleRedirect env
     = proc redir
-    -> do BaseURI baseURI <- getSysConfA (envSysConf env) -< ()
-          returnA -< redirect Found (mkPageURI baseURI $ redirDest redir) -- FIXME
+    -> returnA -< do mType <- getEntityType
+                     case mType of
+                       MIMEType "application" "xhtml+xml" _
+                           -> do BaseURI baseURI <- getSysConf (envSysConf env)
+                                 let uri = mkPageFragmentURI
+                                           baseURI
+                                           (redirDest redir)
+                                           ("Redirect:" ++ redirName redir)
+                                 redirect Found uri
+
+                       MIMEType "text" "xml" _
+                           -> do setContentType mType
+                                 [resultStr] <- liftIO $ runX ( setErrorMsgHandler False fail
+                                                                >>>
+                                                                constA redir
+                                                                >>>
+                                                                xmlizePage
+                                                                >>>
+                                                                writeDocumentToString [ (a_indent, v_1) ]
+                                                              )
+                                 output resultStr
+
+                       _   -> fail ("internal error: getEntityType returned " ++ show mType)
 
 
 handleGetEntity :: (ArrowXml a, ArrowChoice a, ArrowIO a) => Environment -> a Page (Resource ())
index 2e9dd0ed2d586b9cee37e451625572241df5cdd7..757e5f930c8a03dc91d050f9c3eb68d1a9eee8df 100644 (file)
@@ -436,5 +436,32 @@ img {
     bottom: 1em;
     right: 1em;
 }
+
+/* redirection message ********************************************************/
+.redirection {
+    margin: 5px;
+    padding: 2px;
+
+    font-size: 80%;
+
+    background-color: #fafafa;
+    color: #888888;
+
+    border-color: #eeeeee;
+    border-width: 1px;
+    border-style: dotted
+}
+
+.redirection input[type="button"] {
+    background-color: inherit;
+
+    color: #008800;
+    
+    border-width: 0;
+}
+
+.redirection input[type="button"]:hover {
+    color: #880000;
+}
 </textData>
 </page>
index 689deeed31adb6c42462599fcf99dccb04b8715a..effc48b0c16e51d44a2c781deb7bd51e9db5d67b 100644 (file)
@@ -6,6 +6,7 @@ SOURCES = \
        jquery-dom.js \
        base.js \
        editPage.js \
+       redirection.js \
        screen.js \
        $(NULL)
 
diff --git a/js/redirection.js b/js/redirection.js
new file mode 100644 (file)
index 0000000..b379437
--- /dev/null
@@ -0,0 +1,30 @@
+$(document).ready(function () {
+    var fragment;
+    
+    if ($.browser.mozilla) {
+        fragment = window.location.hash; // 何故か勝手に URI デコードされる
+    }
+    else {
+        fragment = decodeURIComponent(window.location.hash);
+    }
+
+    var m = fragment.match(/^#Redirect:(.*)$/);
+    if (m) {
+        var from = m[1];
+
+        var editButton
+            = $.INPUT({className: "editButton",
+                       type:      "button",
+                       value:     from,
+                       title:     "Edit the page"});
+        $(editButton).click(function () {
+            alert("not implemented");
+        });
+
+        var box
+            = $.P({className: "redirection"},
+                  "This page is redirected from ", editButton, ".");
+
+        $("div.title").after(box);
+    }
+});
\ No newline at end of file