@@ -108,15 +108,17 @@ func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte {
108
108
109
109
// wikiContentsByName returns the contents of a wiki page, along with a boolean
110
110
// indicating whether the page exists. Writes to ctx if an error occurs.
111
- func wikiContentsByName (ctx * context.Context , commit * git.Commit , wikiName string ) ([]byte , bool ) {
112
- entry , err := findEntryForFile (commit , models .WikiNameToFilename (wikiName ))
113
- if err != nil {
111
+ func wikiContentsByName (ctx * context.Context , commit * git.Commit , wikiName string ) ([]byte , * git.TreeEntry , string , bool ) {
112
+ var entry * git.TreeEntry
113
+ var err error
114
+ pageFilename := models .WikiNameToFilename (wikiName )
115
+ if entry , err = findEntryForFile (commit , pageFilename ); err != nil {
114
116
ctx .ServerError ("findEntryForFile" , err )
115
- return nil , false
117
+ return nil , nil , "" , false
116
118
} else if entry == nil {
117
- return nil , false
119
+ return nil , nil , "" , true
118
120
}
119
- return wikiContentsByEntry (ctx , entry ), true
121
+ return wikiContentsByEntry (ctx , entry ), entry , pageFilename , false
120
122
}
121
123
122
124
func renderWikiPage (ctx * context.Context , isViewPage bool , isFileHistory bool ) (* git.Repository , * git.TreeEntry ) {
@@ -158,30 +160,49 @@ func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) (
158
160
ctx .Data ["Pages" ] = pages
159
161
}
160
162
163
+ // get requested pagename
161
164
pageName := models .NormalizeWikiName (ctx .Params (":page" ))
162
165
if len (pageName ) == 0 {
163
166
pageName = "Home"
164
167
}
165
168
ctx .Data ["PageURL" ] = models .WikiNameToSubURL (pageName )
166
-
167
169
ctx .Data ["old_title" ] = pageName
168
170
ctx .Data ["Title" ] = pageName
169
171
ctx .Data ["title" ] = pageName
170
172
ctx .Data ["RequireHighlightJS" ] = true
171
173
172
- pageFilename := models .WikiNameToFilename (pageName )
173
- var entry * git.TreeEntry
174
- if entry , err = findEntryForFile (commit , pageFilename ); err != nil {
175
- ctx .ServerError ("findEntryForFile" , err )
176
- return nil , nil
177
- } else if entry == nil {
174
+ //lookup filename in wiki - get filecontent, gitTree entry , real filename
175
+ data , entry , pageFilename , noEntry := wikiContentsByName (ctx , commit , pageName )
176
+ if noEntry {
178
177
ctx .Redirect (ctx .Repo .RepoLink + "/wiki/_pages" )
178
+ }
179
+ if entry == nil || ctx .Written () {
179
180
return nil , nil
180
181
}
181
182
182
- data := wikiContentsByEntry (ctx , entry )
183
- if ctx .Written () {
184
- return nil , nil
183
+ if isViewPage {
184
+ sidebarContent , _ , _ , _ := wikiContentsByName (ctx , commit , "_Sidebar" )
185
+ if ctx .Written () {
186
+ return nil , nil
187
+ }
188
+
189
+ footerContent , _ , _ , _ := wikiContentsByName (ctx , commit , "_Footer" )
190
+ if ctx .Written () {
191
+ return nil , nil
192
+ }
193
+
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" ] = ""
185
206
}
186
207
187
208
// get commit count - wiki revisions
@@ -211,31 +232,6 @@ func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) (
211
232
ctx .Data ["Page" ] = pager
212
233
}
213
234
214
- if isViewPage {
215
- sidebarContent , sidebarPresent := wikiContentsByName (ctx , commit , "_Sidebar" )
216
- if ctx .Written () {
217
- return nil , nil
218
- }
219
-
220
- footerContent , footerPresent := wikiContentsByName (ctx , commit , "_Footer" )
221
- if ctx .Written () {
222
- return nil , nil
223
- }
224
-
225
- metas := ctx .Repo .Repository .ComposeMetas ()
226
- ctx .Data ["content" ] = markdown .RenderWiki (data , ctx .Repo .RepoLink , metas )
227
- ctx .Data ["sidebarPresent" ] = sidebarPresent
228
- ctx .Data ["sidebarContent" ] = markdown .RenderWiki (sidebarContent , ctx .Repo .RepoLink , metas )
229
- ctx .Data ["footerPresent" ] = footerPresent
230
- ctx .Data ["footerContent" ] = markdown .RenderWiki (footerContent , ctx .Repo .RepoLink , metas )
231
- } else {
232
- ctx .Data ["content" ] = string (data )
233
- ctx .Data ["sidebarPresent" ] = false
234
- ctx .Data ["sidebarContent" ] = ""
235
- ctx .Data ["footerPresent" ] = false
236
- ctx .Data ["footerContent" ] = ""
237
- }
238
-
239
235
return wikiRepo , entry
240
236
}
241
237
0 commit comments