Skip to content

Commit b1a0a78

Browse files
Redirect .wiki/* ui link to /wiki (#18831) (#19184)
Backport #18831 Redirect .wiki/* ui link to /wiki fix #18590 Signed-off-by: a1012112796 <1012112796@qq.com> Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: a1012112796 <1012112796@qq.com>
1 parent 9c7d8b3 commit b1a0a78

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

modules/context/repo.go

+20
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,26 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
440440
ctx.Repo.Owner = owner
441441
ctx.Data["Username"] = ctx.Repo.Owner.Name
442442

443+
// redirect link to wiki
444+
if strings.HasSuffix(repoName, ".wiki") {
445+
// ctx.Req.URL.Path does not have the preceding appSubURL - any redirect must have this added
446+
// Now we happen to know that all of our paths are: /:username/:reponame/whatever_else
447+
originalRepoName := ctx.Params(":reponame")
448+
redirectRepoName := strings.TrimSuffix(repoName, ".wiki")
449+
redirectRepoName += originalRepoName[len(redirectRepoName)+5:]
450+
redirectPath := strings.Replace(
451+
ctx.Req.URL.EscapedPath(),
452+
url.PathEscape(userName)+"/"+url.PathEscape(originalRepoName),
453+
url.PathEscape(userName)+"/"+url.PathEscape(redirectRepoName)+"/wiki",
454+
1,
455+
)
456+
if ctx.Req.URL.RawQuery != "" {
457+
redirectPath += "?" + ctx.Req.URL.RawQuery
458+
}
459+
ctx.Redirect(path.Join(setting.AppSubURL, redirectPath))
460+
return
461+
}
462+
443463
// Get repository.
444464
repo, err := repo_model.GetRepositoryByName(owner.ID, repoName)
445465
if err != nil {

0 commit comments

Comments
 (0)