Skip to content

Commit 62cef5b

Browse files
committed
Fix paths
1 parent 48c75f8 commit 62cef5b

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

routers/web/repo/wiki.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry, stri
204204
return nil, nil, ""
205205
}
206206
if pTree != nil && pTree.IsDir() {
207-
ctx.Redirect(ctx.Repo.RepoLink + fmt.Sprintf("/wiki/%s?action=_pages", url.QueryEscape(p)))
207+
ctx.Redirect(ctx.Repo.RepoLink + fmt.Sprintf("/wiki/%s?action=_pages", p))
208208
return nil, nil, ""
209209
}
210210

@@ -213,9 +213,10 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry, stri
213213
treePath := wiki_service.WebDirPathToGitPath(wiki_service.WebPath(dirPath))
214214
tree, err := commit.SubTree(treePath)
215215
if err != nil {
216-
ctx.ServerError("SubTree", err)
216+
ctx.NotFoundOrServerError("SubTree", git.IsErrNotExist, err)
217217
return nil, nil, ""
218218
}
219+
ctx.Data["dirPath"] = dirPath
219220

220221
// Get page list.
221222
entries, err := tree.ListEntries()
@@ -247,11 +248,13 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry, stri
247248
_, displayName := wiki_service.WebPathToUserTitle(wikiName)
248249
pages = append(pages, PageMeta{
249250
Name: displayName,
250-
SubURL: wiki_service.WebPathToURLPath(wikiName),
251+
SubURL: wiki_service.WebPathToURLPath(wiki_service.WebPath(dirPath) + wikiName),
251252
GitEntryName: entry.Name(),
252253
})
253254
}
254255
ctx.Data["Pages"] = pages
256+
ctx.Data["PageURL"] = wiki_service.WebPathToURLPath(wiki_service.WebPath(p))
257+
ctx.Data["PageDir"] = wiki_service.WebPathToURLPath(wiki_service.WebPath(dirPath))
255258

256259
// get requested page name
257260
if len(pageName) == 0 {
@@ -260,7 +263,6 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry, stri
260263
}
261264

262265
_, displayName := wiki_service.WebPathToUserTitle(wiki_service.WebPath(pageName))
263-
ctx.Data["PageURL"] = wiki_service.WebPathToURLPath(wiki_service.WebPath(pageName))
264266
ctx.Data["old_title"] = displayName
265267
ctx.Data["Title"] = displayName
266268
ctx.Data["title"] = displayName
@@ -489,13 +491,14 @@ func renderEditPage(ctx *context.Context) {
489491
}
490492

491493
// get requested pagename
492-
pageName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("*"))
494+
pageName := wiki_service.WebPath(util.PathJoinRelX(ctx.PathParamRaw("*")))
493495
if len(pageName) == 0 {
494496
pageName = "Home"
495497
}
496498

497499
_, displayName := wiki_service.WebPathToUserTitle(pageName)
498500
ctx.Data["PageURL"] = wiki_service.WebPathToURLPath(pageName)
501+
ctx.Data["PageDir"] = wiki_service.WebPathToURLPath(wiki_service.WebPath(path.Dir(string(pageName))))
499502
ctx.Data["old_title"] = displayName
500503
ctx.Data["Title"] = displayName
501504
ctx.Data["title"] = displayName
@@ -727,6 +730,7 @@ func WikiPages(ctx *context.Context) {
727730
})
728731
}
729732
ctx.Data["Pages"] = pages
733+
ctx.Data["PageDir"] = ctx.PathParamRaw("*")
730734

731735
ctx.HTML(http.StatusOK, tplWikiPages)
732736
}
@@ -810,7 +814,7 @@ func NewWikiPost(ctx *context.Context) {
810814
return
811815
}
812816

813-
wikiName := wiki_service.UserTitleToWebPath("", form.Title)
817+
wikiName := wiki_service.UserTitleToWebPath(ctx.PathParam("*"), form.Title)
814818

815819
if len(form.Message) == 0 {
816820
form.Message = ctx.Locale.TrString("repo.editor.add", form.Title)
@@ -861,8 +865,9 @@ func EditWikiPost(ctx *context.Context) {
861865
return
862866
}
863867

864-
oldWikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("*"))
865-
newWikiName := wiki_service.UserTitleToWebPath("", form.Title)
868+
p := util.PathJoinRelX(ctx.PathParamRaw("*"))
869+
oldWikiName := wiki_service.WebPath(p)
870+
newWikiName := wiki_service.UserTitleToWebPath(path.Dir(p), form.Title)
866871

