diff --git a/WikiServer.go b/WikiServer.go index 5b98da6..f47ed7d 100644 --- a/WikiServer.go +++ b/WikiServer.go @@ -76,6 +76,15 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { this.routeView(w, r, articleTitle) return + } else if strings.HasPrefix(r.URL.Path, this.opts.ExpectBaseURL+"modify/") { + articleTitle, err := url.QueryUnescape(r.URL.Path[len(this.opts.ExpectBaseURL+"modify/"):]) + if err != nil { + this.serveErrorMessage(w, err) + return + } + this.routeModify(w, r, articleTitle) + return + } else if strings.HasPrefix(r.URL.Path, this.opts.ExpectBaseURL+"raw/") { revId, err := strconv.Atoi(r.URL.Path[len(this.opts.ExpectBaseURL+"raw/"):]) if err != nil { diff --git a/rModify.go b/rModify.go new file mode 100644 index 0000000..309e25c --- /dev/null +++ b/rModify.go @@ -0,0 +1,68 @@ +package yatwiki3 + +import ( + "database/sql" + "fmt" + "html/template" + "net/http" + "net/url" +) + +func (this *WikiServer) routeModify(w http.ResponseWriter, r *http.Request, articleTitle string) { + + isNewArticle := false + + a, err := this.db.GetLatestVersion(articleTitle) + if err != nil { + + if err == sql.ErrNoRows { + // this is fine - we're creating it for the first time + isNewArticle = true + + } else { + this.serveErrorMessage(w, err) + return + } + } + + var pageTitleHTML string + var baseRev int + var existingBody string + if isNewArticle { + pageTitleHTML = `Creating new article` + baseRev = 0 + } else { + pageTitleHTML = `Editing article "` + template.HTMLEscapeString(articleTitle) + `"` + baseRev = a.ID + existingBody = string(a.Body) + } + + content := ` +

` + pageTitleHTML + `


+ +
+
+ + + | formatting help +
+
+
+ ` + + pto := DefaultPageTemplateOptions(this.opts) + if isNewArticle { + pto.CurrentPageName = "New article" + } else { + pto.CurrentPageName = articleTitle + pto.CurrentPageIsArticle = true + } + pto.Content = template.HTML(content) + this.servePageResponse(w, r, pto) + return + +}