@@ -121,7 +121,7 @@ func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName strin
121
121
return wikiContentsByEntry (ctx , entry ), entry , pageFilename , false
122
122
}
123
123
124
- func renderWikiPage (ctx * context.Context , isViewPage bool , isFileHistory bool ) (* git.Repository , * git.TreeEntry ) {
124
+ func renderViewPage (ctx * context.Context ) (* git.Repository , * git.TreeEntry ) {
125
125
wikiRepo , commit , err := findWikiRepoCommit (ctx )
126
126
if err != nil {
127
127
if ! git .IsErrNotExist (err ) {
@@ -131,34 +131,32 @@ func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) (
131
131
}
132
132
133
133
// Get page list.
134
- if isViewPage {
135
- entries , err := commit .ListEntries ()
136
- if err != nil {
137
- ctx .ServerError ("ListEntries" , err )
138
- return nil , nil
134
+ entries , err := commit .ListEntries ()
135
+ if err != nil {
136
+ ctx .ServerError ("ListEntries" , err )
137
+ return nil , nil
138
+ }
139
+ pages := make ([]PageMeta , 0 , len (entries ))
140
+ for _ , entry := range entries {
141
+ if ! entry .IsRegular () {
142
+ continue
139
143
}
140
- pages := make ([]PageMeta , 0 , len (entries ))
141
- for _ , entry := range entries {
142
- if ! entry .IsRegular () {
143
- continue
144
- }
145
- wikiName , err := models .WikiFilenameToName (entry .Name ())
146
- if err != nil {
147
- if models .IsErrWikiInvalidFileName (err ) {
148
- continue
149
- }
150
- ctx .ServerError ("WikiFilenameToName" , err )
151
- return nil , nil
152
- } else if wikiName == "_Sidebar" || wikiName == "_Footer" {
144
+ wikiName , err := models .WikiFilenameToName (entry .Name ())
145
+ if err != nil {
146
+ if models .IsErrWikiInvalidFileName (err ) {
153
147
continue
154
148
}
155
- pages = append ( pages , PageMeta {
156
- Name : wikiName ,
157
- SubURL : models . WikiNameToSubURL ( wikiName ),
158
- })
149
+ ctx . ServerError ( "WikiFilenameToName" , err )
150
+ return nil , nil
151
+ } else if wikiName == "_Sidebar" || wikiName == "_Footer" {
152
+ continue
159
153
}
160
- ctx .Data ["Pages" ] = pages
154
+ pages = append (pages , PageMeta {
155
+ Name : wikiName ,
156
+ SubURL : models .WikiNameToSubURL (wikiName ),
157
+ })
161
158
}
159
+ ctx .Data ["Pages" ] = pages
162
160
163
161
// get requested pagename
164
162
pageName := models .NormalizeWikiName (ctx .Params (":page" ))
@@ -180,59 +178,127 @@ func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) (
180
178
return nil , nil
181
179
}
182
180
183
- if isViewPage {
184
- sidebarContent , _ , _ , _ := wikiContentsByName (ctx , commit , "_Sidebar" )
185
- if ctx .Written () {
186
- return nil , nil
187
- }
181
+ sidebarContent , _ , _ , _ := wikiContentsByName (ctx , commit , "_Sidebar" )
182
+ if ctx .Written () {
183
+ return nil , nil
184
+ }
188
185
189
- footerContent , _ , _ , _ := wikiContentsByName (ctx , commit , "_Footer" )
190
- if ctx .Written () {
191
- return nil , nil
186
+ footerContent , _ , _ , _ := wikiContentsByName (ctx , commit , "_Footer" )
187
+ if ctx .Written () {
188
+ return nil , nil
189
+ }
190
+
191
+ metas := ctx .Repo .Repository .ComposeMetas ()
192
+ ctx .Data ["content" ] = markdown .RenderWiki (data , ctx .Repo .RepoLink , metas )
193
+ ctx .Data ["sidebarPresent" ] = sidebarContent != nil
194
+ ctx .Data ["sidebarContent" ] = markdown .RenderWiki (sidebarContent , ctx .Repo .RepoLink , metas )
195
+ ctx .Data ["footerPresent" ] = footerContent != nil
196
+ ctx .Data ["footerContent" ] = markdown .RenderWiki (footerContent , ctx .Repo .RepoLink , metas )
197
+
198
+ // get commit count - wiki revisions
199
+ commitsCount , _ := wikiRepo .FileCommitsCount ("master" , pageFilename )
200
+ ctx .Data ["CommitCount" ] = commitsCount
201
+
202
+ return wikiRepo , entry
203
+ }
204
+
205
+ func renderRevisionPage (ctx * context.Context ) (* git.Repository , * git.TreeEntry ) {
206
+ wikiRepo , commit , err := findWikiRepoCommit (ctx )
207
+ if err != nil {
208
+ if ! git .IsErrNotExist (err ) {
209
+ ctx .ServerError ("GetBranchCommit" , err )
192
210
}
211
+ return nil , nil
212
+ }
193
213
194
- metas := ctx .Repo .Repository .ComposeMetas ()
195
- ctx .Data ["content" ] = markdown .RenderWiki (data , ctx .Repo .RepoLink , metas )
196
- ctx .Data ["sidebarPresent" ] = sidebarContent != nil
197
- ctx .Data ["sidebarContent" ] = markdown .RenderWiki (sidebarContent , ctx .Repo .RepoLink , metas )
198
- ctx .Data ["footerPresent" ] = footerContent != nil
199
- ctx .Data ["footerContent" ] = markdown .RenderWiki (footerContent , ctx .Repo .RepoLink , metas )
200
- } else {
201
- ctx .Data ["content" ] = string (data )
202
- ctx .Data ["sidebarPresent" ] = false
203
- ctx .Data ["sidebarContent" ] = ""
204
- ctx .Data ["footerPresent" ] = false
205
- ctx .Data ["footerContent" ] = ""
214
+ // get requested pagename
215
+ pageName := models .NormalizeWikiName (ctx .Params (":page" ))
216
+ if len (pageName ) == 0 {
217
+ pageName = "Home"
206
218
}
219
+ ctx .Data ["PageURL" ] = models .WikiNameToSubURL (pageName )
220
+ ctx .Data ["old_title" ] = pageName
221
+ ctx .Data ["Title" ] = pageName
222
+ ctx .Data ["title" ] = pageName
223
+ ctx .Data ["RequireHighlightJS" ] = true
224
+
225
+ //lookup filename in wiki - get filecontent, gitTree entry , real filename
226
+ data , entry , pageFilename , noEntry := wikiContentsByName (ctx , commit , pageName )
227
+ if noEntry {
228
+ ctx .Redirect (ctx .Repo .RepoLink + "/wiki/_pages" )
229
+ }
230
+ if entry == nil || ctx .Written () {
231
+ return nil , nil
232
+ }
233
+
234
+ ctx .Data ["content" ] = string (data )
235
+ ctx .Data ["sidebarPresent" ] = false
236
+ ctx .Data ["sidebarContent" ] = ""
237
+ ctx .Data ["footerPresent" ] = false
238
+ ctx .Data ["footerContent" ] = ""
207
239
208
240
// get commit count - wiki revisions
209
241
commitsCount , _ := wikiRepo .FileCommitsCount ("master" , pageFilename )
210
242
ctx .Data ["CommitCount" ] = commitsCount
211
243
212
- if isFileHistory {
213
- // get page
214
- page := ctx .QueryInt ("page" )
215
- if page <= 1 {
216
- page = 1
217
- }
244
+ // get page
245
+ page := ctx .QueryInt ("page" )
246
+ if page <= 1 {
247
+ page = 1
248
+ }
218
249
219
- // get Commit Count
220
- commitsHistory , err := wikiRepo .CommitsByFileAndRange ("master" , pageFilename , page )
221
- if err != nil {
222
- ctx .ServerError ("CommitsByFileAndRange" , err )
223
- return nil , nil
250
+ // get Commit Count
251
+ commitsHistory , err := wikiRepo .CommitsByFileAndRange ("master" , pageFilename , page )
252
+ if err != nil {
253
+ ctx .ServerError ("CommitsByFileAndRange" , err )
254
+ return nil , nil
255
+ }
256
+ commitsHistory = models .ValidateCommitsWithEmails (commitsHistory )
257
+ commitsHistory = models .ParseCommitsWithSignature (commitsHistory )
258
+
259
+ ctx .Data ["Commits" ] = commitsHistory
260
+
261
+ pager := context .NewPagination (int (commitsCount ), git .CommitsRangeSize , page , 5 )
262
+ pager .SetDefaultParams (ctx )
263
+ ctx .Data ["Page" ] = pager
264
+
265
+ return wikiRepo , entry
266
+ }
267
+
268
+ func renderEditPage (ctx * context.Context ) {
269
+ _ , commit , err := findWikiRepoCommit (ctx )
270
+ if err != nil {
271
+ if ! git .IsErrNotExist (err ) {
272
+ ctx .ServerError ("GetBranchCommit" , err )
224
273
}
225
- commitsHistory = models . ValidateCommitsWithEmails ( commitsHistory )
226
- commitsHistory = models . ParseCommitsWithSignature ( commitsHistory )
274
+ return
275
+ }
227
276
228
- ctx .Data ["Commits" ] = commitsHistory
277
+ // get requested pagename
278
+ pageName := models .NormalizeWikiName (ctx .Params (":page" ))
279
+ if len (pageName ) == 0 {
280
+ pageName = "Home"
281
+ }
282
+ ctx .Data ["PageURL" ] = models .WikiNameToSubURL (pageName )
283
+ ctx .Data ["old_title" ] = pageName
284
+ ctx .Data ["Title" ] = pageName
285
+ ctx .Data ["title" ] = pageName
286
+ ctx .Data ["RequireHighlightJS" ] = true
229
287
230
- pager := context .NewPagination (int (commitsCount ), git .CommitsRangeSize , page , 5 )
231
- pager .SetDefaultParams (ctx )
232
- ctx .Data ["Page" ] = pager
288
+ //lookup filename in wiki - get filecontent, gitTree entry , real filename
289
+ data , entry , _ , noEntry := wikiContentsByName (ctx , commit , pageName )
290
+ if noEntry {
291
+ ctx .Redirect (ctx .Repo .RepoLink + "/wiki/_pages" )
292
+ }
293
+ if entry == nil || ctx .Written () {
294
+ return
233
295
}
234
296
235
- return wikiRepo , entry
297
+ ctx .Data ["content" ] = string (data )
298
+ ctx .Data ["sidebarPresent" ] = false
299
+ ctx .Data ["sidebarContent" ] = ""
300
+ ctx .Data ["footerPresent" ] = false
301
+ ctx .Data ["footerContent" ] = ""
236
302
}
237
303
238
304
// Wiki renders single wiki page
@@ -246,7 +312,7 @@ func Wiki(ctx *context.Context) {
246
312
return
247
313
}
248
314
249
- wikiRepo , entry := renderWikiPage (ctx , true , false )
315
+ wikiRepo , entry := renderViewPage (ctx )
250
316
if ctx .Written () {
251
317
return
252
318
}
@@ -283,7 +349,7 @@ func WikiRevision(ctx *context.Context) {
283
349
return
284
350
}
285
351
286
- wikiRepo , entry := renderWikiPage (ctx , false , true )
352
+ wikiRepo , entry := renderRevisionPage (ctx )
287
353
if ctx .Written () {
288
354
return
289
355
}
@@ -457,7 +523,7 @@ func EditWiki(ctx *context.Context) {
457
523
return
458
524
}
459
525
460
- renderWikiPage (ctx , false , false )
526
+ renderEditPage (ctx )
461
527
if ctx .Written () {
462
528
return
463
529
}
0 commit comments