867872
if len(form.Message) == 0 {
868873
form.Message = ctx.Locale.TrString("repo.editor.update", form.Title)
@@ -880,7 +885,7 @@ func EditWikiPost(ctx *context.Context) {
880885

881886
// DeleteWikiPagePost delete wiki page
882887
func DeleteWikiPagePost(ctx *context.Context) {
883-
wikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("*"))
888+
wikiName := wiki_service.WebPath(util.PathJoinRelX(ctx.PathParamRaw("*")))
884889
if len(wikiName) == 0 {
885890
wikiName = "Home"
886891
}

templates/repo/wiki/new.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="ui header flex-text-block tw-justify-between">
77
{{ctx.Locale.Tr "repo.wiki.new_page"}}
88
{{if .PageIsWikiEdit}}
9-
<a class="ui tiny primary button" href="{{.RepoLink}}/wiki?action=_new">{{ctx.Locale.Tr "repo.wiki.new_page_button"}}</a>
9+
<a class="ui tiny primary button" href="{{.RepoLink}}/wiki/{{.PageDir}}?action=_new">{{ctx.Locale.Tr "repo.wiki.new_page_button"}}</a>
1010
{{end}}
1111
</div>
1212
<form class="ui form" action="?action={{if .PageIsWikiEdit}}_edit{{else}}_new{{end}}" method="post">

templates/repo/wiki/pages.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<span>{{ctx.Locale.Tr "repo.wiki.pages"}}</span>
77
<span>
88
{{if and .CanWriteWiki (not .Repository.IsMirror)}}
9-
<a class="ui small primary button" href="{{.RepoLink}}/wiki?action=_new">{{ctx.Locale.Tr "repo.wiki.new_page_button"}}</a>
9+
<a class="ui small primary button" href="{{.RepoLink}}/wiki/{{.PageDir}}?action=_new">{{ctx.Locale.Tr "repo.wiki.new_page_button"}}</a>
1010
{{end}}
1111
</span>
1212
</h2>
@@ -18,7 +18,7 @@
1818
<td>
1919
{{if .IsDir}}{{svg "octicon-file-directory"}}{{else}}{{svg "octicon-file"}}{{end}}
2020
<a href="{{$.RepoLink}}/wiki/{{.SubURL}}{{if .IsDir}}?action=_pages{{end}}">{{.Name}}</a>
21-
<a class="wiki-git-entry" href="{{$.RepoLink}}/wiki/{{.GitEntryName | PathEscape}}" data-tooltip-content="{{ctx.Locale.Tr "repo.wiki.original_git_entry_tooltip"}}">{{svg "octicon-chevron-right"}}</a>
21+
<a class="wiki-git-entry" href="{{$.RepoLink}}/wiki/{{.SubURL}}{{if .IsDir}}?action=_pages{{end}}" data-tooltip-content="{{ctx.Locale.Tr "repo.wiki.original_git_entry_tooltip"}}">{{svg "octicon-chevron-right"}}</a>
2222
</td>
2323
{{$timeSince := DateUtils.TimeSince .UpdatedUnix}}
2424
<td class="text right">{{ctx.Locale.Tr "repo.wiki.last_updated" $timeSince}}</td>

templates/repo/wiki/view.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
{{end}}
5050
{{if and .CanWriteWiki (not .Repository.IsMirror)}}
5151
<a class="ui small button" href="{{.RepoLink}}/wiki/{{.PageURL}}?action=_edit">{{ctx.Locale.Tr "repo.wiki.edit_page_button"}}</a>
52-
<a class="ui small primary button" href="{{.RepoLink}}/wiki?action=_new">{{ctx.Locale.Tr "repo.wiki.new_page_button"}}</a>
52+
<a class="ui small primary button" href="{{.RepoLink}}/wiki/{{.PageDir}}?action=_new">{{ctx.Locale.Tr "repo.wiki.new_page_button"}}</a>
5353
<a class="ui small red button delete-button" href="" data-url="{{.RepoLink}}/wiki/{{.PageURL}}?action=_delete" data-id="{{.PageURL}}">{{ctx.Locale.Tr "repo.wiki.delete_page_button"}}</a>
5454
{{end}}
5555
</div>

0 commit comments

Comments
 (0)