summaryrefslogtreecommitdiffstats
path: root/modules/context/repo.go
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2022-03-23 21:29:18 +0800
committerGitHub <noreply@github.com>2022-03-23 13:29:18 +0000
commitd8f578412ebbf5b05de254a717f71cf5d3f5dab1 (patch)
tree2f3922047265072fa239a61c165b45119c296f8a /modules/context/repo.go
parent5248232c44f3819fbb8a6cdac258740afbb94823 (diff)
downloadgitea-d8f578412ebbf5b05de254a717f71cf5d3f5dab1.tar.gz
gitea-d8f578412ebbf5b05de254a717f71cf5d3f5dab1.zip
Redirect .wiki/* ui link to /wiki (#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>
Diffstat (limited to 'modules/context/repo.go')
-rw-r--r--modules/context/repo.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 87be2af135..b345decf7e 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -441,6 +441,26 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
ctx.Repo.Owner = owner
ctx.Data["Username"] = ctx.Repo.Owner.Name
+ // redirect link to wiki
+ if strings.HasSuffix(repoName, ".wiki") {
+ // ctx.Req.URL.Path does not have the preceding appSubURL - any redirect must have this added
+ // Now we happen to know that all of our paths are: /:username/:reponame/whatever_else
+ originalRepoName := ctx.Params(":reponame")
+ redirectRepoName := strings.TrimSuffix(repoName, ".wiki")
+ redirectRepoName += originalRepoName[len(redirectRepoName)+5:]
+ redirectPath := strings.Replace(
+ ctx.Req.URL.EscapedPath(),
+ url.PathEscape(userName)+"/"+url.PathEscape(originalRepoName),
+ url.PathEscape(userName)+"/"+url.PathEscape(redirectRepoName)+"/wiki",
+ 1,
+ )
+ if ctx.Req.URL.RawQuery != "" {
+ redirectPath += "?" + ctx.Req.URL.RawQuery
+ }
+ ctx.Redirect(path.Join(setting.AppSubURL, redirectPath))
+ return
+ }
+
// Get repository.
repo, err := repo_model.GetRepositoryByName(owner.ID, repoName)
if err != nil {