2017-07-12 06:43:11 +00:00
|
|
|
package yatwiki
|
2017-07-09 01:50:13 +00:00
|
|
|
|
|
|
|
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
|
2017-07-09 06:45:28 +00:00
|
|
|
var baseRev int64
|
2017-07-09 01:50:13 +00:00
|
|
|
var existingBody string
|
|
|
|
if isNewArticle {
|
|
|
|
pageTitleHTML = `Creating new article`
|
|
|
|
baseRev = 0
|
|
|
|
} else {
|
2017-08-13 05:51:44 +00:00
|
|
|
pageTitleHTML = `Editing article "<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.PathEscape(articleTitle)) + `">` + template.HTMLEscapeString(articleTitle) + `</a>"`
|
2017-07-09 01:50:13 +00:00
|
|
|
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 »">
|
|
|
|
| <a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`formatting`) + `" target="_blank">formatting 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
|
|
|
|
|
|
|
|
}
|