]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
more improvements related to redirection
authorpho <pho@cielonegro.org>
Tue, 25 Dec 2007 10:19:08 +0000 (19:19 +0900)
committerpho <pho@cielonegro.org>
Tue, 25 Dec 2007 10:19:08 +0000 (19:19 +0900)
darcs-hash:20071225101908-62b54-0e0e490eecdbb89ca510df7d627702c69d26580c.gz

Rakka/Page.hs
Rakka/Resource/PageEntity.hs
Rakka/Storage/Impl.hs
Rakka/Storage/Repos.hs
js/editPage.js

index 2462bab30f14d44004fa4fd61e81972fa385fb96..0d355faee8b88a637ea7d671c826504d7bc632cc 100644 (file)
@@ -10,6 +10,7 @@ module Rakka.Page
 
     , pageName
     , pageUpdateInfo
+    , pageRevision
 
     , encodePageName
     , decodePageName
@@ -108,14 +109,21 @@ pageName :: Page -> PageName
 pageName p
     | isRedirect p = redirName p
     | isEntity   p = entityName p
-    | otherwise    = fail "neither redirection nor entity"
+    | otherwise    = error "neither redirection nor entity"
 
 
 pageUpdateInfo :: Page -> Maybe UpdateInfo
 pageUpdateInfo p
     | isRedirect p = redirUpdateInfo p
     | isEntity   p = entityUpdateInfo p
-    | otherwise    = fail "neither redirection nor entity"
+    | otherwise    = error "neither redirection nor entity"
+
+
+pageRevision :: Page -> RevNum
+pageRevision p
+    | isRedirect p = redirRevision p
+    | isEntity   p = entityRevision p
+    | otherwise    = error "neither redirection nor entity"
 
 
 -- UTF-8 に encode してから 0x20 - 0x7E の範圍を除いて URI escape する。
index 37c2aa8a85b9e8e914f5d388d4f923aa3d14122a..1a8eb03c4d07e750760193e12035c9e360ff5f6f 100644 (file)
@@ -60,13 +60,13 @@ handleGet env name
 
 {-
   HTTP/1.1 302 Found
-  Location: http://example.org/Destination?from=Source
+  Location: http://example.org/Destination#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 $ redirName redir) -- FIXME
+          returnA -< redirect Found (mkPageURI baseURI $ redirDest redir) -- FIXME
 
 
 handleGetEntity :: (ArrowXml a, ArrowChoice a, ArrowIO a) => Environment -> a Page (Resource ())
index 515667a9b40ddca019859b3b63fdcdbd6a6a8d76..b1b05e34ecbeb21abbc1007d5f2522ecf6bda2e7 100644 (file)
@@ -178,7 +178,7 @@ updateIndex index repos mkDraft rev name
            Just page
                -> do draft <- mkDraft page
                      putDocument index draft [CleaningPut]
-                     infoM logger ("Indexed page " ++ name ++ " of revision " ++ show (entityRevision page))
+                     infoM logger ("Indexed page " ++ name ++ " of revision " ++ show (pageRevision page))
 
 
 updateIndexRev :: FilePath -> (RevNum -> IO RevNum) -> IO ()
index 0b53568b4290e9b0d433d71a291fbf1fec9b35d1..f8ac5ddcea7e9a3c587a5477a5c2c6762b936487 100644 (file)
@@ -6,6 +6,7 @@ module Rakka.Storage.Repos
     )
     where
 
+import           Codec.Binary.UTF8.String
 import           Control.Exception
 import           Control.Monad
 import           Data.List
@@ -101,12 +102,12 @@ loadPageInRepository repos name rev
       path = mkPagePath name
 
       loadPage' :: Rev Page
-      loadPage' = do redirect <- getNodeProp path "rakka:redirect"
-                     case redirect of
-                       Nothing
-                           -> loadPageEntity
-                       Just _
+      loadPage' = do mType <- liftM (fmap (read . chomp)) (getNodeProp path "svn:mime-type")
+                     case mType of
+                       Just (MIMEType "application" "x-rakka-redirection" _)
                            -> loadPageRedirect
+                       _
+                           -> loadPageEntity
 
       loadPageEntity :: Rev Page
       loadPageEntity
@@ -148,7 +149,23 @@ loadPageInRepository repos name rev
                           }
       
       loadPageRedirect :: Rev Page
