Skip to content

Commit 3331335

Browse files
committed
move functions 1
Signed-off-by: Michael Gnehr <[email protected]>
1 parent 278fec8 commit 3331335

File tree

1 file changed

+37
-41
lines changed

1 file changed

+37
-41
lines changed

routers/repo/wiki.go

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,17 @@ func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte {
108108

109109
// wikiContentsByName returns the contents of a wiki page, along with a boolean
110110
// 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 {
114116
ctx.ServerError("findEntryForFile", err)
115-
return nil, false
117+
return nil, nil, "", false
116118
} else if entry == nil {
117-
return nil, false
119+
return nil, nil, "", true
118120
}
119-
return wikiContentsByEntry(ctx, entry), true
121+
return wikiContentsByEntry(ctx, entry), entry, pageFilename, false
120122
}
121123

122124
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) (
158160
ctx.Data["Pages"] = pages
159161
}
160162

163+
// get requested pagename
161164
pageName := models.NormalizeWikiName(ctx.Params(":page"))
162165
if len(pageName) == 0 {
163166
pageName = "Home"
164167
}
165168
ctx.Data["PageURL"] = models.WikiNameToSubURL(pageName)
166-
167169
ctx.Data["old_title"] = pageName
168170
ctx.Data["Title"] = pageName
169171
ctx.Data["title"] = pageName
170172
ctx.Data["RequireHighlightJS"] = true
171173

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 {
178177
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/_pages")
178+
}
179+
if entry == nil || ctx.Written() {
179180
return nil, nil
180181
}
181182

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"] = ""
185206
}
186207

187208
// get commit count - wiki revisions
@@ -211,31 +232,6 @@ func renderWikiPage(ctx *context.Context, isViewPage bool, isFileHistory bool) (
211232
ctx.Data["Page"] = pager
212233
}
213234

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-
239235
return wikiRepo, entry
240236
}
241237

0 commit comments

Comments
 (0)