2017-07-12 06:43:11 +00:00
package yatwiki
2017-07-09 06:05:03 +00:00
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 {
2017-08-13 06:25:58 +00:00
this . serveNoSuchArticle ( w , articleTitle )
2017-07-09 06:05:03 +00:00
return
}
this . serveErrorMessage ( w , err )
return
}
2017-08-13 05:58:01 +00:00
if len ( revs ) == 0 {
2017-08-13 06:25:58 +00:00
this . serveNoSuchArticle ( w , articleTitle )
2017-08-13 05:58:01 +00:00
return
}
2017-07-09 06:05:03 +00:00
pto := DefaultPageTemplateOptions ( this . opts )
pto . CurrentPageName = articleTitle
pto . CurrentPageIsArticle = true
content := ` <h2>Page History</h2><br> ` +
2017-08-13 05:51:44 +00:00
` <em>There have been ` + fmt . Sprintf ( "%d" , len ( revs ) ) + ` edits to the page "<a href=" ` + template . HTMLEscapeString ( this . opts . ExpectBaseURL + ` view/ ` + url . PathEscape ( articleTitle ) ) + ` "> ` + template . HTMLEscapeString ( articleTitle ) + ` </a>".</em> ` +
2017-07-09 06:05:03 +00:00
` <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
}