diff options
author | zeripath <art27@cantab.net> | 2022-02-06 04:22:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-06 04:22:20 +0000 |
commit | f65e29c077f3df3822d7b7f874ba719fc08d267e (patch) | |
tree | 1f7788128579153eff6661c0ef439f259bb1dd29 /routers | |
parent | a97c8a89660d39b4f8b73649e1bd7da3c153ae99 (diff) | |
download | gitea-f65e29c077f3df3822d7b7f874ba719fc08d267e.tar.gz gitea-f65e29c077f3df3822d7b7f874ba719fc08d267e.zip |
Ensure that blob-excerpt links work for wiki (#18587) (#18624)
Backport #18587
It appears that the blob-excerpt links do not work on the wiki - likely since their
introduction.
This PR adds support for the wiki on these links.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/compare.go | 9 | ||||
-rw-r--r-- | routers/web/web.go | 21 |
2 files changed, 29 insertions, 1 deletions
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 3b07c35cb0..7ddeee8ab5 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -786,6 +786,15 @@ func ExcerptBlob(ctx *context.Context) { direction := ctx.FormString("direction") filePath := ctx.FormString("path") gitRepo := ctx.Repo.GitRepo + if ctx.FormBool("wiki") { + var err error + gitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath()) + if err != nil { + ctx.ServerError("OpenRepository", err) + return + } + defer gitRepo.Close() + } chunkSize := gitdiff.BlobExcerptChunkSize commit, err := gitRepo.GetCommit(commitID) if err != nil { diff --git a/routers/web/web.go b/routers/web/web.go index 55a64ee7d5..1eea2794b0 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -5,6 +5,7 @@ package web import ( + gocontext "context" "net/http" "os" "path" @@ -952,7 +953,25 @@ func RegisterRoutes(m *web.Route) { m.Group("/blob_excerpt", func() { m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob) - }, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader) + }, func(ctx *context.Context) (cancel gocontext.CancelFunc) { + if ctx.FormBool("wiki") { + ctx.Data["PageIsWiki"] = true + repo.MustEnableWiki(ctx) + return + } + + reqRepoCodeReader(ctx) + if ctx.Written() { + return + } + cancel = context.RepoRef()(ctx) + if ctx.Written() { + return + } + + repo.MustBeNotEmpty(ctx) + return + }) m.Group("/pulls/{index}", func() { m.Get(".diff", repo.DownloadPullDiff) |