64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package yatwiki
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"html/template"
|
|
"math"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
func (this *WikiServer) routeRecentChanges(w http.ResponseWriter, r *http.Request, pageNum int) {
|
|
|
|
totalEdits, err := this.db.TotalRevisions()
|
|
if err != nil {
|
|
this.serveInternalError(w, r, err)
|
|
return
|
|
}
|
|
|
|
minPage := 1
|
|
maxPage := int(math.Ceil(float64(totalEdits) / float64(this.opts.RecentChanges)))
|
|
|
|
if pageNum < minPage || pageNum > maxPage {
|
|
this.serveErrorMessage(w, errors.New("Invalid page."))
|
|
return
|
|
}
|
|
|
|
recents, err := this.db.GetRecentChanges((pageNum-1)*this.opts.RecentChanges, this.opts.RecentChanges)
|
|
if err != nil {
|
|
this.serveErrorMessage(w, err)
|
|
return
|
|
}
|
|
|
|
//
|
|
|
|
pto := DefaultPageTemplateOptions(this.opts)
|
|
pto.CurrentPageName = "Recent Changes"
|
|
|
|
content := `<h2>Recent Changes</h2><br>` +
|
|
`<em>Showing up to ` + fmt.Sprintf("%d", this.opts.RecentChanges) + ` changes.</em><br>` +
|
|
`<table>`
|
|
for _, rev := range recents {
|
|
content += `<tr>` +
|
|
`<td><a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.QueryEscape(rev.Title)) + `">` + template.HTMLEscapeString(rev.Title) + `</a>` +
|
|
` [<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`archive/`+fmt.Sprintf("%d", rev.ID)) + `">a</a>]` +
|
|
`</td>` +
|
|
`<td>` + this.formatTimestamp(rev.Modified) + ` by ` + template.HTMLEscapeString(rev.Author) + `</td>` +
|
|
`</tr>`
|
|
}
|
|
content += `<tr><td>`
|
|
if pageNum > 1 {
|
|
content += `<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`recent/`+fmt.Sprintf("%d", pageNum-1)) + `">« Newer</a>`
|
|
}
|
|
content += `</td><td></td><td style="text-align:right;">`
|
|
if pageNum < maxPage {
|
|
content += `<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`recent/`+fmt.Sprintf("%d", pageNum+1)) + `">Older »</a>`
|
|
}
|
|
content += `</td></tr></table>`
|
|
|
|
pto.Content = template.HTML(content)
|
|
this.servePageResponse(w, r, pto)
|
|
return
|
|
}
|