Skip to content

Commit c102abe

Browse files
committed
add wiki page revision list
- list who, how often and when a wiki page was changed fix go-gitea#7 Signed-off-by: Michael Gnehr <[email protected]>
1 parent 8baa2dc commit c102abe

File tree

7 files changed

+194
-7
lines changed

7 files changed

+194
-7
lines changed

options/locale/locale_en-US.ini

+2
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,8 @@ wiki.save_page = Save Page
10321032
wiki.last_commit_info = %s edited this page %s
10331033
wiki.edit_page_button = Edit
10341034
wiki.new_page_button = New Page
1035+
wiki.file_revision = Page Revision
1036+
wiki.back_to_wiki = Back to wiki page
10351037
wiki.delete_page_button = Delete Page
10361038
wiki.delete_page_notice_1 = Deleting the wiki page '%s' cannot be undone. Continue?
10371039
wiki.page_already_exists = A wiki page with the same name already exists.

public/css/index.css

+2
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ footer .ui.left,footer .ui.right{line-height:40px}
287287
.markdown:not(code) .csv-data tr{border-top:0}
288288
.markdown:not(code) .csv-data th{font-weight:700;background:#f8f8f8;border-top:0}
289289
.markdown:not(code) .ui.list .list,.markdown:not(code) ol.ui.list ol,.markdown:not(code) ul.ui.list ul{padding-left:2em}
290+
.file-revisions-btn{display:block;float:left;padding:11px!important;margin-right:10px!important}
291+
.file-revisions-btn i{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}
290292
.home .logo{max-width:220px}
291293
@media only screen and (max-width:767px){.home .hero h1{font-size:3.5em}
292294
.home .hero h2{font-size:2em}

public/less/_markdown.less

+16
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,19 @@
494494
padding-left: 2em;
495495
}
496496
}
497+
498+
.file-revisions-btn {
499+
display: block;
500+
float: left;
501+
padding: 11px !important;
502+
margin-right: 10px !important;
503+
504+
i {
505+
-webkit-touch-callout: none;
506+
-webkit-user-select: none;
507+
-khtml-user-select: none;
508+
-moz-user-select: none;
509+
-ms-user-select: none;
510+
user-select: none;
511+
}
512+
}

routers/repo/wiki.go

+69-7
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import (
2323
)
2424

2525
const (
26-
tplWikiStart base.TplName = "repo/wiki/start"
27-
tplWikiView base.TplName = "repo/wiki/view"
28-
tplWikiNew base.TplName = "repo/wiki/new"
29-
tplWikiPages base.TplName = "repo/wiki/pages"
26+
tplWikiStart base.TplName = "repo/wiki/start"
27+
tplWikiView base.TplName = "repo/wiki/view"
28+
tplWikiRevision base.TplName = "repo/wiki/revision"
29+
tplWikiNew base.TplName = "repo/wiki/new"
30+
tplWikiPages base.TplName = "repo/wiki/pages"
3031
)
3132

3233
// MustEnableWiki check if wiki is enabled, if external then redirect
@@ -118,7 +119,7 @@ func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName strin
118119
return wikiContentsByEntry(ctx, entry), true
119120
}
120121

