49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
package yatwiki
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"html/template"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
func (this *WikiServer) routeHistory(w http.ResponseWriter, r *http.Request, articleTitle string) {
|
|
revs, err := this.db.GetRevisionHistory(articleTitle)
|
|
if err != nil {
|
|
if err == sql.ErrNoRows {
|
|
this.serveErrorHTMLMessage(w, this.noSuchArticleError(articleTitle))
|
|
return
|
|
}
|
|
|
|
this.serveErrorMessage(w, err)
|
|
return
|
|
}
|
|
|
|
pto := DefaultPageTemplateOptions(this.opts)
|
|
pto.CurrentPageName = articleTitle
|
|
pto.CurrentPageIsArticle = true
|
|
|
|
content := `<h2>Page History</h2><br>` +
|
|
`<em>There have been ` + fmt.Sprintf("%d", len(revs)) + ` edits to the page "<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.QueryEscape(articleTitle)) + `">` + template.HTMLEscapeString(articleTitle) + `</a>".</em>` +
|
|
`<br><br>` +
|
|
`<form method="GET" action="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`diff`) + `">` +
|
|
`<table>`
|
|
compareRow := `<tr><td colspan="2"></td><td><input type="submit" value="Compare Selected »"></td></tr>`
|
|
content += compareRow
|
|
for _, rev := range revs {
|
|
revIdStr := fmt.Sprintf("%d", rev.ID)
|
|
content += `<tr>` +
|
|
`<td><a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`archive/`+revIdStr) + `">` + this.formatTimestamp(rev.Modified) + `</a></td>` +
|
|
`<td>` + template.HTMLEscapeString(rev.Author) + `</td>` +
|
|
`<td><input type="radio" name="t" value="` + revIdStr + `"> <input type="radio" name="f" value="` + revIdStr + `"></td>` +
|
|
`</tr>`
|
|
}
|
|
content += compareRow
|
|
content += `</table></form>`
|
|
|
|
pto.Content = template.HTML(content)
|
|
this.servePageResponse(w, r, pto)
|
|
return
|
|
}
|