yatwiki2-compatible /view/ endpoint urls

This commit is contained in:
mappu 2017-07-09 13:04:45 +12:00
parent 19b8fdb504
commit 187f8b8417

View File

@ -121,6 +121,14 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
// Yatwiki2 always required a trailing slash at the end of the URL
// If this was an old link, it might not be present.
// Redirect if possible
if len(articleTitle) > 0 && articleTitle[len(articleTitle)-1] == '/' {
this.serveRedirect(w, this.opts.ExpectBaseURL+"view/"+url.QueryEscape(articleTitle[0:len(articleTitle)-1]))
return
}
this.serveErrorHTMLMessage(w, this.noSuchArticleError(articleTitle)) this.serveErrorHTMLMessage(w, this.noSuchArticleError(articleTitle))
return return
} }
@ -162,7 +170,11 @@ func (this *WikiServer) serveInternalError(w http.ResponseWriter, r *http.Reques
} }
func (this *WikiServer) serveErrorHTMLMessage(w http.ResponseWriter, msg template.HTML) { func (this *WikiServer) serveErrorHTMLMessage(w http.ResponseWriter, msg template.HTML) {
w.Header().Set("Location", this.opts.ExpectBaseURL+"view/"+url.QueryEscape(this.opts.DefaultPage)+"?error="+url.QueryEscape(string(msg))) this.serveRedirect(w, this.opts.ExpectBaseURL+"view/"+url.QueryEscape(this.opts.DefaultPage)+"?error="+url.QueryEscape(string(msg)))
}
func (this *WikiServer) serveRedirect(w http.ResponseWriter, location string) {
w.Header().Set("Location", location)
w.WriteHeader(302) // moved (not permanently) w.WriteHeader(302) // moved (not permanently)
} }