41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
package yatwiki3
|
|
|
|
import (
|
|
"html/template"
|
|
"log"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
func (this *WikiServer) noSuchArticleError(title string) template.HTML {
|
|
return template.HTML(`No such article exists. <a href="` + this.opts.ExpectBaseURL + `modify/` + template.HTMLEscapeString(url.QueryEscape(title)) + `">Click here</a> to create it.`)
|
|
}
|
|
|
|
func (this *WikiServer) serveErrorMessage(w http.ResponseWriter, message error) {
|
|
this.serveErrorHTMLMessage(w, template.HTML(template.HTMLEscapeString(message.Error())))
|
|
}
|
|
|
|
func (this *WikiServer) serveInternalError(w http.ResponseWriter, r *http.Request, e error) {
|
|
log.Printf("Internal error from %s while accessing %s(%s): %s", r.RemoteAddr, r.Method, r.URL.Path, e.Error())
|
|
http.Error(w, "An internal error occurred. Please ask an administrator to check the log file.", 500)
|
|
}
|
|
|
|
func (this *WikiServer) serveErrorHTMLMessage(w http.ResponseWriter, msg template.HTML) {
|
|
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)
|
|
}
|
|
|
|
func (this *WikiServer) servePageResponse(w http.ResponseWriter, r *http.Request, pto *pageTemplateOptions) {
|
|
w.WriteHeader(200)
|
|
pto.SessionMessage = template.HTML(r.URL.Query().Get("error")) // FIXME reflected XSS (although Chrome automatically blocks it..)
|
|
|
|
err := this.pageTmp.Execute(w, pto)
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
}
|
|
}
|