2017-07-12 06:43:11 +00:00
|
|
|
package yatwiki
|
2017-07-09 01:26:26 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2017-08-13 05:51:44 +00:00
|
|
|
"fmt"
|
2017-07-09 01:26:26 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (this *WikiServer) routeView(w http.ResponseWriter, r *http.Request, articleTitle string) {
|
2017-08-13 05:51:44 +00:00
|
|
|
fmt.Printf("%#v\n", articleTitle)
|
2017-07-09 01:26:26 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
this.serveErrorHTMLMessage(w, this.noSuchArticleError(articleTitle))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.serveErrorMessage(w, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pto := DefaultPageTemplateOptions(this.opts)
|
|
|
|
pto.CurrentPageName = articleTitle
|
|
|
|
pto.CurrentPageIsArticle = true
|
|
|
|
|
|
|
|
bcr := NewBBCodeRenderer(this.opts.ExpectBaseURL)
|
|
|
|
pto.Content = bcr.RenderHTML(string(a.Body))
|
|
|
|
pto.LoadCodeResources = bcr.CodePresent
|
|
|
|
|
|
|
|
this.servePageResponse(w, r, pto)
|
|
|
|
return
|
|
|
|
}
|