2017-07-12 06:43:11 +00:00
|
|
|
package yatwiki
|
2017-07-09 01:26:26 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (this *WikiServer) routeIndex(w http.ResponseWriter, r *http.Request) {
|
2018-04-02 05:41:47 +00:00
|
|
|
titles, err := this.db.ListTitles(true) // Always load deleted pages, even if we don't display them in the list
|
2017-07-09 01:26:26 +00:00
|
|
|
if err != nil {
|
|
|
|
this.serveInternalError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-02 05:42:34 +00:00
|
|
|
showDeleted := (r.FormValue("deleted") == "1")
|
|
|
|
anyDeleted := false
|
|
|
|
|
2017-07-09 01:26:26 +00:00
|
|
|
totalRevs, err := this.db.TotalRevisions()
|
|
|
|
if err != nil {
|
|
|
|
this.serveInternalError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
content := fmt.Sprintf(`<h2>Article Index</h2><br><em>There are %d edits to %d pages.</em><br><br><ul>`, totalRevs, len(titles))
|
|
|
|
for _, title := range titles {
|
2018-04-02 05:42:34 +00:00
|
|
|
classAttr := ""
|
|
|
|
if title.IsDeleted {
|
|
|
|
anyDeleted = true
|
|
|
|
if !showDeleted {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
classAttr = `class="deleted"`
|
|
|
|
}
|
|
|
|
content += `<li><a ` + classAttr + ` href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.PathEscape(title.Title)) + `">` + template.HTMLEscapeString(title.Title) + `</a></li>`
|
2017-07-09 01:26:26 +00:00
|
|
|
}
|
|
|
|
content += `</ul>`
|
|
|
|
|
2018-04-02 05:42:34 +00:00
|
|
|
if anyDeleted {
|
|
|
|
content += `<br>`
|
|
|
|
if !showDeleted {
|
|
|
|
content += `<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`index?deleted=1`) + `">Show deleted pages</a>`
|
|
|
|
} else {
|
|
|
|
content += `<a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`index`) + `">Hide deleted pages</a>`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-09 01:26:26 +00:00
|
|
|
pto := DefaultPageTemplateOptions(this.opts)
|
|
|
|
pto.CurrentPageName = "Index"
|
|
|
|
pto.Content = template.HTML(content)
|
|
|
|
this.servePageResponse(w, r, pto)
|
|
|
|
return
|
|
|
|
}
|