@@ -23,10 +23,11 @@ import (
23
23
)
24
24
25
25
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"
30
31
)
31
32
32
33
// MustEnableWiki check if wiki is enabled, if external then redirect
@@ -118,7 +119,7 @@ func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName strin
118
119
return wikiContentsByEntry (ctx , entry ), true
119
120
}
120
121
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 ) {
122
123
wikiRepo , commit , err := findWikiRepoCommit (ctx )
123
124
if err != nil {
124
125
if ! git .IsErrNotExist (err ) {
@@ -177,11 +178,39 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi
177
178
ctx .Redirect (ctx .Repo .RepoLink + "/wiki/_pages" )
178
179
return nil , nil
179
180
}
181
+
180
182
data := wikiContentsByEntry (ctx , entry )
181
183
if ctx .Written () {
182
184
return nil , nil
183
185
}
184
186
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
+
185
214
if isViewPage {
186
215
sidebarContent , sidebarPresent := wikiContentsByName (ctx , commit , "_Sidebar" )
187
216
if ctx .Written () {
@@ -221,7 +250,7 @@ func Wiki(ctx *context.Context) {
221
250
return
222
251
}
223
252
224
- wikiRepo , entry := renderWikiPage (ctx , true )
253
+ wikiRepo , entry := renderWikiPage (ctx , true , false )
225
254
if ctx .Written () {
226
255
return
227
256
}
@@ -247,6 +276,39 @@ func Wiki(ctx *context.Context) {
247
276
ctx .HTML (200 , tplWikiView )
248
277
}
249
278
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
+
250
312
// WikiPages render wiki pages list page
251
313
func WikiPages (ctx * context.Context ) {
252
314
if ! ctx .Repo .Repository .HasWiki () {
@@ -399,7 +461,7 @@ func EditWiki(ctx *context.Context) {
399
461
return
400
462
}
401
463
402
- renderWikiPage (ctx , false )
464
+ renderWikiPage (ctx , false , false )
403
465
if ctx .Written () {
404
466
return
405
467
}
0 commit comments