-      loadPageRedirect = fail "FIXME: loadPageRedirect: not implemented"
+      loadPageRedirect
+          = do hist    <- getNodeHistory True path
+               content <- getFileContents path
+
+               let pageRev = fst $ head hist
+                   dest    = chomp $ decodeString content
+
+               lastMod <- getRevisionProp "svn:date"
+                          >>= return . fromJust . parseW3CDateTime . chomp . fromJust
+
+               return Redirection {
+                            redirName       = name
+                          , redirDest       = dest
+                          , redirRevision   = pageRev
+                          , redirLastMod    = zonedTimeToUTC lastMod
+                          , redirUpdateInfo = undefined
+                          }
 
 
 putPageIntoRepository :: Repository -> Page -> IO StatusCode
@@ -207,7 +224,18 @@ putPageIntoRepository repos page
 
       updatePageRedirect :: PageName -> Txn ()
       updatePageRedirect name
-          = fail "FIXME: updatePageRedirect: not implemented yet"
+          = do let path = mkPagePath name
+               setNodeProp path "svn:mime-type"   (Just "application/x-rakka-redirection")
+               setNodeProp path "rakka:lang"      Nothing
+               setNodeProp path "rakka:fileName"  Nothing
+               setNodeProp path "rakka:isTheme"   Nothing
+               setNodeProp path "rakka:isFeed"    Nothing
+               setNodeProp path "rakka:isLocked"  Nothing
+               setNodeProp path "rakka:isBoring"  Nothing
+               setNodeProp path "rakka:isBinary"  Nothing
+               setNodeProp path "rakka:summary"   Nothing
+               setNodeProp path "rakka:otherLang" Nothing
+               applyText path Nothing (encodeString (redirDest page) ++ "\n")
 
       updatePageEntity :: PageName -> Txn ()
       updatePageEntity name
@@ -230,7 +258,7 @@ putPageIntoRepository repos page
                applyTextLBS path Nothing (entityContent page)
 
       encodeFlag :: Bool -> Maybe String
-      encodeFlag True  = Just "*\n"
+      encodeFlag True  = Just "*"
       encodeFlag False = Nothing
 
 
index 43dc7766f5397a7874a63ac5b62cb6ae1cee111b..ad1765891dfb9b3093f32377f2654c8836c56522 100644 (file)
@@ -15,9 +15,13 @@ Rakka.editPage = function (baseURI, pageName) {
                 = $page.attr("isBinary") == "yes"          ? "binary"
                 : $page.attr("type")     == "text/x-rakka" ? "rakka"
                 : $page.attr("type")     == "text/css"     ? "css"
+                : $page.attr("redirect") != null           ? "redirect"
                 :                                            "unknown"
                 ;
-            var source = $page.find("textData").text();
+            var source
+                = $page.attr("redirect") != null ? $page.attr("redirect")
+                : $page.find("textData").text()
+                ;
             Rakka.displayPageEditor(baseURI, pageName, oldRevision, defaultType, source);
         },
         error  : function (req) {
@@ -49,18 +53,22 @@ Rakka.displayPageEditor = function (baseURI, pageName, oldRevision, defaultType,
     var btnTypeRakka
         = $.INPUT({type   : "radio",
                    name   : "type",
-                   checked: (defaultType == "rakka"  ? "checked" : "")});
+                   checked: (defaultType == "rakka"    ? "checked" : "")});
 
     var btnTypeCSS
         = $.INPUT({type   : "radio",
                    name   : "type",
-                   checked: (defaultType == "css"    ? "checked" : "")});
+                   checked: (defaultType == "css"      ? "checked" : "")});
 
     var btnTypeBinary
         = $.INPUT({type   : "radio",
                    name   : "type",
-                   checked: (defaultType == "binary" ? "checked" : "")});
-    
+                   checked: (defaultType == "binary"   ? "checked" : "")});
+
+    var btnTypeRedirect
+        = $.INPUT({type   : "radio",
+                   name   : "type",
+                   checked: (defaultType == "redirect" ? "checked" : "")});
 
     var fldRakkaSource
         = $.TEXTAREA({}, (defaultType == "rakka" && source != null ? source : ""));
