From bb9575473ed1064965f9c0322f14991ef62fe523 Mon Sep 17 00:00:00 2001 From: pho Date: Tue, 25 Dec 2007 19:19:08 +0900 Subject: [PATCH] more improvements related to redirection darcs-hash:20071225101908-62b54-0e0e490eecdbb89ca510df7d627702c69d26580c.gz --- Rakka/Page.hs | 12 +++- Rakka/Resource/PageEntity.hs | 4 +- Rakka/Storage/Impl.hs | 2 +- Rakka/Storage/Repos.hs | 44 +++++++++++--- js/editPage.js | 108 +++++++++++++++++++++++++++++------ 5 files changed, 139 insertions(+), 31 deletions(-) diff --git a/Rakka/Page.hs b/Rakka/Page.hs index 2462bab..0d355fa 100644 --- a/Rakka/Page.hs +++ b/Rakka/Page.hs @@ -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 する。 diff --git a/Rakka/Resource/PageEntity.hs b/Rakka/Resource/PageEntity.hs index 37c2aa8..1a8eb03 100644 --- a/Rakka/Resource/PageEntity.hs +++ b/Rakka/Resource/PageEntity.hs @@ -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 ()) diff --git a/Rakka/Storage/Impl.hs b/Rakka/Storage/Impl.hs index 515667a..b1b05e3 100644 --- a/Rakka/Storage/Impl.hs +++ b/Rakka/Storage/Impl.hs @@ -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 () diff --git a/Rakka/Storage/Repos.hs b/Rakka/Storage/Repos.hs index 0b53568..f8ac5dd 100644 --- a/Rakka/Storage/Repos.hs +++ b/Rakka/Storage/Repos.hs @@ -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 diff --git a/js/editPage.js b/js/editPage.js index 43dc776..ad17658 100644 --- a/js/editPage.js +++ b/js/editPage.js @@ -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 -- 2.40.0