121-
func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *git.TreeEntry) {
122+
func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) (*git.Repository, *git.TreeEntry) {
122123
wikiRepo, commit, err := findWikiRepoCommit(ctx)
123124
if err != nil {
124125
if !git.IsErrNotExist(err) {
@@ -177,11 +178,39 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi
177178
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
178179
return nil, nil
179180
}
181+
180182
data := wikiContentsByEntry(ctx, entry)
181183
if ctx.Written() {
182184
return nil, nil
183185
}
184186

187+
// get commit count - wiki revisions
188+
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
189+
ctx.Data["CommitCount"] = commitsCount
190+
191+
if isFileHistory {
192+
// get page
193+
page := ctx.QueryInt("page")
194+
if page <= 1 {
195+
page = 1
196+
}
197+
198+
// get Commit Count
199+
commitsHistory, err := wikiRepo.CommitsByFileAndRange("master", pageFilename, page)
200+
if err != nil {
201+
ctx.ServerError("CommitsByFileAndRange", err)
202+
return nil, nil
203+
}
204+
commitsHistory = models.ValidateCommitsWithEmails(commitsHistory)
205+
commitsHistory = models.ParseCommitsWithSignature(commitsHistory)
206+
207+
ctx.Data["Commits"] = commitsHistory
208+
209+
pager := context.NewPagination(int(commitsCount), git.CommitsRangeSize, page, 5)
210+
pager.SetDefaultParams(ctx)
211+
ctx.Data["Page"] = pager
212+
}
213+
185214
if isViewPage {
186215
sidebarContent, sidebarPresent := wikiContentsByName(ctx, commit, "_Sidebar")
187216
if ctx.Written() {
@@ -221,7 +250,7 @@ func Wiki(ctx *context.Context) {
221250
return
222251
}
223252

224-
wikiRepo, entry := renderWikiPage(ctx, true)
253+
wikiRepo, entry := renderWikiPage(ctx, true, false)
225254
if ctx.Written() {
226255
return
227256
}
@@ -247,6 +276,39 @@ func Wiki(ctx *context.Context) {
247276
ctx.HTML(200, tplWikiView)
248277
}
249278

279+
// Wiki renders file revision list of wiki page
280+
func WikiRevision(ctx *context.Context) {
281+
ctx.Data["PageIsWiki"] = true
282+
ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(models.UnitTypeWiki) && !ctx.Repo.Repository.IsArchived
283+
284+
if !ctx.Repo.Repository.HasWiki() {
285+
ctx.Data["Title"] = ctx.Tr("repo.wiki")
286+
ctx.HTML(200, tplWikiStart)
287+
return
288+
}
289+
290+
wikiRepo, entry := renderWikiPage(ctx, false, true)
291+
if ctx.Written() {
292+
return
293+
}
294+
if entry == nil {
295+
ctx.Data["Title"] = ctx.Tr("repo.wiki")
296+
ctx.HTML(200, tplWikiStart)
297+
return
298+
}
299+
300+
// Get last change information.
301+
wikiPath := entry.Name()
302+
lastCommit, err := wikiRepo.GetCommitByPath(wikiPath)
303+
if err != nil {
304+
ctx.ServerError("GetCommitByPath", err)
305+
return
306+
}
307+
ctx.Data["Author"] = lastCommit.Author
308+
309+
ctx.HTML(200, tplWikiRevision)
310+
}
311+
250312
// WikiPages render wiki pages list page
251313
func WikiPages(ctx *context.Context) {
252314
if !ctx.Repo.Repository.HasWiki() {
@@ -399,7 +461,7 @@ func EditWiki(ctx *context.Context) {
399461
return
400462
}
401463

402-
renderWikiPage(ctx, false)
464+
renderWikiPage(ctx, false, false)
403465
if ctx.Written() {
404466
return
405467
}

routers/routes/routes.go

+1
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ func RegisterRoutes(m *macaron.Macaron) {
804804
m.Group("/wiki", func() {
805805
m.Get("/?:page", repo.Wiki)
806806
m.Get("/_pages", repo.WikiPages)
807+
m.Get("/:page/_revision", repo.WikiRevision)
807808

808809
m.Group("", func() {
809810
m.Combo("/_new").Get(repo.NewWiki).

templates/repo/wiki/revision.tmpl

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{{template "base/head" .}}
2+
<div class="repository wiki revisions">
3+
{{template "repo/header" .}}
4+
{{ $title := .title}}
5+
<div class="ui container">
6+
<div class="ui stackable grid">
7+
<div class="ui header ten wide column">
8+
<a class="file-revisions-btn ui basic button" title="{{.i18n.Tr "repo.wiki.back_to_wiki"}}" href="{{.RepoLink}}/wiki/{{.PageURL}}" ><span>{{.revision}}</span> <i class="fa fa-fw fa-file-text-o"></i></a>
9+
{{$title}}
10+
<div class="ui sub header">
11+
{{$timeSince := TimeSince .Author.When $.Lang}}
12+
{{.i18n.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince | Safe}}
13+
</div>
14+
</div>
15+
<div class="ui six wide column">
16+
<div class="ui action small input" id="clone-panel">
17+
{{if not $.DisableHTTP}}
18+
<button class="ui basic clone button" id="repo-clone-https" data-link="{{.WikiCloneLink.HTTPS}}">
19+
{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
20+
</button>
21+
{{end}}
22+
{{if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
23+
<button class="ui basic clone button" id="repo-clone-ssh" data-link="{{.WikiCloneLink.SSH}}">
24+
SSH
25+
</button>
26+
{{end}}
27+
{{if not $.DisableHTTP}}
28+
<input id="repo-clone-url" value="{{$.WikiCloneLink.HTTPS}}" readonly>
29+
{{else if and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)}}
30+
<input id="repo-clone-url" value="{{$.WikiCloneLink.SSH}}" readonly>
31+
{{end}}
32+
{{if or ((not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH)))}}
33+
<button class="ui basic icon button poping up clipboard" id="clipboard-btn" data-original="{{.i18n.Tr "repo.copy_link"}}" data-success="{{.i18n.Tr "repo.copy_link_success"}}" data-error="{{.i18n.Tr "repo.copy_link_error"}}" data-content="{{.i18n.Tr "repo.copy_link"}}" data-variation="inverted tiny" data-clipboard-target="#repo-clone-url">
34+
<i class="octicon octicon-clippy"></i>
35+
</button>
36+
{{end}}
37+
</div>
38+
</div>
39+
</div>
40+
<div class="ui" style="margin-top: 1rem;">
41+
<h4 class="ui top attached header">
42+
<div class="ui stackable grid">
43+
<div class="sixteen wide column">
44+
{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}}
45+
</div>
46+
</div>
47+
</h4>
48+
49+
{{if and .Commits (gt .CommitCount 0)}}
50+
<div class="ui attached table segment">
51+
<table class="ui very basic striped fixed table single line" id="commits-table">
52+
<thead>
53+
<tr>
54+
<th class="eight wide">{{.i18n.Tr "repo.commits.author"}}</th>
55+
<th class="four wide sha">SHA1</th>
56+
<th class="four wide">{{.i18n.Tr "repo.commits.date"}}</th>
57+
</tr>
58+
</thead>
59+
<tbody class="commit-list">
60+
{{ $r:= List .Commits}}
61+
{{range $r}}
62+
<tr>
63+
<td class="author">
64+
{{if .User}}
65+
{{if .User.FullName}}
66+
<img class="ui avatar image" src="{{.User.RelAvatarLink}}" alt=""/>&nbsp;&nbsp;<a href="{{AppSubUrl}}/{{.User.Name}}">{{.User.FullName}}</a>
67+
{{else}}
68+
<img class="ui avatar image" src="{{.User.RelAvatarLink}}" alt=""/>&nbsp;&nbsp;<a href="{{AppSubUrl}}/{{.User.Name}}">{{.Author.Name}}</a>
69+
{{end}}
70+
{{else}}
71+
<img class="ui avatar image" src="{{AvatarLink .Author.Email}}" alt=""/>&nbsp;&nbsp;{{.Author.Name}}
72+
{{end}}
73+
</td>
74+
<td class="sha">
75+
<label rel="nofollow" class="ui sha label {{if .Signature}} isSigned {{if .Verification.Verified }} isVerified {{end}}{{end}}">
76+
{{ShortSha .ID.String}}
77+
{{if .Signature}}
78+
<div class="ui detail icon button">
79+
{{if .Verification.Verified}}
80+
<i title="{{.Verification.Reason}}" class="lock green icon"></i>
81+
{{else}}
82+
<i title="{{$.i18n.Tr .Verification.Reason}}" class="unlock icon"></i>
83+
{{end}}
84+
</div>
85+
{{end}}
86+
</label>
87+
</td>
88+
<td class="grey text">{{TimeSince .Author.When $.Lang}}</td>
89+
</tr>
90+
{{end}}
91+
</tbody>
92+
</table>
93+
</div>
94+
{{end}}
95+
96+
{{template "base/paginate" .}}
97+
98+
</div>
99+
</div>
100+
</div>
101+
102+
103+
{{template "base/footer" .}}

templates/repo/wiki/view.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<div class="ui dividing header">
5757
<div class="ui stackable grid">
5858
<div class="eight wide column">
59+
<a class="file-revisions-btn ui basic button" title="{{.i18n.Tr "repo.wiki.file_revision"}}" href="{{.RepoLink}}/wiki/{{.PageURL}}/_revision" ><span>{{.CommitCount}}</span> <i class="fa fa-fw fa-history"></i></a>
5960
{{$title}}
6061
<div class="ui sub header">
6162
{{$timeSince := TimeSince .Author.When $.Lang}}

0 commit comments

Comments
 (0)