@@ -71,6 +79,9 @@ Rakka.displayPageEditor = function (baseURI, pageName, oldRevision, defaultType,
     var fldUploadFile
         = $.INPUT({type: "file"});
 
+    var fldRedirect
+        = $.INPUT({type: "text", value: (defaultType == "redirect" ? source : "")});
+
     var trContent
         = $.TR({}, 
                $.TH({}),
@@ -114,6 +125,14 @@ Rakka.displayPageEditor = function (baseURI, pageName, oldRevision, defaultType,
                 fldPageName.value,
                 fldUploadFile.value);
         }
+        else if (btnTypeRedirect.checked) {
+            Rakka.submitRedirection(
+                baseURI,
+                pageName,
+                oldRevision,
+                fldPageName.value,
+                fldRedirect.value);
+        }
     });
 
     var btnDelete
@@ -127,19 +146,28 @@ Rakka.displayPageEditor = function (baseURI, pageName, oldRevision, defaultType,
         if (btnTypeRakka.checked) {
             $(trContent).find("th").text("Wiki source");
             $(trContent).find("td").empty().append(fldRakkaSource);
+            $(btnPreview).show();
         }
         else if (btnTypeCSS.checked) {
             $(trContent).find("th").text("CSS source");
             $(trContent).find("td").empty().append(fldCSSSource);
+            $(btnPreview).hide();
         }
         else if (btnTypeBinary.checked) {
             $(trContent).find("th").text("File");
             $(trContent).find("td").empty().append(fldUploadFile);
+            $(btnPreview).show();
+        }
+        else if (btnTypeRedirect.checked) {
+            $(trContent).find("th").text("Destination Page");
+            $(trContent).find("td").empty().append(fldRedirect);
+            $(btnPreview).hide();
         }
     };
-    $(btnTypeRakka ).change(updateTRContent);
-    $(btnTypeCSS   ).change(updateTRContent);
-    $(btnTypeBinary).change(updateTRContent);
+    $(btnTypeRakka   ).change(updateTRContent);
+    $(btnTypeCSS     ).change(updateTRContent);
+    $(btnTypeBinary  ).change(updateTRContent);
+    $(btnTypeRedirect).change(updateTRContent);
     updateTRContent();
 
     var pageEditor
@@ -170,6 +198,12 @@ Rakka.displayPageEditor = function (baseURI, pageName, oldRevision, defaultType,
                                                       btnTypeBinary,
                                                       "Binary file"
                                                      )
+                                             ),
+                                         $.LI({},
+                                              $.LABEL({},
+                                                      btnTypeRedirect,
+                                                      "Redirection"
+                                                     )
                                              )
                                         )
                                    )
@@ -210,18 +244,13 @@ Rakka.submitTextPage = function (baseURI, pageName, oldRevision, givenPageName,
         page.appendChild(updateInfo);
     }
 
-    if (0) {
-        // redirection
-    }
-    else {
-        page.setAttribute("type", mimeType);
+    page.setAttribute("type", mimeType);
 
-        var textData = doc.createElement("textData");
-        textData.appendChild(
-            doc.createTextNode(text));
+    var textData = doc.createElement("textData");
+    textData.appendChild(
+        doc.createTextNode(text));
 
-        page.appendChild(textData);
-    }
+    page.appendChild(textData);
 
     Rakka.displayWaitingMessage("Submitting... please wait.");
 
@@ -243,3 +272,46 @@ Rakka.submitTextPage = function (baseURI, pageName, oldRevision, givenPageName,
         }
     });
 };
+
+Rakka.submitRedirection = function (baseURI, pageName, oldRevision, givenPageName, destination) {
+    var doc = document.implementation.createDocument(
+        "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
+
+    var page = doc.documentElement;
+
+    if (oldRevision != null) {
+        // ページ書換時
+        var updateInfo = doc.createElement("updateInfo");
+        updateInfo.setAttribute("oldRevision", oldRevision);
+
+        if (pageName != givenPageName) {
+            var move = doc.createElement("move");
+            move.setAttribute("from", pageName);
+            updateInfo.appendChild(move);
+        }
+
+        page.appendChild(updateInfo);
+    }
+
+    page.setAttribute("redirect", destination);
+
+    Rakka.displayWaitingMessage("Submitting... please wait.");
+
+    var url = baseURI + encodeURI(givenPageName);
+    $.ajax({
+        type       : "PUT",
+        url        : url,
+        contentType: "text/xml",
+        data       : doc,
+        processData: false,
+        success    : function () {
+            window.location.replace(url);
+        },
+        error      : function (req) {
+            Rakka.hideWaitingMessage();
+            
+            var $area = Rakka.switchScreen();
+            $area.text("Error: " + req.status + " " + req.statusText);
+        }
+    });
+};
\ No newline at end of file