2017-07-12 06:43:11 +00:00
|
|
|
package yatwiki
|
2017-07-09 01:26:26 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (this *WikiServer) routeView(w http.ResponseWriter, r *http.Request, articleTitle string) {
|
|
|
|
a, err := this.db.GetLatestVersion(articleTitle)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
// Yatwiki2 always required a trailing slash at the end of the URL
|
|
|
|
// If this was an old link, it might not be present.
|
|
|
|
// Redirect if possible
|
|
|
|
if len(articleTitle) > 0 && articleTitle[len(articleTitle)-1] == '/' {
|
2017-08-13 05:51:44 +00:00
|
|
|
this.serveRedirect(w, this.opts.ExpectBaseURL+"view/"+url.PathEscape(articleTitle[0:len(articleTitle)-1]))
|
2017-07-09 01:26:26 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-13 06:25:58 +00:00
|
|
|
this.serveNoSuchArticle(w, articleTitle)
|
2017-07-09 01:26:26 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
this.serveErrorMessage(w, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pto := DefaultPageTemplateOptions(this.opts)
|
|
|
|
pto.CurrentPageName = articleTitle
|
|
|
|
pto.CurrentPageIsArticle = true
|
|
|
|
|
2017-11-18 02:04:19 +00:00
|
|
|
bcr := this.GetBBCodeRenderer()
|
2017-07-09 01:26:26 +00:00
|
|
|
pto.Content = bcr.RenderHTML(string(a.Body))
|
|
|
|
pto.LoadCodeResources = bcr.CodePresent
|
|
|
|
|
|
|
|
this.servePageResponse(w, r, pto)
|
|
|
|
return
|
|
|
|
}
|