yatwiki/rModify.go

69 lines
1.8 KiB
Go

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 int64
var existingBody string
if isNewArticle {
pageTitleHTML = `Creating new article`
baseRev = 0
} else {
pageTitleHTML = `Editing article &quot;<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.QueryEscape(articleTitle)) + `">` + template.HTMLEscapeString(articleTitle) + `</a>&quot;`
baseRev = a.ID
existingBody = string(a.Body)
}
content := `
<h2>` + pageTitleHTML + `</h2><br>
<form method="POST" action="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`save`) + `" class="editor" accept-charset="UTF-8">
<div class="frm">
<label>
Save as:
<input type="hidden" name="baserev" value="` + fmt.Sprintf("%d", baseRev) + `" />
<input type="text" name="pname" value="` + template.HTMLEscapeString(articleTitle) + `"/>
</label>
<input type="submit" value="Save &raquo;">
| <a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`formatting`) + `" target="_blank">formatting&nbsp;help</a>
</div>
<div id="contentctr"><textarea name="content">` + template.HTMLEscapeString(existingBody) + `</textarea></div>
</form>
`
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
}