)
where
+import Codec.Binary.UTF8.String
import Control.Exception
import Control.Monad
import Data.List
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
}
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
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
applyTextLBS path Nothing (entityContent page)
encodeFlag :: Bool -> Maybe String
- encodeFlag True = Just "*\n"
+ encodeFlag True = Just "*"
encodeFlag False = Nothing
= $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) {
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 : ""));
var fldUploadFile
= $.INPUT({type: "file"});
+ var fldRedirect
+ = $.INPUT({type: "text", value: (defaultType == "redirect" ? source : "")});
+
var trContent
= $.TR({},
$.TH({}),
fldPageName.value,
fldUploadFile.value);
}
+ else if (btnTypeRedirect.checked) {
+ Rakka.submitRedirection(
+ baseURI,
+ pageName,
+ oldRevision,
+ fldPageName.value,
+ fldRedirect.value);
+ }
});
var btnDelete
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
btnTypeBinary,
"Binary file"
)
+ ),
+ $.LI({},
+ $.LABEL({},
+ btnTypeRedirect,
+ "Redirection"
+ )
)
)
)
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.");
}
});
};
+
+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