Repository: go-gitea/gitea
File: routers/web/repo/wiki.go (Go)

Code before:
		}
		// update the default branch in the database
		errDb := repo_model.UpdateRepositoryColsNoAutoTime(ctx, &repo_model.Repository{ID: ctx.Repo.Repository.ID, DefaultWikiBranch: gitRepoDefaultBranch}, "default_wiki_branch")
		if errDb != nil {
			return wikiGitRepo, nil, errDb
		}
		ctx.Repo.Repository.DefaultWikiBranch = gitRepoDefaultBranch
		// retry to get the commit from the correct default branch
		commit, errCommit = wikiGitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultWikiBranch)
	}
	if errCommit != nil {
		return wikiGitRepo, nil, errCommit
	}
	return wikiGitRepo, commit, nil
}

// wikiContentsByEntry returns the contents of the wiki page referenced by the
// given tree entry. Writes to ctx if an error occurs.
func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte {
	reader, err := entry.Blob().DataAsync()
	if err != nil {
		ctx.ServerError("Blob.Data", err)
		return nil
	}
	defer reader.Close()
	content, err := io.ReadAll(reader)
	if err != nil {
		ctx.ServerError("ReadAll", err)
		return nil
	}
	return content
}

// wikiEntryByName returns the entry of a wiki page, along with a boolean
// indicating whether the entry exists. Writes to ctx if an error occurs.
// The last return value indicates whether the file should be returned as a raw file
func wikiEntryByName(ctx *context.Context, commit *git.Commit, wikiName wiki_service.WebPath) (*git.TreeEntry, string, bool, bool) {
	isRaw := false
	gitFilename := wiki_service.WebPathToGitPath(wikiName)
	entry, err := findEntryForFile(commit, gitFilename)
	if err != nil && !git.IsErrNotExist(err) {
		ctx.ServerError("findEntryForFile", err)
		return nil, "", false, false
	}
	if entry == nil {
		// check if the file without ".md" suffix exists
		gitFilename := strings.TrimSuffix(gitFilename, ".md")
		entry, err = findEntryForFile(commit, gitFilename)
		if err != nil && !git.IsErrNotExist(err) {
			ctx.ServerError("findEntryForFile", err)
			return nil, "", false, false

Review comment (suggestion):
Actually, I can imagine one case where a wiki page needs more:
`<img src="data:image/png;base64,…">`

Code after:
		}
		// update the default branch in the database
		errDb := repo_model.UpdateRepositoryColsNoAutoTime(ctx, &repo_model.Repository{ID: ctx.Repo.Repository.ID, DefaultWikiBranch: gitRepoDefaultBranch}, "default_wiki_branch")
		if errDb != nil {
			return wikiGitRepo, nil, errDb
		}
		ctx.Repo.Repository.DefaultWikiBranch = gitRepoDefaultBranch
		// retry to get the commit from the correct default branch
		commit, errCommit = wikiGitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultWikiBranch)
	}
	if errCommit != nil {
		return wikiGitRepo, nil, errCommit
	}
	return wikiGitRepo, commit, nil
}

// wikiContentsByEntry returns the contents of the wiki page referenced by the
// given tree entry. Writes to ctx if an error occurs.
func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte {
	reader, err := entry.Blob().DataAsync()
	if err != nil {
		ctx.ServerError("Blob.Data", err)
		return nil
	}
	defer reader.Close()
	content, err := util.ReadWithLimit(reader, 5*1024*1024) // 5MB should be enough for a wiki page
	if err != nil {
		ctx.ServerError("ReadAll", err)
		return nil
	}
	return content
}

// wikiEntryByName returns the entry of a wiki page, along with a boolean
// indicating whether the entry exists. Writes to ctx if an error occurs.
// The last return value indicates whether the file should be returned as a raw file
func wikiEntryByName(ctx *context.Context, commit *git.Commit, wikiName wiki_service.WebPath) (*git.TreeEntry, string, bool, bool) {
	isRaw := false
	gitFilename := wiki_service.WebPathToGitPath(wikiName)
	entry, err := findEntryForFile(commit, gitFilename)
	if err != nil && !git.IsErrNotExist(err) {
		ctx.ServerError("findEntryForFile", err)
		return nil, "", false, false
	}
	if entry == nil {
		// check if the file without ".md" suffix exists
		gitFilename := strings.TrimSuffix(gitFilename, ".md")
		entry, err = findEntryForFile(commit, gitFilename)
		if err != nil && !git.IsErrNotExist(err) {
			ctx.ServerError("findEntryForFile", err)
			return nil, "", false, false